https://github.com/rnburn/rules_cc_module
Rules for using C++20 modules with bazel
https://github.com/rnburn/rules_cc_module
bazel bazel-rules cpp20 modules
Last synced: 4 days ago
JSON representation
Rules for using C++20 modules with bazel
- Host: GitHub
- URL: https://github.com/rnburn/rules_cc_module
- Owner: rnburn
- License: apache-2.0
- Created: 2021-03-02T03:52:02.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-13T07:22:04.000Z (over 3 years ago)
- Last Synced: 2023-07-31T17:25:39.572Z (almost 2 years ago)
- Topics: bazel, bazel-rules, cpp20, modules
- Language: Starlark
- Homepage:
- Size: 127 KB
- Stars: 36
- Watchers: 6
- Forks: 5
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rules_cc_module
Rules to use C++20 modules with Bazel.
## Getting started
Note: Currently only works with a recent version of clang.
Build a simple module:
```bazel
cc_module(
name = "Hello",
src = "say_hello.cc", # say_hello exports the module Hello
)# Build a binary with the module
cc_module_binary(
name = "a.out",
srcs = [
"main.cc", # We can import Hello in main.cc
],
deps = [
":Hello",
],
)
```Build a module with implementation units:
```bazel
cc_module_binary(
name = "speech",
src = "speech.cc", # speech.cc exports the module speech
impl_srcs = [
"speech_impl.cc", # speech_impl.cc provides implements (but doesn't export) speech
],
)
```Interoperate with regular cc libraries
```bazel
cc_module(
name = "a",
src = "a.cc",
)cc_module_library(
name = "b",
hdrs = [
"b.h",
],
srcs = [
"b.cc", # b can import module a, but shouldn't export a module
],
deps = [
":a",
],
)# We can use b with regular cc rules
cc_binary(
name = "a.out",
srcs = [
"main.cc",
],
deps = [
":b",
],
)
```## Documentation
[How to Use C++20 Modules with Bazel](https://buildingblock.ai/cpp20-modules-bazel)## Examples
The directory [example](https://github.com/rnburn/bazel-cpp20-modules/tree/main/example) demonstrates
usage and there is a docker image that provides a build environment. To build the examples,
run
```
./ci/run_docker.sh # spins up a build environment
bazel build //example/... # build the examples
```