Reputation: 151
Recently I wanted to migrate all my projects to bazel and finally I am building them with command setting c++ standard manually for different operations systems:
bazel build //... --cxxopt=-std=c++17 --compilation_mode opt
bazel build //... --cxxopt=/std:c++17 --compilation_mode opt
I would set it in .bzl
file but setting standard is different for linux and windows, so I will anyway need to override it with --cxxopt=/std:c++17
for MSVC.
I tried to add global variable to .bzl
file and load it for all projects, e.g.:
# variables.bzl
COPTS = ["-std=c++17"]
This works (but as I mentioned before it will anyway require changing for different platforms). Then I've tried:
# variables.bzl
COPTS = select({
"//tools/cc_target_os:windows": ["/std:c++17"],
"//conditions:default": ["-std=c++17"],
})
But it lead to error:
ERROR: path/to/project/BUILD:2:1: no such package 'tools/cc_target_os': BUILD file not found on package path and referenced by '//project:smth'
Is it possible to set c++ flags to all projects depending on platform (compiler)? Unfortunately, I could not find any working example. Could you please help me?
Upvotes: 4
Views: 1552
Reputation: 13463
Use @bazel_tools//src/conditions:windows
instead.
# variables.bzl
COPTS = select({
"@bazel_tools//src/conditions:windows": ["/std:c++17"],
"//conditions:default": ["-std=c++17"],
})
Upvotes: 2