diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel +++ b/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 diff --git a/utils/bazel/llvm-project-overlay/llvm/config.bzl b/utils/bazel/llvm-project-overlay/llvm/config.bzl --- a/utils/bazel/llvm-project-overlay/llvm/config.bzl +++ b/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"), }) + [