From 43781c308665049e69f57493738181aa827b3b55 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Fri, 2 Oct 2026 16:07:46 +0200 Subject: [PATCH] windows: Statically link C++ runtime Since smartmontools was added, the release binary depends on MSVCP140.dll, which is not present on a clean Windows install. cc compiles C/C++ dependencies with /MD unless the crt-static target feature is set, which links the C++ STL dynamically. static_vcruntime only changes linker arguments, so it doesn't help there. Set +crt-static for MSVC targets and add a CI check that the binary doesn't depend on the VC++ redistributable. Signed-off-by: Daniel Schaefer --- .cargo/config.toml | 6 ++++++ .github/workflows/ci.yml | 13 +++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..4985474 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,6 @@ +# Compile C/C++ dependencies (e.g. smartmontools) with /MT instead of /MD. +# Otherwise they link the C++ STL dynamically and the binary needs +# MSVCP140.dll, which isn't present on a clean Windows install. +# See framework_tool/build.rs for how vcruntime is linked statically. +[target.'cfg(all(windows, target_env = "msvc"))'] +rustflags = ["-C", "target-feature=+crt-static"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d577f6..5ae6a91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -148,6 +148,19 @@ jobs: - name: Check if Windows tool can start run: target/release/framework_tool.exe --help + # The runner has the VC++ redistributable installed, a clean Windows doesn't + - name: Check Windows tool doesn't need VC++ redistributable + shell: pwsh + run: | + $vs = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath + $dumpbin = Get-ChildItem "$vs\VC\Tools\MSVC\*\bin\Hostx64\x64\dumpbin.exe" | Select-Object -First 1 + $deps = & $dumpbin /dependents target/release/framework_tool.exe + $deps + if ($deps -match '(?i)(msvcp|vcruntime)\d+') { + Write-Error "framework_tool.exe depends on the VC++ redistributable" + exit 1 + } + # Upload release build so that vcruntime is statically linked - name: Upload Windows App uses: actions/upload-artifact@v6