From 5933b52e1117e0aca1cd3635ef0370577bbff865 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Thu, 1 Dec 2022 09:57:02 -0800 Subject: [PATCH] Build native MacOS arm64 artifacts (universal2) (#31747) * Attempt to build universal2 artifacts * Whoops * Reverse the hack * Turn off boringssl assembly optimizations * Whoopsie --- tools/run_tests/artifacts/artifact_targets.py | 7 +++---- .../artifacts/build_artifact_python.sh | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tools/run_tests/artifacts/artifact_targets.py b/tools/run_tests/artifacts/artifact_targets.py index 3300a43bcc19b..a9108ff858046 100644 --- a/tools/run_tests/artifacts/artifact_targets.py +++ b/tools/run_tests/artifacts/artifact_targets.py @@ -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) diff --git a/tools/run_tests/artifacts/build_artifact_python.sh b/tools/run_tests/artifacts/build_artifact_python.sh index 3e94623ca7149..0d84f24df43b2 100755 --- a/tools/run_tests/artifacts/build_artifact_python.sh +++ b/tools/run_tests/artifacts/build_artifact_python.sh @@ -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 }