Quantcast
Viewing all articles
Browse latest Browse all 22032

Configution "copts" based on compiler (gcc vs clang) in Bazel

I have a Bazel-based C project and I want to compile it with both gcc and clang on Linux. To switch between compilers, I prefix the invocation with CC=<compiler, like so:

CC=clang bazel build //my-package:my-target

This works as expected, except I also invoke a Bazel rule with the copts parameter:

cc_binary(
    name = "my-target",
    srcs = [
        "my-src.c",
    ],
    copts = [
        "-std=c89",
        "-Wno-unused-label",
        "-Wno-unused-variable",
        "-Wno-unused-but-set-variable",
        "-Wno-misleading-indentation",
    ],
)

This works, but I get "unknown warning option" messages from clang:

warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]

warning: unknown warning option '-Wno-misleading-indentation'; did you mean '-Wno-binding-in-condition'? [-Wunknown-warning-option]

Is it possible to specify copts arguments conditional on the C compiler used for the specific Bazel invocation?


Viewing all articles
Browse latest Browse all 22032

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>