Skip to content

Commit 45278c5

Browse files
committed
Add feature injection
Add feature injection to toolchain gcc extension. This option will allow users to add external defined features.
1 parent 332c9c9 commit 45278c5

14 files changed

Lines changed: 133 additions & 368 deletions

docs/examples_and_validation.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ platforms.
4545
`examples/BUILD`
4646

4747
Contains small C++ targets used to verify compilation, linking, pthread
48-
support, and sanitizer integration.
48+
support, and optional sanitizer integration when sanitizer features are
49+
registered explicitly.
4950

5051
`examples/test.sh`
5152

@@ -85,4 +86,12 @@ In practice this means checking among other things:
8586
- correct toolchain registration and platform matching,
8687
- basic linking behavior,
8788
- feature coverage such as pthread-enabled builds,
88-
- optional sanitizer feature wiring for the local Linux toolchain path.
89+
- optional sanitizer feature wiring for the local Linux toolchain path.
90+
91+
## Sanitizer Note
92+
93+
Sanitizer features are not included by default by the generated toolchains.
94+
If a workspace wants to use targets such as `asan_test`, it must first
95+
register the sanitizer `cc_feature` definitions explicitly, for example via
96+
`extra_known_features` or `extra_enabled_features` when declaring the
97+
toolchain and by providing the feature definitions from `score_cpp_policies`.

docs/extension_api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ Flag and runtime attributes:
7272
- `extra_c_compile_flags`
7373
- `extra_cxx_compile_flags`
7474
- `extra_link_flags`
75+
- `extra_known_features`
76+
- `extra_enabled_features`
7577
- `ld_library_paths`
7678
- `runtime_ecosystem`
7779
- `use_base_constraints_only`
@@ -112,5 +114,9 @@ configurations for this activation step.
112114
- The extension is intended for the root module.
113115
- When `use_default_package` is enabled, the version matrix can inject extra
114116
include and link flags required by non-standard sysroot layouts.
117+
- Sanitizer features are not registered automatically. Workspaces that want
118+
sanitizer support must provide the relevant rule-based `cc_feature`
119+
definitions explicitly, typically from `score_cpp_policies`, through
120+
`extra_known_features` or `extra_enabled_features`.
115121
- QNX toolchains use additional licensing and include-path parameters that do
116122
not apply to Linux toolchains.

examples/BUILD

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -51,57 +51,3 @@ cc_test(
5151
linkstatic = False,
5252
deps = [":math_lib"],
5353
)
54-
55-
cc_test(
56-
name = "asan_test",
57-
srcs = ["asan_test.cpp"],
58-
features = ["asan"],
59-
deps = [
60-
"@googletest//:gtest",
61-
"@googletest//:gtest_main",
62-
],
63-
)
64-
65-
# for some reason this test is very flaky.
66-
# cc_test(
67-
# name = "tsan_test",
68-
# srcs = ["tsan_test.cpp"],
69-
# features = ["tsan"],
70-
# env = {
71-
# "TSAN_OPTIONS": "halt_on_error=1",
72-
# },
73-
# deps = [
74-
# "@googletest//:gtest",
75-
# "@googletest//:gtest_main",
76-
# ],
77-
# )
78-
79-
cc_test(
80-
name = "ubsan_test",
81-
srcs = ["ubsan_test.cpp"],
82-
env = {
83-
"UBSAN_OPTIONS": "halt_on_error=1",
84-
},
85-
features = ["ubsan"],
86-
deps = [
87-
"@googletest//:gtest",
88-
"@googletest//:gtest_main",
89-
],
90-
)
91-
92-
cc_test(
93-
name = "lsan_test",
94-
srcs = ["lsan_test.cpp"],
95-
env = {
96-
"ASAN_OPTIONS": "detect_leaks=1",
97-
"LSAN_OPTIONS": "exitcode=23",
98-
},
99-
features = [
100-
"lsan",
101-
"asan",
102-
],
103-
deps = [
104-
"@googletest//:gtest",
105-
"@googletest//:gtest_main",
106-
],
107-
)

examples/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ bazel_dep(name = "score_bazel_platforms", version = "0.1.2")
3030
# *******************************************************************************
3131
# C++ Rules for Bazel
3232
# *******************************************************************************
33-
bazel_dep(name = "rules_cc", version = "0.2.14")
33+
bazel_dep(name = "rules_cc", version = "0.2.17")
3434
bazel_dep(name = "googletest", version = "1.17.0")
3535

3636
# *******************************************************************************

examples/MODULE.bazel.lock

Lines changed: 21 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ The toolchain configurations are defined in:
1010

1111
## Building Targets
1212

13+
## Sanitizer Feature Registration
14+
15+
Sanitizer features are no longer included by default by the example toolchain
16+
declarations. Targets that request features such as `score_asan` require the
17+
workspace to register those feature definitions explicitly, for example from
18+
`score_cpp_policies` via `extra_known_features` or `extra_enabled_features` on
19+
the corresponding `gcc.toolchain(...)` declaration.
20+
21+
Without that explicit registration, sanitizer-specific example targets are not
22+
expected to build.
23+
1324
### Default Toolchain
1425

1526
Build a specific target with the default toolchain:

examples/asan_test.cpp

Lines changed: 0 additions & 36 deletions
This file was deleted.

examples/lsan_test.cpp

Lines changed: 0 additions & 31 deletions
This file was deleted.

examples/tsan_test.cpp

Lines changed: 0 additions & 40 deletions
This file was deleted.

extensions/gcc.bzl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ _attrs_tc = {
6868
default = [],
6969
doc = "List of additional flags to be passed to linker.",
7070
),
71+
"extra_enabled_features": attr.label_list(
72+
mandatory = False,
73+
doc = ("Extra `cc_feature` features to add to this toolchain in an initially " +
74+
"enabled state. This attribute has limited integration with `cc_feature`, " +
75+
"and does not run additional correctness checks or handle things like `data` " +
76+
"files. This is only offered as a migration bridge for projects transitioning " +
77+
"to rule-based toolchain configurations, or sharing of simple argument sets " +
78+
"with older toolchains."),
79+
),
80+
"extra_known_features": attr.label_list(
81+
mandatory = False,
82+
doc = ("Extra `cc_feature` features to add to this toolchain in an initially " +
83+
"disabled state. This attribute has limited integration with `cc_feature`, " +
84+
"and does not run additional correctness checks or handle things like `data` " +
85+
"files. This is only offered as a migration bridge for projects transitioning " +
86+
"to rule-based toolchain configurations, or sharing of simple argument sets " +
87+
"with older toolchains."),
88+
),
7189
"license_info_url": attr.string(
7290
default = "",
7391
mandatory = False,
@@ -193,6 +211,8 @@ def _get_toolchains(tags):
193211
"tc_extra_compile_flags": tag.extra_compile_flags,
194212
"tc_extra_cxx_compile_flags": tag.extra_cxx_compile_flags,
195213
"tc_extra_link_flags": tag.extra_link_flags,
214+
"tc_extra_known_features": tag.extra_known_features,
215+
"tc_extra_enabled_features": tag.extra_enabled_features,
196216
"tc_license_info_url": tag.license_info_url,
197217
"tc_license_info_variable": tag.license_info_variable,
198218
"tc_license_path": tag.license_path,
@@ -333,6 +353,8 @@ def _impl(mctx):
333353
extra_compile_flags = toolchain_info["tc_extra_compile_flags"],
334354
extra_c_compile_flags = toolchain_info["tc_extra_c_compile_flags"],
335355
extra_cxx_compile_flags = toolchain_info["tc_extra_cxx_compile_flags"],
356+
extra_known_features = toolchain_info["tc_extra_known_features"],
357+
extra_enabled_features = toolchain_info["tc_extra_enabled_features"],
336358
extra_link_flags = toolchain_info["tc_extra_link_flags"],
337359
license_info_variable = toolchain_info["tc_license_info_variable"],
338360
license_info_value = toolchain_info["tc_license_info_url"],

0 commit comments

Comments
 (0)