From fabd9f331c0f07fb1dfe063296284cdc58dbd998 Mon Sep 17 00:00:00 2001 From: Dylan Abraham Date: Tue, 17 Mar 2026 11:35:35 -0700 Subject: [PATCH 1/3] 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/3] 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(). From 56032d3cf55793455dd0c786a996e347588138a4 Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Sun, 24 May 2026 23:01:19 +0800 Subject: [PATCH 3/3] fix cppflags overwrite Signed-off-by: Jay Lee --- jemalloc-sys/build.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jemalloc-sys/build.rs b/jemalloc-sys/build.rs index 49d25c2c6..845b9d43f 100644 --- a/jemalloc-sys/build.rs +++ b/jemalloc-sys/build.rs @@ -158,6 +158,9 @@ fn main() { let ldflags = read_and_watch_env("LDFLAGS") .map(OsString::from) .unwrap_or_default(); + let cppflags = read_and_watch_env("CPPFLAGS") + .map(OsString::from) + .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(). @@ -171,6 +174,7 @@ fn main() { info!("CC={:?}", cc); info!("CFLAGS={:?}", cflags); info!("LDFLAGS={:?}", ldflags); + info!("CPPFLAGS={:?}", cppflags); assert!(out_dir.exists(), "OUT_DIR does not exist"); let jemalloc_repo_dir = PathBuf::from("jemalloc"); @@ -207,7 +211,7 @@ fn main() { .env("CC", &cc) .env("CFLAGS", &cflags) .env("LDFLAGS", &ldflags) - .env("CPPFLAGS", &cflags) + .env("CPPFLAGS", &cppflags) .arg(format!("--with-version={je_version}")) .arg("--disable-cxx") .arg("--enable-doc=no")