-
Notifications
You must be signed in to change notification settings - Fork 495
Expand file tree
/
Copy pathunix_cc_toolchain_config.patch
More file actions
113 lines (108 loc) · 4.36 KB
/
unix_cc_toolchain_config.patch
File metadata and controls
113 lines (108 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
diff --git a/cc_toolchain_config.bzl b/cc_toolchain_config.bzl
index 0b77afc..a046faf 100644
--- a/cc_toolchain_config.bzl
+++ b/cc_toolchain_config.bzl
@@ -27,6 +27,7 @@ load(
"with_feature_set",
)
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
+load(":toolchain_features.bzl", "pl_toolchain_pre_features", "PL_EXTRA_CC_CONFIG_ATTRS", "pl_toolchain_post_features", "pl_action_configs")
def layering_check_features(compiler):
if compiler != "clang":
@@ -147,7 +148,7 @@ def _impl(ctx):
tool_path(name = name, path = path)
for name, path in ctx.attr.tool_paths.items()
]
- action_configs = []
+ action_configs = pl_action_configs(ctx)
llvm_cov_action = action_config(
action_name = ACTION_NAMES.llvm_cov,
@@ -168,6 +169,10 @@ def _impl(ctx):
name = "supports_start_end_lib",
enabled = True,
)
+ default_opt_level_flags_feature = feature(
+ name = "default_opt_level_flags",
+ enabled = True,
+ )
default_compile_flags_feature = feature(
name = "default_compile_flags",
@@ -203,7 +208,7 @@ def _impl(ctx):
flags = ctx.attr.dbg_compile_flags,
),
] if ctx.attr.dbg_compile_flags else []),
- with_features = [with_feature_set(features = ["dbg"])],
+ with_features = [with_feature_set(features = ["dbg", "default_opt_level_flags"])],
),
flag_set(
actions = all_compile_actions,
@@ -212,7 +217,7 @@ def _impl(ctx):
flags = ctx.attr.opt_compile_flags,
),
] if ctx.attr.opt_compile_flags else []),
- with_features = [with_feature_set(features = ["opt"])],
+ with_features = [with_feature_set(features = ["opt", "default_opt_level_flags"])],
),
flag_set(
actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend],
@@ -244,7 +249,7 @@ def _impl(ctx):
flags = ctx.attr.opt_link_flags,
),
] if ctx.attr.opt_link_flags else []),
- with_features = [with_feature_set(features = ["opt"])],
+ with_features = [with_feature_set(features = ["opt", "default_opt_level_flags"])],
),
],
)
@@ -1255,6 +1260,7 @@ def _impl(ctx):
strip_debug_symbols_feature,
coverage_feature,
supports_pic_feature,
+ default_opt_level_flags_feature,
] + (
[
supports_start_end_lib_feature,
@@ -1276,6 +1282,7 @@ def _impl(ctx):
else:
features = [
supports_pic_feature,
+ default_opt_level_flags_feature,
] + (
[
supports_start_end_lib_feature,
@@ -1294,6 +1301,17 @@ def _impl(ctx):
unfiltered_compile_flags_feature,
] + layering_check_features(ctx.attr.compiler)
+ features = pl_toolchain_pre_features(ctx) + features + pl_toolchain_post_features(ctx)
+
+ sysroot_path = ctx.attr.builtin_sysroot
+ # Only override with toolchain sysroot if this cc_toolchain is configured to use a sysroot
+ # (i.e., builtin_sysroot is non-empty). This prevents exec toolchains from incorrectly
+ # inheriting the target sysroot.
+ if sysroot_path:
+ sysroot_toolchain = ctx.toolchains["@px//bazel/cc_toolchains/sysroots/build:toolchain_type"]
+ if sysroot_toolchain:
+ sysroot_path = sysroot_toolchain.sysroot.path
+
return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
features = features,
@@ -1308,7 +1322,7 @@ def _impl(ctx):
abi_version = ctx.attr.abi_version,
abi_libc_version = ctx.attr.abi_libc_version,
tool_paths = tool_paths,
- builtin_sysroot = ctx.attr.builtin_sysroot,
+ builtin_sysroot = sysroot_path,
)
cc_toolchain_config = rule(
@@ -1336,5 +1350,8 @@ cc_toolchain_config = rule(
"coverage_link_flags": attr.string_list(),
"supports_start_end_lib": attr.bool(),
"builtin_sysroot": attr.string(),
- },
+ } | PL_EXTRA_CC_CONFIG_ATTRS,
provides = [CcToolchainConfigInfo],
+ toolchains = [
+ config_common.toolchain_type("@px//bazel/cc_toolchains/sysroots/build:toolchain_type", mandatory = False),
+ ],
)