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

Add native support for Apple Silicon #12900

Closed
Closed
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
85 changes: 85 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,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",
Expand Down Expand Up @@ -322,6 +346,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",
],
Expand All @@ -331,13 +356,15 @@ 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",
},
urls = {
"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",
Expand Down Expand Up @@ -475,6 +502,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",
Expand Down Expand Up @@ -514,6 +555,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",
Expand Down Expand Up @@ -608,6 +663,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",
Expand Down Expand Up @@ -650,6 +720,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",
Expand Down
14 changes: 14 additions & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ filegroup(
"//src/conditions:darwin_x86_64": [
"@openjdk_macos_x86_64//file",
],
"//src/conditions:darwin_arm64": [
"@openjdk_macos_aarch64//file",
],
"//src/conditions:windows": [
"@openjdk_win//file",
],
Expand All @@ -196,6 +199,9 @@ filegroup(
"//src/conditions:darwin_x86_64": [
"@openjdk_macos_x86_64_minimal//file",
],
"//src/conditions:darwin_arm64": [
"@openjdk_macos_aarch64_minimal//file",
],
"//src/conditions:windows": [
"@openjdk_win_minimal//file",
],
Expand All @@ -215,6 +221,9 @@ filegroup(
"//src/conditions:darwin_x86_64": [
"@openjdk_macos_x86_64_vanilla//file",
],
"//src/conditions:darwin_arm64": [
"@openjdk_macos_aarch64_vanilla//file",
],
"//src/conditions:windows": [
"@openjdk_win_vanilla//file",
],
Expand Down Expand Up @@ -700,14 +709,17 @@ filegroup(
"@bazel_skylib//:WORKSPACE",
"@com_google_protobuf//:WORKSPACE",
"@openjdk11_darwin_archive//:WORKSPACE",
"@openjdk11_darwin_aarch64_archive//:WORKSPACE",
"@openjdk11_linux_archive//:WORKSPACE",
"@openjdk11_windows_archive//:WORKSPACE",
"@openjdk15_darwin_archive//:WORKSPACE",
"@openjdk15_darwin_aarch64_archive//:WORKSPACE",
"@openjdk15_linux_archive//:WORKSPACE",
"@openjdk15_windows_archive//:WORKSPACE",
"@openjdk_linux_aarch64_minimal//file",
"@openjdk_linux_minimal//file",
"@openjdk_macos_x86_64_minimal//file",
"@openjdk_macos_aarch64_minimal//file",
"@openjdk_win_minimal//file",
"@remote_coverage_tools//:WORKSPACE",
"@remote_java_tools_darwin_for_testing//:WORKSPACE",
Expand All @@ -723,9 +735,11 @@ filegroup(
"@remotejdk11_linux_ppc64le_for_testing//:WORKSPACE",
"@remotejdk11_linux_s390x_for_testing//:WORKSPACE",
"@remotejdk11_macos_for_testing//:WORKSPACE",
"@remotejdk11_macos_aarch64_for_testing//:WORKSPACE",
"@remotejdk11_win_for_testing//:WORKSPACE",
"@remotejdk15_linux_for_testing//:WORKSPACE",
"@remotejdk15_macos_for_testing//:WORKSPACE",
"@remotejdk15_macos_aarch64_for_testing//:WORKSPACE",
"@remotejdk15_win_for_testing//:WORKSPACE",
"@rules_cc//:WORKSPACE",
"@rules_java//:WORKSPACE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ public class AutoCpuConverter implements Converter<String> {
public String convert(String input) throws OptionsParsingException {
if (input.isEmpty()) {
// TODO(philwo) - replace these deprecated names with more logical ones (e.g. k8 becomes
// linux-x86_64, darwin includes the CPU architecture, ...).
// linux-x86_64 ...).
switch (OS.getCurrent()) {
case DARWIN:
return "darwin";
switch (CPU.getCurrent()) {
case X86_64:
return "darwin_x86_64";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing "darwin" to "darwin_x86_64" might cause some issues. @katre is probably more familiar with this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It indeed broke the test_disable_cc_toolchain_detection test on macOS, check the latest commit for the fix. I'm not sure if there are more issues I missed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long term this will be great because there's existing ambiguity between darwin and darwin_x86_64

case AARCH64:
return "darwin_arm64";
default:
return "unknown";
}
case FREEBSD:
return "freebsd";
case OPENBSD:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ maybe(
version = "11",
)

# This must be kept in sync with the top-level WORKSPACE file.
maybe(
remote_java_repository,
name = "remotejdk11_macos_aarch64",
exec_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
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",
],
version = "11",
)

# This must be kept in sync with the top-level WORKSPACE file.
maybe(
remote_java_repository,
Expand Down Expand Up @@ -149,6 +166,23 @@ maybe(
version = "15",
)

# This must be kept in sync with the top-level WORKSPACE file.
maybe(
remote_java_repository,
name = "remotejdk15_macos_aarch64",
exec_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
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",
],
version = "15",
)

# This must be kept in sync with the top-level WORKSPACE file.
maybe(
remote_java_repository,
Expand Down
2 changes: 2 additions & 0 deletions src/test/py/bazel/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ 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',
'remotejdk15_linux_for_testing',
'remotejdk15_macos_for_testing',
'remotejdk15_macos_aarch64_for_testing',
'remotejdk15_win_for_testing',
'remote_java_tools_for_testing',
'remote_java_tools_darwin_for_testing',
Expand Down
26 changes: 26 additions & 0 deletions src/test/shell/bazel/testdata/jdk_http_archives.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

################### Remote java_tools with embedded javac 11 ###################
{remote_java_tools_test}
{remote_java_tools_test_linux}
Expand All @@ -22,6 +23,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'])",
Expand Down Expand Up @@ -60,6 +72,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 = """
Expand Down
5 changes: 5 additions & 0 deletions src/test/shell/testenv.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,17 @@ EOF
"bazel_toolchains"
"com_google_protobuf"
"openjdk11_darwin_archive"
"openjdk11_darwin_aarch64_archive"
"openjdk11_linux_archive"
"openjdk11_windows_archive"
"openjdk15_darwin_archive"
"openjdk15_darwin_aarch64_archive"
"openjdk15_linux_archive"
"openjdk15_windows_archive"
"openjdk_linux_aarch64_minimal"
"openjdk_linux_minimal"
"openjdk_macos_x86_64_minimal"
"openjdk_macos_aarch64_minimal"
"openjdk_win_minimal"
"remote_coverage_tools"
"remote_java_tools_for_testing"
Expand All @@ -309,9 +312,11 @@ EOF
"remotejdk11_linux_ppc64le_for_testing"
"remotejdk11_linux_s390x_for_testing"
"remotejdk11_macos_for_testing"
"remotejdk11_macos_aarch64_for_testing"
"remotejdk11_win_for_testing"
"remotejdk15_linux_for_testing"
"remotejdk15_macos_for_testing"
"remotejdk15_macos_aarch64_for_testing"
"remotejdk15_win_for_testing"
"rules_cc"
"rules_java"
Expand Down
4 changes: 2 additions & 2 deletions tools/cpp/cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion tools/cpp/lib_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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_" + result.stdout.strip()
if os_name.find("freebsd") != -1:
return "freebsd"
if os_name.find("openbsd") != -1:
Expand Down
Loading