-
Notifications
You must be signed in to change notification settings - Fork 319
Description
Problem
If you are attempting to use any rule from @build_bazel_rules_apple on an Intel x86_64 Mac with anything that relies on the cpuinfo project (like Tensorflow) you will face the build error described by this mediapipe issue and this tensorflow issue.
Root Cause
The root cause of the problem falls with the complex interplay between cpuinfo, tensorflow, bazel, and the @build_bazel_rules_apple library. Bazel has reverted the default cpu value on x86 macOS to "darwin" in this commit.
This means that bazel expects Intel x86_64 Macs to report their cpu as darwin. @build_bazel_rules_apple will report the cpu as darwin_x86_64. This cpu does not exist in the cpuinfo project as it expects darwin. Although there is an unmerged pull request to fix this behavior, it is unlikely to be resolved soon.
Solution
In order to fix the problem, I have created a patch so that the library can read the host_cpu value which will report as darwin on an Intel x86_64 Mac. If this value is present, it will return darwin instead of darwin_x86_64.
The Fix
It is necessary to add the --incompatible_enable_apple_toolchain_resolution flag to your build command and modify@build_bazel_rules_apple with the following patch:
diff --git a/apple/internal/transition_support.bzl b/apple/internal/transition_support.bzl
index 65f51b89..7da7ade3 100644
--- a/apple/internal/transition_support.bzl
+++ b/apple/internal/transition_support.bzl
@@ -102,6 +102,9 @@ def _cpu_string(*, cpu, platform_type, settings = {}):
return "ios_sim_arm64"
return "ios_x86_64"
if platform_type == "macos":
+ host_cpu = settings["//command_line_option:host_cpu"]
+ if host_cpu == "darwin":
+ return "darwin"
if cpu:
return "darwin_{}".format(cpu)
macos_cpus = settings["//command_line_option:macos_cpus"]
@@ -342,6 +345,7 @@ _apple_rule_common_transition_inputs = [
"//command_line_option:apple_crosstool_top",
]
_apple_rule_base_transition_inputs = _apple_rule_common_transition_inputs + [
+ "//command_line_option:host_cpu",
"//command_line_option:cpu",
"//command_line_option:ios_multi_cpus",
"//command_line_option:macos_cpus",