Skip to content

Commit

Permalink
Allow setting C++ standard with standard in swift test targets
Browse files Browse the repository at this point in the history
This is already supported in `swift_cc_library` and `swift_cc_tool`.
  • Loading branch information
peddie committed Oct 16, 2024
1 parent 7837ae9 commit 304f801
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions cc/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ def _common_cc_opts(nocopts, pedantic = False):
"//conditions:default": ["-Werror"],
}) + ["-pedantic"] if pedantic else []

# Options specific to C++ language standard
def _common_cxx_standard_opts(standard = None):
return select({
Label("//cc:cxx17"): [_cxx_standard("-std=c++17", standard)],
Label("//cc:cxx20"): [_cxx_standard("-std=c++20", standard)],
Label("//cc:cxx23"): [_cxx_standard("-std=c++23", standard)],
"//conditions:default": [_cxx_standard("-std=c++14", standard)],
})

# Options specific to c++ code (exceptions, rtti, etc..)
def _common_cxx_opts(exceptions = False, rtti = False, standard = None):
return select({
Expand All @@ -66,12 +75,7 @@ def _common_cxx_opts(exceptions = False, rtti = False, standard = None):
}) + select({
Label("//cc:_enable_rtti"): ["-frtti"],
"//conditions:default": ["-fno-rtti" if not rtti else "-frtti"],
}) + select({
Label("//cc:cxx17"): [_cxx_standard("-std=c++17", standard)],
Label("//cc:cxx20"): [_cxx_standard("-std=c++20", standard)],
Label("//cc:cxx23"): [_cxx_standard("-std=c++23", standard)],
"//conditions:default": [_cxx_standard("-std=c++14", standard)],
})
}) + _common_cxx_standard_opts(standard)

# Handle various nuances of local include paths
def _construct_local_includes(local_includes):
Expand Down Expand Up @@ -638,7 +642,7 @@ def swift_cc_test(name, type, **kwargs):

local_includes = _construct_local_includes(kwargs.pop("local_includes", []))

kwargs["copts"] = local_includes + kwargs.get("copts", []) + _tests_warn_deprecated_declarations()
kwargs["copts"] = local_includes + kwargs.get("copts", []) + _tests_warn_deprecated_declarations() + _common_cxx_standard_opts(kwargs.pop("standard", []))
kwargs["data"] = kwargs.get("data", []) + _symbolizer_data()
kwargs["env"] = _symbolizer_env(kwargs.get("env", {}))
kwargs["linkstatic"] = kwargs.get("linkstatic", True)
Expand Down

0 comments on commit 304f801

Please sign in to comment.