From 66012e36f23d7456d973df0e984d431bfb4711e4 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Mon, 5 Oct 2026 08:34:04 +0200 Subject: [PATCH] windows: try to use custom action --- .github/actions/ninja_msvc/action.yml | 58 +++++++++++++++++++++++ .github/workflows/amd64_windows_cmake.yml | 15 ++---- 2 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 .github/actions/ninja_msvc/action.yml diff --git a/.github/actions/ninja_msvc/action.yml b/.github/actions/ninja_msvc/action.yml new file mode 100644 index 0000000..9ef12f4 --- /dev/null +++ b/.github/actions/ninja_msvc/action.yml @@ -0,0 +1,58 @@ +name: 'Ninja x MSVC' +description: 'Use ninja generator with MSVC cl.exe' +runs: + using: "composite" + steps: + - name: Configure Native MSVC Environment for Ninja generator + shell: powershell + run: | + # Locate the installation path of the Visual Studio Enterprise edition on the runner + # e.g. "C:\Program Files\Microsoft Visual Studio\2022\Community" + $vsInstallPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath + if (-not $vsInstallPath) { + Write-Error "Visual Studio installation could not be found." + exit 1 + } + + # 1. Snapshot current environment before loading VS DevShell + $oldEnv = @{} + Get-ChildItem env: | ForEach-Object { $oldEnv[$_.Name] = $_.Value } + + # 2. Target the PowerShell-native developer shell script + $devCmdPath = Join-Path $vsInstallPath "Common7\Tools\Launch-VsDevShell.ps1" + Write-Host "Found Developer Shell at: $devCmdPath" + + # 3. Run the script to load VS variables directly into this PowerShell session + # Specify both -Arch amd64 and -HostArch amd64 to target x64 natively with 64-bit tools + & $devCmdPath -Arch amd64 -HostArch amd64 -SkipAutomaticLocation + + # 4. Read the updated environment variables natively from PowerShell's env: drive + $envVars = Get-ChildItem env: + + # 5. Parse and append only new/modified variables to GitHub Actions runner environment + foreach ($var in $envVars) { + $name = $var.Name + $value = $var.Value + + if ($oldEnv.ContainsKey($name) -and $oldEnv[$name] -eq $value) { + continue + } + + if ($name -eq "Path") { + # GitHub Actions PREPENDS each line of GITHUB_PATH as it reads top-to-bottom. + # We must reverse the array so the first path (MSVC Hostx64/x64) is prepended last + # and stays at the very front of PATH (ahead of VC/Tools/Llvm/x64/bin). + $paths = $value -split ";" + [array]::Reverse($paths) + foreach ($p in $paths) { + if ($p -and (Test-Path $p)) { + $p | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + } + } + } else { + # Inject modified/new environment variables (INCLUDE, LIB, LIBPATH, etc.) into GITHUB_ENV + "$name=$value" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + } + } + Write-Host "Successfully injected MSVC environment into GitHub Runner!" + diff --git a/.github/workflows/amd64_windows_cmake.yml b/.github/workflows/amd64_windows_cmake.yml index 61f37b6..345aa1a 100644 --- a/.github/workflows/amd64_windows_cmake.yml +++ b/.github/workflows/amd64_windows_cmake.yml @@ -30,16 +30,12 @@ jobs: SCCACHE_GHA_ENABLED: "true" CTEST_OUTPUT_ON_FAILURE: 1 steps: + - uses: actions/checkout@v7 - name: Run sccache-cache uses: mozilla-actions/sccache-action@v0.0.11 - # Extract and inject MSVC environment variables - - name: Set up MSVC x64 + - uses: ./.github/actions/ninja_msvc if: ${{matrix.cmake.generator == 'Ninja'}} - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: x64 - - uses: actions/checkout@v7 - name: Check CMake run: | cmake --version @@ -59,10 +55,9 @@ jobs: -v -j2 - name: Test run: > - cmake --build build - --config ${{matrix.cmake.config}} - --target ${{matrix.cmake.test_target}} - -v + ctest --test-dir build + -C ${{matrix.cmake.config}} + -V - name: Install run: > cmake --build build