[PATCH] D109839: Add support for targeting macOS arm64 with bazel

Geoffrey Martin-Noble via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 15 17:16:22 PDT 2021


GMNGeoffrey added inline comments.


================
Comment at: utils/bazel/llvm-project-overlay/llvm/BUILD.bazel:21
+# Support for targeting macOS arm64 architecture with `bazel<4.2`. This
+# implementation is lifted from `src/conditions/BUILD` in the bazel source.
+config_setting(
----------------
dfm wrote:
> GMNGeoffrey wrote:
> > We already use `@bazel_tools//src/conditions:foo` in config.bzl. Looking at the history of src/conditions/BUILD, there's some bug in Bazel that means that cross-compiling from darwinn x86 to darwinn arm is broken and this is worked around in src/conditions by adding a `--darwin_arm64` flag (https://github.com/bazelbuild/bazel/issues/12655 and https://github.com/bazelbuild/bazel/commit/52457b18bd), but only after Bazel 4.0 (the version we're currently on). Is that cross-compiling something you actually need? If not, I'd prefer we use the src/conditions constraints for now (at least until such a time as we decide to define all our own config settings)
> Thanks for your response! Yeah, that's exactly what we're looking to do (I came to this when trying to build binaries for a Python library using x86 hardware), although the existing implementation wouldn't work even when building on an arm machine. I also tried your suggested change (using `@bazel_tools//src/conditions:darwin_arm64`) and I was still getting the wrong compiler flags when building locally, but I'm far from an expert in any of this though so there's a good shout that I was doing something wrong. I understand the hesitation to copy this over and I'd be happy to look into alternative ideas if you have suggestions. Thanks again!
Ah in that case, I think we should probably upgrade to fix the Bazel bug :-) (in addition to adding the right selects in config.bzl). I would've done it already except that support for `rbe_autoconfig` was dropped for versions >4.0.0. I posted on bazel-discuss about how that squares with it being an LTS release.

So to clarify, with these edits you can cross-compile from darwin x86_64 to arm? That makes sense to me given the linked issue in Bazel that was worked around. How blocking is this for you? Like can you patch this in locally and then continue on your way for a bit while we fiddle around with using a newer version of Bazel? Can you just build with Bazel >4.2 (ignore the .bazelversion file) after adding the patch to use the src/conditions configs? I think the default Bazel install these days has a shell wrapper that automatically uses the version in the .bazelrc file, but if you specifically use a bazel-4.2 binary then it should work.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109839/new/

https://reviews.llvm.org/D109839



More information about the llvm-commits mailing list