diff --git a/WORKSPACE b/WORKSPACE index d466fb33a..d9a068918 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -42,8 +42,6 @@ git_repository( "@//patches:0003-original_dst_cluster-Avoid-multiple-hosts-for-the-sa.patch", "@//patches:0004-thread_local-reset-slot-in-worker-threads-first.patch", "@//patches:0005-http-header-expose-attribute.patch", - "@//patches:0006-build-Fix-arm-build-for-liburing.patch", - "@//patches:0007-Add-latomic-back-for-arm-build.patch", ], # // clang-format off: Envoy's format check: Only repository_locations.bzl may contains URL references remote = "https://github.com/envoyproxy/envoy.git", diff --git a/bazel/toolchains/BUILD b/bazel/toolchains/BUILD index 4a9e68bbc..814b19110 100644 --- a/bazel/toolchains/BUILD +++ b/bazel/toolchains/BUILD @@ -55,6 +55,17 @@ cc_toolchain_config( ], cxx_flags = ["-std=c++0x"], dbg_compile_flags = ["-g"], + # Cross-compilation flags exported as environment variables for foreign_cc + # rules (e.g. liburing's configure_make). This ensures foreign build systems + # see the correct --target when they use CFLAGS/CPPFLAGS from the environment. + foreign_cc_env = { + "CFLAGS": "--target=aarch64-unknown-linux-gnu -fuse-ld=lld", + "CPPFLAGS": "--target=aarch64-unknown-linux-gnu -fuse-ld=lld", + # -lc is needed because liburing builds a shared library with -Wl,-z,defs + # which requires all symbols (including memset from libc) to be resolved. + # The cross-compiler driver doesn't implicitly add -lc for shared libraries. + "LDFLAGS": "--target=aarch64-unknown-linux-gnu -fuse-ld=lld -lc", + }, host_system_name = "local", link_flags = [ "--target=aarch64-unknown-linux-gnu", @@ -63,7 +74,10 @@ cc_toolchain_config( "-Wl,-z,relro,-z,now", "-lm", ], - link_libs = ["-l:libstdc++.a"], + link_libs = [ + "-l:libstdc++.a", + "-latomic", + ], opt_compile_flags = [ "-g0", "-O2", @@ -162,7 +176,10 @@ cc_toolchain_config( "-Wl,-z,relro,-z,now", "-lm", ], - link_libs = ["-l:libstdc++.a"], + link_libs = [ + "-l:libstdc++.a", + "-latomic", + ], opt_compile_flags = [ "-g0", "-O2", diff --git a/bazel/toolchains/cc_toolchain_config.bzl b/bazel/toolchains/cc_toolchain_config.bzl index ce91d9c07..500f69d96 100644 --- a/bazel/toolchains/cc_toolchain_config.bzl +++ b/bazel/toolchains/cc_toolchain_config.bzl @@ -20,6 +20,8 @@ load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") load( "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "env_entry", + "env_set", "feature", "feature_set", "flag_group", @@ -1145,6 +1147,26 @@ def _impl(ctx): ], ) + # Export cross-compilation flags as environment variables for foreign_cc rules + # (e.g. rules_foreign_cc's configure_make). These env vars are picked up by + # cc_common.get_environment_variables() and exported globally in the build + # script prelude, making them available to both configure and make steps. + # This is needed because some foreign build systems (like liburing) override + # CFLAGS internally, losing the --target flag from the toolchain's compile_flags. + foreign_cc_env_feature = feature( + name = "foreign_cc_env", + enabled = bool(ctx.attr.foreign_cc_env), + env_sets = [ + env_set( + actions = all_compile_actions + all_link_actions, + env_entries = [ + env_entry(key = key, value = value) + for key, value in ctx.attr.foreign_cc_env.items() + ], + ), + ] if ctx.attr.foreign_cc_env else [], + ) + is_linux = ctx.attr.target_libc != "macosx" # TODO(#8303): Mac crosstool should also declare every feature. @@ -1194,6 +1216,7 @@ def _impl(ctx): user_compile_flags_feature, sysroot_feature, unfiltered_compile_flags_feature, + foreign_cc_env_feature, ] + layering_check_features(ctx.attr.compiler) else: features = [ @@ -1213,6 +1236,7 @@ def _impl(ctx): user_compile_flags_feature, sysroot_feature, unfiltered_compile_flags_feature, + foreign_cc_env_feature, ] + layering_check_features(ctx.attr.compiler) return cc_common.create_cc_toolchain_config_info( @@ -1257,6 +1281,7 @@ cc_toolchain_config = rule( "coverage_link_flags": attr.string_list(), "supports_start_end_lib": attr.bool(), "builtin_sysroot": attr.string(), + "foreign_cc_env": attr.string_dict(), }, provides = [CcToolchainConfigInfo], ) diff --git a/patches/0006-build-Fix-arm-build-for-liburing.patch b/patches/0006-build-Fix-arm-build-for-liburing.patch deleted file mode 100644 index 250c280d8..000000000 --- a/patches/0006-build-Fix-arm-build-for-liburing.patch +++ /dev/null @@ -1,37 +0,0 @@ -From 42db1598d81cbccb575c0cd40578f9481a3549e7 Mon Sep 17 00:00:00 2001 -From: Tam Mach -Date: Wed, 14 May 2025 11:27:14 +1000 -Subject: [PATCH] build: Fix arm build for liburing - ---- - bazel/foreign_cc/BUILD | 14 ++++++++++++++ - 1 file changed, 14 insertions(+) - -diff --git a/bazel/foreign_cc/BUILD b/bazel/foreign_cc/BUILD -index 2cd885639a..d4b3ea1277 100644 ---- a/bazel/foreign_cc/BUILD -+++ b/bazel/foreign_cc/BUILD -@@ -28,6 +28,20 @@ config_setting( - configure_make( - name = "liburing", - configure_in_place = True, -+ env = select({ -+ # (sayboras) Ideally, this should be passed as part of environment variables during cross-compilation, -+ # but somehow it doesn't work. So, we have to pass them manually for arm cross-compilation. -+ # The config should be kept in sync with bazel/toolchains/BUILD -+ "//bazel:linux_aarch64": { -+ "CFLAGS": "--target=aarch64-unknown-linux-gnu -fuse-ld=lld-18", -+ "CPPFLAGS": "--target=aarch64-unknown-linux-gnu -fuse-ld=lld-18", -+ "LDFLAGS": "-Wl,-S --target=aarch64-unknown-linux-gnu -fuse-ld=lld-18 -Wl,-no-as-needed -Wl,-z,relro,-z,now -lm -l:libstdc++.a -lc", -+ "CC": "/usr/bin/clang-18", -+ "CXX": "/usr/bin/clang-18", -+ "LD": "/usr/bin/lld-18", -+ }, -+ "//conditions:default": {}, -+ }), - lib_source = "@com_github_axboe_liburing//:all", - tags = [ - "nocompdb", --- -2.49.0 - diff --git a/patches/0007-Add-latomic-back-for-arm-build.patch b/patches/0007-Add-latomic-back-for-arm-build.patch deleted file mode 100644 index ead05c16f..000000000 --- a/patches/0007-Add-latomic-back-for-arm-build.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 4dad6252057e395d8c87831419e6e05d55d323a6 Mon Sep 17 00:00:00 2001 -From: Tam Mach -Date: Fri, 12 Dec 2025 13:45:27 +1100 -Subject: [PATCH] Add latomic back for arm build - ---- - bazel/v8.patch | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/bazel/v8.patch b/bazel/v8.patch -index 9b0cb2374f..512b22ebf4 100644 ---- a/bazel/v8.patch -+++ b/bazel/v8.patch -@@ -284,7 +284,7 @@ index 39663c97df4..14b90ec6905 100644 - ], - "@v8//bazel/config:is_macos": ["-pthread"], - - "//conditions:default": ["-Wl,--no-as-needed -ldl -latomic -pthread"], --+ "//conditions:default": ["-Wl,--no-as-needed -ldl -pthread"], -++ "//conditions:default": ["-Wl,--no-as-needed -ldl -latomic -pthread"], - }) + select({ - ":should_add_rdynamic": ["-rdynamic"], - "//conditions:default": [], --- -2.43.0 -