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

build: integrate new cross toolchains w/ Bazel #77960

Merged
merged 1 commit into from
Apr 7, 2022
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
6 changes: 5 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ build:crosswindows '--workspace_status_command=./build/bazelutil/stamp.sh x86_64
build:crosswindows --config=crosswindowsbase
build:crosswindowsbase --platforms=//build/toolchains:cross_windows
build:crosswindowsbase --config=cross
build:crossmacos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-apple-darwin19'
build:crossmacos '--workspace_status_command=./build/bazelutil/stamp.sh x86_64-apple-darwin21.2'
build:crossmacos --config=crossmacosbase
build:crossmacosbase --platforms=//build/toolchains:cross_macos
build:crossmacosbase --config=cross
build:crossmacosarm '--workspace_status_command=./build/bazelutil/stamp.sh aarch64-apple-darwin21.2'
build:crossmacosarm --config=crossmacosarmbase
build:crossmacosarmbase --platforms=//build/toolchains:cross_macos_arm
build:crossmacosarmbase --config=cross
build:crosslinuxarm '--workspace_status_command=./build/bazelutil/stamp.sh aarch64-unknown-linux-gnu'
build:crosslinuxarm --config=crosslinuxarmbase
build:crosslinuxarmbase --platforms=//build/toolchains:cross_linux_arm
Expand Down
14 changes: 10 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,16 @@ load("//build/toolchains:REPOSITORIES.bzl", "toolchain_dependencies")
toolchain_dependencies()

register_toolchains(
"//build/toolchains:cross_linux_toolchain",
"//build/toolchains:cross_linux_arm_toolchain",
"//build/toolchains:cross_macos_toolchain",
"//build/toolchains:cross_windows_toolchain",
"//build/toolchains:cross_x86_64_linux_toolchain",
"//build/toolchains:cross_x86_64_linux_arm_toolchain",
"//build/toolchains:cross_x86_64_macos_toolchain",
"//build/toolchains:cross_x86_64_macos_arm_toolchain",
"//build/toolchains:cross_x86_64_windows_toolchain",
"//build/toolchains:cross_arm64_linux_toolchain",
"//build/toolchains:cross_arm64_linux_arm_toolchain",
"//build/toolchains:cross_arm64_windows_toolchain",
"//build/toolchains:cross_arm64_macos_toolchain",
"//build/toolchains:cross_arm64_macos_arm_toolchain",
"//build/toolchains:dev_darwin_x86_64_toolchain",
)

Expand Down
197 changes: 192 additions & 5 deletions build/toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

# We define a number of toolchains, each of which has a name of the form:
# cross_HOST_TARGET_toolchain
# The "HOST" is either x86_64 or arm64. The TARGET is either linux, windows,
# macos, s390x, linux_arm, or macos_arm. (As you might expect, the targets
# are x86_64 in general unless they end with "_arm".) You can enable any of
# these toolchains with `--config crossTARGET` (see .bazelrc).

toolchain(
name = "cross_linux_toolchain",
name = "cross_x86_64_linux_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
Expand All @@ -26,7 +33,7 @@ platform(
)

toolchain(
name = "cross_windows_toolchain",
name = "cross_x86_64_windows_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
Expand All @@ -51,7 +58,7 @@ platform(
)

toolchain(
name = "cross_macos_toolchain",
name = "cross_x86_64_macos_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
Expand All @@ -63,7 +70,7 @@ toolchain(
target_settings = [
":cross",
],
toolchain = "@toolchain_cross_x86_64-apple-darwin19//:toolchain",
toolchain = "@cross_x86_64_macos_toolchain//:toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

Expand All @@ -76,7 +83,32 @@ platform(
)

toolchain(
name = "cross_linux_arm_toolchain",
name = "cross_x86_64_macos_arm_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
target_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:arm64",
],
target_settings = [
":cross",
],
toolchain = "@cross_x86_64_macos_arm_toolchain//:toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

platform(
name = "cross_macos_arm",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:arm64",
],
)

toolchain(
name = "cross_x86_64_linux_arm_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
Expand All @@ -100,6 +132,136 @@ platform(
],
)

platform(
name = "cross_linux_s390x",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:s390x",
],
)

toolchain(
name = "cross_x86_64_s390x_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:s390x",
],
target_settings = [
":cross",
],
toolchain = "@toolchain_cross_s390x-ibm-linux-gnu//:toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

toolchain(
name = "cross_arm64_linux_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:arm64",
],
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
target_settings = [
":cross",
],
toolchain = "@armtoolchain_cross_x86_64-unknown-linux-gnu//:toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

toolchain(
name = "cross_arm64_windows_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:arm64",
],
target_compatible_with = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
target_settings = [
":cross",
],
toolchain = "@armtoolchain_cross_x86_64-w64-mingw32//:toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

toolchain(
name = "cross_arm64_linux_arm_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:arm64",
],
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:arm64",
],
target_settings = [
":cross",
],
toolchain = "@armtoolchain_cross_aarch64-unknown-linux-gnu//:toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

toolchain(
name = "cross_arm64_s390x_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:s390x",
],
target_settings = [
":cross",
],
toolchain = "@armtoolchain_cross_s390x-ibm-linux-gnu//:toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

toolchain(
name = "cross_arm64_macos_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:arm64",
],
target_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
target_settings = [
":cross",
],
toolchain = "@cross_arm64_macos_toolchain//:toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

toolchain(
name = "cross_arm64_macos_arm_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:arm64",
],
target_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:arm64",
],
target_settings = [
":cross",
],
toolchain = "@cross_arm64_macos_arm_toolchain//:toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

# This is the dev macOS toolchain which uses the same version of Clang that we
# use in CI. We don't have a dev macOS toolchain for ARM yet because Clang
# doesn't publish compilers that run on M1 Macs.
toolchain(
name = "dev_darwin_x86_64_toolchain",
exec_compatible_with = [
Expand All @@ -125,6 +287,9 @@ platform(
],
)

# There are aliases for each of these flags defined in .bazelrc; for example,
# --crdb_test instead of --//build/toolchains:crdb_test_flag.

bool_flag(
name = "crdb_test_flag",
build_setting_default = False,
Expand Down Expand Up @@ -185,6 +350,28 @@ config_setting(
},
)

config_setting(
name = "is_cross_macos_x86_64",
constraint_values = [
"@io_bazel_rules_go//go/toolchain:darwin",
"@platforms//cpu:x86_64",
],
flag_values = {
":cross_flag": "true",
},
)

config_setting(
name = "is_cross_macos_arm64",
constraint_values = [
"@io_bazel_rules_go//go/toolchain:darwin",
"@platforms//cpu:arm64",
],
flag_values = {
":cross_flag": "true",
},
)

config_setting(
name = "is_cross_linux",
constraint_values = [
Expand Down
42 changes: 35 additions & 7 deletions build/toolchains/REPOSITORIES.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,58 @@ load(
_crosstool_toolchain_repo = "crosstool_toolchain_repo",
)
load(
"//build/toolchains:darwin-x86_64/toolchain.bzl",
_macos_toolchain_repo = "macos_toolchain_repo",
"//build/toolchains:darwin/toolchain.bzl",
_macos_toolchain_repos = "macos_toolchain_repos",
)

def toolchain_dependencies():
_dev_darwin_x86_repo(name = "toolchain_dev_darwin_x86-64")
_crosstool_toolchain_repo(
name = "toolchain_cross_aarch64-unknown-linux-gnu",
host = "x86_64",
target = "aarch64-unknown-linux-gnu",
tarball_sha256 = "ed7ebe618794c0a64aec742d1bf9274302f86a8a81505758c97dc99dab5fd6ab",
tarball_sha256 = "76efd6ee539a0a358c03a6405c95c2f758935bbe70572e030fad86fb328b7d7b",
)
_crosstool_toolchain_repo(
name = "toolchain_cross_s390x-ibm-linux-gnu",
host = "x86_64",
target = "s390x-ibm-linux-gnu",
tarball_sha256 = "93c34d3111e38882fd88f38df33243c52466f703d78e7dd8ac0260c9e1ca35c6",
tarball_sha256 = "3917b7ba50b30d4907d05a3060e79e931e541cb7096913285e4fc0b06ccc98fe",
)
_crosstool_toolchain_repo(
name = "toolchain_cross_x86_64-unknown-linux-gnu",
host = "x86_64",
target = "x86_64-unknown-linux-gnu",
tarball_sha256 = "38f06a929fcc3d1405fe229aa8bc30e57ca78312f4e07e10a68cd3568a64412e",
tarball_sha256 = "267331e9c9cefdcb079a1487b346014f956e6b95332286fadb43d41b6cdd8ce0",
)
_crosstool_toolchain_repo(
name = "toolchain_cross_x86_64-w64-mingw32",
host = "x86_64",
target = "x86_64-w64-mingw32",
tarball_sha256 = "6900b96f7bbd86ba96c4c9704eab6fcb2241fdb5df0a8b9cb3416505a6ef19f7",
tarball_sha256 = "6b2a41d551f91d43b00ce086c60bb589e0ae95da2b14cc3fc6e2f2bf4494b21d",
)
_macos_toolchain_repo(name = "toolchain_cross_x86_64-apple-darwin19")
_crosstool_toolchain_repo(
name = "armtoolchain_cross_aarch64-unknown-linux-gnu",
host = "aarch64",
target = "aarch64-unknown-linux-gnu",
tarball_sha256 = "8e8455a9f5cec46aa6f8a7ffa53b6fb470f98ae169c49a8fe65ed2fbeb83e82f",
)
_crosstool_toolchain_repo(
name = "armtoolchain_cross_s390x-ibm-linux-gnu",
host = "aarch64",
target = "s390x-ibm-linux-gnu",
tarball_sha256 = "013e7ad3294b7f77b4937e988e0766bd0eb02186876c9e12f51314af38a43597",
)
_crosstool_toolchain_repo(
name = "armtoolchain_cross_x86_64-unknown-linux-gnu",
host = "aarch64",
target = "x86_64-unknown-linux-gnu",
tarball_sha256 = "a74aa2fb685b23e32a099f4c0bd32618640fc6f1070237edfd3f0c7f613ea983",
)
_crosstool_toolchain_repo(
name = "armtoolchain_cross_x86_64-w64-mingw32",
host = "aarch64",
target = "x86_64-w64-mingw32",
tarball_sha256 = "6baff5e7658215aabfbc6d37374f4fcdd1b62269828d55ebef841248a99373cc",
)
_macos_toolchain_repos()
2 changes: 1 addition & 1 deletion build/toolchains/crosstool-ng/BUILD.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ load(":cc_toolchain_config.bzl", "cc_toolchain_config")
cc_toolchain_suite(
name = "suite",
toolchains = {
"k8": ":toolchain",
"%{host}": ":toolchain",
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def _impl(ctx):
ctx = ctx,
features = features,
toolchain_identifier = "%{target}-cross-toolchain",
host_system_name = "%{target}",
host_system_name = "%{host}",
target_system_name = "%{target}",
target_cpu = "%{target}",
target_libc = "glibc-2.14",
Expand Down
Loading