filippo
filippo

Reputation: 146

Bazel: add compile flags to default C++ toolchain

I would like to add some compiler and linker flags to the default C++ toolchain, so that all the targets I build (local or imported) share them.

I know that can define my own toolchain, but I don't want to do that as it's very complicated and easy to get wrong.

Ideally I would like something like this:

cc_toolchain = cc_default_toolchain()
cc_toolchain.copts = [...]
cc_toolchain.linkopts = [...]

Also, I don't want to set global flags in the .bashrc file, as it's hard to configure per platform and it's not easy to share among different repositories.

Thanks!

Upvotes: 7

Views: 3773

Answers (2)

user7610
user7610

Reputation: 28751

I think you have to copy the default generated toolchain into your project and make modifications in it.

You'd run bazel info to locate your output_base directory, and find the toolchain files there.

Source: https://groups.google.com/g/bazel-discuss/c/N1qvsGMJoAE

Upvotes: 2

dms
dms

Reputation: 1380

You could set --cxxopt and --linkopt in a shared .bazelrc file that you reference from the different projects (as sub-module or similar) or import in the workspace's local .bazelrc file.

Upvotes: 3

Related Questions