Support C++20 standard modules in the rules-based toolchain#654
Draft
fmeum wants to merge 1 commit into
Draft
Conversation
4891671 to
8da110f
Compare
Drive Bazel's C++20 modules pipeline (clang-scan-deps -> .ddi -> aggregate-ddi -> generate-modmap -> module compile) through the rules-based cc/toolchains API. Toolchain: - Add tools/internal/deps_scanner.c, a wrapper that runs `clang-scan-deps -format=p1689 -- clang++ <args>` and writes the P1689 JSON to DEPS_SCANNER_OUTPUT_FILE, mirroring the other internal tool wrappers. Wire it as the cpp_module_deps_scanning tool in both the prebuilt (toolchain/llvm/llvm.bzl) and bootstrap (toolchain/bootstrap/declare_toolchains.bzl) toolchains. - Add cc_args for the compiler-specific C++20 module flags only: module output (-fmodule-output), the modmap (@ModMap) and the dependency scanner output env. The generic -c / -o / -MD -MF / copt flags are emitted by rules_cc's legacy compile features, which #750 extends to the C++20 module actions, so every rules_cc toolchain benefits. Gate -fno-cxx-modules on the new cpp_modules feature being disabled. - Add the cpp_modules feature and extend sysroot / header search-path / resource-dir args to cover cpp20_module_actions. rules_cc currently requires bazelbuild/rules_cc PRs #750 (rules-based module build variables/actions, plus extending the legacy compile features -- compiler_input_flags, compiler_output_flags, dependency_file, user_compile_flags -- to the C++20 module actions) and #775 (compile.bzl analysis fix). Until a release ships them, they are applied to rules_cc 0.2.20 as checked-in patches (3rd_party/rules_cc) via single_version_override. The e2e/rules_cc module is a separate root module, so it carries its own single_version_override and symlinks the patch files from the parent. e2e: add //:cpp20_modules_test exercising an exported `math` module (math.cppm) imported by modules_main.cc, built with --features=cpp_modules and --experimental_cpp_modules.
f606dfd to
25ed393
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Drives Bazel's C++20 modules pipeline (
clang-scan-deps→.ddi→ aggregate-ddi → generate-modmap → module compile) through the rules-basedcc/toolchainsAPI.Toolchain
tools/internal/deps_scanner.c, a compiled wrapper that runsclang-scan-deps -format=p1689 -- clang++ <args>and writes the P1689 JSON toDEPS_SCANNER_OUTPUT_FILE, mirroring the other internal tool wrappers. Wire it as thecpp_module_deps_scanningtool in both the prebuilt (toolchain/llvm/llvm.bzl) and bootstrap (toolchain/bootstrap/declare_toolchains.bzl) toolchains.cc_argsfor the C++20 module actions: module output (-fmodule-output), modmap (@modmap), scanner output env, source/output flags, dependency file and user compile flags. Gate-fno-cxx-moduleson the newcpp_modulesfeature being disabled.cpp_modulesfeature and extend the sysroot / header search-path / resource-dir args to covercpp20_module_actions.rules_cc dependency
This currently requires two unreleased rules_cc PRs, applied to
rules_cc0.2.20 as checked-in patches (3rd_party/rules_cc) viasingle_version_override:cpp_module_output_file,cpp_module_modmap_file) and thecpp20_module_actionsaction set.cc/private/compile/compile.bzlanalysis fix.The
e2e/rules_ccmodule is a separate root module, so it carries its ownsingle_version_overrideand symlinks the patch files from the parent (single_version_overrideonly accepts main-repo patch labels).Draft because of the above: it should land once those PRs are merged and a
rules_ccrelease includes them, at which point the patches and overrides are dropped and therules_ccversion is bumped.e2e
Adds
//:cpp20_modules_testine2e/rules_cc, exercising an exportedmathmodule (math.cppm) imported bymodules_main.cc, built with--features=cpp_modulesand--experimental_cpp_modules. Passes on macOS arm64.🤖 Generated with Claude Code