From 1e36865bb3c03e04c88c559c546187387f5c9f39 Mon Sep 17 00:00:00 2001 From: deepend-tildeclub <58404188+deepend-tildeclub@users.noreply.github.com> Date: Sun, 1 Feb 2026 18:05:38 -0700 Subject: [PATCH] Refactor Windows build workflow for better dependency handling Updated the Windows build workflow to improve dependency installation and streamline the build process. --- .github/workflows/windows-build.yml | 303 ++++++---------------------- 1 file changed, 61 insertions(+), 242 deletions(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 824bf382..dafb0ab7 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -34,209 +34,90 @@ jobs: - uses: actions/setup-python@v5 with: - python-version: "3.14.2" + python-version: '3.14.2' architecture: ${{ matrix.arch }} - - name: Install Dependencies (GTK3 toolchain + packagers) + - name: Install Dependencies env: - GITHUB_TOKEN: ${{ github.token }} + GH_TOKEN: ${{ github.token }} run: | New-Item -Name "deps" -ItemType "Directory" -Force | Out-Null + New-Item -Path "C:\gtk-build" -ItemType "Directory" -Force | Out-Null - # Inno Setup + IDP (kept as-is) Invoke-WebRequest http://files.jrsoftware.org/is/5/innosetup-5.5.9-unicode.exe -OutFile deps\innosetup-unicode.exe & deps\innosetup-unicode.exe /VERYSILENT | Out-Null - Invoke-WebRequest https://github.com/zoitechat/gvsbuild/releases/download/zoitechat-2.17.0/idpsetup-1.5.1.exe -OutFile deps\idpsetup.exe + Invoke-WebRequest https://github.com/ZoiteChat/gvsbuild/releases/download/zoitechat-2.17.0/idpsetup-1.5.1.exe -OutFile deps\idpsetup.exe & deps\idpsetup.exe /VERYSILENT - # WinSparkle / gendef / perl (kept as-is) - Invoke-WebRequest https://github.com/zoitechat/gvsbuild/releases/download/zoitechat-2.17.0/gendef-20111031.7z -OutFile deps\gendef.7z - & 7z.exe x deps\gendef.7z -oC:\gtk-build | Out-Null + # --- GTK stack from wingtk/gvsbuild (NO MSYS build here; use their prebuilt release) --- + $repo = "wingtk/gvsbuild" + $tag = (gh release view --repo $repo --json tagName -q .tagName) + Write-Host "Using $repo release: $tag" - Invoke-WebRequest https://github.com/zoitechat/gvsbuild/releases/download/zoitechat-2.17.0/WinSparkle-20151011.7z -OutFile deps\WinSparkle.7z - & 7z.exe x deps\WinSparkle.7z -oC:\gtk-build\WinSparkle | Out-Null - - Invoke-WebRequest https://github.com/zoitechat/gvsbuild/releases/download/zoitechat-2.17.0/perl-5.20.0-${{ matrix.arch }}.7z -OutFile deps\perl-${{ matrix.arch }}.7z - & 7z.exe x deps\perl-${{ matrix.arch }}.7z -oC:\gtk-build\perl-5.20\${{ matrix.platform }} | Out-Null - - # ----------------------------- - # GTK3 stack (MSVC) from wingtk/gvsbuild (robust layout detection) - # ----------------------------- - $wantArch = if ("${{ matrix.platform }}" -eq "x64") { "x64" } else { "x86" } - - $headers = @{ - "User-Agent" = "zoitechat-ci" - "Authorization" = "Bearer $env:GITHUB_TOKEN" - "X-GitHub-Api-Version" = "2022-11-28" + $patterns = @() + if ("${{ matrix.platform }}" -eq "x64") { + $patterns = @("*x64*.zip", "*win64*.zip", "*x64*.7z", "*win64*.7z", "*gtk*.zip", "*gtk*.7z") + } else { + $patterns = @("*x86*.zip", "*win32*.zip", "*x86*.7z", "*win32*.7z", "*gtk*.zip", "*gtk*.7z") } - $releases = Invoke-RestMethod -Headers $headers -Uri "https://api.github.com/repos/wingtk/gvsbuild/releases?per_page=20" + $downloaded = $false + foreach ($p in $patterns) { + gh release download $tag --repo $repo --pattern $p --dir deps + if ($LASTEXITCODE -eq 0) { $downloaded = $true; break } + } + if (-not $downloaded) { + throw "Could not download a wingtk/gvsbuild GTK asset for platform=${{ matrix.platform }} arch=${{ matrix.arch }}" + } - $asset = $null - foreach ($rel in $releases) { - $asset = $rel.assets | - Where-Object { - $_.name -match "(?i)^GTK3_.*_${wantArch}\.zip$" -or - ($_.name -match "(?i)gtk3" -and $_.name -match "(?i)\b${wantArch}\b" -and $_.name -match "(?i)\.zip$") - } | + $gtkPkg = Get-ChildItem deps -File | Where-Object { $_.Name -match '(?i)\.(zip|7z)$' } | Sort-Object Length -Descending | Select-Object -First 1 + if (-not $gtkPkg) { throw "GTK package download succeeded but no archive found in deps/." } + Write-Host "Downloaded GTK package: $($gtkPkg.Name)" + + $tmp = Join-Path $env:TEMP "wingtk-gtk-extract" + Remove-Item $tmp -Recurse -Force -ErrorAction SilentlyContinue + New-Item -Path $tmp -ItemType Directory -Force | Out-Null + + if ($gtkPkg.Extension -ieq ".zip") { + Expand-Archive -Path $gtkPkg.FullName -DestinationPath $tmp -Force + } else { + & 7z.exe x $gtkPkg.FullName "-o$tmp" | Out-Null + } + + # Find the extracted root (either directly contains bin/include/lib, or has a single child dir that does) + $root = $null + if (Test-Path (Join-Path $tmp "bin")) { + $root = Get-Item $tmp + } else { + $root = Get-ChildItem $tmp -Directory | + Where-Object { Test-Path (Join-Path $_.FullName "bin") } | Select-Object -First 1 - if ($asset) { break } } + if (-not $root) { + $root = Get-ChildItem $tmp -Directory | Select-Object -First 1 + } + if (-not $root) { throw "Failed to determine GTK extract root under $tmp" } - $usingLegacyGtk2 = $false + $target = "C:\gtk-build\gtk\${{ matrix.platform }}\Release" + New-Item -Path $target -ItemType Directory -Force | Out-Null - if (-not $asset) { - if ($wantArch -eq "x86") { - # Fallback: keep 32-bit build working if GTK3 x86 isn't published. - $usingLegacyGtk2 = $true - Write-Host "No GTK3 x86 bundle found in recent wingtk/gvsbuild releases. Falling back to legacy GTK2 bundle for win32 to keep builds working." - Invoke-WebRequest https://github.com/zoitechat/gvsbuild/releases/download/zoitechat-2.17.0/gtk-${{ matrix.platform }}-2018-08-29-openssl1.1.7z -OutFile deps\gtk-legacy-${{ matrix.platform }}.7z - if (Test-Path C:\gtk-build\gtk) { Remove-Item C:\gtk-build\gtk -Recurse -Force } - & 7z.exe x deps\gtk-legacy-${{ matrix.platform }}.7z -oC:\gtk-build\gtk | Out-Null - } else { - Write-Host "Available assets in recent releases:" - foreach ($rel in $releases) { - Write-Host ("Release: " + $rel.tag_name) - $rel.assets | ForEach-Object { Write-Host (" - " + $_.name) } - } - throw "Could not find a GTK3 $wantArch bundle in wingtk/gvsbuild recent releases." + foreach ($d in @("bin","include","lib","share","etc")) { + $src = Join-Path $root.FullName $d + if (Test-Path $src) { + Copy-Item $src $target -Recurse -Force } } - if (-not $usingLegacyGtk2) { - $bundlePath = "deps\GTK3_Gvsbuild_${wantArch}.zip" - Invoke-WebRequest $asset.browser_download_url -OutFile $bundlePath + # --- remaining deps still from ZoiteChat/gvsbuild (as requested) --- + Invoke-WebRequest https://github.com/ZoiteChat/gvsbuild/releases/download/zoitechat-2.17.0/gendef-20111031.7z -OutFile deps\gendef.7z + & 7z.exe x deps\gendef.7z -oC:\gtk-build - $extractRoot = "C:\gtk3-bundle" - if (Test-Path $extractRoot) { Remove-Item $extractRoot -Recurse -Force } - New-Item -Path $extractRoot -ItemType Directory -Force | Out-Null - Expand-Archive -Force $bundlePath -DestinationPath $extractRoot + Invoke-WebRequest https://github.com/ZoiteChat/gvsbuild/releases/download/zoitechat-2.17.0/WinSparkle-20151011.7z -OutFile deps\WinSparkle.7z + & 7z.exe x deps\WinSparkle.7z -oC:\gtk-build\WinSparkle - # Infer the "release" root from a guaranteed artifact: gtk-3.0.lib or libgtk-3-0.dll - $gtk3lib = Get-ChildItem -Path $extractRoot -Recurse -Filter "gtk-3.0.lib" -ErrorAction SilentlyContinue | Select-Object -First 1 - $gtk3dll = $null - if (-not $gtk3lib) { - $gtk3dll = Get-ChildItem -Path $extractRoot -Recurse -Include "libgtk-3-0.dll","gtk-3*.dll" -ErrorAction SilentlyContinue | Select-Object -First 1 - } - - if ($gtk3lib) { - $gtkLibDir = Split-Path $gtk3lib.FullName -Parent - $releaseDir = Split-Path $gtkLibDir -Parent - } elseif ($gtk3dll) { - $gtkBinDir = Split-Path $gtk3dll.FullName -Parent - $releaseDir = Split-Path $gtkBinDir -Parent - } else { - throw "GTK3 bundle extracted, but neither gtk-3.0.lib nor libgtk-3-0.dll was found. Layout unexpected." - } - - $gtkBin = Join-Path $releaseDir "bin" - if (-not (Test-Path $gtkBin)) { - throw "GTK3 release root inferred, but bin/ was not found at: $gtkBin" - } - - # Normalize expected path: - # C:\gtk-build\gtk\\release -> - $platDir = "C:\gtk-build\gtk\${{ matrix.platform }}" - New-Item -Path $platDir -ItemType Directory -Force | Out-Null - $link = Join-Path $platDir "release" - if (Test-Path $link) { Remove-Item $link -Recurse -Force -ErrorAction SilentlyContinue } - New-Item -Path $platDir -Name "release" -ItemType Junction -Value $releaseDir | Out-Null - - $gtkLib = Join-Path "C:\gtk-build\gtk\${{ matrix.platform }}\release\lib" "" - - # ----------------------------- - # Compatibility aliases while vcxproj still names GTK2/OpenSSL libs. - # ----------------------------- - if (Test-Path $gtkLib) { - $gtk3 = Get-ChildItem -Path $gtkLib -Filter "gtk-3*.lib" -ErrorAction SilentlyContinue | Select-Object -First 1 - if ($gtk3 -and (-not (Test-Path (Join-Path $gtkLib "gtk-win32-2.0.lib")))) { - Copy-Item $gtk3.FullName (Join-Path $gtkLib "gtk-win32-2.0.lib") -Force - } - - $gdk3 = Get-ChildItem -Path $gtkLib -Filter "gdk-3*.lib" -ErrorAction SilentlyContinue | Select-Object -First 1 - if ($gdk3 -and (-not (Test-Path (Join-Path $gtkLib "gdk-win32-2.0.lib")))) { - Copy-Item $gdk3.FullName (Join-Path $gtkLib "gdk-win32-2.0.lib") -Force - } - - # libxml2 alias: libxml2.lib <- libxml2-2.0.lib / xml2.lib - $xmlWant = Join-Path $gtkLib "libxml2.lib" - if (-not (Test-Path $xmlWant)) { - $xmlAlt = @( - (Join-Path $gtkLib "libxml2-2.0.lib"), - (Join-Path $gtkLib "libxml2-2.lib"), - (Join-Path $gtkLib "xml2.lib") - ) | Where-Object { Test-Path $_ } | Select-Object -First 1 - if ($xmlAlt) { Copy-Item $xmlAlt $xmlWant -Force } - } - - # OpenSSL legacy aliases: ssleay32/libeay32 for older vcxproj link lines - $sslWant = Join-Path $gtkLib "ssleay32.lib" - $cryptoWant = Join-Path $gtkLib "libeay32.lib" - - if (-not (Test-Path $sslWant)) { - $sslAlt = @( - (Join-Path $gtkLib "libssl.lib"), - (Join-Path $gtkLib "libssl-3.lib"), - (Join-Path $gtkLib "ssl.lib") - ) | Where-Object { Test-Path $_ } | Select-Object -First 1 - if ($sslAlt) { Copy-Item $sslAlt $sslWant -Force } - } - - if (-not (Test-Path $cryptoWant)) { - $cryptoAlt = @( - (Join-Path $gtkLib "libcrypto.lib"), - (Join-Path $gtkLib "libcrypto-3.lib"), - (Join-Path $gtkLib "crypto.lib") - ) | Where-Object { Test-Path $_ } | Select-Object -First 1 - if ($cryptoAlt) { Copy-Item $cryptoAlt $cryptoWant -Force } - } - } - - # ----------------------------- - # glib-genmarshal wrapper (python-called) that ALWAYS runs a real .exe - # Prefer bundle glib-genmarshal.exe; else install MSYS2 glib2 and use that. - # ----------------------------- - $bundleGenExe = Join-Path $gtkBin "glib-genmarshal.exe" - $msysGenExe = $null - $msysBinDir = $null - - if (-not (Test-Path $bundleGenExe)) { - Write-Host "glib-genmarshal.exe not present in GTK3 bin/. Installing MSYS2 glib2 tools as a fallback." - - choco install msys2 -y --no-progress - - $msysBash = "C:\msys64\usr\bin\bash.exe" - if (-not (Test-Path $msysBash)) { throw "MSYS2 install failed: bash.exe not found." } - - $mingw = if ("${{ matrix.platform }}" -eq "x64") { "mingw64" } else { "mingw32" } - $pkg = if ("${{ matrix.platform }}" -eq "x64") { "mingw-w64-x86_64-glib2" } else { "mingw-w64-i686-glib2" } - - & $msysBash -lc "pacman -Sy --noconfirm --needed $pkg" - - $msysGenExe = "C:\msys64\$mingw\bin\glib-genmarshal.exe" - if (-not (Test-Path $msysGenExe)) { throw "MSYS2 glib-genmarshal.exe not found at expected path: $msysGenExe" } - $msysBinDir = Split-Path $msysGenExe -Parent - } - - $genTarget = Join-Path $gtkBin "glib-genmarshal" # called via python.exe ... - - $exeToRun = if (Test-Path $bundleGenExe) { $bundleGenExe } else { $msysGenExe } - $exeDir = if (Test-Path $bundleGenExe) { (Split-Path $bundleGenExe -Parent) } else { $msysBinDir } - - $exeToRunEsc = $exeToRun.Replace('\','\\') - $exeDirEsc = $exeDir.Replace('\','\\') - - $pyWrapper = @( - 'import os, subprocess, sys', - "exe = r`"$exeToRunEsc`"", - 'env = os.environ.copy()', - "env[`"PATH`"] = r`"$exeDirEsc`" + `";`" + env.get(`"PATH`",`"`")", - 'sys.exit(subprocess.call([exe] + sys.argv[1:], env=env))' - ) -join "`r`n" - - Set-Content -Path $genTarget -Value $pyWrapper -Encoding ASCII - } + Invoke-WebRequest https://github.com/ZoiteChat/gvsbuild/releases/download/zoitechat-2.17.0/perl-5.20.0-${{ matrix.arch }}.7z -OutFile deps\perl-${{ matrix.arch }}.7z + & 7z.exe x deps\perl-${{ matrix.arch }}.7z -oC:\gtk-build\perl-5.20\${{ matrix.platform }} # Resolve python root from setup-python $pyRoot = $env:pythonLocation @@ -255,11 +136,7 @@ jobs: - name: Build run: | - if "${{ matrix.platform }}"=="x64" ( - call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" -host_arch=amd64 -arch=amd64 - ) else ( - call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" -host_arch=amd64 -arch=x86 - ) + call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" set "PYTHON_DIR=C:\gtk-build\python-3.14.2\${{ matrix.platform }}" if not exist "%PYTHON_DIR%\libs\python314.lib" ( @@ -271,64 +148,6 @@ jobs: set "LIB=%PYTHON_DIR%\libs;%LIB%" set "INCLUDE=%PYTHON_DIR%\include;%INCLUDE%" - set "GTKROOT=C:\gtk-build\gtk\${{ matrix.platform }}\release" - if not exist "%GTKROOT%\bin" ( - echo GTKROOT bin not found at %GTKROOT%\bin - dir "C:\gtk-build\gtk\${{ matrix.platform }}" - exit /b 1 - ) - - set "PATH=%GTKROOT%\bin;%PATH%" - set "INCLUDE=%GTKROOT%\include;%INCLUDE%" - if exist "%GTKROOT%\include\libxml2" set "INCLUDE=%GTKROOT%\include\libxml2;%INCLUDE%" - set "LIB=%GTKROOT%\lib;%LIB%" - - rem Ensure OpenSSL legacy libs exist if vcxproj still references them - if not exist "%GTKROOT%\lib\ssleay32.lib" ( - if exist "%GTKROOT%\lib\libssl.lib" copy /y "%GTKROOT%\lib\libssl.lib" "%GTKROOT%\lib\ssleay32.lib" - if exist "%GTKROOT%\lib\libssl-3.lib" copy /y "%GTKROOT%\lib\libssl-3.lib" "%GTKROOT%\lib\ssleay32.lib" - if exist "%GTKROOT%\lib\ssl.lib" copy /y "%GTKROOT%\lib\ssl.lib" "%GTKROOT%\lib\ssleay32.lib" - ) - if not exist "%GTKROOT%\lib\libeay32.lib" ( - if exist "%GTKROOT%\lib\libcrypto.lib" copy /y "%GTKROOT%\lib\libcrypto.lib" "%GTKROOT%\lib\libeay32.lib" - if exist "%GTKROOT%\lib\libcrypto-3.lib" copy /y "%GTKROOT%\lib\libcrypto-3.lib" "%GTKROOT%\lib\libeay32.lib" - if exist "%GTKROOT%\lib\crypto.lib" copy /y "%GTKROOT%\lib\crypto.lib" "%GTKROOT%\lib\libeay32.lib" - ) - - rem Build LuaJIT (MSVC) if lua.h isn't present in the GTK bundle. - if not exist "%GTKROOT%\include\luajit-2.1\lua.h" ( - set "LUABASE=C:\gtk-build\luajit\${{ matrix.platform }}" - if not exist "%LUABASE%\include\lua.h" ( - rmdir /s /q C:\gtk-build\luajit-src 2>nul - git clone --depth 1 --branch v2.1 https://github.com/LuaJIT/LuaJIT.git C:\gtk-build\luajit-src - pushd C:\gtk-build\luajit-src\src - call msvcbuild.bat - popd - - mkdir "%LUABASE%\include" 2>nul - copy /y C:\gtk-build\luajit-src\src\lua.h "%LUABASE%\include\" - copy /y C:\gtk-build\luajit-src\src\lauxlib.h "%LUABASE%\include\" - copy /y C:\gtk-build\luajit-src\src\luaconf.h "%LUABASE%\include\" - copy /y C:\gtk-build\luajit-src\src\luajit.h "%LUABASE%\include\" 2>nul - - mkdir "%LUABASE%\lib" 2>nul - copy /y C:\gtk-build\luajit-src\src\lua51.lib "%LUABASE%\lib\" - ) - - rem Make vcxproj happy no matter how its include dirs are configured: - rem also place headers under GTK-style include\luajit-2.1 - mkdir "%GTKROOT%\include\luajit-2.1" 2>nul - copy /y "%LUABASE%\include\lua.h" "%GTKROOT%\include\luajit-2.1\" - copy /y "%LUABASE%\include\lauxlib.h" "%GTKROOT%\include\luajit-2.1\" - copy /y "%LUABASE%\include\luaconf.h" "%GTKROOT%\include\luajit-2.1\" - if exist "%LUABASE%\include\luajit.h" copy /y "%LUABASE%\include\luajit.h" "%GTKROOT%\include\luajit-2.1\" - - set "INCLUDE=%GTKROOT%\include\luajit-2.1;%LUABASE%\include;%INCLUDE%" - set "LIB=%LUABASE%\lib;%LIB%" - ) else ( - set "INCLUDE=%GTKROOT%\include\luajit-2.1;%INCLUDE%" - ) - msbuild win32\zoitechat.sln /m /verbosity:minimal /p:Configuration=Release /p:Platform=${{ matrix.platform }} shell: cmd