Skip to content

Global C++ version #152

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
28 changes: 28 additions & 0 deletions cc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,34 @@ config_setting(
visibility = ["//visibility:public"],
)

# Globally sets the default C++ version, even for third-party libraries
string_flag(
name = "global_cxx_standard",
build_setting_default = "", #inactive by default
visibility = ["//visibility:public"],
)

# Enable with --@rules_swiftnav//:global_cxx_standard=17
config_setting(
name = "global_cxx17",
flag_values = {":global_cxx_standard": "17"},
visibility = ["//visibility:public"],
)

# Enable with --@rules_swiftnav//:global_cxx_standard=20
config_setting(
name = "global_cxx20",
flag_values = {":global_cxx_standard": "20"},
visibility = ["//visibility:public"],
)

# Enable with --@rules_swiftnav//:global_cxx_standard=23
config_setting(
name = "global_cxx23",
flag_values = {":global_cxx_standard": "23"},
visibility = ["//visibility:public"],
)

bool_flag(
name = "enable_symbolizer",
build_setting_default = False,
Expand Down
10 changes: 6 additions & 4 deletions cc/toolchains/llvm/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ def cc_toolchain_config(
"-fdata-sections",
]

cxx_flags = [
# The whole codebase should build with c++14
"-std=c++14",
]
cxx_flags = select({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this compare to https://github.com/swift-nav/rules_swiftnav/blob/main/cc/defs.bzl#L62 ? I actually wasn't aware of the flag directly in the toolchain file.

Copy link
Contributor Author

@RReichert RReichert May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with what is highlighted here, if you use the bazel cc_library or cc_binary directly it will impose the "global cxx standard". in the code snippet that you posted, that only applies to swift_cc_library and swift_cc_binary targets and overrules the global setting.

"//cc:global_cxx17": ["-std=c++17"],
"//cc:global_cxx20": ["-std=c++20"],
"//cc:global_cxx23": ["-std=c++23"],
"//conditions:default": ["-std=c++14"],
})

link_flags = [
"--target=" + target_system_name,
Expand Down
Loading