ci: build Windows release with MSVC Qt
Some checks failed
Build Windows Release / Build Windows x64 Release (MSVC + Qt) (push) Failing after -2s
Some checks failed
Build Windows Release / Build Windows x64 Release (MSVC + Qt) (push) Failing after -2s
This commit is contained in:
@@ -13,17 +13,17 @@ permissions:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-windows-release:
|
build-windows-release:
|
||||||
name: Build Windows x64 Release
|
name: Build Windows x64 Release (MSVC + Qt)
|
||||||
# Windows runner 已注册标签:windows-latest、windows-2022、self-hosted;均为 host 模式。
|
# Windows runner 已注册标签:windows-latest、windows-2022、self-hosted;均为 host 模式。
|
||||||
runs-on: windows-2022
|
runs-on: windows-2022
|
||||||
|
|
||||||
env:
|
env:
|
||||||
BUILD_TYPE: Release
|
BUILD_TYPE: Release
|
||||||
MSYS2_ROOT: C:\msys64
|
QT_VERSION: 6.7.3
|
||||||
MSYSTEM: UCRT64
|
QT_ARCH: win64_msvc2022_64
|
||||||
CHERE_INVOKING: 1
|
QT_DIR_NAME: msvc2022_64
|
||||||
PACKAGE_BASENAME: chengnan-windows-x64
|
PACKAGE_BASENAME: chengnan-windows-x64-msvc
|
||||||
PACKAGE_NAME: chengnan-windows-x64
|
PACKAGE_NAME: chengnan-windows-x64-msvc
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Prepare source
|
- name: Prepare source
|
||||||
@@ -49,49 +49,77 @@ jobs:
|
|||||||
Copy-Item -Path $src.FullName -Destination $srcFixed -Recurse -Force
|
Copy-Item -Path $src.FullName -Destination $srcFixed -Recurse -Force
|
||||||
Write-Host "Source dir: $srcFixed"
|
Write-Host "Source dir: $srcFixed"
|
||||||
|
|
||||||
- name: Install MSYS2 and build dependencies
|
- name: Install official Qt for MSVC
|
||||||
shell: powershell
|
shell: powershell
|
||||||
run: |
|
run: |
|
||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
$msysRoot = $env:MSYS2_ROOT
|
$qtRoot = Join-Path $env:RUNNER_TEMP 'qt-msvc'
|
||||||
if (-not (Test-Path "$msysRoot\usr\bin\bash.exe")) {
|
$qtPrefix = Join-Path $qtRoot "$env:QT_VERSION\$env:QT_DIR_NAME"
|
||||||
$installer = Join-Path $env:RUNNER_TEMP 'msys2-installer.exe'
|
$windeployqt = Join-Path $qtPrefix 'bin\windeployqt.exe'
|
||||||
$installerUrl = 'https://github.com/msys2/msys2-installer/releases/latest/download/msys2-x86_64-latest.exe'
|
if (Test-Path $windeployqt) {
|
||||||
Write-Host "Downloading MSYS2 installer from $installerUrl"
|
Write-Host "Qt already installed: $qtPrefix"
|
||||||
Invoke-WebRequest -Uri $installerUrl -OutFile $installer
|
exit 0
|
||||||
& $installer in --confirm-command --accept-messages --root $msysRoot
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$bash = "$msysRoot\usr\bin\bash.exe"
|
$pyLauncher = Get-Command py -ErrorAction SilentlyContinue
|
||||||
& $bash -lc "pacman --noconfirm -Syuu"
|
if ($pyLauncher) {
|
||||||
if ($LASTEXITCODE -ne 0) { Write-Host 'First pacman system update returned non-zero; continuing with second update.' }
|
$pythonExe = $pyLauncher.Source
|
||||||
& $bash -lc "pacman --noconfirm -Syuu"
|
$pythonArgs = @('-3')
|
||||||
if ($LASTEXITCODE -ne 0) { throw "pacman system update failed, exit code: $LASTEXITCODE" }
|
} else {
|
||||||
& $bash -lc "pacman --noconfirm -S --needed git zip unzip p7zip mingw-w64-ucrt-x86_64-toolchain mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-ninja mingw-w64-ucrt-x86_64-qt6-base mingw-w64-ucrt-x86_64-qt6-imageformats"
|
$python = Get-Command python -ErrorAction SilentlyContinue
|
||||||
if ($LASTEXITCODE -ne 0) { throw "pacman dependency installation failed, exit code: $LASTEXITCODE" }
|
if (-not $python) { throw 'Python is required to install Qt with aqtinstall, but py/python was not found on PATH.' }
|
||||||
|
$pythonExe = $python.Source
|
||||||
|
$pythonArgs = @()
|
||||||
|
}
|
||||||
|
|
||||||
- name: Configure and build
|
& $pythonExe @pythonArgs -m pip install --user --upgrade aqtinstall
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw "pip install aqtinstall failed, exit code: $LASTEXITCODE" }
|
||||||
|
|
||||||
|
& $pythonExe @pythonArgs -m aqt install-qt windows desktop $env:QT_VERSION $env:QT_ARCH -O $qtRoot -m qtimageformats
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw "aqt Qt installation failed, exit code: $LASTEXITCODE" }
|
||||||
|
if (-not (Test-Path $windeployqt)) { throw "Qt installation finished but windeployqt was not found: $windeployqt" }
|
||||||
|
Write-Host "Qt installed: $qtPrefix"
|
||||||
|
|
||||||
|
- name: Configure, build, and deploy with MSVC
|
||||||
shell: powershell
|
shell: powershell
|
||||||
run: |
|
run: |
|
||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
$bash = "$env:MSYS2_ROOT\usr\bin\bash.exe"
|
$src = Join-Path $env:RUNNER_TEMP 'chengnan-work'
|
||||||
$srcWin = Join-Path $env:RUNNER_TEMP 'chengnan-work'
|
$qtRoot = Join-Path $env:RUNNER_TEMP 'qt-msvc'
|
||||||
$src = $srcWin -replace '\\','/'
|
$qtPrefix = Join-Path $qtRoot "$env:QT_VERSION\$env:QT_DIR_NAME"
|
||||||
$src = $src -replace '^([A-Za-z]):','/$1'
|
|
||||||
$src = $src.ToLower()
|
$vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
|
||||||
$script = @"
|
if (-not (Test-Path $vswhere)) { throw "vswhere not found: $vswhere. Install Visual Studio 2022 Build Tools with Desktop development with C++." }
|
||||||
set -euo pipefail
|
$vsPath = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
|
||||||
cd '$src'
|
if ([string]::IsNullOrWhiteSpace($vsPath)) { throw 'Visual Studio 2022 C++ build tools were not found. Install Desktop development with C++.' }
|
||||||
export PATH=/ucrt64/bin:/usr/bin:`$PATH
|
$vsDevCmd = Join-Path $vsPath 'Common7\Tools\VsDevCmd.bat'
|
||||||
cmake -S . -B build-windows -G Ninja -DCMAKE_BUILD_TYPE=Release
|
if (-not (Test-Path $vsDevCmd)) { throw "VsDevCmd.bat not found: $vsDevCmd" }
|
||||||
cmake --build build-windows --parallel `$(nproc)
|
|
||||||
rm -rf dist-windows
|
$vsCmake = Join-Path $vsPath 'Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin'
|
||||||
mkdir -p dist-windows/chengnan
|
if (Test-Path (Join-Path $vsCmake 'cmake.exe')) { $env:PATH = "$vsCmake;$env:PATH" }
|
||||||
cp build-windows/chengnan.exe dist-windows/chengnan/
|
if (-not (Get-Command cmake -ErrorAction SilentlyContinue)) { throw 'cmake was not found on PATH or in Visual Studio bundled CMake.' }
|
||||||
/ucrt64/bin/windeployqt6.exe --release --no-translations dist-windows/chengnan/chengnan.exe || /ucrt64/bin/windeployqt.exe --release --no-translations dist-windows/chengnan/chengnan.exe
|
|
||||||
printf '%s\n' 'chengnan Windows x64 package' '' 'Usage:' '1. Extract the whole directory.' '2. Double-click chengnan.exe to run.' '' 'Note:' '- This package is built by Windows Runner with MSYS2 UCRT64 + Qt.' '- Do not copy chengnan.exe alone; keep DLLs and Qt plugin directories together.' > dist-windows/chengnan/README.txt
|
$buildDir = Join-Path $src 'build-windows'
|
||||||
"@
|
$distDir = Join-Path $src 'dist-windows\chengnan'
|
||||||
& $bash -lc $script
|
$script = Join-Path $src 'build-windows.ps1'
|
||||||
|
$cmd = "`"$vsDevCmd`" -arch=x64 -host_arch=x64 && powershell -NoProfile -ExecutionPolicy Bypass -File `"$script`" -QtPrefix `"$qtPrefix`" -BuildDir `"$buildDir`" -DistDir `"$distDir`" -Generator `"Visual Studio 17 2022`" -Arch x64 -Config Release"
|
||||||
|
Write-Host "Building with Visual Studio at: $vsPath"
|
||||||
|
Write-Host "Using Qt: $qtPrefix"
|
||||||
|
& cmd.exe /c $cmd
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw "MSVC build failed, exit code: $LASTEXITCODE" }
|
||||||
|
|
||||||
|
$readme = Join-Path $distDir 'README.txt'
|
||||||
|
@(
|
||||||
|
'chengnan Windows x64 package',
|
||||||
|
'',
|
||||||
|
'Usage:',
|
||||||
|
'1. Extract the whole directory.',
|
||||||
|
'2. Double-click chengnan.exe to run.',
|
||||||
|
'',
|
||||||
|
'Note:',
|
||||||
|
'- This package is built by Windows Runner with MSVC + official Qt.',
|
||||||
|
'- Do not copy chengnan.exe alone; keep DLLs and Qt plugin directories together.'
|
||||||
|
) | Out-File -FilePath $readme -Encoding ascii
|
||||||
|
|
||||||
- name: Package
|
- name: Package
|
||||||
shell: powershell
|
shell: powershell
|
||||||
@@ -157,7 +185,7 @@ jobs:
|
|||||||
tag_name = $tagName
|
tag_name = $tagName
|
||||||
target_commitish = $env:GITHUB_SHA
|
target_commitish = $env:GITHUB_SHA
|
||||||
name = $releaseName
|
name = $releaseName
|
||||||
body = "Automated Windows x64 build from Gitea Actions.`n"
|
body = "Automated Windows x64 MSVC build from Gitea Actions.`n"
|
||||||
draft = $false
|
draft = $false
|
||||||
prerelease = $isPrerelease
|
prerelease = $isPrerelease
|
||||||
} | ConvertTo-Json -Depth 5
|
} | ConvertTo-Json -Depth 5
|
||||||
|
|||||||
Reference in New Issue
Block a user