From a741f49a073d618d42989be0c9dd740ed0267fad Mon Sep 17 00:00:00 2001 From: Vytautas Astrauskas Date: Tue, 28 Oct 2025 17:40:22 +0200 Subject: [PATCH] feat: statically link cpp redist for MSVC target Signed-off-by: Vytautas Astrauskas --- core/build.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 core/build.rs diff --git a/core/build.rs b/core/build.rs new file mode 100644 index 00000000..bf4b66cd --- /dev/null +++ b/core/build.rs @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: © 2025 Sysand contributors +// SPDX-License-Identifier: MIT OR Apache-2.0 + +fn main() -> Result<(), Box> { + if std::env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default() == "msvc" { + // Statically link VCRUNTIME140.dll when building for MSVC target + // because otherwise Sysand may segfault if the system has a conflicting + // version of VCRUNTIME140.dll. + + // Do not link these versions of VCRUNTIME140.dll + println!("cargo:rustc-link-arg=/NODEFAULTLIB:libvcruntimed.lib"); + println!("cargo:rustc-link-arg=/NODEFAULTLIB:vcruntime.lib"); + println!("cargo:rustc-link-arg=/NODEFAULTLIB:vcruntimed.lib"); + // Link this version of VCRUNTIME140.dll + println!("cargo:rustc-link-arg=/DEFAULTLIB:libvcruntime.lib"); + return Ok(()); + } + + Ok(()) +}