'What is the best practive in bazel to overwrite the copts of an external dependency?

Suppose I have a workspace(name == "foo") who requires an external lib "bar".

In the workspace I declair a cc_binary(name = "baz", deps = ["@bar"]).

"bar" is a static library (".lib" on Windows or ".a" on Linux), but I want to compile bar.a with the same copts as "baz". For example on Windows, one may want to use /Qspectre flags or /D_UNICODE to compile baz.lib.

One way is to overwrite --copts in .bazelrc file or command line, but it will apply to all targets.

Another possible way is to use a new BUILD file for "bar", but I wonder what's the best practice to do so?



Sources

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

Source: Stack Overflow

Solution Source