Skip to content

Commit

Permalink
Implement static_link_cpp_runtimes feature
Browse files Browse the repository at this point in the history
This patch implements the `static_link_cpp_runtimes` feature
in `unix_cc_toolchain_config`.  The feature is documented as
a well-known feature[1] and was added to the toolchain[2] but
not implemented.

The patch follows the solution proposed on GitHub.[3]

For the feature to work as expected, users have to remove
the linker flag `"-lstdc++"` from `link_libs` (or `link_flags`)
from the call to `unix_cc_toolchain_config`.

[1] https://bazel.build/docs/cc-toolchain-config-reference#wellknown-features
[2] bazelbuild#17391
[3] bazelbuild#14342
  • Loading branch information
Synss committed Aug 3, 2024
1 parent 914db36 commit 5cc2cc3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tools/cpp/unix_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,17 @@ def _impl(ctx):
static_link_cpp_runtimes_feature = feature(
name = "static_link_cpp_runtimes",
enabled = False,
flag_sets = [
flag_set(
actions = [
ACTION_NAMES.cpp_link_executable,
ACTION_NAMES.cpp_link_dynamic_library,
ACTION_NAMES.lto_index_for_executable,
ACTION_NAMES.lto_index_for_dynamic_library,
],
flag_groups = [flag_group(flags = ["-static-libstdc++"])],
),
],
)

default_compile_flags_feature = feature(
Expand Down Expand Up @@ -1059,6 +1070,15 @@ def _impl(ctx):
),
],
),
flag_set(
actions = all_link_actions + lto_index_actions,
flag_groups = [flag_group(flags = ["-lstdc++"])],
with_features = [
with_feature_set(
not_features = ["static_link_cpp_runtimes"],
),
],
),
],
)

Expand Down

0 comments on commit 5cc2cc3

Please sign in to comment.