rules_rust
rules_rust copied to clipboard
C/CXX Bazel flags are propagated to crate dependencies
Follow-up from a thread on the Bazel Slack. CC @illicitonion.
MRE Clone MRE in https://github.com/fmorency/bazelsyscov and run
$ CARGO_BAZEL_REPIN=1 bazel sync --only=crate_index
$ bazel coverage --combined_report=lcov //...:all-targets
The above will fail to build.
Running the following works as expected
$ bazel build //...:all-targets
Tested using Bazel 5.2
Problem
Bazel is propagating C/CXX flags to crate dependencies. I stumbled on at least one crate where this is causing an issue when using bazel coverage.
Bazel propagates the --coverage flag to the GCC build of the -sys crate resulting in a compilation error due to additional missing flags according to the -sys crate's Makefile.
Workaround Setting
[crate.annotation(
build_script_env = {
"CRATE_CC_NO_DEFAULTS": "",
"CFLAGS": "",
"CXXFLAGS": "",
"LDFLAGS": "",
},
)]
on the problematic crate.