commit | fc057d2b154d4aba4a9ad2128dd41ea4252e0e6e | [log] [tgz] |
---|---|---|
author | PikachuHy <pikachuhy@linux.alibaba.com> | Fri Aug 30 01:47:30 2024 -0700 |
committer | Copybara-Service <copybara-worker@google.com> | Fri Aug 30 01:48:57 2024 -0700 |
tree | 42ffd35f33b5dd22329d0f762c17651819be07ff | |
parent | 63c23630f0752772fa2e160bf39c74a2e8f36285 [diff] |
[3/5] support C++20 Modules, add deps-scanner and update toolchains ## Summary I have splited the XXL PR [#19940](https://github.com/bazelbuild/bazel/pull/19940) into several smaller patches. This is the third patch to support C++20 Modules, which adds the `deps-scanner` tool and updates toolchains. This patch includes: 1. New action names 2. File extensions 3. Build variables 4. Updated toolchains for compiling C++20 Modules ## Action Names Three action names have been added: - `c++-module-deps-scanning` - `c++20-module-compile` - `c++20-module-codegen` When two-phase compilation is employed: - `c++-module-deps-scanning`: Scans source files and retrieves C++20 Modules dependencies, storing them in `<filename>.ddi`. - `c++20-module-compile`: Compiles the C++20 Modules Interfaces to a Built Module Interface (BMI), converting `<filename>.cppm` to `<filename>.pcm`. - `c++20-module-codegen`: Compiles the BMI to an object file, converting `<filename>.pcm` to `<filename>.o`. When one-phase compilation is employed: - `c++-module-deps-scanning`: Operates similarly to two-phase compilation. - `c++20-module-compile`: Compiles the C++20 Modules Interfaces directly to an object file `<filename>.o` and produces a BMI `<filename>.pcm` as a byproduct. ## File Extensions We follow the file extensions preferred by different compilers, adding two new `ArtifactCategory`s: `CPP_MODULE_GCM` and `CPP_MODULE_IFC`. - Clang uses `.pcm` (CPP_MODULE, already exists). - GCC uses `.gcm` (CPP_MODULE_GCM, new). - MSVC uses `.ifc` (CPP_MODULE_IFC, new). Following the CMake implementation, we added three extra `ArtifactCategory`s: `CPP_MODULES_INFO`, `CPP_MODULES_DDI`, and `CPP_MODULES_MODMAP`. - The `.ddi` file (CPP_MODULES_DDI) stores the dependencies information of one source file. - The `.CXXModules.json` file (CPP_MODULES_INFO) stores dependencies information for an entire target. - The `.modmap` file (CPP_MODULES_MODMAP) maps module names to BMIs, with different formats for each compiler. Additionally, a special `ArtifactCategory`, `CPP_MODULES_MODMAP_INPUT`, is an auxiliary file used to easily obtain the requested BMI paths. ## Build Variables Two build variables, `CPP_MODULE_MODMAP_FILE` and `CPP_MODULE_OUTPUT_FILE`, have been added. - `CPP_MODULE_MODMAP_FILE` specifies the path to the `.modmap` file and is used by the `cpp20_modmap_file_feature`. - `CPP_MODULE_OUTPUT_FILE` specifies the output name of the BMI when one-phase compilation is employed and is used by the `cpp20_module_compile_flags_feature`. ## Toolchains Three action configs (`cpp_module_scan_deps`, `cpp20_module_compile`, and `cpp20_module_codegen`) have been added, corresponding to the action names section. Two features (`cpp_module_modmap_file_feature` and `cpp20_module_compile_flags_feature`) have been added, corresponding to the build variables section. Using C++20 Modules necessitates topological ordering for the compilation units. For more details, see the [Discovering Dependencies](https://clang.llvm.org/docs/StandardCPlusPlusModules.html#discovering-dependencies) section. Considering the various compilers, I have added the `deps-scanner` tool. The default implementation is a script wrapper that uses different scanning methods depending on the compiler. The wrapper `deps_scanner_wrapper` is generated by a template file `<compiler>_deps_scanner_wrapper.sh.tpl`. Three template files have been added: - `clang_deps_scanner_wrapper.sh.tpl` - `gcc_deps_scanner_wrapper.sh.tpl` - `mvsc_deps_scanner_wrapper.bat.tpl` For a demonstration of how to scan C++20 dependencies, please refer to this [demo](https://github.com/PikachuHyA/cpp20_modules_scan_dependency_demo). Closes #22429. PiperOrigin-RevId: 669241384 Change-Id: Id9ee2f66cb075446d0c38e6a6c70786ad9b28022
{Fast, Correct} - Choose two
Build and test software of any size, quickly and reliably.
Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.
One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.
Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.
Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.
Follow our tutorials:
To report a security issue, please email security@bazel.build with a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue. Our vulnerability management team will respond within 3 working days of your email. If the issue is confirmed as a vulnerability, we will open a Security Advisory. This project follows a 90 day disclosure timeline.
See CONTRIBUTING.md