From fe1493758567beffa2d076ce89932dbb7fa40139 Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Wed, 27 Jan 2021 03:23:12 -0800 Subject: [PATCH] Add native support for Apple Silicon After this PR, we can use a x86 version of Bazel to build an ARM64 Bazel binary for Apple Silicon by ``` bazel build --cpu=darwin_arm64 //src:bazel ``` The Bazel client, embedded tools and embedded JDK are all native ARM64 binaries. Changes in this PR: 1. Add OpenJDK definitions for ARM64 macOS 2. Manually created the embedded JDK binaries on an Apple Silicon machine and uploaded them to the bazel mirror site. 3. AutoCpuConverter.java: identify the cpu value correctly 4. cc_toolchain_config.bzl: Explicitly specify the target platform also in the x86 cc toolchain, so that we can also do cross-platform compile from ARM64 to x86. With the native arm64 Bazel binary, building Bazel itself takes only half of the time compared with the x86 Bazel binary on an Apple DTK machine: ``` $ bazel build --cpu=darwin_arm64 --disk_cache= --repository_cache= //src:bazel Starting local Bazel server and connecting to it... ... Target //src:bazel up-to-date: bazel-bin/src/bazel INFO: Elapsed time: 1044.462s, Critical Path: 180.08s INFO: 2984 processes: 179 internal, 2092 darwin-sandbox, 1 local, 712 worker. INFO: Build completed successfully, 2984 total actions cp ./bazel-bin/src/bazel ~/bin/bazel-arm64 $ bazel-arm64 clean --expunge $ bazel-arm64 build --disk_cache= --repository_cache= //src:bazel Starting local Bazel server and connecting to it... ... Target //src:bazel up-to-date: bazel-bin/src/bazel INFO: Elapsed time: 464.470s, Critical Path: 114.88s INFO: 2984 processes: 179 internal, 2092 darwin-sandbox, 1 local, 712 worker. INFO: Build completed successfully, 2984 total actions ``` Closes: https://github.com/bazelbuild/bazel/issues/11628 Closes #12900. PiperOrigin-RevId: 354058336 Revert default cpu value on x86 macOS to "darwin" Many downstream projects are still depending on the default cpu value on x86 macOS being "darwin" instead of "darwin_x86_64" https://buildkite.com/bazel/bazel-auto-sheriff-face-with-cowboy-hat/builds/412 Related: #11628 Closes #12918. PiperOrigin-RevId: 354279409 --- WORKSPACE | 85 +++++++++++++++++++ src/BUILD | 14 +++ .../lib/analysis/config/AutoCpuConverter.java | 9 +- .../build/lib/bazel/rules/java/jdk.WORKSPACE | 26 ++++++ src/test/py/bazel/test_base.py | 2 + .../shell/bazel/testdata/jdk_http_archives | 26 ++++++ src/test/shell/testenv.sh | 5 ++ tools/cpp/cc_configure.bzl | 4 +- tools/cpp/lib_cc_configure.bzl | 4 +- tools/osx/crosstool/cc_toolchain_config.bzl | 40 ++++++++- 10 files changed, 208 insertions(+), 7 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index ab7af311738ee6..200a813879f0d8 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -409,6 +409,30 @@ http_file( urls = ["https://mirror.bazel.build/openjdk/azul-zulu11.37.17-ca-jdk11.0.6/zulu11.37.17-ca-jdk11.0.6-macosx_x64-minimal-b23d4e05466f2aa1fdcd72d3d3a8e962206b64bf-1581689063.tar.gz"], ) +http_file( + name = "openjdk_macos_aarch64", + downloaded_file_path = "zulu-macos-aarch64.tar.gz", + sha256 = "a900ef793cb34b03ac5d93ea2f67291b6842e99d500934e19393a8d8f9bfa6ff", + urls = ["https://mirror.bazel.build/openjdk/azul-zulu11.45.27-ca-jdk11.0.10/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64-allmodules-1611665569.tar.gz"], +) + +http_file( + name = "openjdk_macos_aarch64_vanilla", + downloaded_file_path = "zulu-macos-aarch64-vanilla.tar.gz", + sha256 = "3dcc636e64ae58b922269c2dc9f20f6f967bee90e3f6847d643c4a566f1e8d8a", + urls = [ + "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz", + "https://cdn.azul.com/zulu/bin/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz", + ], +) + +http_file( + name = "openjdk_macos_aarch64_minimal", + downloaded_file_path = "zulu-macos-aarch64-minimal.tar.gz", + sha256 = "f4f606926e6deeaa8b8397e299313d9df87642fe464b0ccf1ed0432aeb00640b", + urls = ["https://mirror.bazel.build/openjdk/azul-zulu11.45.27-ca-jdk11.0.10/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64-minimal-1611665562.tar.gz"], +) + http_file( name = "openjdk_win", downloaded_file_path = "zulu-win.zip", @@ -552,6 +576,7 @@ distdir_tar( "zulu11.37.17-ca-jdk11.0.6-linux_x64.tar.gz", "zulu11.37.48-ca-jdk11.0.6-linux_aarch64.tar.gz", "zulu11.37.17-ca-jdk11.0.6-macosx_x64.tar.gz", + "zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz", "zulu11.37.17-ca-jdk11.0.6-win_x64.zip", "android_tools_pkg-0.19.0rc3.tar.gz", # bazelbuild/bazel-skylib @@ -586,6 +611,7 @@ distdir_tar( "zulu11.37.17-ca-jdk11.0.6-linux_x64.tar.gz": "360626cc19063bc411bfed2914301b908a8f77a7919aaea007a977fa8fb3cde1", "zulu11.37.48-ca-jdk11.0.6-linux_aarch64.tar.gz": "a452f1b9682d9f83c1c14e54d1446e1c51b5173a3a05dcb013d380f9508562e4", "zulu11.37.17-ca-jdk11.0.6-macosx_x64.tar.gz": "e1fe56769f32e2aaac95e0a8f86b5a323da5af3a3b4bba73f3086391a6cc056f", + "zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz": "3dcc636e64ae58b922269c2dc9f20f6f967bee90e3f6847d643c4a566f1e8d8a", "zulu11.37.17-ca-jdk11.0.6-win_x64.zip": "a9695617b8374bfa171f166951214965b1d1d08f43218db9a2a780b71c665c18", "android_tools_pkg-0.19.0rc3.tar.gz": "ea5c0589a01e2a9f43c20e5c145d3530e3b3bdbe7322789bc5da38d0ca49b837", # bazelbuild/bazel-skylib @@ -619,6 +645,7 @@ distdir_tar( "zulu11.37.17-ca-jdk11.0.6-linux_x64.tar.gz": ["https://mirror.bazel.build/openjdk/azul-zulu11.37.17-ca-jdk11.0.6/zulu11.37.17-ca-jdk11.0.6-linux_x64.tar.gz"], "zulu11.37.48-ca-jdk11.0.6-linux_aarch64.tar.gz": ["https://mirror.bazel.build/openjdk/azul-zulu11.37.48-ca-jdk11.0.6/zulu11.37.48-ca-jdk11.0.6-linux_aarch64.tar.gz"], "zulu11.37.17-ca-jdk11.0.6-macosx_x64.tar.gz": ["https://mirror.bazel.build/openjdk/azul-zulu11.37.17-ca-jdk11.0.6/zulu11.37.17-ca-jdk11.0.6-macosx_x64.tar.gz"], + "zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz": ["https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz"], "zulu11.37.17-ca-jdk11.0.6-win_x64.zip": ["https://mirror.bazel.build/openjdk/azul-zulu11.37.17-ca-jdk11.0.6/zulu11.37.17-ca-jdk11.0.6-win_x64.zip"], "android_tools_pkg-0.19.0rc3.tar.gz": [ "https://mirror.bazel.build/bazel_android_tools/android_tools_pkg-0.19.0rc3.tar.gz", @@ -827,6 +854,20 @@ http_archive( urls = ["https://mirror.bazel.build/openjdk/azul-zulu11.37.17-ca-jdk11.0.6/zulu11.37.17-ca-jdk11.0.6-macosx_x64.tar.gz"], ) +# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE. +http_archive( + name = "remotejdk11_macos_aarch64_for_testing", + build_file = "@local_jdk//:BUILD.bazel", + patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE, + patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN, + sha256 = "3dcc636e64ae58b922269c2dc9f20f6f967bee90e3f6847d643c4a566f1e8d8a", + strip_prefix = "zulu11.45.27-ca-jdk11.0.10-macosx_aarch64", + urls = [ + "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz", + "https://cdn.azul.com/zulu/bin/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz", + ], +) + # This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE. http_archive( name = "remotejdk11_win_for_testing", @@ -899,6 +940,20 @@ http_archive( ], ) +# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE. +http_archive( + name = "remotejdk15_macos_aarch64_for_testing", + build_file = "@local_jdk//:BUILD.bazel", + patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE, + patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN, + sha256 = "2613c3f15eef6b6ecd0fd102da92282b985e4573905dc902f1783d8059c1efc5", + strip_prefix = "zulu15.29.15-ca-jdk15.0.2-macosx_aarch64", + urls = [ + "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu15.29.15-ca-jdk15.0.2-macosx_aarch64.tar.gz", + "https://cdn.azul.com/zulu/bin/zulu15.29.15-ca-jdk15.0.2-macosx_aarch64.tar.gz", + ], +) + # This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE. http_archive( name = "remotejdk15_win_for_testing", @@ -1006,6 +1061,21 @@ exports_files(["WORKSPACE"], visibility = ["//visibility:public"]) urls = ["https://mirror.bazel.build/openjdk/azul-zulu11.37.17-ca-jdk11.0.6/zulu11.37.17-ca-jdk11.0.6-macosx_x64.tar.gz"], ) +# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives. +http_archive( + name = "openjdk11_darwin_aarch64_archive", + build_file_content = """ +java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public']) +exports_files(["WORKSPACE"], visibility = ["//visibility:public"]) +""", + sha256 = "3dcc636e64ae58b922269c2dc9f20f6f967bee90e3f6847d643c4a566f1e8d8a", + strip_prefix = "zulu11.45.27-ca-jdk11.0.10-macosx_aarch64", + urls = [ + "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz", + "https://cdn.azul.com/zulu/bin/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz", + ], +) + # This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives. http_archive( name = "openjdk11_windows_archive", @@ -1084,6 +1154,21 @@ exports_files(["WORKSPACE"], visibility = ["//visibility:public"]) ], ) +# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives. +http_archive( + name = "openjdk15_darwin_aarch64_archive", + build_file_content = """ +java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public']) +exports_files(["WORKSPACE"], visibility = ["//visibility:public"]) +""", + sha256 = "2613c3f15eef6b6ecd0fd102da92282b985e4573905dc902f1783d8059c1efc5", + strip_prefix = "zulu15.29.15-ca-jdk15.0.2-macosx_aarch64", + urls = [ + "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu15.29.15-ca-jdk15.0.2-macosx_aarch64.tar.gz", + "https://cdn.azul.com/zulu/bin/zulu15.29.15-ca-jdk15.0.2-macosx_aarch64.tar.gz", + ], +) + # This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives. http_archive( name = "openjdk15_windows_archive", diff --git a/src/BUILD b/src/BUILD index 90dc39c1bdb62f..e2d27ddfa25090 100644 --- a/src/BUILD +++ b/src/BUILD @@ -178,6 +178,9 @@ filegroup( "//src/conditions:darwin": [ "@openjdk_macos//file", ], + "//src/conditions:darwin_arm64": [ + "@openjdk_macos_aarch64//file", + ], "//src/conditions:windows": [ "@openjdk_win//file", ], @@ -197,6 +200,9 @@ filegroup( "//src/conditions:darwin": [ "@openjdk_macos_minimal//file", ], + "//src/conditions:darwin_arm64": [ + "@openjdk_macos_aarch64_minimal//file", + ], "//src/conditions:windows": [ "@openjdk_win_minimal//file", ], @@ -216,6 +222,9 @@ filegroup( "//src/conditions:darwin": [ "@openjdk_macos_vanilla//file", ], + "//src/conditions:darwin_arm64": [ + "@openjdk_macos_aarch64_vanilla//file", + ], "//src/conditions:windows": [ "@openjdk_win_vanilla//file", ], @@ -749,18 +758,21 @@ filegroup( "@bazel_skylib//:WORKSPACE", "@bazel_toolchains//:WORKSPACE", "@com_google_protobuf//:WORKSPACE", + "@openjdk11_darwin_aarch64_archive//:WORKSPACE", "@openjdk11_darwin_archive//:WORKSPACE", "@openjdk11_linux_archive//:WORKSPACE", "@openjdk11_windows_archive//:WORKSPACE", "@openjdk14_darwin_archive//:WORKSPACE", "@openjdk14_linux_archive//:WORKSPACE", "@openjdk14_windows_archive//:WORKSPACE", + "@openjdk15_darwin_aarch64_archive//:WORKSPACE", "@openjdk15_darwin_archive//:WORKSPACE", "@openjdk15_linux_archive//:WORKSPACE", "@openjdk15_windows_archive//:WORKSPACE", "@openjdk_linux_aarch64_minimal//file", "@openjdk_linux_minimal//file", "@openjdk_macos_minimal//file", + "@openjdk_macos_aarch64_minimal//file", "@openjdk_win_minimal//file", "@remote_coverage_tools_for_testing//:WORKSPACE", "@remote_java_tools_darwin_for_testing//:WORKSPACE", @@ -773,12 +785,14 @@ filegroup( "@remotejdk11_linux_for_testing//:WORKSPACE", "@remotejdk11_linux_ppc64le_for_testing//:WORKSPACE", "@remotejdk11_linux_s390x_for_testing//:WORKSPACE", + "@remotejdk11_macos_aarch64_for_testing//:WORKSPACE", "@remotejdk11_macos_for_testing//:WORKSPACE", "@remotejdk11_win_for_testing//:WORKSPACE", "@remotejdk14_linux_for_testing//:WORKSPACE", "@remotejdk14_macos_for_testing//:WORKSPACE", "@remotejdk14_win_for_testing//:WORKSPACE", "@remotejdk15_linux_for_testing//:WORKSPACE", + "@remotejdk15_macos_aarch64_for_testing//:WORKSPACE", "@remotejdk15_macos_for_testing//:WORKSPACE", "@remotejdk15_win_for_testing//:WORKSPACE", "@rules_cc//:WORKSPACE", diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/AutoCpuConverter.java b/src/main/java/com/google/devtools/build/lib/analysis/config/AutoCpuConverter.java index c0edc7ce5a08d1..9f5fbca65fd003 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/config/AutoCpuConverter.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/AutoCpuConverter.java @@ -34,7 +34,14 @@ public String convert(String input) throws OptionsParsingException { // linux-x86_64, darwin includes the CPU architecture, ...). switch (OS.getCurrent()) { case DARWIN: - return "darwin"; + switch (CPU.getCurrent()) { + case X86_64: + return "darwin"; + case AARCH64: + return "darwin_arm64"; + default: + return "unknown"; + } case FREEBSD: return "freebsd"; case OPENBSD: diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE index e24c0c4b88e274..1b18472455055a 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE @@ -76,6 +76,19 @@ maybe( ], ) +# This must be kept in sync with the top-level WORKSPACE file. +maybe( + http_archive, + name = "remotejdk11_macos_aarch64", + build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + sha256 = "3dcc636e64ae58b922269c2dc9f20f6f967bee90e3f6847d643c4a566f1e8d8a", + strip_prefix = "zulu11.45.27-ca-jdk11.0.10-macosx_aarch64", + urls = [ + "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz", + "https://cdn.azul.com/zulu/bin/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz", + ], +) + # This must be kept in sync with the top-level WORKSPACE file. maybe( http_archive, @@ -146,6 +159,19 @@ maybe( ], ) +# This must be kept in sync with the top-level WORKSPACE file. +maybe( + http_archive, + name = "remotejdk15_macos_aarch64", + build_file = "@bazel_tools//tools/jdk:jdk.BUILD", + strip_prefix = "zulu15.29.15-ca-jdk15.0.2-macosx_aarch64", + sha256 = "2613c3f15eef6b6ecd0fd102da92282b985e4573905dc902f1783d8059c1efc5", + urls = [ + "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu15.29.15-ca-jdk15.0.2-macosx_aarch64.tar.gz", + "https://cdn.azul.com/zulu/bin/zulu15.29.15-ca-jdk15.0.2-macosx_aarch64.tar.gz", + ], +) + # This must be kept in sync with the top-level WORKSPACE file. maybe( http_archive, diff --git a/src/test/py/bazel/test_base.py b/src/test/py/bazel/test_base.py index d12da1252be117..2429cefae19303 100644 --- a/src/test/py/bazel/test_base.py +++ b/src/test/py/bazel/test_base.py @@ -62,12 +62,14 @@ class TestBase(unittest.TestCase): 'remotejdk11_linux_ppc64le_for_testing', 'remotejdk11_linux_s390x_for_testing', 'remotejdk11_macos_for_testing', + 'remotejdk11_macos_aarch64_for_testing', 'remotejdk11_win_for_testing', 'remotejdk14_linux_for_testing', 'remotejdk14_macos_for_testing', 'remotejdk14_win_for_testing', 'remotejdk15_linux_for_testing', 'remotejdk15_macos_for_testing', + 'remotejdk15_macos_aarch64_for_testing', 'remotejdk15_win_for_testing', 'remote_java_tools_darwin_for_testing', 'remote_java_tools_linux_for_testing', diff --git a/src/test/shell/bazel/testdata/jdk_http_archives b/src/test/shell/bazel/testdata/jdk_http_archives index e1f553f1ebd5a4..34f2bf602a9cad 100644 --- a/src/test/shell/bazel/testdata/jdk_http_archives +++ b/src/test/shell/bazel/testdata/jdk_http_archives @@ -1,3 +1,4 @@ + ################### Remote java_tools with embedded javac 11 ################### # This must be kept in sync with the top-level WORKSPACE file. http_archive( @@ -42,6 +43,17 @@ http_archive( urls = ["https://mirror.bazel.build/openjdk/azul-zulu11.37.17-ca-jdk11.0.6/zulu11.37.17-ca-jdk11.0.6-macosx_x64.tar.gz"], ) # This must be kept in sync with the top-level WORKSPACE file. +http_archive( + name = "openjdk11_darwin_aarch64_archive", + build_file_content = "java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])", + sha256 = "3dcc636e64ae58b922269c2dc9f20f6f967bee90e3f6847d643c4a566f1e8d8a", + strip_prefix = "zulu11.45.27-ca-jdk11.0.10-macosx_aarch64", + urls = [ + "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz", + "https://cdn.azul.com/zulu/bin/zulu11.45.27-ca-jdk11.0.10-macosx_aarch64.tar.gz", + ], +) +# This must be kept in sync with the top-level WORKSPACE file. http_archive( name = "openjdk11_windows_archive", build_file_content = "java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])", @@ -106,6 +118,20 @@ exports_files(["WORKSPACE"], visibility = ["//visibility:public"]) ], ) # This must be kept in sync with the top-level WORKSPACE file. +http_archive( + name = "openjdk15_darwin_aarch64_archive", + build_file_content = """ +java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public']) +exports_files(["WORKSPACE"], visibility = ["//visibility:public"]) +""", + sha256 = "2613c3f15eef6b6ecd0fd102da92282b985e4573905dc902f1783d8059c1efc5", + strip_prefix = "zulu15.29.15-ca-jdk15.0.2-macosx_aarch64", + urls = [ + "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu15.29.15-ca-jdk15.0.2-macosx_aarch64.tar.gz", + "https://cdn.azul.com/zulu/bin/zulu15.29.15-ca-jdk15.0.2-macosx_aarch64.tar.gz", + ], +) +# This must be kept in sync with the top-level WORKSPACE file. http_archive( name = "openjdk15_windows_archive", build_file_content = """ diff --git a/src/test/shell/testenv.sh b/src/test/shell/testenv.sh index 1d5775e5b39356..45a58f98b5a8d3 100755 --- a/src/test/shell/testenv.sh +++ b/src/test/shell/testenv.sh @@ -284,17 +284,20 @@ EOF "bazel_toolchains" "com_google_protobuf" "openjdk11_darwin_archive" + "openjdk11_darwin_aarch64_archive" "openjdk11_linux_archive" "openjdk11_windows_archive" "openjdk14_darwin_archive" "openjdk14_linux_archive" "openjdk14_windows_archive" "openjdk15_darwin_archive" + "openjdk15_darwin_aarch64_archive" "openjdk15_linux_archive" "openjdk15_windows_archive" "openjdk_linux_aarch64_minimal" "openjdk_linux_minimal" "openjdk_macos_minimal" + "openjdk_macos_aarch64_minimal" "openjdk_win_minimal" "remote_coverage_tools_for_testing" "remote_java_tools_darwin_for_testing" @@ -308,12 +311,14 @@ EOF "remotejdk11_linux_ppc64le_for_testing" "remotejdk11_linux_s390x_for_testing" "remotejdk11_macos_for_testing" + "remotejdk11_macos_aarch64_for_testing" "remotejdk11_win_for_testing" "remotejdk14_linux_for_testing" "remotejdk14_macos_for_testing" "remotejdk14_win_for_testing" "remotejdk15_linux_for_testing" "remotejdk15_macos_for_testing" + "remotejdk15_macos_aarch64_for_testing" "remotejdk15_win_for_testing" "rules_cc" "rules_java" diff --git a/tools/cpp/cc_configure.bzl b/tools/cpp/cc_configure.bzl index 406425c6436b8b..c72cd9f8a70944 100644 --- a/tools/cpp/cc_configure.bzl +++ b/tools/cpp/cc_configure.bzl @@ -56,7 +56,7 @@ def cc_autoconf_toolchains_impl(repository_ctx): if not should_detect_cpp_toolchain: repository_ctx.file("BUILD", "# C++ toolchain autoconfiguration was disabled by BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN env variable.") - elif cpu_value == "darwin" and not should_use_cpp_only_toolchain: + elif cpu_value.startswith("darwin") and not should_use_cpp_only_toolchain: xcode_toolchains = [] # Only detect xcode if the user didn't tell us it will be there. @@ -120,7 +120,7 @@ def cc_autoconf_impl(repository_ctx, overriden_tools = dict()): # TODO(ibiryukov): overriden_tools are only supported in configure_unix_toolchain. # We might want to add that to Windows too(at least for msys toolchain). configure_windows_toolchain(repository_ctx) - elif (cpu_value == "darwin" and + elif (cpu_value.startswith("darwin") and ("BAZEL_USE_CPP_ONLY_TOOLCHAIN" not in env or env["BAZEL_USE_CPP_ONLY_TOOLCHAIN"] != "1")): configure_osx_toolchain(repository_ctx, overriden_tools) else: diff --git a/tools/cpp/lib_cc_configure.bzl b/tools/cpp/lib_cc_configure.bzl index ee89b9d849d312..1464d8ca6688e5 100644 --- a/tools/cpp/lib_cc_configure.bzl +++ b/tools/cpp/lib_cc_configure.bzl @@ -181,7 +181,9 @@ def get_cpu_value(repository_ctx): """Compute the cpu_value based on the OS name. Doesn't %-escape the result!""" os_name = repository_ctx.os.name.lower() if os_name.startswith("mac os"): - return "darwin" + # Check if we are on x86_64 or arm64 and return the corresponding cpu value. + result = repository_ctx.execute(["uname", "-m"]) + return "darwin" + ("_arm64" if result.stdout.strip() == "arm64" else "") if os_name.find("freebsd") != -1: return "freebsd" if os_name.find("openbsd") != -1: diff --git a/tools/osx/crosstool/cc_toolchain_config.bzl b/tools/osx/crosstool/cc_toolchain_config.bzl index ab391eb8efd2e0..972600c334aae5 100644 --- a/tools/osx/crosstool/cc_toolchain_config.bzl +++ b/tools/osx/crosstool/cc_toolchain_config.bzl @@ -3851,7 +3851,11 @@ def _impl(ctx): ["objc-executable", "objc++-executable"], flag_groups = [ flag_group( - flags = ["-no-canonical-prefixes"], + flags = [ + "-no-canonical-prefixes", + "-target", + "x86_64-apple-macosx", + ], ), ], ), @@ -5161,8 +5165,38 @@ def _impl(ctx): ), ], ) - elif (ctx.attr.cpu == "armeabi-v7a" or - ctx.attr.cpu == "darwin_x86_64"): + elif (ctx.attr.cpu == "darwin_x86_64"): + unfiltered_compile_flags_feature = feature( + name = "unfiltered_compile_flags", + flag_sets = [ + flag_set( + actions = [ + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.linkstamp_compile, + ], + flag_groups = [ + flag_group( + flags = [ + "-no-canonical-prefixes", + "-Wno-builtin-macro-redefined", + "-D__DATE__=\"redacted\"", + "-D__TIMESTAMP__=\"redacted\"", + "-D__TIME__=\"redacted\"", + "-target", + "x86_64-apple-macosx", + ], + ), + ], + ), + ], + ) + elif (ctx.attr.cpu == "armeabi-v7a"): unfiltered_compile_flags_feature = feature( name = "unfiltered_compile_flags", flag_sets = [