From 68355af110dca2654703821cc41d67a4729942a6 Mon Sep 17 00:00:00 2001 From: Ricky Stewart Date: Wed, 16 Mar 2022 13:32:25 -0500 Subject: [PATCH] build: integrate new cross toolchains w/ Bazel 1. Add new toolchains that run on ARM hosts. 2. Add new toolchains that target M1 Mac's. Release note: None --- .bazelrc | 6 +- WORKSPACE | 14 +- build/toolchains/BUILD.bazel | 197 +++++++++++++++++- build/toolchains/REPOSITORIES.bzl | 42 +++- build/toolchains/crosstool-ng/BUILD.tmpl | 2 +- .../crosstool-ng/cc_toolchain_config.bzl.tmpl | 2 +- build/toolchains/crosstool-ng/toolchain.bzl | 13 +- build/toolchains/darwin-x86_64/toolchain.bzl | 28 --- .../{darwin-x86_64 => darwin}/BUILD.tmpl | 20 +- .../cc_toolchain_config.bzl.tmpl | 30 +-- build/toolchains/darwin/toolchain.bzl | 58 ++++++ c-deps/BUILD.bazel | 50 +++-- 12 files changed, 372 insertions(+), 90 deletions(-) delete mode 100644 build/toolchains/darwin-x86_64/toolchain.bzl rename build/toolchains/{darwin-x86_64 => darwin}/BUILD.tmpl (69%) rename build/toolchains/{darwin-x86_64 => darwin}/cc_toolchain_config.bzl.tmpl (85%) create mode 100644 build/toolchains/darwin/toolchain.bzl diff --git a/.bazelrc b/.bazelrc index 08fda85a2beb..20817443f7b9 100644 --- a/.bazelrc +++ b/.bazelrc @@ -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 diff --git a/WORKSPACE b/WORKSPACE index 7ffc54c22492..03b75070f83c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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", ) diff --git a/build/toolchains/BUILD.bazel b/build/toolchains/BUILD.bazel index f6857021a6d4..c77956684ce6 100644 --- a/build/toolchains/BUILD.bazel +++ b/build/toolchains/BUILD.bazel @@ -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", @@ -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", @@ -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", @@ -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", ) @@ -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", @@ -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 = [ @@ -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, @@ -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 = [ diff --git a/build/toolchains/REPOSITORIES.bzl b/build/toolchains/REPOSITORIES.bzl index 5c4f7713a69e..8038baddf041 100644 --- a/build/toolchains/REPOSITORIES.bzl +++ b/build/toolchains/REPOSITORIES.bzl @@ -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() diff --git a/build/toolchains/crosstool-ng/BUILD.tmpl b/build/toolchains/crosstool-ng/BUILD.tmpl index 487e09f3c8e0..58164b4ed1f9 100644 --- a/build/toolchains/crosstool-ng/BUILD.tmpl +++ b/build/toolchains/crosstool-ng/BUILD.tmpl @@ -5,7 +5,7 @@ load(":cc_toolchain_config.bzl", "cc_toolchain_config") cc_toolchain_suite( name = "suite", toolchains = { - "k8": ":toolchain", + "%{host}": ":toolchain", }, ) diff --git a/build/toolchains/crosstool-ng/cc_toolchain_config.bzl.tmpl b/build/toolchains/crosstool-ng/cc_toolchain_config.bzl.tmpl index d5ec0041380f..23968c771e7d 100644 --- a/build/toolchains/crosstool-ng/cc_toolchain_config.bzl.tmpl +++ b/build/toolchains/crosstool-ng/cc_toolchain_config.bzl.tmpl @@ -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", diff --git a/build/toolchains/crosstool-ng/toolchain.bzl b/build/toolchains/crosstool-ng/toolchain.bzl index 92875e77118c..7436eb69187d 100644 --- a/build/toolchains/crosstool-ng/toolchain.bzl +++ b/build/toolchains/crosstool-ng/toolchain.bzl @@ -1,10 +1,10 @@ def _impl(rctx): + if rctx.attr.host == "x86_64": + url = "https://storage.googleapis.com/public-bazel-artifacts/toolchains/crosstool-ng/{}/20220317-191459/{}.tar.gz".format(rctx.attr.host, rctx.attr.target) + elif rctx.attr.host == "aarch64": + url = "https://storage.googleapis.com/public-bazel-artifacts/toolchains/crosstool-ng/{}/20220316-165237/{}.tar.gz".format(rctx.attr.host, rctx.attr.target) rctx.download_and_extract( - url = [ - "https://storage.googleapis.com/public-bazel-artifacts/toolchains/crosstool-ng/20210601-231954/{}.tar.gz".format( - rctx.attr.target, - ), - ], + url = [url], sha256 = rctx.attr.tarball_sha256, stripPrefix = "x-tools/{}/".format(rctx.attr.target), ) @@ -15,6 +15,7 @@ def _impl(rctx): "BUILD", Label("@cockroach//build:toolchains/crosstool-ng/BUILD.tmpl"), substitutions = { + "%{host}": rctx.attr.host, "%{target}": rctx.attr.target, }, executable = False, @@ -24,6 +25,7 @@ def _impl(rctx): Label("@cockroach//build:toolchains/crosstool-ng/cc_toolchain_config.bzl.tmpl"), substitutions = { "%{target}": rctx.attr.target, + "%{host}": rctx.attr.host, "%{repo_path}": repo_path, }, executable = False, @@ -32,6 +34,7 @@ def _impl(rctx): crosstool_toolchain_repo = repository_rule( implementation = _impl, attrs = { + "host": attr.string(mandatory = True), "target": attr.string(mandatory = True), "tarball_sha256": attr.string(mandatory = True), }, diff --git a/build/toolchains/darwin-x86_64/toolchain.bzl b/build/toolchains/darwin-x86_64/toolchain.bzl deleted file mode 100644 index 54ab88ab8383..000000000000 --- a/build/toolchains/darwin-x86_64/toolchain.bzl +++ /dev/null @@ -1,28 +0,0 @@ -def _impl(rctx): - rctx.download_and_extract( - url = [ - "https://storage.googleapis.com/public-bazel-artifacts/toolchains/crosstool-ng/20210601-231954/x86_64-apple-darwin19.tar.gz", - ], - sha256 = "79ecc64d57f05cc4eccb3e57ce19fe016a3ba24c00fbe2435650f58168df8937", - stripPrefix = "x-tools/x86_64-apple-darwin19/", - ) - - repo_path = str(rctx.path("")) - - rctx.template( - "BUILD", - Label("@cockroach//build:toolchains/darwin-x86_64/BUILD.tmpl"), - executable = False, - ) - rctx.template( - "cc_toolchain_config.bzl", - Label("@cockroach//build:toolchains/darwin-x86_64/cc_toolchain_config.bzl.tmpl"), - substitutions = { - "%{repo_path}": repo_path, - }, - executable = False, - ) - -macos_toolchain_repo = repository_rule( - implementation = _impl, -) diff --git a/build/toolchains/darwin-x86_64/BUILD.tmpl b/build/toolchains/darwin/BUILD.tmpl similarity index 69% rename from build/toolchains/darwin-x86_64/BUILD.tmpl rename to build/toolchains/darwin/BUILD.tmpl index 8888b5bf461b..fb9cff09767a 100644 --- a/build/toolchains/darwin-x86_64/BUILD.tmpl +++ b/build/toolchains/darwin/BUILD.tmpl @@ -3,14 +3,14 @@ package(default_visibility = ["//visibility:public"]) load(":cc_toolchain_config.bzl", "cc_toolchain_config") exports_files([ - "bin/x86_64-apple-darwin19-install_name_tool", - "bin/x86_64-apple-darwin19-otool", + "bin/%{target}-apple-darwin21.2-install_name_tool", + "bin/%{target}-apple-darwin21.2-otool", ]) cc_toolchain_suite( name = "suite", toolchains = { - "k8": ":toolchain", + "%{host}": ":toolchain", }, ) @@ -31,22 +31,22 @@ filegroup( filegroup( name = "compiler_files", srcs = [ - "bin/x86_64-apple-darwin19-cc", - "bin/x86_64-apple-darwin19-c++", + "bin/%{target}-apple-darwin21.2-cc", + "bin/%{target}-apple-darwin21.2-c++", ], ) filegroup( name = "ar_files", srcs = [ - "bin/x86_64-apple-darwin19-ar", + "bin/%{target}-apple-darwin21.2-ar", ], ) filegroup( name = "linker_files", srcs = [ - "bin/x86_64-apple-darwin19-cc", + "bin/%{target}-apple-darwin21.2-cc", "bin/xcrun", ], ) @@ -54,20 +54,20 @@ filegroup( filegroup( name = "objcopy_files", srcs = [ - "bin/x86_64-apple-darwin19-objcopy", + "bin/%{target}-apple-darwin21.2-objcopy", ], ) filegroup( name = "strip_files", srcs = [ - "bin/x86_64-apple-darwin19-strip", + "bin/%{target}-apple-darwin21.2-strip", ], ) cc_toolchain( name = "toolchain", - toolchain_identifier = "x86_64-apple-darwin19-cross-toolchain", + toolchain_identifier = "%{target}-apple-darwin21.2-cross-toolchain", toolchain_config = ":toolchain_config", all_files = ":all_files", ar_files = ":ar_files", diff --git a/build/toolchains/darwin-x86_64/cc_toolchain_config.bzl.tmpl b/build/toolchains/darwin/cc_toolchain_config.bzl.tmpl similarity index 85% rename from build/toolchains/darwin-x86_64/cc_toolchain_config.bzl.tmpl rename to build/toolchains/darwin/cc_toolchain_config.bzl.tmpl index 49cb777d4b41..b5b53c8f54d3 100644 --- a/build/toolchains/darwin-x86_64/cc_toolchain_config.bzl.tmpl +++ b/build/toolchains/darwin/cc_toolchain_config.bzl.tmpl @@ -34,35 +34,35 @@ def _impl(ctx): tool_paths = [ tool_path( name = "gcc", - path = "bin/x86_64-apple-darwin19-cc", + path = "bin/%{target}-apple-darwin21.2-cc", ), tool_path( name = "ld", - path = "bin/x86_64-apple-darwin19-ld", + path = "bin/%{target}-apple-darwin21.2-ld", ), tool_path( name = "cpp", - path = "bin/x86_64-apple-darwin19-c++", + path = "bin/%{target}-apple-darwin21.2-c++", ), tool_path( name = "gcov", - path = "bin/x86_64-apple-darwin19-gcov", + path = "bin/%{target}-apple-darwin21.2-gcov", ), tool_path( name = "nm", - path = "bin/x86_64-apple-darwin19-nm", + path = "bin/%{target}-apple-darwin21.2-nm", ), tool_path( name = "objdump", - path = "bin/x86_64-apple-darwin19-objdump", + path = "bin/%{target}-apple-darwin21.2-objdump", ), tool_path( name = "strip", - path = "bin/x86_64-apple-darwin19-strip", + path = "bin/%{target}-apple-darwin21.2-strip", ), tool_path( name = "ar", - path = "bin/x86_64-apple-darwin19-ar", + path = "bin/%{target}-apple-darwin21.2-ar", ), ] @@ -112,7 +112,7 @@ def _impl(ctx): flags = [ "-g1", "-Wall", - "-I%{repo_path}/SDK/MacOSX10.15.sdk/usr/include/c++/v1", + "-I%{repo_path}/SDK/MacOSX12.1.sdk/usr/include/c++/v1", ], ), ]), @@ -191,20 +191,20 @@ def _impl(ctx): return cc_common.create_cc_toolchain_config_info( ctx = ctx, features = features, - toolchain_identifier = "x86_64-apple-darwin19-cross-toolchain", - host_system_name = "x86_64-apple-darwin19", - target_system_name = "x86_64-apple-darwin19", - target_cpu = "x86_64-apple-darwin19", + toolchain_identifier = "%{target}-apple-darwin21.2-cross-toolchain", + host_system_name = "{host}-apple-darwin21.2", + target_system_name = "%{target}-apple-darwin21.2", + target_cpu = "%{target}-apple-darwin21.2", target_libc = "glibc-2.14", compiler = "clang", abi_version = "clang-10.0.0", - abi_libc_version = "x86_64-apple-darwin19", + abi_libc_version = "%{target}-apple-darwin21.2", tool_paths = tool_paths, cxx_builtin_include_directories = [ "%sysroot%/usr/include", "/usr/lib/llvm-10/lib/clang/10.0.0/include", ], - builtin_sysroot = "%{repo_path}/SDK/MacOSX10.15.sdk", + builtin_sysroot = "%{repo_path}/SDK/MacOSX12.1.sdk", ) cc_toolchain_config = rule( diff --git a/build/toolchains/darwin/toolchain.bzl b/build/toolchains/darwin/toolchain.bzl new file mode 100644 index 000000000000..4601aeebdd40 --- /dev/null +++ b/build/toolchains/darwin/toolchain.bzl @@ -0,0 +1,58 @@ +def _impl(rctx): + if rctx.attr.host == "arm64": + url = "https://storage.googleapis.com/public-bazel-artifacts/toolchains/osxcross/aarch64/20220317-160719/x86_64-apple-darwin21.2.tar.gz" + sha256 = "a0fda00934d9f6f17cdd62ce685d0a12751c34686df14085b72e40d5803e93a6" + elif rctx.attr.host == "x86_64": + url = "https://storage.googleapis.com/public-bazel-artifacts/toolchains/osxcross/x86_64/20220317-165434/x86_64-apple-darwin21.2.tar.gz" + sha256 = "751365dbfb5db66fe8e9f47fcf82cbbd7d1c176b79112ab91945d1be1d160dd5" + rctx.download_and_extract( + url = [url], + sha256 = sha256, + stripPrefix = "x-tools/x86_64-apple-darwin21.2/", + ) + + repo_path = str(rctx.path("")) + + rctx.template( + "BUILD", + Label("@cockroach//build:toolchains/darwin/BUILD.tmpl"), + substitutions = { + "%{host}": rctx.attr.host, + "%{target}": rctx.attr.target, + }, + executable = False, + ) + rctx.template( + "cc_toolchain_config.bzl", + Label("@cockroach//build:toolchains/darwin/cc_toolchain_config.bzl.tmpl"), + substitutions = { + "%{host}": rctx.attr.host, + "%{repo_path}": repo_path, + "%{target}": rctx.attr.target, + }, + executable = False, + ) + +macos_toolchain_repo = repository_rule( + implementation = _impl, + attrs = { + "host": attr.string(mandatory = True), + "target": attr.string(mandatory = True), + }, +) + +def macos_toolchain_repos_for_host(host): + macos_toolchain_repo( + name = "cross_{}_macos_arm_toolchain".format(host), + host = host, + target = 'arm64', + ) + macos_toolchain_repo( + name = "cross_{}_macos_toolchain".format(host), + host = host, + target = 'x86_64', + ) + +def macos_toolchain_repos(): + macos_toolchain_repos_for_host('arm64') + macos_toolchain_repos_for_host('x86_64') diff --git a/c-deps/BUILD.bazel b/c-deps/BUILD.bazel index 7b48794119e7..778c92d5c922 100644 --- a/c-deps/BUILD.bazel +++ b/c-deps/BUILD.bazel @@ -11,8 +11,13 @@ configure_make( "--enable-prof", ] + select({ "@io_bazel_rules_go//go/platform:windows": ["--host=x86_64-w64-mingw32"], - "@io_bazel_rules_go//go/platform:darwin_amd64": ["--host=x86_64-apple-darwin19"], - "@io_bazel_rules_go//go/platform:darwin_arm64": ["--host=aarch64-apple-darwin19"], + "@io_bazel_rules_go//go/platform:darwin_amd64": ["--host=x86_64-apple-darwin21.2"], + "@io_bazel_rules_go//go/platform:darwin_arm64": [ + "--host=aarch64-apple-darwin21.2", + "--with-lg-page=16", + ], + "@io_bazel_rules_go//go/platform:linux_amd64": ["--host=x86_64-unknown-linux-gnu"], + "@io_bazel_rules_go//go/platform:linux_arm64": ["--host=aarch64-unknown-linux-gnu"], # NB: Normally host detection is handled by configure, but the version # of jemalloc we have vendored is pretty ancient and can't handle some # of the newer M1 Macs. This arm of the select() can probably be deleted @@ -21,7 +26,6 @@ configure_make( "--host=aarch64-apple-darwin19", "--build=aarch64-apple-darwin19", ], - "@io_bazel_rules_go//go/platform:linux_arm64": ["--host=aarch64-unknown-linux-gnu"], "//conditions:default": [], }), env = select({ @@ -92,16 +96,24 @@ cmake( }, }), data = select({ - "//build/toolchains:is_cross_macos": [ - "@toolchain_cross_x86_64-apple-darwin19//:bin/x86_64-apple-darwin19-install_name_tool", - "@toolchain_cross_x86_64-apple-darwin19//:bin/x86_64-apple-darwin19-otool", + "//build/toolchains:is_cross_macos_x86_64": [ + "@cross_x86_64_macos_toolchain//:bin/x86_64-apple-darwin21.2-install_name_tool", + "@cross_x86_64_macos_toolchain//:bin/x86_64-apple-darwin21.2-otool", + ], + "//build/toolchains:is_cross_macos_arm64": [ + "@cross_arm64_macos_toolchain//:bin/arm64-apple-darwin21.2-install_name_tool", + "@cross_arm64_macos_toolchain//:bin/arm64-apple-darwin21.2-otool", ], "//conditions:default": [], }), env = select({ - "//build/toolchains:is_cross_macos": { - "CMAKE_INSTALL_NAME_TOOL": "$(execpath @toolchain_cross_x86_64-apple-darwin19//:bin/x86_64-apple-darwin19-install_name_tool)", - "OTOOL": "$(execpath @toolchain_cross_x86_64-apple-darwin19//:bin/x86_64-apple-darwin19-otool)", + "//build/toolchains:is_cross_macos_x86_64": { + "CMAKE_INSTALL_NAME_TOOL": "$(execpath @cross_x86_64_macos_toolchain//:bin/x86_64-apple-darwin21.2-install_name_tool)", + "OTOOL": "$(execpath @cross_x86_64_macos_toolchain//:bin/x86_64-apple-darwin21.2-otool)", + }, + "//build/toolchains:is_cross_macos_arm64": { + "CMAKE_INSTALL_NAME_TOOL": "$(execpath @cross_arm64_macos_toolchain//:bin/arm64-apple-darwin21.2-install_name_tool)", + "OTOOL": "$(execpath @cross_arm64_macos_toolchain//:bin/arm64-apple-darwin21.2-otool)", }, "//conditions:default": {}, }), @@ -160,13 +172,25 @@ configure_make( configure_options = [ "--enable-static", "--disable-shared", - ], + ] + select({ + "@io_bazel_rules_go//go/platform:linux_amd64": ["--host=x86_64-unknown-linux-gnu"], + "@io_bazel_rules_go//go/platform:linux_arm64": ["--host=aarch64-unknown-linux-gnu"], + "//conditions:default": [], + }), # We specify -fcommon to get around duplicate definition errors in recent gcc. copts = ["-fcommon"], data = [":autom4te"], - env = { - "AUTOM4TE": "$(execpath :autom4te)", - }, + env = select({ + "//build/toolchains:cross": { + "AUTOM4TE": "$(execpath :autom4te)", + "krb5_cv_attr_constructor_destructor": "yes", + "ac_cv_func_regcomp": "yes", + "ac_cv_printf_positional": "yes", + }, + "//conditions:default": { + "AUTOM4TE": "$(execpath :autom4te)", + }, + }), lib_source = "@krb5//:all", out_static_libs = [ "libgssapi_krb5.a",