bazelbuild / bazelbuild/rules_cc
Add new `cc_preprocess` rule for preprocessing arbitrary files
- Dominant language
- Starlark
- Stars
- 247
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
Add a simple `cc_preprocess` rule that invokes the configured C/C++ compiler's preprocessor on an arbitrary input file.
This would be useful for generating files such as linker scripts, preprocessing Microsoft assembly files, or using the C preprocessor as a lightweight template engine. Using the configured C/C++ toolchain would also avoid having to manually determine the compiler-specific preprocessing flags.
Usage could look something like this:
```starlark
load("@rules_cc//cc:defs.bzl", "cc_preprocess")
cc_preprocess(
name = "linker_script",
input = "linker.ld.in",
output = "linker.ld",
copts = [],
defines = [
"HIGHERHALF_ADDRESS=0xFFFFFFFF80000000",
],
)
```
`defines` could alternatively be represented as a dictionary:
```starlark
defines = {
"HIGHERHALF_ADDRESS": "0xFFFFFFFF80000000",
}
```
However, an array such as `["HIGHERHALF_ADDRESS=..."]` may be simpler, since both MSVC and GNU-compatible compilers use essentially the same syntax for command-line preprocessor definitions.
The rule should handle translating its attributes into the appropriate compiler-specific flags and use the C/C++ toolchain selected for the target.
Having this functionality directly in `rules_cc` would be useful for projects that need standalone preprocessing and would avoid requiring users to implement or patch a custom preprocessing rule themselves.
Contributor guide
Research direction
The issue does not name a source file or test; begin by locating existing rules_cc rule implementations and the entry point for selecting the configured C/C++ toolchain. Done means a standalone rule accepts an input and output plus copts and defines, translates them for the selected compiler, and supports the described preprocessing use cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100