-
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
Support macOS Big Sur and Apple Silicon hardware platform #11628
Comments
This may be out of the scope of this discussion, but I think it would be nice to break the assumptions in bazel that if you're compiling for an Apple CPU you have to be running on |
I also have a DTK coming and would be happy to contribute some here as this is a pre-req for us long term as well. |
My DTK has arrived and I've hit this roadblock. Happy to help. |
Just to be clear to what roadblock are you referring? |
Just FYI, we're still waiting for the DTK, so no news from my side yet. |
FYI b235517#diff-1f4964536f397e8679625954c7139bd6 and e4e06c0#diff-1f4964536f397e8679625954c7139bd6 add support for
|
I think that #12035 should unblock folks. Apologies on my earlier assertions as I was using a different crosstool and forgot that my changes there were not available externally. We will leave this bug open for the time being until we have bazel working natively on Apple Silicon, but for the time being you should be able to build on x86_64 for arm64(e) and build (running an emulated bazel) on arm64 for arm64(e). |
This adds support for darwin_arm64(e) to the crosstool. `bazel build examples/cpp:hello-world --cpu=darwin_arm64 --xcode_version=12` should function on both a intel and arm64 mac. Note that bazel still runs in emulation on arm64 mac until we have an arm64 darwin jdk. Fix for #11628 Closes #12035. PiperOrigin-RevId: 329582842
Related bazelbuild/rules_apple#980 Any general update on this from google folks? Is anyone actively looking at this? I could probably spend some time on this soon, I have a DTK |
We are also blocked on being able to target arm64 and the iOS simulator. I also have a DTK but I'm unfamiliar with Bazel core, but happy to help in any way I can. |
AFAIUI currently we're blocked on the JDK not supporting Apple Silicon. Realistically after that I imagine the fact that homebrew doesn't support it either will make it difficult to build and test this. |
@keith Isn't the fact that Bazel doesn't support Apple Silicon a different problem? With my understanding, I assumed we should be able to still pass the right arguments to the compiler and build targeting arm64 and the iOS simulator even if Bazel isn't yet optimized with Apple Silicon. |
Sorry I thought you were hoping to do the build on the DTK as well. Yes we should be able to target the apple silicon simulator from x86_64 bazel runs. I don't think this will be an easy change based on a discussion at bazelcon (not sure if you were in the apple BoF). I think the problem is there isn't a way to differentiate simulator or device for the same architecture. |
Yeah, I was in the discussion so I'd love to know how big of a change this would be from some Google folks, since it could block Bazel adoption relatively soon for teams who want/need to support this new architecture. |
Looks like there's a zulu release for Apple Silicon https://www.azul.com/downloads/zulu-community/?os=macos&architecture=arm-64-bit&package=jdk |
@philwo given the blocker around simulator vs device builds, do googlers have an opinion on the solution? I'm interested in working on this but want to submit something that you all will be happy with as well. |
@keith I think we'd be more than happy to take your design proposal / contribution on this 😊, but let's check whether there are any conflicts or opinions here - @dmaclach @susinmotion any concerns or opinions on this from your side? The relevant context is how bazelbuild/rules_apple#980 should be dealt with, if I understand correctly. |
@keith FYI, @meteorcloudy and me are looking into getting Bazel to build with the Apple Silicon native JDK. Thanks for pointing out that Azul has a Zulu release for this! |
Happy to hear you're working on the build! Once it's ready I'm definitely interested in trying it! |
Yes, please, that would be amazing! I think this is related to some work that @gregestren 's team is doing; looping him in. |
@katre is there a relation to platforms or execution environments here? |
@gregestren There shouldn't be any need for changes to Bazel's platforms or toolchains machinery to support this. I'm happy to consult on using those facilities if needed. |
Pasting some notes here, so I don't forget: If we just run Bazel with the Apple Silicon Zulu, loading the JNI libraries will not work, because they're x86_64. So we have to use an x86_64 Bazel (with x86_64 Zulu) and cross-compile Bazel first, which "should" work via:
However, @meteorcloudy pointed out that this could lead Bazel to selecting the wrong sources for the mac build (as we use "darwin" only in the select statements). So we'll need something like this, but for Bazel: meteorcloudy@3139666 Regarding arm64 vs. arm64e, the latter one is more modern, but it appears that Zulu is built for arm64 - which is good (for now), because that doesn't require us to codesign every binary. Apparently that's only required for the newer arm64e binaries. If we do want to go to arm64e eventually, we'll have to |
I wonder if we should replace the |
I see the same behavior as @ayankumarh which suggests that those of you who have this working have something else in your repo that isn't available to the rest of us. I can't get it working with any combination of the patches mentioned here. |
It is surprisingly easy. I successfully built the latest commit (bbeb1da) on my M1 Mac mini.
That's it.
https://drive.google.com/file/d/13b5_sd4d8LrZS18aVq8K2EOuxtPNmuWL/view?usp=sharing |
Um.. This happens as well. |
This change allows rules_foreign_cc to work on architectures other than x86_64. Bug: bazelbuild/bazel#11628 Test: manual. no longer fails with "ln: illegal option -- t" on darwin_arm64
Many downstream projects are still depending on the default cpu value being "darwin" instead of "darwin_x86_64" https://buildkite.com/bazel/bazel-auto-sheriff-face-with-cowboy-hat/builds/412 Related: bazelbuild#11628
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
Should this be closed given that there hasn't been a release yet with this support? |
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
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
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
Bazel version |
@Darko-Huma: This is an issue with rules_go, you'll need to report it there. |
bazelbuild/bazel#11628 is in Release 4.1 - May 2021 #13099 Pin vs rm for build repeatability.
This is a tracking bug for adding support for macOS Big Sur and the Apple Silicon platform to Bazel. I'm currently trying to acquire a DTK to run some initial tests and will follow up here when I find out more.
We aim to have full support in time for their final release.
The text was updated successfully, but these errors were encountered: