Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting C++ standard with standard in swift test targets #140

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading