Skip to content

Support C++20 modules in the rules-based toolchain API#750

Open
fmeum wants to merge 1 commit into
bazelbuild:mainfrom
fmeum:fmeum/cpp20-modules-rules-based
Open

Support C++20 modules in the rules-based toolchain API#750
fmeum wants to merge 1 commit into
bazelbuild:mainfrom
fmeum:fmeum/cpp20-modules-rules-based

Conversation

@fmeum

@fmeum fmeum commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Add toolchain variables and and an action type set for C++20 module actions, allowing them to be configured in a rule-based toolchain.

@google-cla

google-cla Bot commented Jun 14, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@fmeum fmeum force-pushed the fmeum/cpp20-modules-rules-based branch 2 times, most recently from 1855ab6 to 2642dab Compare June 15, 2026 08:44
Comment thread cc/toolchains/actions/BUILD Outdated
Comment thread cc/private/compile/compile.bzl Outdated
Comment thread cc/toolchains/legacy_file_group.bzl Outdated
@fmeum fmeum force-pushed the fmeum/cpp20-modules-rules-based branch 2 times, most recently from ae97e7e to d9e66fb Compare June 26, 2026 20:32
@fmeum fmeum marked this pull request as ready for review June 26, 2026 20:33
@fmeum fmeum requested review from c-mita, pzembrod and trybka as code owners June 26, 2026 20:33
@fmeum

fmeum commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator Author

FYI @dzbarsky

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.
@fmeum fmeum force-pushed the fmeum/cpp20-modules-rules-based branch from d9e66fb to 460d4a1 Compare June 27, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant