'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?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source