Search code examples
c++buildbazelbazel-rules

How can ignore bazel features like `treat_warnings_as_errors` only on some files?


I have a library like the following in my bazel build file for C++:

cc_library(
    name = "mylib",
    srcs = [
        "main.cpp",
        "file1.cpp",
        "file2.cpp",
        ...
    ],
    hdrs = [
        "main.h",
        "file1.h",
        "file2.h",
        ...
    ],
    features = [
        "treat_warnings_as_errors",
        "strict_warnings",
        "additional_warnings",
    ],
    deps = [
        "my_dependency1",
        "my_dependency2",
        "third_party_dependency",
        ...
    ],
)

I need the constraints specified in features to be applied to all source files, except to third_party_dependency which is used by file1.

What I tried was removing file1 from mylib, putting it in a new library (i.e. mylib2) and then adding that lib to mylib as a dependency. The only problem is that I don't want the whole file1 to scape from the constraints, only third_party_dependency.

Is there any way to do that?


Solution

  • My solution for this was creating a new library as a wrapper for third_party_dependency not to mess up with third party code and on that second library I just had to add #pragma GCC system_header on the header file so that my gcc compiler ignores that file.

    redits for How to eliminate external lib/third party warnings in GCC