1
1
# Copyright The OpenTelemetry Authors
2
2
# SPDX-License-Identifier: Apache-2.0
3
3
4
- load ("@bazel_skylib//rules:common_settings.bzl" , "bool_flag" )
4
+ load ("@bazel_skylib//rules:common_settings.bzl" , "bool_flag" , "string_flag" )
5
5
6
6
package (default_visibility = ["//visibility:public" ])
7
7
@@ -10,12 +10,39 @@ bool_flag(
10
10
build_setting_default = False ,
11
11
)
12
12
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
+
13
28
cc_library (
14
29
name = "api" ,
15
30
hdrs = glob (["include/**/*.h" ]),
16
31
defines = select ({
17
32
":with_external_abseil" : ["HAVE_ABSEIL" ],
18
33
"//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" : [],
19
46
}),
20
47
strip_include_prefix = "include" ,
21
48
tags = ["api" ],
@@ -33,3 +60,14 @@ config_setting(
33
60
name = "with_external_abseil" ,
34
61
flag_values = {":with_abseil" : "true" },
35
62
)
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