Skip to content

Commit c78d5e9

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 c78d5e9

9 files changed

Lines changed: 134 additions & 288 deletions

File tree

examples/BUILD

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -52,56 +52,42 @@ cc_test(
5252
deps = [":math_lib"],
5353
)
5454

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-
)
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+
# )
6464

65-
# for some reason this test is very flaky.
6665
# cc_test(
67-
# name = "tsan_test",
68-
# srcs = ["tsan_test.cpp"],
69-
# features = ["tsan"],
66+
# name = "ubsan_test",
67+
# srcs = ["ubsan_test.cpp"],
7068
# env = {
71-
# "TSAN_OPTIONS": "halt_on_error=1",
69+
# "UBSAN_OPTIONS": "halt_on_error=1",
7270
# },
71+
# features = ["ubsan"],
7372
# deps = [
7473
# "@googletest//:gtest",
7574
# "@googletest//:gtest_main",
7675
# ],
7776
# )
7877

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-
)
78+
# cc_test(
79+
# name = "lsan_test",
80+
# srcs = ["lsan_test.cpp"],
81+
# env = {
82+
# "ASAN_OPTIONS": "detect_leaks=1",
83+
# "LSAN_OPTIONS": "exitcode=23",
84+
# },
85+
# features = [
86+
# "lsan",
87+
# "asan",
88+
# ],
89+
# deps = [
90+
# "@googletest//:gtest",
91+
# "@googletest//:gtest_main",
92+
# ],
93+
# )

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/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"],

rules/common.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,14 @@ def get_flag_group(flags):
4545
),
4646
]
4747
return []
48+
49+
def label_list_to_string(input_list):
50+
""" Small helper function to transform label list into string list
51+
52+
Args:
53+
input_list (list[labels]): A list of Bazel labels.
54+
55+
Return:
56+
str: Formated string
57+
"""
58+
return "[{}]".format(", ".join(["\"{}\"".format(item) for item in input_list]))

rules/gcc.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
""" Module rule for defining GCC toolchains in Bazel.
1515
"""
1616

17-
load("@score_bazel_cpp_toolchains//rules:common.bzl", "get_flag_groups")
17+
load("@score_bazel_cpp_toolchains//rules:common.bzl", "get_flag_groups", "label_list_to_string")
1818

1919
def dict_union(x, y):
2020
""" Helper function to merge 2 dict
@@ -53,12 +53,16 @@ cc_toolchain_config(
5353
sysroot = "@{tc_pkg_repo}//:sysroot_dir",
5454
target_cpu = "{tc_cpu}",
5555
target_os = "{tc_os}",
56+
extra_known_features = {tc_extra_known_features},
57+
extra_enabled_features = {tc_extra_enabled_features},
5658
visibility = ["//visibility:public"],
5759
)
5860
""".format(
5961
tc_pkg_repo = rctx.attr.tc_pkg_repo,
6062
tc_cpu = rctx.attr.tc_cpu,
6163
tc_os = rctx.attr.tc_os,
64+
tc_extra_known_features = label_list_to_string(rctx.attr.extra_known_features),
65+
tc_extra_enabled_features = label_list_to_string(rctx.attr.extra_enabled_features),
6266
)
6367

6468
def _get_cc_config_qnx(rctx):
@@ -244,6 +248,8 @@ gcc_toolchain = repository_rule(
244248
"extra_c_compile_flags": attr.string_list(doc = "Extra/Additional C-specific compile flags."),
245249
"extra_compile_flags": attr.string_list(doc = "Extra/Additional compile flags."),
246250
"extra_cxx_compile_flags": attr.string_list(doc = "Extra/Additional C++-specific compile flags."),
251+
"extra_known_features": attr.label_list(doc = "Extra/Additional C++ FeatureInfo provider list"),
252+
"extra_enabled_features": attr.label_list(doc = "Extra/Additional C++ FeatureInfo provider list enabled by default"),
247253
"extra_link_flags": attr.string_list(doc = "Extra/Additional link flags."),
248254
"gcc_version": attr.string(doc = "GCC version string"),
249255
"use_base_constraints_only": attr.bool(doc = "Boolean flag to state only base constraints should be used for toolchain compatibility definition"),

0 commit comments

Comments
 (0)