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

Isaac/docker mac exp #94

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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"],
)
16 changes: 16 additions & 0 deletions cc/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,27 @@ 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 = "9bd27c7ec6aa4bd3d4df60cd04228669bcf366aec32d4b4dc7b504de2f63121e",
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")
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-linux:cc-toolchain-x86_64-linux")
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-aarch64-linux:cc-toolchain-x86_64-aarch64-linux")
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-darwin-x86_64-linux:cc-toolchain-x86_64-darwin-x86_64-linux")

def aarch64_linux_musl_toolchain():
http_archive(
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
157 changes: 157 additions & 0 deletions cc/toolchains/llvm/x86_64-darwin-x86_64-linux/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Copyright (C) 2022 Swift Navigation Inc.
# Contact: Swift Navigation <[email protected]>
#
# This source is subject to the license found in the file 'LICENSE' which must
# be be distributed together with this source. All other rights reserved.
#
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# 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("//cc/toolchains/llvm:cc_toolchain_config.bzl", "cc_toolchain_config")
load("//cc/toolchains/llvm:target_triplets.bzl", "X86_64_DARWIN", "X86_64_LINUX")

filegroup(
name = "wrappers",
srcs = glob([
"wrappers/**",
]),
visibility = ["//visibility:public"],
)

filegroup(
name = "ar_files",
srcs = [
":wrappers",
"@x86_64-sysroot",
"@x86_64-darwin-llvm//:ar",
],
)

filegroup(
name = "as_files",
srcs = [
":wrappers",
"@x86_64-sysroot",
"@x86_64-darwin-llvm//:as",
],
)

filegroup(
name = "compiler_files",
srcs = [
":wrappers",
"@x86_64-sysroot",
"@x86_64-darwin-llvm//:clang",
"@x86_64-darwin-llvm//:include",
],
)

filegroup(
name = "dwp_files",
srcs = [
":wrappers",
"@x86_64-sysroot",
"@x86_64-darwin-llvm//:dwp",
],
)

filegroup(
name = "linker_files",
srcs = [
":wrappers",
"@x86_64-sysroot",
"@x86_64-darwin-llvm//:ar",
"@x86_64-darwin-llvm//:clang",
"@x86_64-darwin-llvm//:ld",
"@x86_64-darwin-llvm//:lib",
],
)

filegroup(
name = "objcopy_files",
srcs = [
":wrappers",
"@x86_64-sysroot",
"@x86_64-darwin-llvm//:objcopy",
],
)

filegroup(
name = "strip_files",
srcs = [
":wrappers",
"@x86_64-darwin-llvm//:strip",
],
)

filegroup(
name = "all_files",
srcs = [
"linker_files",
":compiler_files",
"@x86_64-darwin-llvm//:bin",
],
)

cc_toolchain_config(
name = "local-x86_64-darwin",
abi_libc_version = "darwin_x86_64",
abi_version = "darwin_x86_64",
builtin_sysroot = "external/x86_64-sysroot",
compiler = "clang",
cxx_builtin_include_directories = [
"%sysroot%/usr/include",
],
host_system_name = X86_64_DARWIN,
is_darwin = False,
target_cpu = "k8",
target_libc = "glibc_unknown",
target_system_name = X86_64_LINUX,
tool_paths = {
"ar": "wrappers/llvm-ar",
"cpp": "wrappers/clang-cpp",
"gcc": "wrappers/clang",
"gcov": "wrappers/llvm-profdata",
"llvm-cov": "wrappers/llvm-cov",
"llvm-profdata": "wrappers/llvm-profdata",
"ld": "wrappers/ld.ldd",
"nm": "wrappers/llvm-nm",
"objcopy": "wrappers/llvm-objcopy",
"objdump": "wrappers/llvm-objdump",
"strip": "wrappers/llvm-strip",
},
toolchain_identifier = "clang-x86_64-darwin-x86_64-linux",
toolchain_path_prefix = "external/x86_64-darwin-llvm",
)

cc_toolchain(
name = "cc-clang-x86_64-darwin-x86_64-linux",
all_files = ":all_files",
ar_files = ":ar_files",
as_files = ":as_files",
compiler_files = ":compiler_files",
dwp_files = ":dwp_files",
linker_files = ":linker_files",
objcopy_files = ":objcopy_files",
strip_files = ":strip_files",
toolchain_config = ":local-x86_64-darwin",
)

toolchain(
name = "cc-toolchain-x86_64-darwin-x86_64-linux",
exec_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:macos",
],
target_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
"//cc/constraints:glibc_2_31",
],
target_settings = None,
toolchain = ":cc-clang-x86_64-darwin-x86_64-linux",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
58 changes: 58 additions & 0 deletions cc/toolchains/llvm/x86_64-darwin-x86_64-linux/wrappers/wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

# Copyright (C) 2022 Swift Navigation Inc.
# Contact: Swift Navigation <[email protected]>
#
# This source is subject to the license found in the file 'LICENSE' which must
# be be distributed together with this source. All other rights reserved.
#
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

# Locates the actual tool paths relative to the location this script is
# executed from.
#
# This is necessary because we download the toolchain using
# http_archive, which bazel places in _execroot_/external/_repo_name_.
#
# Unfortunately we cannot provide this location as the argument of tool_path
# when configuring the toolchain, because tool_path only takes a relative path.
#
# This is the fairly common workaround to handle this.
#
# TODO: [BUILD-549] - Remove need for wrapper files
#
# Recent versions of Bazel may have introduced a mechanism that removes
# the need for this workaround: https://github.com/bazelbuild/bazel/issues/7746

set -e

# Use --actionv_env=SWIFTNAV_VERBOSE_TOOLCHAIN to enable
if [[ -n "$SWIFTNAV_VERBOSE_TOOLCHAIN" ]]; then
set -x
fi

tool_name=$(basename "${BASH_SOURCE[0]}")
toolchain_bindir=external/x86_64-darwin-llvm/bin

if [[ -f "${toolchain_bindir}"/"${tool_name}" ]]; then
# We're running under _execroot_, call the real tool.
exec "${toolchain_bindir}"/"${tool_name}" "$@"
elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
# This branch exists because some users of the toolchain,
# namely rules_foreign_cc, will change CWD and call $CC (this script)
# with its absolute path.
#
# To deal with this we find the tool relative to this script, which is at
# _execroot_/external/rules_swiftnav/cc/toolchain/llvm/x86_64-linux/wrappers/wrapper.
#
# If the wrapper is relocated then this line needs to be adjusted.
execroot_path="${BASH_SOURCE[0]%/*/*/*/*/*/*/*/*}"
tool="${execroot_path}/${toolchain_bindir}/${tool_name}"
exec "${tool}" "${@}"
else
>&2 echo "ERROR: could not find ${tool_name}; PWD=\"$(pwd)\"; PATH=\"${PATH}\"."
exit 5
fi

Loading