Skip to content

Use labels to work properly as external dependency [IO-410] #156

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

Merged
merged 1 commit into from
Jun 30, 2025
Merged
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
34 changes: 17 additions & 17 deletions cc/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"""Swift wrappers for native cc rules."""

load("//stamp:stamp_file.bzl", "stamp_file")
load(":utils.bzl", "construct_local_include")
load(":copts.bzl", "DEFAULT_COPTS", "GCC5_COPTS", "GCC6_COPTS")
load(":cc_static_library.bzl", _cc_static_library = "cc_static_library")
load(":copts.bzl", "DEFAULT_COPTS", "GCC5_COPTS", "GCC6_COPTS")
load(":utils.bzl", "construct_local_include")

# Name for a unit test
UNIT = "unit"
Expand Down Expand Up @@ -50,30 +50,30 @@ def _cxx_standard(default, override):
# Options common to both c and c++ code
def _common_cc_opts(nocopts, pedantic = False):
return select({
Label("//cc/constraints:gcc-6"): [copt for copt in GCC6_COPTS if copt not in nocopts],
Label("//cc/constraints:gcc-5"): [copt for copt in GCC5_COPTS if copt not in nocopts],
Label("@rules_swiftnav//cc/constraints:gcc-6"): [copt for copt in GCC6_COPTS if copt not in nocopts],
Label("@rules_swiftnav//cc/constraints:gcc-5"): [copt for copt in GCC5_COPTS if copt not in nocopts],
"//conditions:default": [copt for copt in DEFAULT_COPTS if copt not in nocopts],
}) + select({
Label("//cc:_disable_warnings_as_errors"): [],
Label("@rules_swiftnav//cc:_disable_warnings_as_errors"): [],
"//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)],
Label("@rules_swiftnav//cc:cxx17"): [_cxx_standard("-std=c++17", standard)],
Label("@rules_swiftnav//cc:cxx20"): [_cxx_standard("-std=c++20", standard)],
Label("@rules_swiftnav//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({
Label("//cc:_enable_exceptions"): ["-fexceptions"],
Label("@rules_swiftnav//cc:_enable_exceptions"): ["-fexceptions"],
"//conditions:default": ["-fno-exceptions" if not exceptions else "-fexceptions"],
}) + select({
Label("//cc:_enable_rtti"): ["-frtti"],
Label("@rules_swiftnav//cc:_enable_rtti"): ["-frtti"],
"//conditions:default": ["-fno-rtti" if not rtti else "-frtti"],
}) + _common_cxx_standard_opts(standard)

Expand All @@ -84,14 +84,14 @@ def _construct_local_includes(local_includes):
# Handle whether to link statically
def _link_static(linkstatic = True):
return select({
Label("//cc:_enable_shared"): False,
Label("@rules_swiftnav//cc:_enable_shared"): False,
"//conditions:default": linkstatic,
})

# Disable building when --//:disable_tests=true or when building on windows
def _test_compatible_with():
return select({
Label("//cc:_disable_tests"): ["@platforms//:incompatible"],
Label("@rules_swiftnav//cc:_disable_tests"): ["@platforms//:incompatible"],
"@platforms//os:windows": ["@platforms//:incompatible"],
"//conditions:default": [],
})
Expand All @@ -114,13 +114,13 @@ def _symbolizer_env(val):
return select({
# The + operator is not supported on dict and select types so we need to be
# clever here.
Label("//cc:enable_symbolizer_x86_64_linux"): dict(val, **{
Label("@rules_swiftnav//cc:enable_symbolizer_x86_64_linux"): dict(val, **{
"ASAN_SYMBOLIZER_PATH": "$(location @x86_64-linux-llvm//:symbolizer)",
"UBSAN_SYMBOLIZER_PATH": "$(location @x86_64-linux-llvm//:symbolizer)",
"MSAN_SYMBOLIZER_PATH": "$(location @x86_64-linux-llvm//:symbolizer)",
"TSAN_SYMBOLIZER_PATH": "$(location @x86_64-linux-llvm//:symbolizer)",
}),
Label("//cc:enable_symbolizer_x86_64_darwin"): dict(val, **{
Label("@rules_swiftnav//cc:enable_symbolizer_x86_64_darwin"): dict(val, **{
"ASAN_SYMBOLIZER_PATH": "$(location @x86_64-darwin-llvm//:symbolizer)",
"UBSAN_SYMBOLIZER_PATH": "$(location @x86_64-darwin-llvm//:symbolizer)",
"MSAN_SYMBOLIZER_PATH": "$(location @x86_64-darwin-llvm//:symbolizer)",
Expand All @@ -131,15 +131,15 @@ def _symbolizer_env(val):

def _symbolizer_data():
return select({
Label("//cc:enable_symbolizer_x86_64_linux"): ["@x86_64-linux-llvm//:symbolizer"],
Label("//cc:enable_symbolizer_x86_64_darwin"): ["@x86_64-darwin-llvm//:symbolizer"],
Label("@rules_swiftnav//cc:enable_symbolizer_x86_64_linux"): ["@x86_64-linux-llvm//:symbolizer"],
Label("@rules_swiftnav//cc:enable_symbolizer_x86_64_darwin"): ["@x86_64-darwin-llvm//:symbolizer"],
"//conditions:default": [],
})

# Handle whether to enable -Wdeprecated-declarations in tests.
def _tests_warn_deprecated_declarations():
return select({
Label("//cc:_tests_warn_deprecated_declarations"): [],
Label("@rules_swiftnav//cc:_tests_warn_deprecated_declarations"): [],
"//conditions:default": ["-Wno-deprecated-declarations"],
})

Expand Down
12 changes: 6 additions & 6 deletions cc/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//cc/toolchains/yocto_generic:yocto_generic.bzl", "yocto_generic")
load("@rules_swiftnav//cc/toolchains/yocto_generic:yocto_generic.bzl", "yocto_generic")

AARCH64_DARWIN_LLVM = "https://github.com/swift-nav/swift-toolchains/releases/download/llvm-14.0.0/clang%2Bllvm-14.0.0-arm64-apple-darwin.tar.gz"

Expand All @@ -35,7 +35,7 @@ X86_64_LINUX_GCC_ARM_EMBEDDED = "https://github.com/swift-nav/swift-toolchains/r
# Fixes a bug in libcpp that removed the std::allocator<void> specialization
# when building with c++20. This was patched in llvm-15 so once we upgrade to
# that this will no longer be necessary.
LLVM_PATCH_FILE = [Label("//cc/toolchains/llvm:llvm.patch")]
LLVM_PATCH_FILE = [Label("@rules_swiftnav//cc/toolchains/llvm:llvm.patch")]

# Use p1 for patches generated with git.
LLVM_PATCH_ARGS = ["-p1"]
Expand All @@ -44,7 +44,7 @@ def swift_cc_toolchain():
maybe(
http_archive,
name = "aarch64-darwin-llvm",
build_file = Label("//cc/toolchains/llvm:llvm.BUILD.bzl"),
build_file = Label("@rules_swiftnav//cc/toolchains/llvm:llvm.BUILD.bzl"),
patch_args = LLVM_PATCH_ARGS,
patches = LLVM_PATCH_FILE,
url = AARCH64_DARWIN_LLVM,
Expand All @@ -57,7 +57,7 @@ def swift_cc_toolchain():
name = "x86_64-darwin-llvm",
patch_args = LLVM_PATCH_ARGS,
patches = LLVM_PATCH_FILE,
build_file = Label("//cc/toolchains/llvm:llvm.BUILD.bzl"),
build_file = Label("@rules_swiftnav//cc/toolchains/llvm:llvm.BUILD.bzl"),
url = X86_64_DARWIN_LLVM,
strip_prefix = "clang+llvm-14.0.0-x86_64-apple-darwin",
sha256 = "cf5af0f32d78dcf4413ef6966abbfd5b1445fe80bba57f2ff8a08f77e672b9b3",
Expand All @@ -68,7 +68,7 @@ def swift_cc_toolchain():
name = "aarch64-linux-llvm",
patch_args = LLVM_PATCH_ARGS,
patches = LLVM_PATCH_FILE,
build_file = Label("//cc/toolchains/llvm:llvm.BUILD.bzl"),
build_file = Label("@rules_swiftnav//cc/toolchains/llvm:llvm.BUILD.bzl"),
url = AARCH64_LINUX_LLVM,
strip_prefix = "clang+llvm-14.0.0-aarch64-linux-gnu",
sha256 = "1792badcd44066c79148ffeb1746058422cc9d838462be07e3cb19a4b724a1ee",
Expand All @@ -77,7 +77,7 @@ def swift_cc_toolchain():
maybe(
http_archive,
name = "x86_64-linux-llvm",
build_file = Label("//cc/toolchains/llvm:llvm.BUILD.bzl"),
build_file = Label("@rules_swiftnav//cc/toolchains/llvm:llvm.BUILD.bzl"),
patch_args = LLVM_PATCH_ARGS,
patches = LLVM_PATCH_FILE,
url = X86_64_LINUX_LLVM,
Expand Down
12 changes: 6 additions & 6 deletions cc/toolchains/gcc_arm_embedded/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -81,31 +81,31 @@ config(
name = "config",
c_opts = select(
{
"//cc/constraints:cortex-m4": [
"@rules_swiftnav//cc/constraints:cortex-m4": [
"-mcpu=cortex-m4",
"-march=armv7e-m",
"-mthumb",
"-mfloat-abi=hard",
"-mfpu=fpv4-sp-d16",
],
"//cc/constraints:cortex-m7": [
"@rules_swiftnav//cc/constraints:cortex-m7": [
"-mcpu=cortex-m7",
"-mthumb",
"-mfpu=fpv5-d16",
"-mfloat-abi=hard",
],
"//cc/constraints:cortex-m3": [
"@rules_swiftnav//cc/constraints:cortex-m3": [
"-mcpu=cortex-m3",
"-march=armv7-m",
"-mthumb",
"-msoft-float",
],
"//cc/constraints:cortex-a7": [
"@rules_swiftnav//cc/constraints:cortex-a7": [
"-mcpu=cortex-a7",
"-mfloat-abi=hard",
"-mfpu=neon-vfpv4",
],
"//cc/constraints:cortex-a9": [
"@rules_swiftnav//cc/constraints:cortex-a9": [
"-mcpu=cortex-a9",
"-march=armv7-a",
"-mthumb",
Expand Down Expand Up @@ -141,7 +141,7 @@ toolchain(
],
target_compatible_with = [
"@platforms//os:none",
"//cc/constraints:gcc_arm_cpu",
"@rules_swiftnav//cc/constraints:gcc_arm_cpu",
],
toolchain = ":cc_toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
Expand Down
2 changes: 1 addition & 1 deletion cc/toolchains/gcc_arm_gnu_8_3/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ toolchain(
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:aarch64",
"//cc/toolchains/gcc_arm_gnu_8_3:gcc_arm_gnu_8_3_toolchain",
"@rules_swiftnav//cc/toolchains/gcc_arm_gnu_8_3:gcc_arm_gnu_8_3_toolchain",
],
toolchain = ":cc_toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
Expand Down
8 changes: 4 additions & 4 deletions cc/toolchains/llvm/aarch64-darwin/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

package(default_visibility = ["//visibility:public"])
load("@rules_swiftnav//cc/toolchains/llvm:cc_toolchain_config.bzl", "cc_toolchain_config")
load("@rules_swiftnav//cc/toolchains/llvm:target_triplets.bzl", "AARCH64_DARWIN")

load("//cc/toolchains/llvm:cc_toolchain_config.bzl", "cc_toolchain_config")
load("//cc/toolchains/llvm:target_triplets.bzl", "AARCH64_DARWIN")
package(default_visibility = ["//visibility:public"])

filegroup(
name = "wrappers",
Expand Down Expand Up @@ -144,7 +144,7 @@ toolchain(
target_compatible_with = [
"@platforms//cpu:aarch64",
"@platforms//os:macos",
"//cc/constraints:llvm_toolchain",
"@rules_swiftnav//cc/constraints:llvm_toolchain",
],
target_settings = None,
toolchain = ":cc-clang-aarch64-darwin",
Expand Down
26 changes: 13 additions & 13 deletions cc/toolchains/llvm/aarch64-linux/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

package(default_visibility = ["//visibility:public"])
load("@rules_swiftnav//cc/toolchains/llvm:cc_toolchain_config.bzl", "cc_toolchain_config")
load("@rules_swiftnav//cc/toolchains/llvm:target_triplets.bzl", "AARCH64_LINUX")

load("//cc/toolchains/llvm:cc_toolchain_config.bzl", "cc_toolchain_config")
load("//cc/toolchains/llvm:target_triplets.bzl", "AARCH64_LINUX")
package(default_visibility = ["//visibility:public"])

filegroup(
name = "wrappers",
Expand All @@ -27,7 +27,7 @@ filegroup(
":wrappers",
"@aarch64-linux-llvm//:ar",
] + select({
"//cc:_use_libcpp": [],
"@rules_swiftnav//cc:_use_libcpp": [],
"//conditions:default": ["@aarch64-sysroot"],
}),
)
Expand All @@ -38,7 +38,7 @@ filegroup(
":wrappers",
"@aarch64-linux-llvm//:as",
] + select({
"//cc:_use_libcpp": [],
"@rules_swiftnav//cc:_use_libcpp": [],
"//conditions:default": ["@aarch64-sysroot"],
}),
)
Expand All @@ -50,7 +50,7 @@ filegroup(
"@aarch64-linux-llvm//:clang",
"@aarch64-linux-llvm//:include",
] + select({
"//cc:_use_libcpp": [],
"@rules_swiftnav//cc:_use_libcpp": [],
"//conditions:default": ["@aarch64-sysroot"],
}),
)
Expand All @@ -61,7 +61,7 @@ filegroup(
":wrappers",
"@aarch64-linux-llvm//:dwp",
] + select({
"//cc:_use_libcpp": [],
"@rules_swiftnav//cc:_use_libcpp": [],
"//conditions:default": ["@aarch64-sysroot"],
}),
)
Expand All @@ -75,7 +75,7 @@ filegroup(
"@aarch64-linux-llvm//:ld",
"@aarch64-linux-llvm//:lib",
] + select({
"//cc:_use_libcpp": [],
"@rules_swiftnav//cc:_use_libcpp": [],
"//conditions:default": ["@aarch64-sysroot"],
}),
)
Expand All @@ -86,7 +86,7 @@ filegroup(
":wrappers",
"@aarch64-linux-llvm//:objcopy",
] + select({
"//cc:_use_libcpp": [],
"@rules_swiftnav//cc:_use_libcpp": [],
"//conditions:default": ["@aarch64-sysroot"],
}),
)
Expand All @@ -106,7 +106,7 @@ filegroup(
":compiler_files",
"@aarch64-linux-llvm//:bin",
] + select({
"//cc:_use_libcpp": [],
"@rules_swiftnav//cc:_use_libcpp": [],
"//conditions:default": ["@aarch64-sysroot"],
}),
)
Expand All @@ -116,12 +116,12 @@ cc_toolchain_config(
abi_libc_version = "glibc_unknown",
abi_version = "clang",
builtin_sysroot = select({
"//cc:_use_libcpp": None,
"@rules_swiftnav//cc:_use_libcpp": None,
"//conditions:default": "external/aarch64-sysroot",
}),
compiler = "clang",
cxx_builtin_include_directories = select({
"//cc:_use_libcpp": [
"@rules_swiftnav//cc:_use_libcpp": [
"/include",
"/usr/include",
"/usr/local/include",
Expand Down Expand Up @@ -171,7 +171,7 @@ toolchain(
target_compatible_with = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
"//cc/constraints:llvm_toolchain",
"@rules_swiftnav//cc/constraints:llvm_toolchain",
],
target_settings = None,
toolchain = ":cc-clang-aarch64-linux",
Expand Down
8 changes: 4 additions & 4 deletions cc/toolchains/llvm/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

load("@rules_swiftnav//cc/toolchains/llvm:target_triplets.bzl", "is_target_triplet")
load(
"unix_cc_toolchain_config.bzl",
unix_cc_toolchain_config = "cc_toolchain_config",
)
load("//cc/toolchains/llvm:target_triplets.bzl", "is_target_triplet")

def cc_toolchain_config(
name,
Expand Down Expand Up @@ -78,9 +78,9 @@ def cc_toolchain_config(
]

cxx_flags = select({
"//cc:global_cxx17": ["-std=c++17"],
"//cc:global_cxx20": ["-std=c++20"],
"//cc:global_cxx23": ["-std=c++23"],
"@rules_swiftnav//cc:global_cxx17": ["-std=c++17"],
"@rules_swiftnav//cc:global_cxx20": ["-std=c++20"],
"@rules_swiftnav//cc:global_cxx23": ["-std=c++23"],
"//conditions:default": ["-std=c++14"],
})

Expand Down
Loading
Loading