Skip to content

Commit 460d4a1

Browse files
committed
[1] Support C++20 modules in the rules-based toolchain API
The rules-based cc/toolchains toolchain API was missing several pieces needed to drive Bazel's C++20 modules pipeline (clang-scan-deps -> .ddi -> aggregate-ddi -> generate-modmap -> module compile): - Add a cpp20_module_actions action type set grouping the module interface compile, codegen and dependency scanning actions. These are deliberately kept out of compile_actions/source_compile_actions so that flags incompatible with C++20 modules can keep targeting only the non-module compiles. - Register the cpp_module_output_file and cpp_module_modmap_file build variables and make dependency_file, output_file, source_file and user_compile_flags available to the C++20 module actions. - Extend the legacy compile features (compiler_input_flags, compiler_output_flags, dependency_file, user_compile_flags) to the C++20 module actions, so the generic -c / -o / -MD -MF / user-copt flags are emitted for module interface compile, codegen and dependency scanning the same way they are for ordinary compiles. Toolchains that use these features then need no module-specific source/output/dependency/copt args of their own. - Include the C++20 module actions in the compiler_files legacy file group so their tools (e.g. the dependency scanner) are available to the compile actions. The C++20 modules pipeline lives only in rules_cc's compile.bzl (Bazel's native rules do not implement it), and was previously untested here: Bazel's CppModulesConfiguredTargetTest only checks the --experimental_cpp_modules / cpp_modules gating, and the shell integration test self-skips unless a host clang >= 17 is present. Add an analysis test that drives the module interface compile + dependency scanning actions with a mock toolchain (no real compiler needed) and asserts the scanning action emits both the P1689 .ddi file and the Make-style .ddi.d dependency file. This test fails without the fixes in the preceding commit.
1 parent 69561f1 commit 460d4a1

7 files changed

Lines changed: 59 additions & 7 deletions

File tree

cc/toolchains/actions/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ cc_action_type_set(
272272
],
273273
)
274274

275+
cc_action_type_set(
276+
name = "cpp20_module_actions",
277+
actions = [
278+
":cpp20_module_compile",
279+
":cpp20_module_codegen",
280+
":cpp_module_deps_scanning",
281+
],
282+
)
283+
275284
cc_action_type_set(
276285
name = "compile_actions_without_header_parsing",
277286
actions = [

cc/toolchains/args/compile_flags/BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ cc_feature(
3737

3838
cc_args(
3939
name = "user_compile_flags",
40-
actions = ["//cc/toolchains/actions:compile_actions"],
40+
actions = [
41+
"//cc/toolchains/actions:compile_actions",
42+
"//cc/toolchains/actions:cpp20_module_actions",
43+
],
4144
args = ["{user_compile_flags}"],
4245
format = {"user_compile_flags": "//cc/toolchains/variables:user_compile_flags"},
4346
iterate_over = "//cc/toolchains/variables:user_compile_flags",

cc/toolchains/args/compiler_input_flags/BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ cc_feature(
1313

1414
cc_args(
1515
name = "flags",
16-
actions = ["//cc/toolchains/actions:compile_actions_without_header_parsing"],
16+
actions = [
17+
"//cc/toolchains/actions:compile_actions_without_header_parsing",
18+
"//cc/toolchains/actions:cpp20_module_actions",
19+
],
1720
args = [
1821
"-c",
1922
"{source_file}",

cc/toolchains/args/compiler_output_flags/BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ cc_args(
3434

3535
cc_args(
3636
name = "output_flags",
37-
actions = ["//cc/toolchains/actions:compile_actions"],
37+
actions = [
38+
"//cc/toolchains/actions:compile_actions",
39+
"//cc/toolchains/actions:cpp20_module_actions",
40+
],
3841
args = [
3942
"-o",
4043
"{output_file}",

cc/toolchains/args/dependency_file/BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ cc_feature(
1010

1111
cc_args(
1212
name = "flags",
13-
actions = ["//cc/toolchains/actions:compile_actions"],
13+
actions = [
14+
"//cc/toolchains/actions:compile_actions",
15+
"//cc/toolchains/actions:cpp20_module_actions",
16+
],
1417
args = [
1518
"-MD",
1619
"-MF",

cc/toolchains/legacy_file_group.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ LEGACY_FILE_GROUPS = {
2828
Label("//cc/toolchains/actions:c_compile"),
2929
Label("//cc/toolchains/actions:cpp_compile"),
3030
Label("//cc/toolchains/actions:cpp_header_parsing"),
31+
Label("//cc/toolchains/actions:cpp20_module_compile"),
32+
Label("//cc/toolchains/actions:cpp20_module_codegen"),
33+
Label("//cc/toolchains/actions:cpp_module_deps_scanning"),
3134
],
3235
# There are no actions listed for coverage and objcopy in action_names.bzl.
3336
"coverage_files": [],

cc/toolchains/variables/BUILD

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ load("//cc/toolchains/impl:variables.bzl", "cc_builtin_variables", "cc_variable"
22

33
package(default_visibility = ["//visibility:public"])
44

5+
cc_variable(
6+
name = "cpp_module_modmap_file",
7+
actions = [
8+
"//cc/toolchains/actions:cpp_compile",
9+
"//cc/toolchains/actions:cpp20_module_compile",
10+
"//cc/toolchains/actions:cpp20_module_codegen",
11+
],
12+
type = types.option(types.file),
13+
)
14+
15+
cc_variable(
16+
name = "cpp_module_output_file",
17+
actions = ["//cc/toolchains/actions:cpp20_module_compile"],
18+
type = types.option(types.file),
19+
)
20+
521
cc_variable(
622
name = "cs_fdo_instrument_path",
723
actions = [
@@ -19,7 +35,10 @@ cc_variable(
1935

2036
cc_variable(
2137
name = "dependency_file",
22-
actions = ["//cc/toolchains/actions:compile_actions"],
38+
actions = [
39+
"//cc/toolchains/actions:compile_actions",
40+
"//cc/toolchains/actions:cpp20_module_actions",
41+
],
2342
type = types.option(types.file),
2443
)
2544

@@ -424,6 +443,7 @@ cc_variable(
424443
name = "output_file",
425444
actions = [
426445
"//cc/toolchains/actions:compile_actions",
446+
"//cc/toolchains/actions:cpp20_module_actions",
427447
"//cc/toolchains/actions:strip",
428448
],
429449
type = types.option(types.file),
@@ -485,7 +505,10 @@ cc_variable(
485505

486506
cc_variable(
487507
name = "source_file",
488-
actions = ["//cc/toolchains/actions:compile_actions"],
508+
actions = [
509+
"//cc/toolchains/actions:compile_actions",
510+
"//cc/toolchains/actions:cpp20_module_actions",
511+
],
489512
type = types.option(types.file),
490513
)
491514

@@ -566,7 +589,10 @@ cc_variable(
566589

567590
cc_variable(
568591
name = "user_compile_flags",
569-
actions = ["//cc/toolchains/actions:compile_actions"],
592+
actions = [
593+
"//cc/toolchains/actions:compile_actions",
594+
"//cc/toolchains/actions:cpp20_module_actions",
595+
],
570596
type = types.option(types.list(types.string)),
571597
)
572598

@@ -581,6 +607,8 @@ cc_builtin_variables(
581607
srcs = [
582608
":attr_linkopts",
583609
":cc_library_exec_paths",
610+
":cpp_module_modmap_file",
611+
":cpp_module_output_file",
584612
":cs_fdo_instrument_path",
585613
":def_file_path",
586614
":dep_linkopts",

0 commit comments

Comments
 (0)