1- diff --color -Naur a/cc_toolchain_config.bzl b/cc_toolchain_config.bzl
2- --- a/cc_toolchain_config.bzl 2023-01-06 15:34:50.000000000 -0800
3- +++ b/cc_toolchain_config.bzl 2023-01-22 15:33:16.794758043 -0800
4- @@ -27,6 +27,7 @@
1+ diff --git a/cc_toolchain_config.bzl b/cc_toolchain_config.bzl
2+ index 0b77afc..a046faf 100644
3+ --- a/cc_toolchain_config.bzl
4+ +++ b/cc_toolchain_config.bzl
5+ @@ -27,6 +27,7 @@ load(
56 "with_feature_set",
67 )
78 load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
89+ load(":toolchain_features.bzl", "pl_toolchain_pre_features", "PL_EXTRA_CC_CONFIG_ATTRS", "pl_toolchain_post_features", "pl_action_configs")
9-
10+
1011 def layering_check_features(compiler):
1112 if compiler != "clang":
12- @@ -147,7 +148,7 @@
13+ @@ -147,7 +148,7 @@ def _impl(ctx):
1314 tool_path(name = name, path = path)
1415 for name, path in ctx.attr.tool_paths.items()
1516 ]
1617- action_configs = []
1718+ action_configs = pl_action_configs(ctx)
18-
19+
1920 llvm_cov_action = action_config(
2021 action_name = ACTION_NAMES.llvm_cov,
21- @@ -168,6 +169,10 @@
22+ @@ -168,6 +169,10 @@ def _impl(ctx):
2223 name = "supports_start_end_lib",
2324 enabled = True,
2425 )
2526+ default_opt_level_flags_feature = feature(
2627+ name = "default_opt_level_flags",
2728+ enabled = True,
2829+ )
29-
30+
3031 default_compile_flags_feature = feature(
3132 name = "default_compile_flags",
32- @@ -203,7 +208,7 @@
33+ @@ -203,7 +208,7 @@ def _impl(ctx):
3334 flags = ctx.attr.dbg_compile_flags,
3435 ),
3536 ] if ctx.attr.dbg_compile_flags else []),
@@ -38,7 +39,7 @@ diff --color -Naur a/cc_toolchain_config.bzl b/cc_toolchain_config.bzl
3839 ),
3940 flag_set(
4041 actions = all_compile_actions,
41- @@ -212,7 +217,7 @@
42+ @@ -212,7 +217,7 @@ def _impl(ctx):
4243 flags = ctx.attr.opt_compile_flags,
4344 ),
4445 ] if ctx.attr.opt_compile_flags else []),
@@ -47,7 +48,7 @@ diff --color -Naur a/cc_toolchain_config.bzl b/cc_toolchain_config.bzl
4748 ),
4849 flag_set(
4950 actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend],
50- @@ -244,7 +249,7 @@
51+ @@ -244,7 +249,7 @@ def _impl(ctx):
5152 flags = ctx.attr.opt_link_flags,
5253 ),
5354 ] if ctx.attr.opt_link_flags else []),
@@ -56,44 +57,57 @@ diff --color -Naur a/cc_toolchain_config.bzl b/cc_toolchain_config.bzl
5657 ),
5758 ],
5859 )
59- @@ -1255,6 +1260,7 @@
60+ @@ -1255,6 +1260,7 @@ def _impl(ctx):
6061 strip_debug_symbols_feature,
6162 coverage_feature,
6263 supports_pic_feature,
6364+ default_opt_level_flags_feature,
6465 ] + (
6566 [
6667 supports_start_end_lib_feature,
67- @@ -1276,6 +1282,7 @@
68+ @@ -1276,6 +1282,7 @@ def _impl(ctx):
6869 else:
6970 features = [
7071 supports_pic_feature,
7172+ default_opt_level_flags_feature,
7273 ] + (
7374 [
7475 supports_start_end_lib_feature,
75- @@ -1294,6 +1301,7 @@
76+ @@ -1294,6 +1301,17 @@ def _impl(ctx):
7677 unfiltered_compile_flags_feature,
7778 ] + layering_check_features(ctx.attr.compiler)
78-
79+
7980+ features = pl_toolchain_pre_features(ctx) + features + pl_toolchain_post_features(ctx)
81+ +
82+ + sysroot_path = ctx.attr.builtin_sysroot
83+ + # Only override with toolchain sysroot if this cc_toolchain is configured to use a sysroot
84+ + # (i.e., builtin_sysroot is non-empty). This prevents exec toolchains from incorrectly
85+ + # inheriting the target sysroot.
86+ + if sysroot_path:
87+ + sysroot_toolchain = ctx.toolchains["@px//bazel/cc_toolchains/sysroots/build:toolchain_type"]
88+ + if sysroot_toolchain:
89+ + sysroot_path = sysroot_toolchain.sysroot.path
90+ +
8091 return cc_common.create_cc_toolchain_config_info(
8192 ctx = ctx,
8293 features = features,
83- @@ -1313,7 +1321,7 @@
84-
94+ @@ -1308,7 +1322,7 @@ def _impl(ctx):
95+ abi_version = ctx.attr.abi_version,
96+ abi_libc_version = ctx.attr.abi_libc_version,
97+ tool_paths = tool_paths,
98+ - builtin_sysroot = ctx.attr.builtin_sysroot,
99+ + builtin_sysroot = sysroot_path,
100+ )
101+
85102 cc_toolchain_config = rule(
86- implementation = _impl,
87- - attrs = {
88- + attrs = dict({
89- "cpu": attr.string(mandatory = True),
90- "compiler": attr.string(mandatory = True),
91- "toolchain_identifier": attr.string(mandatory = True),
92- @@ -1336,6 +1344,6 @@
103+ @@ -1336,5 +1350,8 @@ cc_toolchain_config = rule(
93104 "coverage_link_flags": attr.string_list(),
94105 "supports_start_end_lib": attr.bool(),
95106 "builtin_sysroot": attr.string(),
96107- },
97- + }, ** PL_EXTRA_CC_CONFIG_ATTRS) ,
108+ + } | PL_EXTRA_CC_CONFIG_ATTRS,
98109 provides = [CcToolchainConfigInfo],
110+ + toolchains = [
111+ + config_common.toolchain_type("@px//bazel/cc_toolchains/sysroots/build:toolchain_type", mandatory = False),
112+ + ],
99113 )
0 commit comments