diff --git a/src/workerd/server/BUILD.bazel b/src/workerd/server/BUILD.bazel index f3075571c8b9..c981e8905a0d 100644 --- a/src/workerd/server/BUILD.bazel +++ b/src/workerd/server/BUILD.bazel @@ -10,6 +10,18 @@ config_setting( constraint_values = ["@platforms//os:linux"], ) +config_setting( + name = "is_opt", + values = {"compilation_mode": "opt"}, +) + +# bazel enables the --ffunction-sections, --gc-sections flags used to remove dead code by default +# on Linux opt builds. Define the equivalent macOS flag -Wl,-dead_strip if optimization is enabled. +selects.config_setting_group( + name = "use_dead_strip", + match_all = ["@platforms//os:macos", "is_opt"], +) + # Flag that can be used to force-disable tcmalloc. Mainly used for ASAN builds. # TODO(cleanup): This feels ugly but I've exceeded my timebox for fighting Bazel for now. bool_flag( @@ -39,6 +51,10 @@ wd_cc_binary( ":really_use_tcmalloc": "@com_google_tcmalloc//tcmalloc", "//conditions:default": "@bazel_tools//tools/cpp:malloc", }), + linkopts = select({ + ":use_dead_strip": ["-Wl,-dead_strip"], + "//conditions:default": [""], + }), ) wd_cc_library(