fix(windows): compile memset_shim to real .o via get_compiler() #121

Merged
sarman merged 1 commits from fix/cargo-config-sodium into beta 2026-06-19 20:42:29 +00:00

View File

@ -11,20 +11,27 @@ fn main() {
let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default(); let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
if target_os == "windows" && target_env == "gnu" { if target_os == "windows" && target_env == "gnu" {
let out_dir = std::env::var("OUT_DIR").unwrap(); let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR not set");
let obj_path = format!("{}/memset_shim.o", out_dir); let obj_path = format!("{out_dir}/memset_s_shim.o");
cc::Build::new() // Compile directly to a .o file and link it as a positional linker arg.
.file("memset_s_shim.c") // This sidesteps the static-archive ordering problem: a bare -l flag only
.define("WIN32", None) // pulls symbols that are already undefined at that point in the link,
.define("__WIN32__", None) // but libsodium's reference to memset_explicit comes later. A positional
.out_dir(&out_dir) // object file is always included unconditionally.
.compile("memset_shim"); let compiler = cc::Build::new().get_compiler();
let status = compiler
.to_command()
.args(["-DWIN32", "-D__WIN32__", "-c"])
.arg("-o")
.arg(&obj_path)
.arg("memset_s_shim.c")
.status()
.expect("failed to invoke C compiler for memset_s_shim.c");
assert!(status.success(), "failed to compile memset_s_shim.c");
println!("cargo:rerun-if-changed=memset_s_shim.c"); println!("cargo:rerun-if-changed=memset_s_shim.c");
// Directly link the object file instead of using -l flag println!("cargo:rustc-link-arg={obj_path}");
// This ensures the symbol is available regardless of link order
println!("cargo:rustc-link-arg={}", obj_path);
} }
tauri_build::build() tauri_build::build()