Skip to content

Commit 77a857f

Browse files
committed
Improved bzlmod extension to better control registered toolchains
1 parent 92f81ee commit 77a857f

27 files changed

+2241
-1889
lines changed

.bazelci/config.yaml

+22-27
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,37 @@ tasks:
44
platform: ubuntu2004
55
build_targets:
66
- "//..."
7+
- "@rules_foreign_cc_toolchains//..."
78
test_targets:
89
- "//..."
910
rbe_ubuntu2004:
1011
platform: rbe_ubuntu2004
1112
build_targets:
1213
- "//..."
14+
- "@rules_foreign_cc_toolchains//..."
1315
test_targets:
1416
- "//..."
1517
macos:
1618
platform: macos
1719
build_targets:
1820
- "//..."
21+
- "@rules_foreign_cc_toolchains//..."
1922
test_targets:
2023
- "//..."
2124
windows:
2225
platform: windows
2326
build_targets:
2427
- "//..."
28+
- "@rules_foreign_cc_toolchains//..."
2529
test_targets:
2630
- "//..."
2731
# TODO: https://github.com/bazel-contrib/rules_foreign_cc/issues/495
2832
- "-//test:shell_method_symlink_contents_to_dir_test"
2933
- "-//test:shell_script_inner_fun_test"
3034
build_flags:
31-
- "--noenable_bzlmod"
32-
- "--enable_workspace"
35+
- "--config=no-bzlmod"
3336
test_flags:
34-
- "--noenable_bzlmod"
35-
- "--enable_workspace"
37+
- "--config=no-bzlmod"
3638
ubuntu1804_examples_standalone:
3739
name: Examples (spawn_strategy=standalone)
3840
platform: ubuntu1804
@@ -54,8 +56,8 @@ tasks:
5456
- "--spawn_strategy=standalone"
5557
- "--noenable_bzlmod"
5658
- "--enable_workspace"
57-
ubuntu2004_examples:
58-
name: Examples
59+
ubuntu2004_examples_no_bzlmod:
60+
name: Examples (No Bzlmod)
5961
platform: ubuntu2004
6062
working_directory: examples
6163
linux_targets: &linux_targets
@@ -64,13 +66,11 @@ tasks:
6466
build_targets: *linux_targets
6567
test_targets: *linux_targets
6668
build_flags:
67-
- "--noenable_bzlmod"
68-
- "--enable_workspace"
69+
- "--config=no-bzlmod"
6970
test_flags:
70-
- "--noenable_bzlmod"
71-
- "--enable_workspace"
72-
ubuntu2004_examples_bzlmod:
73-
name: Examples (bzlmod)
71+
- "--config=no-bzlmod"
72+
ubuntu2004_examples:
73+
name: Examples
7474
platform: ubuntu2004
7575
working_directory: examples
7676
linux_targets: &linux_targets_bzlmod
@@ -80,10 +80,7 @@ tasks:
8080
- "-//cmake_android/..."
8181
build_targets: *linux_targets_bzlmod
8282
test_targets: *linux_targets_bzlmod
83-
build_flags:
84-
- "--enable_bzlmod"
8583
rbe_ubuntu2004_examples:
86-
name: Examples
8784
platform: rbe_ubuntu2004
8885
working_directory: examples
8986
rbe_targets: &rbe_targets
@@ -95,6 +92,10 @@ tasks:
9592
- "-//:requirements_test"
9693
build_targets: *rbe_targets
9794
test_targets: *rbe_targets
95+
build_flags:
96+
- "--config=no-bzlmod"
97+
test_flags:
98+
- "--config=no-bzlmod"
9899
macos_examples_standalone:
99100
name: Examples (spawn_strategy=standalone)
100101
platform: macos
@@ -112,16 +113,14 @@ tasks:
112113
- "dbg"
113114
- "--spawn_strategy=standalone"
114115
- "--noincompatible_enable_cc_toolchain_resolution"
115-
- "--noenable_bzlmod"
116-
- "--enable_workspace"
116+
- "--config=no-bzlmod"
117117
test_targets: *macos_targets_standalone
118118
test_flags:
119119
- "-c"
120120
- "dbg"
121121
- "--spawn_strategy=standalone"
122122
- "--noincompatible_enable_cc_toolchain_resolution"
123-
- "--noenable_bzlmod"
124-
- "--enable_workspace"
123+
- "--config=no-bzlmod"
125124
macos_examples:
126125
name: Examples
127126
platform: macos
@@ -136,13 +135,11 @@ tasks:
136135
build_targets: *macos_targets
137136
build_flags:
138137
- "--noincompatible_enable_cc_toolchain_resolution"
139-
- "--noenable_bzlmod"
140-
- "--enable_workspace"
138+
- "--config=no-bzlmod"
141139
test_targets: *macos_targets
142140
test_flags:
143141
- "--noincompatible_enable_cc_toolchain_resolution"
144-
- "--noenable_bzlmod"
145-
- "--enable_workspace"
142+
- "--config=no-bzlmod"
146143
windows_examples:
147144
name: Examples
148145
platform: windows
@@ -172,11 +169,9 @@ tasks:
172169
build_targets: *windows_targets
173170
test_targets: *windows_targets
174171
build_flags:
175-
- "--noenable_bzlmod"
176-
- "--enable_workspace"
172+
- "--config=no-bzlmod"
177173
test_flags:
178-
- "--noenable_bzlmod"
179-
- "--enable_workspace"
174+
- "--config=no-bzlmod"
180175
rbe_ubuntu2004_flags:
181176
name: Flags
182177
platform: rbe_ubuntu2004

.bazelrc

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
###############################################################################
2+
## Bazel Configuration Flags
3+
##
4+
## `.bazelrc` is a Bazel configuration file.
5+
## https://bazel.build/docs/best-practices#bazelrc-file
6+
###############################################################################
7+
8+
# https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config
9+
common --enable_platform_specific_config
10+
11+
# Enable the only currently supported report type
12+
# https://bazel.build/reference/command-line-reference#flag--combined_report
13+
coverage --combined_report=lcov
14+
15+
# Avoid fully cached builds reporting no coverage and failing CI
16+
# https://bazel.build/reference/command-line-reference#flag--experimental_fetch_all_coverage_outputs
17+
coverage --experimental_fetch_all_coverage_outputs
18+
19+
# Required for some of the tests
20+
# https://bazel.build/reference/command-line-reference#flag--experimental_cc_shared_library
21+
common --experimental_cc_shared_library
22+
23+
###############################################################################
24+
## Incompatibility flags
25+
###############################################################################
26+
27+
# https://github.com/bazelbuild/bazel/issues/8195
28+
build --incompatible_disallow_empty_glob=true
29+
30+
# https://github.com/bazelbuild/bazel/issues/12821
31+
build --nolegacy_external_runfiles
32+
33+
# Required for cargo_build_script support before Bazel 7
34+
build --incompatible_merge_fixed_and_default_shell_env
35+
36+
###############################################################################
37+
## Bzlmod
38+
###############################################################################
39+
40+
# A configuration for disabling bzlmod.
41+
common:no-bzlmod --noenable_bzlmod --enable_workspace
42+
43+
# Disable the bzlmod lockfile, so we don't accidentally commit MODULE.bazel.lock
44+
common --lockfile_mode=off
45+
46+
###############################################################################
47+
## Custom user flags
48+
##
49+
## This should always be the last thing in the `.bazelrc` file to ensure
50+
## consistent behavior when setting flags in that file as `.bazelrc` files are
51+
## evaluated top to bottom.
52+
###############################################################################
53+
54+
try-import %workspace%/user.bazelrc

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ bazelci.py
8282
#####
8383
# Ignore all bazel-* symlinks. There is no full list since this can change
8484
# based on the name of the directory bazel is cloned into.
85+
user.bazelrc
8586
/bazel-*
8687
/docs/bazel-*
8788
/examples/bazel-*

MODULE.bazel

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"bazel-contrib/rules_foreign_cc"
1+
"""bazel-contrib/rules_foreign_cc"""
22

33
module(
44
name = "rules_foreign_cc",
@@ -26,26 +26,15 @@ python = use_extension("@rules_python//python/extensions:python.bzl", "python")
2626
python.toolchain(python_version = "3.9")
2727
use_repo(python, "python_3_9")
2828

29-
tools = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "tools")
29+
foreign_cc = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "foreign_cc")
3030
use_repo(
31-
tools,
32-
"cmake_3.23.2_toolchains",
33-
"cmake_src",
34-
"gettext_runtime",
35-
"glib_dev",
36-
"glib_src",
37-
"gnumake_src",
38-
"meson_src",
39-
"ninja_1.12.1_toolchains",
40-
"ninja_build_src",
41-
"pkgconfig_src",
31+
foreign_cc,
4232
"rules_foreign_cc_framework_toolchains",
33+
"rules_foreign_cc_toolchains",
4334
)
4435

4536
register_toolchains(
4637
"@rules_foreign_cc_framework_toolchains//:all",
47-
"@cmake_3.23.2_toolchains//:all",
48-
"@ninja_1.12.1_toolchains//:all",
38+
"@rules_foreign_cc_toolchains//:all",
4939
"@python_3_9//:all",
50-
"@rules_foreign_cc//toolchains:all",
5140
)

docs/BUILD.bazel

+8
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,21 @@ stardoc(
4545
deps = ["@rules_foreign_cc//foreign_cc:providers"],
4646
)
4747

48+
stardoc(
49+
name = "extensions_docs",
50+
out = "src/extensions.md",
51+
input = "@rules_foreign_cc//foreign_cc:extensions.bzl",
52+
deps = ["@rules_foreign_cc//foreign_cc:extensions"],
53+
)
54+
4855
DOCS_TARGETS = [
4956
":cmake_docs",
5057
":ninja_docs",
5158
":make_docs",
5259
":configure_make_docs",
5360
":meson_docs",
5461
":providers_docs",
62+
":extensions_docs",
5563
]
5664

5765
build_test(

0 commit comments

Comments
 (0)