Skip to content

Commit 041c5a9

Browse files
committed
add cc_feature for link flags, remove --linkopt and --test_tag_filters
1 parent 07a78d6 commit 041c5a9

6 files changed

Lines changed: 89 additions & 12 deletions

File tree

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ module(
1818

1919
bazel_dep(name = "bazel_skylib", version = "1.8.2")
2020
bazel_dep(name = "platforms", version = "0.0.10")
21+
bazel_dep(name = "rules_cc", version = "0.2.17")
2122

sanitizers/features/BUILD.bazel

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
load("@rules_cc//cc/toolchains:args.bzl", "cc_args")
15+
load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature")
16+
17+
# Link flags for ASan + UBSan + LSan combined
18+
cc_args(
19+
name = "asan_ubsan_lsan_link_args",
20+
actions = [
21+
"@rules_cc//cc/toolchains/actions:cpp_link_executable",
22+
"@rules_cc//cc/toolchains/actions:cpp_link_dynamic_library",
23+
"@rules_cc//cc/toolchains/actions:cpp_link_nodeps_dynamic_library",
24+
],
25+
args = [
26+
"-fsanitize=undefined,address,leak",
27+
"-fsanitize-link-c++-runtime",
28+
],
29+
visibility = ["//visibility:public"],
30+
)
31+
32+
cc_feature(
33+
name = "asan_ubsan_lsan_link",
34+
feature_name = "asan_ubsan_lsan_link",
35+
args = [":asan_ubsan_lsan_link_args"],
36+
visibility = ["//visibility:public"],
37+
)
38+
39+
# Link flags for ThreadSanitizer
40+
cc_args(
41+
name = "tsan_link_args",
42+
actions = [
43+
"@rules_cc//cc/toolchains/actions:cpp_link_executable",
44+
"@rules_cc//cc/toolchains/actions:cpp_link_dynamic_library",
45+
"@rules_cc//cc/toolchains/actions:cpp_link_nodeps_dynamic_library",
46+
],
47+
args = [
48+
"-fsanitize=thread",
49+
"-fsanitize-link-c++-runtime",
50+
],
51+
visibility = ["//visibility:public"],
52+
)
53+
54+
cc_feature(
55+
name = "tsan_link",
56+
feature_name = "tsan_link",
57+
args = [":tsan_link_args"],
58+
visibility = ["//visibility:public"],
59+
)

sanitizers/sanitizers.bazelrc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,26 @@ test:with_debug_symbols --strip=never
3232
build:asan_ubsan_lsan --features=asan
3333
build:asan_ubsan_lsan --features=ubsan
3434
build:asan_ubsan_lsan --features=lsan
35+
build:asan_ubsan_lsan --features=asan_ubsan_lsan_link
3536
build:asan_ubsan_lsan --platform_suffix=asan_ubsan_lsan
3637
test:asan_ubsan_lsan --config=with_debug_symbols
37-
test:asan_ubsan_lsan --test_tag_filters=-no-asan,-no-lsan,-no-ubsan
3838
test:asan_ubsan_lsan --@score_cpp_policies//sanitizers/flags:sanitizer=asan_ubsan_lsan
3939
test:asan_ubsan_lsan --run_under=@score_cpp_policies//sanitizers:wrapper
4040

4141
# AddressSanitizer only
4242
build:asan --config=asan_ubsan_lsan
43-
build:asan --test_tag_filters=-no-asan
4443

4544
# UndefinedBehaviorSanitizer only
4645
build:ubsan --config=asan_ubsan_lsan
47-
build:ubsan --test_tag_filters=-no-ubsan
4846

4947
# LeakSanitizer only
5048
build:lsan --config=asan_ubsan_lsan
51-
build:lsan --test_tag_filters=-no-lsan
5249

5350
# ThreadSanitizer (cannot be combined with ASan/LSan)
5451
build:tsan --features=tsan
52+
build:tsan --features=tsan_link
5553
build:tsan --platform_suffix=tsan
5654
test:tsan --config=with_debug_symbols
5755
test:tsan --cxxopt=-O1
58-
test:tsan --test_tag_filters=-no-tsan
5956
test:tsan --@score_cpp_policies//sanitizers/flags:sanitizer=tsan
6057
test:tsan --run_under=@score_cpp_policies//sanitizers:wrapper

tests/.bazelrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
# *******************************************************************************
1313

1414
# Import centralized sanitizer configurations
15-
# (includes --test_tag_filters for all configs)
1615
import %workspace%/../sanitizers/sanitizers.bazelrc
1716

1817
common --registry=https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/
1918
common --registry=https://bcr.bazel.build
19+
20+
# Use LLVM toolchain for sanitizer configs (same as consuming modules)
21+
build:asan_ubsan_lsan --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux
22+
build:tsan --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux

tests/BUILD.bazel

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test")
2020
cc_test(
2121
name = "sample_test",
2222
srcs = ["sample_test.cpp"],
23-
tags = ["no-tsan"], # TSAN has known issues with googletest
23+
target_compatible_with = ["@score_cpp_policies//sanitizers/constraints:no_tsan"], # TSAN has known issues with googletest
2424
deps = [
2525
"@googletest//:gtest",
2626
"@googletest//:gtest_main",
@@ -67,7 +67,7 @@ sh_test(
6767
"55",
6868
],
6969
data = [":asan_fail_test"],
70-
tags = ["no-tsan"],
70+
target_compatible_with = ["@score_cpp_policies//sanitizers/constraints:no_tsan"],
7171
)
7272

7373
sh_test(
@@ -78,7 +78,7 @@ sh_test(
7878
"55",
7979
],
8080
data = [":lsan_fail_test"],
81-
tags = ["no-tsan"],
81+
target_compatible_with = ["@score_cpp_policies//sanitizers/constraints:no_tsan"],
8282
)
8383

8484
sh_test(
@@ -89,7 +89,7 @@ sh_test(
8989
"55",
9090
],
9191
data = [":tsan_fail_test"],
92-
tags = ["no-asan", "no-lsan", "no-ubsan"],
92+
target_compatible_with = ["@score_cpp_policies//sanitizers/constraints:no_asan_ubsan_lsan"],
9393
)
9494

9595
sh_test(
@@ -100,6 +100,6 @@ sh_test(
100100
"55",
101101
],
102102
data = [":ubsan_fail_test"],
103-
tags = ["no-tsan"],
103+
target_compatible_with = ["@score_cpp_policies//sanitizers/constraints:no_tsan"],
104104
)
105105

tests/MODULE.bazel

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,27 @@ module(
1717
)
1818

1919
bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
20-
bazel_dep(name = "rules_cc", version = "0.2.16")
20+
bazel_dep(name = "rules_cc", version = "0.2.17")
21+
bazel_dep(name = "toolchains_llvm", version = "1.7.0")
22+
23+
git_override(
24+
module_name = "toolchains_llvm",
25+
commit = "576a587e4542733166ac1c3c4fb14c79c421332c",
26+
remote = "https://github.com/bazel-contrib/toolchains_llvm",
27+
)
2128

2229
bazel_dep(name = "score_cpp_policies", version = "")
2330
local_path_override(
2431
module_name = "score_cpp_policies",
2532
path = "..",
2633
)
34+
35+
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
36+
llvm.toolchain(
37+
llvm_version = "19.1.7",
38+
extra_known_features = [
39+
"@score_cpp_policies//sanitizers/features:asan_ubsan_lsan_link",
40+
"@score_cpp_policies//sanitizers/features:tsan_link",
41+
],
42+
)
43+
use_repo(llvm, "llvm_toolchain")

0 commit comments

Comments
 (0)