[PATCH] D109839: Add support for targeting macOS arm64 with bazel
Dan Foreman-Mackey via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 15 10:26:41 PDT 2021
dfm created this revision.
Herald added a subscriber: kristof.beyls.
dfm added a reviewer: GMNGeoffrey.
dfm published this revision for review.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
In attempting to build JAX on Apple Silicon, we discovered an issue with
the bazel configuration in llvm-project-overlay. This patch fixes the logic,
at least when building JAX. More context is included on the following GitHub
issue: https://github.com/google/jax/issues/5501
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D109839
Files:
utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
utils/bazel/llvm-project-overlay/llvm/config.bzl
Index: utils/bazel/llvm-project-overlay/llvm/config.bzl
===================================================================
--- utils/bazel/llvm-project-overlay/llvm/config.bzl
+++ utils/bazel/llvm-project-overlay/llvm/config.bzl
@@ -75,7 +75,8 @@
# TODO: We should split out host vs. target here.
llvm_config_defines = os_defines + select({
"@bazel_tools//src/conditions:windows": native_arch_defines("X86", "x86_64-pc-win32"),
- "@bazel_tools//src/conditions:darwin": native_arch_defines("X86", "x86_64-unknown-darwin"),
+ "//llvm:macos_arm64": native_arch_defines("AArch64", "arm64-apple-darwin"),
+ "//llvm:macos_x86_64": native_arch_defines("X86", "x86_64-apple-darwin"),
"@bazel_tools//src/conditions:linux_aarch64": native_arch_defines("AArch64", "aarch64-unknown-linux-gnu"),
"//conditions:default": native_arch_defines("X86", "x86_64-unknown-linux-gnu"),
}) + [
Index: utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
===================================================================
--- utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -2,6 +2,7 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+load("@bazel_skylib//lib:selects.bzl", "selects")
load(":template_rule.bzl", "template_rule")
load(":tblgen.bzl", "gentbl")
load(":config.bzl", "llvm_config_defines")
@@ -16,6 +17,39 @@
exports_files(["LICENSE.TXT"])
+# Support for targeting macOS arm64 architecture with `bazel<4.2`. This
+# implementation is lifted from `src/conditions/BUILD` in the bazel source.
+config_setting(
+ name = "macos_x86_64",
+ constraint_values = [
+ "@platforms//os:macos",
+ "@platforms//cpu:x86_64",
+ ],
+ visibility = ["//visibility:public"],
+)
+
+config_setting(
+ name = "macos_arm64_constraint",
+ constraint_values = [
+ "@platforms//os:macos",
+ "@platforms//cpu:arm64",
+ ],
+)
+
+config_setting(
+ name = "macos_arm64_flag",
+ values = {"cpu": "darwin_arm64"},
+)
+
+selects.config_setting_group(
+ name = "macos_arm64",
+ match_any = [
+ ":macos_arm64_constraint",
+ ":macos_arm64_flag",
+ ],
+ visibility = ["//visibility:public"],
+)
+
# It may be tempting to add compiler flags here, but that should be avoided.
# The necessary warnings and other compile flags should be provided by the
# toolchain or the `.bazelrc` file. This is just a workaround until we have a
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109839.372744.patch
Type: text/x-patch
Size: 2528 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210915/55b18b00/attachment.bin>
More information about the llvm-commits
mailing list