Skip to content
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
12 changes: 12 additions & 0 deletions cc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,15 @@ config_setting(
flag_values = {":cxx_standard": "23"},
visibility = ["//visibility:public"],
)

bool_flag(
name = "enable_sysroot",
build_setting_default = False,
visibility = ["//visibility:public"],
)

config_setting(
name = "_enable_sysroot",
flag_values = {":enable_sysroot": "true"},
visibility = ["//visibility:public"],
)
15 changes: 15 additions & 0 deletions cc/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ filegroup(
url = "https://github.com/swift-nav/swift-toolchains/releases/download/bullseye-aarch64-sysroot-v1/debian_bullseye_aarch64_sysroot.tar.xz",
)

def x86_64_sysroot():
maybe(
http_archive,
name = "x86_64-sysroot",
sha256 = "a19dd3fe4a61d0e1a18f197be1b0c9a2a06b1deabaff2f1479cfcc2cb0df85d1",
build_file_content = """
filegroup(
name = "x86_64-sysroot",
srcs = glob(["*/**"]),
visibility = ["//visibility:public"],
)
""",
url = "https://github.com/swift-nav/swift-toolchains/releases/download/bullseye-x86_64-sysroot-v1/debian_bullseye_x86_64_sysroot.tar.xz",
)

def register_swift_cc_toolchains():
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/aarch64-darwin:cc-toolchain-aarch64-darwin")
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-darwin:cc-toolchain-x86_64-darwin")
Expand Down
6 changes: 3 additions & 3 deletions cc/toolchains/llvm/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def cc_toolchain_config(
if not is_target_triplet(target_system_name):
fail(target_system_name + " is not a target tripplet")

cross_compile = host_system_name != target_system_name
use_libstdcpp = builtin_sysroot != None and not is_darwin

# Default compiler flags:
compile_flags = [
Expand Down Expand Up @@ -82,7 +82,7 @@ def cc_toolchain_config(
# The whole codebase should build with c++14
"-std=c++14",
# Use bundled libc++ for hermeticity if not cross compiling
] + ["-stdlib=libstdc++"] if cross_compile else ["-stdlib=libc++"]
] + ["-stdlib=libstdc++"] if use_libstdcpp else ["-stdlib=libc++"]

link_flags = [
"--target=" + target_system_name,
Expand Down Expand Up @@ -124,7 +124,7 @@ def cc_toolchain_config(
"-ldl",
])

if cross_compile:
if use_libstdcpp:
link_flags.extend([
# Use libstdc++ from the sysroot when cross compiling
"-l:libstdc++.a",
Expand Down
52 changes: 40 additions & 12 deletions cc/toolchains/llvm/x86_64-linux/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@ filegroup(
srcs = [
":wrappers",
"@x86_64-linux-llvm//:ar",
],
] + select({
"//cc:_enable_sysroot": ["@x86_64-sysroot"],
"//conditions:default": [],
}),
)

filegroup(
name = "as_files",
srcs = [
":wrappers",
"@x86_64-linux-llvm//:as",
],
] + select({
"//cc:_enable_sysroot": ["@x86_64-sysroot"],
"//conditions:default": [],
}),
)

filegroup(
Expand All @@ -43,15 +49,21 @@ filegroup(
":wrappers",
"@x86_64-linux-llvm//:clang",
"@x86_64-linux-llvm//:include",
],
] + select({
"//cc:_enable_sysroot": ["@x86_64-sysroot"],
"//conditions:default": [],
}),
)

filegroup(
name = "dwp_files",
srcs = [
":wrappers",
"@x86_64-linux-llvm//:dwp",
],
] + select({
"//cc:_enable_sysroot": ["@x86_64-sysroot"],
"//conditions:default": [],
}),
)

filegroup(
Expand All @@ -62,15 +74,21 @@ filegroup(
"@x86_64-linux-llvm//:clang",
"@x86_64-linux-llvm//:ld",
"@x86_64-linux-llvm//:lib",
],
] + select({
"//cc:_enable_sysroot": ["@x86_64-sysroot"],
"//conditions:default": [],
}),
)

filegroup(
name = "objcopy_files",
srcs = [
":wrappers",
"@x86_64-linux-llvm//:objcopy",
],
] + select({
"//cc:_enable_sysroot": ["@x86_64-sysroot"],
"//conditions:default": [],
}),
)

filegroup(
Expand All @@ -87,19 +105,29 @@ filegroup(
"linker_files",
":compiler_files",
"@x86_64-linux-llvm//:bin",
],
] + select({
"//cc:_enable_sysroot": ["@x86_64-sysroot"],
"//conditions:default": [],
}),
)

cc_toolchain_config(
name = "local-x86_64-linux",
abi_libc_version = "glibc_unknown",
abi_version = "clang",
builtin_sysroot = select({
"//cc:_enable_sysroot": "external/x86_64-sysroot",
"//conditions:default": None,
}),
compiler = "clang",
cxx_builtin_include_directories = [
"/include",
"/usr/include",
"/usr/local/include",
],
cxx_builtin_include_directories = select({
"//cc:_enable_sysroot": ["%sysroot%/usr/include"],
"//conditions:default": [
"/include",
"/usr/include",
"/usr/local/include",
],
}),
host_system_name = X86_64_LINUX,
target_cpu = "k8",
target_libc = "glibc_unknown",
Expand Down