Skip to content

Commit

Permalink
[bazel] Enable dead code stripping on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
fhanau committed Apr 12, 2023
1 parent a4a045e commit e5fe18a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/workerd/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit e5fe18a

Please # to comment.