rules_foreign_cc icon indicating copy to clipboard operation
rules_foreign_cc copied to clipboard

cxxopts and conlyopts

Open baryluk opened this issue 2 years ago • 3 comments

I often have global settings (via invokation params or .blazerc) to set copts and cxxopts to treat various warnings as errors, and enable some extra warnings (like unused params, variables, etc, etc.).

By default all these params will also propagate to my dependencies used via rules_foreign_cc, (cmake, make, configure_make). But a lot of third party projects will not compile with all my flags.

So I set copts with extra flags to basically disable specific warnings (and errors), so they can compile.

The issue is many projects do have both C and C++ components, and not all options can be passed gcc and g++. Examples are:

C++-only: -Wno-old-style-declaration, -Wno-error=non-virtual-dtor, -Woverloaded-virtual C-only: -std=gnu99

Example when building librdkafka:

[ 93%] Building CXX object src-cpp/CMakeFiles/rdkafka++.dir/MetadataImpl.cpp.o
cc1plus: error: command-line option '-Wno-old-style-declaration' is valid for C/ObjC but not for C++ [-Werror]

So it would be nice to be able to specify conlyopts and cxxopts similar to bazel cli, etc.

baryluk avatar Jun 12 '23 19:06 baryluk

Could you instead use

https://bazel.build/docs/user-manual#per-file-copt

I don’t believe these are propagated by rules_foreign_cc

jheaff1 avatar Jun 17 '23 11:06 jheaff1

I meet the same problem at present, have you got some workarounds?

EternalSaga avatar Jul 12 '23 09:07 EternalSaga

@EternalSaga Currently I use global flags to bazel build (either in .bazelrc, or on a command line from some other scripts). It works for our project for now, but is not optimal (i.e. global options to disable some warnings as errors, causes some other parts of the code to not have them enabled, but we would like to have them there, and only disable them on some external libraries). I do not use per file copt. I know it should be possible, but it adds maintenance complexity.

baryluk avatar Jul 12 '23 13:07 baryluk