erenon
erenon

Reputation: 19118

Change compiler command line with Bazel

I'd like to have complete control over the command line arguments Bazel passes to the compiler when compiling and linking C++ files. For example, I'd like to use a G++ from a custom path, I'd like to change -std=c++0x to -std=c++14 and remove -fno-omit-frame-pointer - with the following constraints:

Preferably, I'd like to get the auto detected, generated toolchain, modify it, and commit it to my workspace, to be used by every C++ target in the workspace, including imported, from source compiled workspaces.

I looked at Toolchains, Configuring C++ toolchain, rules_cc - but I couldn't figure it out.

Upvotes: 5

Views: 1777

Answers (3)

Nick Codignotto
Nick Codignotto

Reputation: 95

You can also do this in your BUILD file for the entire package:

package(features = ["-default_compile_flags"])

or on a specific binary:

cc_binary(
    name = "cppversion",
    srcs = ["cppversion.cpp"],
    copts = ["--std=c++14"],
    features = ["-default_compile_flags"]
)

Upvotes: 1

Vertexwahn
Vertexwahn

Reputation: 8142

Add a .bazelrc to your project. Add the lines

build:your_config --cxxopt=-std=c++14

Build your code:

bazel build --config=your_config //...

Upvotes: 2

erenon
erenon

Reputation: 19118

The default arguments (e.g: -fno-omit-frame-pointer or -std=c++0x) can be removed by disabling the default_compile_flags feature that provides them:

$ bazel build ... --features=-default_compile_flags

Upvotes: 4

Related Questions