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

Support macOS Big Sur and Apple Silicon hardware platform #11628

Closed
philwo opened this issue Jun 23, 2020 · 47 comments
Closed

Support macOS Big Sur and Apple Silicon hardware platform #11628

philwo opened this issue Jun 23, 2020 · 47 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: feature request

Comments

@philwo
Copy link
Member

philwo commented Jun 23, 2020

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.

@philwo philwo added type: feature request P2 We'll consider working on this in future. (Assignee optional) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website labels Jun 23, 2020
@philwo philwo self-assigned this Jun 23, 2020
@keith
Copy link
Member

keith commented Jun 23, 2020

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 darwin_x86_64 (previously, and now darwin*). This would unlock cross-compilation to Apple platforms from Linux and I think could be done without degrading the UX for macOS users. This would also likely make it easier to add more CPUs like this one.

@keith
Copy link
Member

keith commented Jun 24, 2020

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.

@kayasoze
Copy link

My DTK has arrived and I've hit this roadblock. Happy to help.

@dmaclach
Copy link
Contributor

Just to be clear to what roadblock are you referring?

@philwo
Copy link
Member Author

philwo commented Aug 21, 2020

Just FYI, we're still waiting for the DTK, so no news from my side yet.

@dmaclach
Copy link
Contributor

FYI

b235517#diff-1f4964536f397e8679625954c7139bd6

and

e4e06c0#diff-1f4964536f397e8679625954c7139bd6

add support for darwin_arm64 and darwin_arm64e respectively.

blaze build --config=darwin_arm64 should get you a basic Apple Silicon binary.

@dmaclach
Copy link
Contributor

dmaclach commented Sep 1, 2020

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).

bazel-io pushed a commit that referenced this issue Sep 1, 2020
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
@keith
Copy link
Member

keith commented Nov 6, 2020

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

@BalestraPatrick
Copy link
Member

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.

@keith
Copy link
Member

keith commented Nov 15, 2020

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.

@BalestraPatrick
Copy link
Member

@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.

@keith
Copy link
Member

keith commented Nov 15, 2020

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.

@BalestraPatrick
Copy link
Member

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.

@keith
Copy link
Member

keith commented Nov 16, 2020

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

@keith
Copy link
Member

keith commented Nov 19, 2020

@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.

@philwo
Copy link
Member Author

philwo commented Nov 19, 2020

@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.

@philwo
Copy link
Member Author

philwo commented Nov 19, 2020

@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!

@keith
Copy link
Member

keith commented Nov 19, 2020

Happy to hear you're working on the build! Once it's ready I'm definitely interested in trying it!

@susinmotion
Copy link
Contributor

Yes, please, that would be amazing! I think this is related to some work that @gregestren 's team is doing; looping him in.

@gregestren
Copy link
Contributor

@katre is there a relation to platforms or execution environments here?

@katre
Copy link
Member

katre commented Nov 19, 2020

@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.

@philwo
Copy link
Member Author

philwo commented Nov 19, 2020

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:

bazel build --cpu=darwin_arm64 --host_cpu=darwin_arm64 //src:bazel

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 codesign -v -s - --force my_lib.dylib/my_binary everything we build somehow.

@keith
Copy link
Member

keith commented Nov 19, 2020

I wonder if we should replace the darwin conditional with one that means any of the darwin architectures as opposed to splitting out all cases? for example https://github.com/envoyproxy/envoy/pull/6182/files

@jwbee
Copy link

jwbee commented Dec 31, 2020

Please let me know what I am missing.

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.

@jesec
Copy link
Contributor

jesec commented Jan 15, 2021

It is surprisingly easy. I successfully built the latest commit (bbeb1da) on my M1 Mac mini.

  1. Download bazelisk from https://github.com/bazelbuild/bazelisk/releases. darwin-amd64 is fine. Install it to /usr/local/bin/bazelisk.
  2. Download and install JDK 11 (.dmg) from https://www.azul.com/downloads/zulu-community/?os=macos&architecture=arm-64-bit&package=jdk.
  3. Clone Bazel repo: git clone git@github.com:bazelbuild/bazel.git --depth=1 --single-branch
  4. Inside the repo, USE_BAZEL_VERSION=last_green bazelisk build -c opt --apple_platform_type=macos --cpu=darwin_arm64 //src:bazel

That's it.

Target //src:bazel up-to-date:
  bazel-bin/src/bazel
INFO: Elapsed time: 780.524s, Critical Path: 183.13s
INFO: 2985 processes: 179 internal, 2093 darwin-sandbox, 1 local, 712 worker.
INFO: Build completed successfully, 2985 total actions

https://drive.google.com/file/d/13b5_sd4d8LrZS18aVq8K2EOuxtPNmuWL/view?usp=sharing

@jesec
Copy link
Contributor

jesec commented Jan 15, 2021

#11628 (comment)

I spoke too soon 😢 Although it's an arm binary, host tools were built for x86_64 so Bazel still invokes everything under Rosetta.

Um.. This happens as well.

jsharpe pushed a commit to bazel-contrib/rules_foreign_cc that referenced this issue Jan 22, 2021
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
meteorcloudy added a commit to meteorcloudy/bazel that referenced this issue Jan 28, 2021
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
bazel-io pushed a commit that referenced this issue Jan 28, 2021
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
bazel-io pushed a commit that referenced this issue Jan 28, 2021
Related: #11628

Closes #12919.

PiperOrigin-RevId: 354281564
@chandlerc
Copy link

Should this be closed given that there hasn't been a release yet with this support?

meteorcloudy added a commit that referenced this issue Apr 20, 2021
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
meteorcloudy added a commit that referenced this issue Apr 20, 2021
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
meteorcloudy added a commit that referenced this issue Apr 20, 2021
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
meteorcloudy added a commit that referenced this issue Apr 20, 2021
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
philwo pushed a commit that referenced this issue Apr 20, 2021
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
@Darko-Huma
Copy link

 bazel run gazelle                                                                              
(14:52:48) INFO: Current date is 2021-07-13
(14:52:48) ERROR: While resolving toolchains for target //:gazelle-runner: no matching toolchains found for types @io_bazel_rules_go//go:toolchain
(14:52:48) ERROR: Analysis of target '//:gazelle' failed; build aborted: no matching toolchains found for types @io_bazel_rules_go//go:toolchain
(14:52:48) INFO: Elapsed time: 0.082s
(14:52:48) INFO: 0 processes.
(14:52:48) ERROR: Build failed. Not running target

Bazel version
4.1
Apple Silicon M1

@katre
Copy link
Member

katre commented Jul 13, 2021

@Darko-Huma: This is an issue with rules_go, you'll need to report it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.