Skip to content

Commit b92e4d8

Browse files
committed
Set cxxopt with platform-specific syntax
Attempting to use option `--copt=-std=c++17` fails on Windows because the syntax need to be slightly different: `--copt=/std:c++17`. To handle these differences between platforms, we can take advantage of Bazel's `--enable_platform_specific_config` option and define different build configs for Linux, Windows, and Mac.
1 parent b69aa08 commit b92e4d8

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

.bazelrc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,24 @@ common --announce_rc
1919
common --experimental_repo_remote_exec
2020
common --verbose_failures
2121

22-
# Default build options
23-
build --copt -std=c++17
24-
build --copt -D_GLIBCXX_USE_CXX11_ABI=1
22+
# C++ language selection. The variants are needed because MS Visual Studio on
23+
# Windows uses slightly different syntax.
24+
common --enable_platform_specific_config
25+
26+
build:linux --copt=-std=c++17
27+
build:linux --copt=-D_GLIBCXX_USE_CXX11_ABI=1
28+
build:linux --cxxopt=-std=c++17
29+
build:linux --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=1
30+
31+
build:macos --copt=-std=c++17
32+
build:macos --copt=-D_GLIBCXX_USE_CXX11_ABI=1
33+
build:macos --cxxopt=-std=c++17
34+
build:macos --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=1
35+
36+
build:windows --copt=/std:c++17
37+
build:windows --copt=-D_GLIBCXX_USE_CXX11_ABI=1
38+
build:windows --cxxopt=/std:c++17
39+
build:windows --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=1
2540

2641
# Test flags
2742
test --test_output=errors

0 commit comments

Comments
 (0)