Search code examples
cbazel

C compiler option in Bazel CROSSTOOL file


How does one set C only (not C++) compiler flags in the CROSSTOOL file in Bazel.

compiler_flag can be used for both C and C++, cxx_flag for C++ code. What is the corresponding way to set C only options.

In particular I need to specify -std=c99 as an option. The only way I know of doing this right now is by passing copts = ["-std=c99"] to every target which is messy and error prone.


Solution

  • Looking at the protobuf of CROSSTOOL I don't think it's supported. You could write a Skylark macro called "c_library/c_binary" or something similar, and add your required copt before calling cc_library/cc_binary underneath.