@@ -310,33 +310,32 @@ jobs:
310310 - uses : actions/checkout@v4
311311
312312 - name : Compile for ${{ matrix.arch }}
313- shell : cmd
313+ shell : pwsh
314314 run : |
315- @echo off
316- REM Find vcvarsall.bat dynamically
317- for /f "usebackq tokens=*" %%i in (`"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
318- set "VS_PATH=%%i"
319- )
320-
321- if not exist "%VS_PATH%\VC\Auxiliary\Build\vcvarsall.bat" (
322- echo Error: vcvarsall.bat not found.
323- exit /b 1
324- )
325-
326- REM Map architecture for cross-compilation (host_target)
327- REM GitHub Actions windows-latest runners are x64, so we need x64_<target> for cross-compilation
328- set "TARGET_ARCH=${{ matrix.arch }}"
329- set "VCVARS_ARCH=%TARGET_ARCH%"
330- if "%TARGET_ARCH%"=="x86" set "VCVARS_ARCH=x64_x86"
331- if "%TARGET_ARCH%"=="arm64" set "VCVARS_ARCH=x64_arm64"
332-
333- REM Initialize environment for the target architecture
334- call "%VS_PATH%\VC\Auxiliary\Build\vcvarsall.bat" %VCVARS_ARCH%
335-
336- set outName=win-witr-${{ matrix.arch }}.exe
337- echo Compiling %outName%...
338- cl /O2 /Ot /GL /std:c++20 /EHsc main.cpp /DUNICODE /D_UNICODE /Fe:%outName%
339- if errorlevel 1 exit /b 1
315+ # Set version as environment variable
316+ $env:VERSION_NUMBER = "${{ needs.prepare.outputs.version }}"
317+
318+ # Find and initialize MSVC
319+ $vsPath = & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" `
320+ -latest -products * `
321+ -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
322+ -property installationPath
323+
324+ $vcvarsPath = Join-Path $vsPath "VC\Auxiliary\Build\vcvarsall.bat"
325+
326+ $targetArch = "${{ matrix.arch }}"
327+ $vcvarsArch = $targetArch
328+ if ($targetArch -eq "x86") { $vcvarsArch = "x64_x86" }
329+ if ($targetArch -eq "arm64") { $vcvarsArch = "x64_arm64" }
330+
331+ # Use cmd to call vcvarsall and then cl
332+ $outName = "win-witr-${{ matrix.arch }}.exe"
333+ $ver = "${{ needs.prepare.outputs.version_number }}"
334+ cmd /c "`"$vcvarsPath`" $vcvarsArch && cl /O2 /Ot /GL /std:c++20 /EHsc main.cpp /DUNICODE /D_UNICODE /DVERSION_NUMBER=\"$ver\" /Fe:$outName"
335+ if ($LASTEXITCODE -ne 0) {
336+ Write-Host "Build failed with exit code $LASTEXITCODE"
337+ Exit $LASTEXITCODE
338+ }
340339
341340 - name : Upload build artifact for ${{ matrix.arch }}
342341 uses : actions/upload-artifact@v4
0 commit comments