Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Build native MacOS arm64 artifacts (universal2) (grpc#31747)
Browse files Browse the repository at this point in the history
* Attempt to build universal2 artifacts

* Whoops

* Reverse the hack

* Turn off boringssl assembly optimizations

* Whoopsie
  • Loading branch information
gnossen authored Dec 1, 2022
1 parent 964f101 commit 5933b52
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 5933b52

Please sign in to comment.