Building (or Cross-compiling) for macos arm64 (Apple M1 chip)

3,642 views
Skip to first unread message

Sam F.S.

unread,
Aug 19, 2021, 2:56:40 AM8/19/21
to bazel-discuss

I am trying to build or to cross-compile a project for Apple M1. I can build the project on linux-x86_64 without a problem (with gcc11 as the compiler). But when I try to build the same project on Apple M1, I get this error:

ERROR: ./BUILD.bazel:38:10: Target '//:tandem-tap' depends on toolchain '@local_config_cc//:cc-compiler-darwin_arm64', which cannot be found: no such target '@local_config_cc//:cc-compiler-darwin_arm64': target 'cc-compiler-darwin_arm64' not declared in package '' defined by /private/var/tmp/_bazel_meisam/eed07f1d1238ba70d8dab89b67f79478/external/local_config_cc/BUILD'
ERROR: Analysis of target '//:tandem-tap' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.058s
INFO: 0 processes.FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)

I have gcc11 for arm installed on the apple M1 system

$ which gcc-11
/opt/homebrew/bin/gcc-11
$ file /opt/homebrew/bin/gcc-11
/opt/homebrew/bin/gcc-11: Mach-O 64-bit executable arm64


Apple Clang is also installed on the system:
$ which clang
/usr/bin/clang

$ file /usr/bin/clang
/usr/bin/clang: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e]
/usr/bin/clang (for architecture x86_64):       Mach-O 64-bit executable x86_64
/usr/bin/clang (for architecture arm64e):       Mach-O 64-bit executable arm64e

I looked around to see how I can define a toolchain for Bazel, but I cannot find a coherent document that shows all the steps in one place. The bazel documentation jumps around so many times that it is practically impossible to follow, It also appears that, at various spots, the documentation is mixing concepts in bazel 4.x and older versions.

Can someone point me to an example? I'd be happy to help update the documentation or even add an example project to https://github.com/bazelbuild/examples once I figure out how to fix the issues I am facing.

Thanks,
Meisam


Keith Smiley

unread,
Aug 19, 2021, 11:43:41 AM8/19/21
to Sam F.S., bazel-discuss
What bazel version are you using? You'll need at least 4.2.x (released yesterday) for this to work
--
Keith Smiley


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/ecf93e1c-9a22-499c-bcc7-1410236ab6a2n%40googlegroups.com.

Sam F.S.

unread,
Aug 19, 2021, 1:25:17 PM8/19/21
to bazel-discuss
I am using 4.0.x. I see the update about Apple M1 in the release notes for 4.2.0.
Thanks,
Meisam
Reply all
Reply to author
Forward
0 new messages