1 # Fails if a Windows binary depends on the Visual C++ runtime DLLs.
2 #
3 # sigit is linked with +crt-static (see .cargo/config.toml) so it runs on a
4 # clean Windows install. If RUSTFLAGS overrides that, or a native dependency
5 # drags in the DLL runtime, the exe still builds and passes tests on a runner
6 # that has the redistributable installed, then fails to load on users'
7 # machines. This check catches it before release.
8 param(
9 [Parameter(Mandatory = $true)]
10 [string]$Path
11 )
12
13 $ErrorActionPreference = 'Stop'
14
15 $vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
16 $dumpbin = & $vswhere -latest -products * -find 'VC\Tools\MSVC\*\bin\Hostx64\x64\dumpbin.exe' |
17 Select-Object -First 1
18 if (-not $dumpbin) {
19 throw 'dumpbin.exe not found; is the MSVC toolset installed?'
20 }
21
22 $output = & $dumpbin /nologo /dependents $Path
23 if ($LASTEXITCODE -ne 0) {
24 throw "dumpbin failed on $Path"
25 }
26 $output | Write-Host
27
28 $runtime = $output |
29 Where-Object { $_ -match '^\s+(vcruntime|msvcp|concrt|ucrtbase|api-ms-win-crt-)\S*\.dll\s*$' } |
30 ForEach-Object { $_.Trim() }
31 if ($runtime) {
32 Write-Host "::error::$Path depends on the Visual C++ runtime: $($runtime -join ', ')"
33 exit 1
34 }
35 Write-Host "$Path does not depend on the Visual C++ runtime."