rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

C/CXX Bazel flags are propagated to crate dependencies

Open fmorency opened this issue 3 years ago • 0 comments

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.

fmorency avatar Sep 13 '22 12:09 fmorency