Skip to content

Commit 6f406c6

Browse files
committed
ci(windows): find vcvarsall via vswhere instead of hardcoded VS path
1 parent c28fc96 commit 6f406c6

2 files changed

Lines changed: 59 additions & 2 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ jobs:
103103
SCCACHE_GHA_ENABLED: "true"
104104
run: |
105105
$ErrorActionPreference = "Stop"
106-
cmd /c "call `"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat`" x64 && bash -lc `"ci/scripts/build_iceberg.sh `$(pwd) OFF ON`""
106+
& "${env:GITHUB_WORKSPACE}/ci/scripts/run_msvc_bash.ps1" -BashCommand 'ci/scripts/build_iceberg.sh $(pwd) OFF ON'
107107
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
108108
sccache --show-stats
109109
- name: Build Example
110110
shell: pwsh
111111
run: |
112112
$ErrorActionPreference = "Stop"
113-
cmd /c "call `"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat`" x64 && bash -lc `"ci/scripts/build_example.sh `$(pwd)/example`""
113+
& "${env:GITHUB_WORKSPACE}/ci/scripts/run_msvc_bash.ps1" -BashCommand 'ci/scripts/build_example.sh $(pwd)/example'
114114
meson:
115115
name: Meson - ${{ matrix.title }}
116116
runs-on: ${{ matrix.runs-on }}

ci/scripts/run_msvc_bash.ps1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
# Run a Bash command line (passed to bash -lc) after initializing MSVC via
20+
# vcvarsall.bat. Locates Visual Studio using vswhere so CI works across
21+
# Enterprise, Community, Build Tools, and future image layouts.
22+
23+
param(
24+
[Parameter(Mandatory = $true)]
25+
[string]$BashCommand
26+
)
27+
28+
$ErrorActionPreference = "Stop"
29+
30+
$vswhere = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio\Installer\vswhere.exe"
31+
if (-not (Test-Path -LiteralPath $vswhere)) {
32+
Write-Error "vswhere.exe not found: $vswhere"
33+
exit 1
34+
}
35+
36+
$installationPath = & $vswhere `
37+
-latest -products * `
38+
-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
39+
-property installationPath
40+
41+
if ([string]::IsNullOrWhiteSpace($installationPath)) {
42+
$installationPath = & $vswhere -latest -products * -property installationPath
43+
}
44+
45+
if ([string]::IsNullOrWhiteSpace($installationPath)) {
46+
Write-Error "No Visual Studio installation with C++ tools found via vswhere."
47+
exit 1
48+
}
49+
50+
$vcvarsall = Join-Path $installationPath "VC\Auxiliary\Build\vcvarsall.bat"
51+
if (-not (Test-Path -LiteralPath $vcvarsall)) {
52+
Write-Error "vcvarsall.bat not found: $vcvarsall"
53+
exit 1
54+
}
55+
56+
cmd.exe /c "call `"$vcvarsall`" x64 && bash -lc `"$BashCommand`""
57+
exit $LASTEXITCODE

0 commit comments

Comments
 (0)