Skip to content

Commit

Permalink
Backport of #31747 to v1.51.x (Build native MacOS arm64 artifacts (un…
Browse files Browse the repository at this point in the history
…iversal2)) (#32424)
  • Loading branch information
gnossen authored Feb 17, 2023
1 parent 2ee3216 commit 1141f04
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
7 changes: 3 additions & 4 deletions tools/run_tests/artifacts/artifact_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,10 @@ def build_jobspec(self, inner_jobs=None):
# building the native extension is the most time-consuming part of the build
environ['GRPC_PYTHON_BUILD_EXT_COMPILER_JOBS'] = str(inner_jobs)

# This is necessary due to https://github.com/pypa/wheel/issues/406.
# distutils incorrectly generates a universal2 artifact that only contains
# x86_64 libraries.
if self.platform == "macos" and self.arch == "x64":
if self.platform == "macos":
environ['ARCHFLAGS'] = "-arch arm64 -arch x86_64"
environ["GRPC_UNIVERSAL2_REPAIR"] = "true"
environ['GRPC_BUILD_WITH_BORING_SSL_ASM'] = "false"

if self.platform == 'linux_extra':
# Crosscompilation build for armv7 (e.g. Raspberry Pi)
Expand Down
17 changes: 15 additions & 2 deletions tools/run_tests/artifacts/build_artifact_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,23 @@ then
rm -rf venv/
fi

assert_is_universal_wheel() {
WHL="$1"
TMPDIR=$(mktemp -d)
unzip "$WHL" -d "$TMPDIR"
SO=$(find "$TMPDIR" -name '*.so' | head -n1)
if ! file "$SO" | grep "Mach-O universal binary with 2 architectures"; then
echo "$WHL is not universal2. Found the following:" >/dev/stderr
file "$SO" >/dev/stderr
exit 1
fi
}

fix_faulty_universal2_wheel() {
WHL="$1"
if echo "$WHL" | grep "universal2"; then
UPDATED_NAME="${WHL//universal2/x86_64}"
assert_is_universal_wheel "$WHL"
if echo "$WHL" | grep "x86_64"; then
UPDATED_NAME="${WHL//x86_64/universal2}"
mv "$WHL" "$UPDATED_NAME"
fi
}
Expand Down

0 comments on commit 1141f04

Please sign in to comment.