Merge pull request 'fix(windows): compile memset_shim to real .o via get_compiler()' (#121) from fix/cargo-config-sodium into beta
All checks were successful
Release Beta / autotag (push) Successful in 10s
Release Beta / changelog (push) Successful in 1m29s
Test / frontend-tests (push) Successful in 1m49s
Test / frontend-typecheck (push) Successful in 1m56s
Release Beta / build-macos-arm64 (push) Successful in 10m48s
Release Beta / build-linux-amd64 (push) Successful in 9m56s
Release Beta / build-windows-amd64 (push) Successful in 11m25s
Release Beta / build-linux-arm64 (push) Successful in 12m53s
Test / rust-fmt-check (push) Successful in 18m29s
Test / rust-clippy (push) Successful in 20m31s
Test / rust-tests (push) Successful in 22m23s

Reviewed-on: #121
This commit is contained in:
sarman 2026-06-19 20:42:27 +00:00
commit ec14409fd5

View File

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