-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Add native support for Apple Silicon #12900
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @comius
FYI @aiuto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do android tests pass (with a bootstrapped version of bazel on arm architecture)? See #12880
Consider using jdk11.0.9 otherwise, if it's not too much effort.
return "darwin"; | ||
switch (CPU.getCurrent()) { | ||
case X86_64: | ||
return "darwin_x86_64"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
I haven't tried to install the Android SDK yet, looks like they don't have official Apple Silicon support for now. And there are many other tests still broken, so it will probably take a while to enable tests for Apple Silicon. Hopefully we can get that issue resolved by then, otherwise I can revert the JDK version to 11.0.9. |
One problem I noticed from the failing test is that netty doesn't work on Apple Silicon because the jar file actually contains some native shared libraries that're not built for Apple Silicon. This means remote caching/remote execution won't work on Apple Silicon, and I'm not sure what to do.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
cc: @susinmotion |
Hi! So, I use this command: But I'm getting this:
I also tried to checkout 8c7e11a in case it can help, but it doesn’t . Getting the same error Is there something else I should patch? |
@mahenzon Which Bazel version were you using? Can you try with the latest 4.0.0? |
@mahenzon And can you check if |
yeah, there's file I used 3.7.0. So, full list of steps:
Your build will be in
UPD: |
It also works on my Mac Mini M1 and gives a nice ~2x speed increase! 🚀
|
I have successfully used these steps to build bazel 4.0.0 on Apple Silicon. However, another application I am trying to build is throwing an error because this bazel build is unversioned, as @mahenzon mentions (#12900 (comment)). Is there any way to build bazel in a way so that it returns a correct version number? |
@qthequartermasterman |
Thank you!
… On Apr 13, 2021, at 2:34 AM, Yun Peng ***@***.***> wrote:
@qthequartermasterman
--embed_label <version> is the build flag you are looking for.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
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: #11628 Closes #12900. PiperOrigin-RevId: 354058336
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: #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
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: #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 Update platform version to 0.0.4 Use configuration flags for //src/conditions:darwin_arm64 Partially reverts 6d637f4, to allow cross-compiling Bazel from darwin_x86_64 to darwin_arm64 with the `--cpu=darwin_arm64` flag. The only source that is different between darwin_x86_64 and darwin_arm64 now is the embedded JDK. Closes #12653. PiperOrigin-RevId: 346298051 Make sure Bazel selects correct remote JDK on 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: #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 Update platform version to 0.0.4 Use configuration flags for //src/conditions:darwin_arm64 Partially reverts 6d637f4, to allow cross-compiling Bazel from darwin_x86_64 to darwin_arm64 with the `--cpu=darwin_arm64` flag. The only source that is different between darwin_x86_64 and darwin_arm64 now is the embedded JDK. Closes #12653. PiperOrigin-RevId: 346298051 Make sure Bazel selects correct remote JDK on Apple Silicon
I got error: Required bazel version is "4.0.0", but "no_version"" is reported by /Users/xuanquynhle/bin/bazel |
After this PR, we can use a x86 version of Bazel to build an ARM64 Bazel binary for Apple Silicon by
The Bazel client, embedded tools and embedded JDK are all native ARM64 binaries.
Changes in this PR:
darwin_x86_64
ordarwin_arm64
instead of justdarwin
for cpu value on macOS.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:
Closes: #11628