← Back to Pull requests

Add rule-based args for C++20 modules #927

Closed
AustinSchuh closed this pull request without merging on Oct 28, 2026 13:20 UTC
View on GitHub
AustinSchuh AustinSchuh commented on Oct 06, 2026 05:29 UTC
Author

#750 added the C++20 module actions and variables to the rule-based toolchain API, but no args that use them, so every rule-based toolchain that builds modules writes its own. unix_cc_toolchain_config has them as features, and this brings rule-based toolchains up to parity.

Add //cc/toolchains/args/cpp_modules, with the cpp_modules feature Bazel requires before it builds module interfaces, and the clang args: the module map file, -x c++-module and -fmodule-output. Name the dependency scanner's output file in compiler_output_flags, where unix_cc_toolchain_config does. The args only apply to the module actions, so they join the legacy action config features; toolchains that map tools for those actions list cpp_modules as a known feature.

Tested with goldens in legacy_features_as_args, which match the features of the same names in unix_cc_toolchain_config. End to end, toolchains_llvm's rule-based darwin toolchain builds and runs C++20 module tests with these args.

Diff: 294 lines (+293 / -1) across 8 files Reviewer: fmeum Review duration: 32151m
All Vouch review confidence checks passed
Residual risk 0.10 = Change Risk (0.47) × (1 − Review Confidence (0.79)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 294 lines diff across 8 files
0.47
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.76 · 4 substantive comment(s)
0.76
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
78%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.340
Real PR Conversation Timeline
9 items
fmeum fmeum approved these changes on Oct 06, 2026 06:23 UTC
Approved Reviewer

Approved these changes.

keith keith commented on code on Oct 06, 2026 16:12 UTC
Code Review
cc/toolchains/args/cpp_modules/BUILD:1
@@ -0,0 +1,80 @@
+load("//cc/toolchains:args.bzl", "cc_args")
+load("//cc/toolchains:feature.bzl", "cc_feature")
+load("//cc/toolchains:feature_set.bzl", "cc_feature_set")
+
+# The args C++20 modules need from a clang toolchain, matching
+# unix_cc_toolchain_config. Bazel builds module interfaces only once the
+# toolchain knows the `cpp_modules` feature and the build enables it, so
+# toolchains that map tools for the C++20 module actions should list
+# `:cpp_modules` in their known features and `:feature` in their enabled ones.
+
+package(default_visibility = ["//visibility:public"])
+
+cc_feature(
+    name = "cpp_modules",
+    feature_name = "cpp_modules",
+)
+
+cc_feature_set(
+    name = "feature",
+    all_of = [
+        ":cpp_module_modmap_file",
+        ":cpp20_module_compile_flags",
+    ],
+)
+
+# The module map file names the BMI of each module a source imports.
+cc_feature(
+    name = "cpp_module_modmap_file",
+    args = [":modmap_file_args"],
+    feature_name = "cpp_module_modmap_file",
+)
+
+cc_args(
+    name = "modmap_file_args",
+    actions = [
+        "//cc/toolchains/actions:cpp_compile",
+        "//cc/toolchains/actions:cpp20_module_compile",
+        "//cc/toolchains/actions:cpp20_module_codegen",
+    ],
+    args = ["@{cpp_module_modmap_file}"],
+    format = {"cpp_module_modmap_file": "//cc/toolchains/variables:cpp_module_modmap_file"},
+    requires_not_none = "//cc/toolchains/variables:cpp_module_modmap_file",
+    visibility = ["//visibility:private"],
+)
+
+# A module interface unit compiles as one, and writes its BMI where Bazel
+# declared it.
+cc_feature(
+    name = "cpp20_module_compile_flags",
+    args = [
+        ":module_interface_args",
+        ":module_output_args",
+    ],
+    feature_name = "cpp20_module_compile_flags",
+)
+
+cc_args(
+    name = "module_interface_args",
+    actions = ["//cc/toolchains/actions:cpp20_module_compile"],
+    args = [
+        "-x",
+        "c++-module",

i think these args would be after the input arg above, is that a problem? I know for header parsing this has to be first

keith keith commented on code on Oct 06, 2026 16:13 UTC
Code Review
tests/rule_based_toolchain/legacy_features_as_args/BUILD:1
@@ -155,3 +158,27 @@ compare_cc_feature_implementation(
     expected = _WINDOWS_THIN_LTO,
     platform = ":windows",
 )
+
+# C++20 modules. Bazel's CppActionConfigs.java predates them, so these goldens
+# match the features of the same names in unix_cc_toolchain_config.
+
+compare_cc_feature_implementation(
+    name = "cpp_module_modmap_file_unix_test",
+    actual_implementation = "//cc/toolchains/args/cpp_modules:cpp_module_modmap_file",
+    expected = _UNIX_CPP_MODULE_MODMAP_FILE,
+    platform = ":linux",
+)
+
+compare_cc_feature_implementation(
+    name = "cpp20_module_compile_flags_unix_test",
+    actual_implementation = "//cc/toolchains/args/cpp_modules:cpp20_module_compile_flags",
+    expected = _UNIX_CPP20_MODULE_COMPILE_FLAGS,
+    platform = ":linux",
+)

should this be against the 1 feature instead of these separately?

AustinSchuh AustinSchuh commented on code on Oct 07, 2026 07:17 UTC
Code Review
tests/rule_based_toolchain/legacy_features_as_args/BUILD:1
@@ -155,3 +158,27 @@ compare_cc_feature_implementation(
     expected = _WINDOWS_THIN_LTO,
     platform = ":windows",
 )
+
+# C++20 modules. Bazel's CppActionConfigs.java predates them, so these goldens
+# match the features of the same names in unix_cc_toolchain_config.
+
+compare_cc_feature_implementation(
+    name = "cpp_module_modmap_file_unix_test",
+    actual_implementation = "//cc/toolchains/args/cpp_modules:cpp_module_modmap_file",
+    expected = _UNIX_CPP_MODULE_MODMAP_FILE,
+    platform = ":linux",
+)
+
+compare_cc_feature_implementation(
+    name = "cpp20_module_compile_flags_unix_test",
+    actual_implementation = "//cc/toolchains/args/cpp_modules:cpp20_module_compile_flags",
+    expected = _UNIX_CPP20_MODULE_COMPILE_FLAGS,
+    platform = ":linux",
+)

Sure, done!

AustinSchuh AustinSchuh commented on code on Oct 07, 2026 07:17 UTC
Code Review
cc/toolchains/args/cpp_modules/BUILD:1
@@ -0,0 +1,80 @@
+load("//cc/toolchains:args.bzl", "cc_args")
+load("//cc/toolchains:feature.bzl", "cc_feature")
+load("//cc/toolchains:feature_set.bzl", "cc_feature_set")
+
+# The args C++20 modules need from a clang toolchain, matching
+# unix_cc_toolchain_config. Bazel builds module interfaces only once the
+# toolchain knows the `cpp_modules` feature and the build enables it, so
+# toolchains that map tools for the C++20 module actions should list
+# `:cpp_modules` in their known features and `:feature` in their enabled ones.
+
+package(default_visibility = ["//visibility:public"])
+
+cc_feature(
+    name = "cpp_modules",
+    feature_name = "cpp_modules",
+)
+
+cc_feature_set(
+    name = "feature",
+    all_of = [
+        ":cpp_module_modmap_file",
+        ":cpp20_module_compile_flags",
+    ],
+)
+
+# The module map file names the BMI of each module a source imports.
+cc_feature(
+    name = "cpp_module_modmap_file",
+    args = [":modmap_file_args"],
+    feature_name = "cpp_module_modmap_file",
+)
+
+cc_args(
+    name = "modmap_file_args",
+    actions = [
+        "//cc/toolchains/actions:cpp_compile",
+        "//cc/toolchains/actions:cpp20_module_compile",
+        "//cc/toolchains/actions:cpp20_module_codegen",
+    ],
+    args = ["@{cpp_module_modmap_file}"],
+    format = {"cpp_module_modmap_file": "//cc/toolchains/variables:cpp_module_modmap_file"},
+    requires_not_none = "//cc/toolchains/variables:cpp_module_modmap_file",
+    visibility = ["//visibility:private"],
+)
+
+# A module interface unit compiles as one, and writes its BMI where Bazel
+# declared it.
+cc_feature(
+    name = "cpp20_module_compile_flags",
+    args = [
+        ":module_interface_args",
+        ":module_output_args",
+    ],
+    feature_name = "cpp20_module_compile_flags",
+)
+
+cc_args(
+    name = "module_interface_args",
+    actions = ["//cc/toolchains/actions:cpp20_module_compile"],
+    args = [
+        "-x",
+        "c++-module",

Good catch. -x only applies to later inputs: after the source, a .cc interface writes no BMI and a .cppm one only works by extension, with an unused-argument warning. It's now emitted with the source in compiler_input_flags (-x c++-module -c <source>), the way thin_lto does -x ir, so feature order can't break it.

keith keith approved these changes on Oct 07, 2026 18:53 UTC
Approved Reviewer

Approved these changes.

lilygorsheneva lilygorsheneva approved these changes on Oct 21, 2026 22:31 UTC
Approved Reviewer

Approved these changes.

pzembrod pzembrod approved these changes on Oct 27, 2026 09:46 UTC
Approved Reviewer

Approved these changes.

Reviewers
Assignees
AustinSchuh AustinSchuh
Labels
risk: low confidence: 79.0% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 47.3% (MEDIUM) · Higher = larger blast radius
47.3%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 79.0% · Lower = rushed or shallow review
79.0%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 10.0% · Safe to merge
10.0%