From fabd9f331c0f07fb1dfe063296284cdc58dbd998 Mon Sep 17 00:00:00 2001 From: Dylan Abraham Date: Tue, 17 Mar 2026 11:35:35 -0700 Subject: [PATCH 1/2] passthrough cc env/args using native cc features Signed-off-by: Dylan Abraham --- jemalloc-sys/build.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/jemalloc-sys/build.rs b/jemalloc-sys/build.rs index 3841d6bb6..356d19beb 100644 --- a/jemalloc-sys/build.rs +++ b/jemalloc-sys/build.rs @@ -154,14 +154,21 @@ fn main() { // Disable -Wextra warnings - jemalloc doesn't compile free of warnings with // it enabled: https://github.com/jemalloc/jemalloc/issues/1196 let compiler = cc::Build::new().extra_warnings(false).get_compiler(); - let cflags = compiler - .args() - .iter() - .map(|s| s.to_str().unwrap()) - .collect::>() - .join(" "); - let ldflags = read_and_watch_env("LDFLAGS").unwrap_or_else(|_| cflags.clone()); - info!("CC={:?}", compiler.path()); + let cflags = compiler.cflags_env(); + let ldflags = read_and_watch_env("LDFLAGS") + .map(OsString::from) + .unwrap_or_else(|_| cflags.clone()); + + // Use cc_env() to get the full CC value including any wrapper (e.g. sccache). + // cc_env() returns empty when no wrapper is configured, so fall back to path(). + let cc = compiler.cc_env(); + let cc = if cc.is_empty() { + compiler.path().as_os_str().to_owned() + } else { + cc + }; + + info!("CC={:?}", cc); info!("CFLAGS={:?}", cflags); info!("LDFLAGS={:?}", ldflags); @@ -197,10 +204,10 @@ fn main() { .replace('\\', "/"), ) .current_dir(&build_dir) - .env("CC", compiler.path()) - .env("CFLAGS", cflags.clone()) - .env("LDFLAGS", ldflags.clone()) - .env("CPPFLAGS", cflags) + .env("CC", &cc) + .env("CFLAGS", &cflags) + .env("LDFLAGS", &ldflags) + .env("CPPFLAGS", &cflags) .arg(format!("--with-version={je_version}")) .arg("--disable-cxx") .arg("--enable-doc=no") From fbf26aa1151b77af1a996410e225a6582b3c11c6 Mon Sep 17 00:00:00 2001 From: Dylan Abraham Date: Tue, 17 Mar 2026 11:58:20 -0700 Subject: [PATCH 2/2] don't fallback to cflags Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Dylan Abraham --- jemalloc-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jemalloc-sys/build.rs b/jemalloc-sys/build.rs index 356d19beb..35141835f 100644 --- a/jemalloc-sys/build.rs +++ b/jemalloc-sys/build.rs @@ -157,7 +157,7 @@ fn main() { let cflags = compiler.cflags_env(); let ldflags = read_and_watch_env("LDFLAGS") .map(OsString::from) - .unwrap_or_else(|_| cflags.clone()); + .unwrap_or_default(); // Use cc_env() to get the full CC value including any wrapper (e.g. sccache). // cc_env() returns empty when no wrapper is configured, so fall back to path().