| 1 |
if (!$env:VisualStudioDevShell) { |
| 2 |
$vswhere = "${Env:ProgramFiles(x86)}/Microsoft Visual Studio/Installer/vswhere.exe" |
| 3 |
if (!(Test-Path $vswhere)) { |
| 4 |
throw "Failed to find vswhere.exe" |
| 5 |
} |
| 6 |
|
| 7 |
& $vswhere -latest -format json |
| 8 |
$vsInstance = & $vswhere -latest -format json | ConvertFrom-Json |
| 9 |
if ($LASTEXITCODE) { |
| 10 |
throw "vswhere.exe returned exit code $LASTEXITCODE" |
| 11 |
} |
| 12 |
|
| 13 |
Import-Module "$($vsInstance.installationPath)/Common7/Tools/Microsoft.VisualStudio.DevShell.dll" |
| 14 |
$prevCwd = Get-Location |
| 15 |
try { |
| 16 |
Enter-VsDevShell $vsInstance.instanceId -DevCmdArguments "-no_logo -host_arch=amd64 -arch=amd64" |
| 17 |
} catch { |
| 18 |
Write-Host $_ |
| 19 |
Write-Error "Failed to enter Visual Studio Dev Shell" |
| 20 |
exit 1 |
| 21 |
} |
| 22 |
# CI only: the Visual Studio toolchain bundles an LLVM flang Fortran compiler |
| 23 |
# that miscompiles LAPACK's *gedmd routines (e.g. "'ssum' is not an object |
| 24 |
# that can appear in an expression"). vcpkg builds each port in its own |
| 25 |
# environment (regenerated via vcvars), which puts this flang on the PATH, so |
| 26 |
# vcpkg_find_fortran detects it instead of falling back to a working MinGW |
| 27 |
# gfortran and the lapack-reference build fails. Remove the bundled flang in CI |
| 28 |
# so the MinGW gfortran fallback kicks in. COLMAP itself builds with MSVC |
| 29 |
# (cl.exe) and does not use flang. We gate on CI so local Visual Studio |
| 30 |
# installations are left untouched. |
| 31 |
# See https://github.com/llvm/llvm-project/issues/201254 and |
| 32 |
# https://developercommunity.microsoft.com/t/11105096. |
| 33 |
if ($env:GITHUB_ACTIONS -eq "true") { |
| 34 |
$llvmDir = Join-Path $vsInstance.installationPath "VC/Tools/Llvm" |
| 35 |
if (Test-Path $llvmDir) { |
| 36 |
Get-ChildItem -Path $llvmDir -Recurse -Filter "flang*.exe" -ErrorAction SilentlyContinue | ForEach-Object { |
| 37 |
try { |
| 38 |
Remove-Item -LiteralPath $_.FullName -Force -ErrorAction Stop |
| 39 |
Write-Host "Removed bundled flang: $($_.FullName)" |
| 40 |
} catch { |
| 41 |
Write-Warning "Failed to remove bundled flang $($_.FullName): $_" |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
Set-Location $prevCwd |
| 48 |
|
| 49 |
$env:VisualStudioDevShell = $true |
| 50 |
} |