From 5608dfa5aae3b1d12092f733ed625f8d44ad5dd3 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Wed, 12 May 2021 12:07:25 -0700 Subject: [PATCH] Update DEFAULT_MACOS_CPU to match host With Apple Silicon machines host tools that use the apple_binary, or apple fragment to fetch the CPU would be built for the wrong architecture, even though the C++ logic would correctly identify the host CPU. This changes this hardcoded value to correctly determine Apple Silicon as arm64, and otherwise fallback to x86_64. Fixes https://github.com/bazelbuild/bazel/issues/12671 Closes #13440. PiperOrigin-RevId: 373421791 --- .../build/lib/rules/apple/AppleCommandLineOptions.java | 4 +++- src/main/java/com/google/devtools/build/lib/rules/apple/BUILD | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java index 8fdc46cbc7f96e..ff269df1610861 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java @@ -26,6 +26,7 @@ import com.google.devtools.build.lib.skyframe.serialization.SerializationContext; import com.google.devtools.build.lib.skyframe.serialization.SerializationException; import com.google.devtools.build.lib.starlarkbuildapi.apple.AppleBitcodeModeApi; +import com.google.devtools.build.lib.util.CPU; import com.google.devtools.common.options.Converters.CommaSeparatedOptionListConverter; import com.google.devtools.common.options.EnumConverter; import com.google.devtools.common.options.Option; @@ -186,7 +187,8 @@ public class AppleCommandLineOptions extends FragmentOptions { public static final String DEFAULT_TVOS_CPU = "x86_64"; /** The default macOS CPU value. */ - public static final String DEFAULT_MACOS_CPU = "x86_64"; + public static final String DEFAULT_MACOS_CPU = + CPU.getCurrent() == CPU.AARCH64 ? "arm64" : "x86_64"; /** The default Catalyst CPU value. */ public static final String DEFAULT_CATALYST_CPU = "x86_64"; diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/BUILD b/src/main/java/com/google/devtools/build/lib/rules/apple/BUILD index a8bcacad33c229..0d090c59041942 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/BUILD +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/BUILD @@ -40,6 +40,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/skyframe/serialization", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi/apple", + "//src/main/java/com/google/devtools/build/lib/util", "//src/main/java/com/google/devtools/common/options", "//src/main/java/net/starlark/java/eval", "//src/main/java/net/starlark/java/syntax",