Fix jemalloc tools and compiler flags for Bazel musl builds (#43533)

The musl CLI allocator needs declared native tools and consistent header
flags. Configure `tikv-jemalloc-sys` to use Bazel's Make toolchain and LLVM's
`llvm-nm` and `llvm-ranlib`, and patch its build script to honor `MAKE`.
Preserve `CFLAGS` and `CXXFLAGS` when generating jemalloc header dependencies
so dependency generation uses the same compiler flags as compilation.

GitOrigin-RevId: 4022b587ce0c8bce9331c541adbdf29c1d245558
This commit is contained in:
felixxia-oai
2026-09-07 17:53:04 +00:00
committed by copyberry
parent c9c7b73c4f
commit 53ba408a2f
4 changed files with 74 additions and 0 deletions
+21
View File
@@ -613,6 +613,27 @@ crate.annotation(
crate = "opusic-sys",
)
# The musl CLI's allocator needs declared native tools and consistent header flags.
crate.annotation(
build_script_env = {
"MAKE": "$${pwd}/$(MAKE)",
"NM": "$${pwd}/$(execpath @llvm//tools:llvm-nm)",
"RANLIB": "$${pwd}/$(execpath @llvm//tools:llvm-ranlib)",
},
build_script_toolchains = ["@rules_foreign_cc//toolchains:current_make_toolchain"],
build_script_tools = [
"@llvm//tools:llvm-nm",
"@llvm//tools:llvm-ranlib",
"@rules_foreign_cc//toolchains:current_make_toolchain",
],
crate = "tikv-jemalloc-sys",
patch_args = ["-p1"],
patches = [
"//patches:tikv-jemalloc-sys_make_env.patch",
"//patches:tikv-jemalloc-sys_dependency_flags.patch",
],
)
inject_repo(crate, "rules_foreign_cc")
crate.annotation(
+2
View File
@@ -16,6 +16,8 @@ exports_files([
"rules_rs_zlib_snapshot_urls.patch",
"rusty_v8_prebuilt_out_dir.patch",
"ring_windows_msvc_include_dirs.patch",
"tikv-jemalloc-sys_make_env.patch",
"tikv-jemalloc-sys_dependency_flags.patch",
"v8_bazel_rules.patch",
"v8_module_deps.patch",
"v8_source_portability.patch",
@@ -0,0 +1,38 @@
diff --git a/jemalloc/Makefile.in b/jemalloc/Makefile.in
--- a/jemalloc/Makefile.in
+++ b/jemalloc/Makefile.in
@@ -508,7 +508,7 @@
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $(CPPFLAGS) $(CTARGET) $<
ifdef CC_MM
- @$(CC) -MM $(CPPFLAGS) -MT $@ -o $(@:%.$(O)=%.d) $<
+ @$(CC) $(CFLAGS) -MM $(CPPFLAGS) -MT $@ -o $(@:%.$(O)=%.d) $<
endif
$(C_SYMS): %.sym:
@@ -532,7 +532,7 @@
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -c $(CPPFLAGS) $(CTARGET) $<
ifdef CC_MM
- @$(CXX) -MM $(CPPFLAGS) -MT $@ -o $(@:%.$(O)=%.d) $<
+ @$(CXX) $(CXXFLAGS) -MM $(CPPFLAGS) -MT $@ -o $(@:%.$(O)=%.d) $<
endif
ifneq ($(SOREV),$(SO))
@@ -589,14 +589,14 @@
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $(CPPFLAGS) -DJEMALLOC_STRESS_TEST -I$(srcroot)test/include -I$(objroot)test/include $(CTARGET) $<
ifdef CC_MM
- @$(CC) -MM $(CPPFLAGS) -DJEMALLOC_STRESS_TEST -I$(srcroot)test/include -I$(objroot)test/include -MT $@ -o $(@:%.$(O)=%.d) $<
+ @$(CC) $(CFLAGS) -MM $(CPPFLAGS) -DJEMALLOC_STRESS_TEST -I$(srcroot)test/include -I$(objroot)test/include -MT $@ -o $(@:%.$(O)=%.d) $<
endif
$(objroot)test/stress/pa/%.$(O): $(srcroot)test/stress/pa/%.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -c $(CPPFLAGS) -I$(srcroot)test/include -I$(objroot)test/include $(CTARGET) $<
ifdef CC_MM
- @$(CXX) -MM $(CPPFLAGS) -I$(srcroot)test/include -I$(objroot)test/include -MT $@ -o $(@:%.$(O)=%.d) $<
+ @$(CXX) $(CXXFLAGS) -MM $(CPPFLAGS) -I$(srcroot)test/include -I$(objroot)test/include -MT $@ -o $(@:%.$(O)=%.d) $<
endif
build_lib_shared: $(DSOS)
+13
View File
@@ -0,0 +1,13 @@
diff --git a/build.rs b/build.rs
--- a/build.rs
+++ b/build.rs
@@ -331,7 +331,8 @@
run_and_log(&mut cmd, &build_dir.join("config.log"));
// Make:
- let make = make_cmd(&host);
+ let make = read_and_watch_env("MAKE").unwrap_or_else(|_| make_cmd(&host).to_owned());
+ let make = make.as_str();
run(&mut make_command(make, &build_dir, &num_jobs));
// Skip watching this environment variables to avoid rebuild in CI.