RAM
RAM

Reputation: 2749

How to set C++ standard in Bazel project or workspace?

I'm currently migrating a multipackage C++14 project to Bazel, but whenever I run $ bazel build on linux I end up getting build errors because Bazel is calling the compiler with -std=c++0x.

One of the requirements for this project is to gradually migrate its packages to C++17 once the build system is up and running. However, after browsing through Bazel's docs I saw no reference to how to set a project's target C++ standard version. CMake handles this trivially and effortlessly through its CXX_STANDARD target property, but so far I saw no reference to this usecase being supported by Bazel.

With this in mind, does anyone know if Bazel allows users to specify C++ standard versions for specific projects/workspaces? If it does, is it possible to provide a minimal working example?

Upvotes: 2

Views: 812

Answers (2)

warchantua
warchantua

Reputation: 1213

Other good way to add custom compiler flags is to wrap cc_{binary,library} into your own macro:

def my_cc_library(
  name,
  copts=[],
  **kwargs):
  cc_library(
    name = name,
    copts = copts + ["-std=c++14"],
    **kwargs)

Upvotes: 0

slsy
slsy

Reputation: 1304

The envoy project is good place to start when you need to learn how to tune your C/C++ toolchain. In your case just add that line to the .bazelrc file:

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

Upvotes: 1

Related Questions