Skip to content

Commit 28ff0d3

Browse files
committed
[BUILD] Better handling of OPENTELEMETRY_STL_VERSION under Bazel.
1 parent a232328 commit 28ff0d3

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

api/BUILD

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4-
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
4+
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
55

66
package(default_visibility = ["//visibility:public"])
77

@@ -10,12 +10,39 @@ bool_flag(
1010
build_setting_default = False,
1111
)
1212

13+
CPP_STDLIBS = [
14+
"none",
15+
"best",
16+
"2014",
17+
"2017",
18+
"2020",
19+
"2023",
20+
]
21+
22+
string_flag(
23+
name = "with_cxx_stdlib",
24+
build_setting_default = "best",
25+
values = CPP_STDLIBS,
26+
)
27+
1328
cc_library(
1429
name = "api",
1530
hdrs = glob(["include/**/*.h"]),
1631
defines = select({
1732
":with_external_abseil": ["HAVE_ABSEIL"],
1833
"//conditions:default": [],
34+
}) + select({
35+
":set_cxx_stdlib_none": [],
36+
### automatic selection
37+
":set_cxx_stdlib_best": ["OPENTELEMETRY_STL_VERSION=(__cplusplus/100)"],
38+
# See https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus
39+
":set_cxx_stdlib_best_and_msvc": ["OPENTELEMETRY_STL_VERSION=(_MSVC_LANG/100)"],
40+
### manual selection
41+
":set_cxx_stdlib_2014": ["OPENTELEMETRY_STL_VERSION=2014"],
42+
":set_cxx_stdlib_2017": ["OPENTELEMETRY_STL_VERSION=2017"],
43+
":set_cxx_stdlib_2020": ["OPENTELEMETRY_STL_VERSION=2020"],
44+
":set_cxx_stdlib_2023": ["OPENTELEMETRY_STL_VERSION=2023"],
45+
"//conditions:default": [],
1946
}),
2047
strip_include_prefix = "include",
2148
tags = ["api"],
@@ -33,3 +60,14 @@ config_setting(
3360
name = "with_external_abseil",
3461
flag_values = {":with_abseil": "true"},
3562
)
63+
64+
[config_setting(
65+
name = "set_cxx_stdlib_%s" % v,
66+
flag_values = {":with_cxx_stdlib": v},
67+
) for v in CPP_STDLIBS]
68+
69+
config_setting(
70+
name = "set_cxx_stdlib_best_and_msvc",
71+
constraint_values = ["@bazel_tools//tools/cpp:msvc"],
72+
flag_values = {":with_cxx_stdlib": "best"},
73+
)

0 commit comments

Comments
 (0)