Skip to content

Commit

Permalink
Patch rules_foreign_cc to not link bazel default libraries into GNUMa…
Browse files Browse the repository at this point in the history
…ke (#37632)

When upstream `rules_foreign_cc` builds its own GNUMake, it injects
bazel's default libraries into `LDFLAGS`, which causes trouble on Darwin
in newer versions of Bazel that added `-lm` to the list of default
libraries.

As explained nicely in
bazel-contrib/rules_foreign_cc#1227, Apple's
libm re-exports a bunch of symbols and, due to linker argument order,
clobbers some symbols from make itself. We don't need any of the default
libraries in GNUMake, so disable the feature to link them.

Risk Level: low
Testing: CI

---------

Signed-off-by: Alejandro R Sedeño <[email protected]>
Signed-off-by: Alejandro R. Sedeño <[email protected]>
  • Loading branch information
asedeno authored Dec 12, 2024
1 parent da48e79 commit 43d9ac4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,11 @@ def _rules_ruby():
external_http_archive("rules_ruby")

def _foreign_cc_dependencies():
external_http_archive(name = "rules_foreign_cc")
external_http_archive(
name = "rules_foreign_cc",
patches = ["@envoy//bazel:rules_foreign_cc.patch"],
patch_args = ["-p1"],
)

def _com_github_maxmind_libmaxminddb():
external_http_archive(
Expand Down
14 changes: 14 additions & 0 deletions bazel/rules_foreign_cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/toolchains/private/BUILD.bazel b/toolchains/private/BUILD.bazel
index 4ccdeef..25658e9 100644
--- a/toolchains/private/BUILD.bazel
+++ b/toolchains/private/BUILD.bazel
@@ -23,6 +23,9 @@ native_tool_toolchain(
make_tool(
name = "make_tool",
srcs = "@gnumake_src//:all_srcs",
+ features = [
+ "-default_link_libs",
+ ],
tags = ["manual"],
)

0 comments on commit 43d9ac4

Please sign in to comment.