bazelbuild / bazelbuild/rules_rust
rust_bindgen should pass opt-level flags to clang
- Dominant language
- Starlark
- Stars
- 843
- Forks
- 651
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 15
Description
**Description**
Currently, when running `clang`, `rust_bindgen` never passes a `-O` flag. In optimized builds (`-c opt`), it should pass the appropriate `-O` flag to match the C toolchain.
**Reproduction steps**
`bazel build -c opt` a `rust_bindgen` target and observe that the flags passed to clang do not include `-O`
**Impact**
The impact of this is minor, as the output is not a compiled C artifact but a Rust library, but in pathological cases the difference in optimization level could affect the output. Additionally, this has been found to lead to warnings around [`_FORTIFY_SOURCE`](https://developers.redhat.com/articles/2023/07/04/developers-guide-secure-coding-fortifysource) (`warning: _FORTIFY_SOURCE requires compiling with optimization (-O)`), though this is likely because of a mix of GCC and Clang headers being used 🙈.
**Bazel and rules_rust version**
```
bazel 9.1.0
bazel_dep(name = "rules_rust_bindgen", version = "0.74.0")
```
Contributor guide
Research direction
Start by locating the rust_bindgen code that assembles and passes flags to clang, then reproduce the issue with a rust_bindgen target using `bazel build -c opt`. Done means the clang invocation includes the optimization flag corresponding to the optimized C toolchain configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100