From c4acd2a47eb53a56758d55117e84e18608460bbe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Feb 2026 18:02:52 +0000 Subject: [PATCH] Fix macOS cross-compilation from ARM64 to x86_64 in mk_unix_dist.py and mk_util.py When macos-latest changed to ARM64 runners, the mac-build-x64 job started producing arm64 libz3.dylib inside x86_64-tagged wheels, causing import failures on macOS x86_64. Root cause: mk_make.py subprocess detects the ARM64 host at module level (IS_ARCH_ARM64=True), and without --arm64=false override it adds -arch arm64 to SLIBEXTRAFLAGS, overriding the -arch x86_64 set via environment variables. Fix 1 (mk_unix_dist.py): Pass --arm64=false to mk_make.py subprocess when building x64 on an ARM64 host, preventing the arm64 flag inheritance. Fix 2 (mk_util.py): When IS_ARCH_ARM64=False on an ARM64 macOS host, add -arch x86_64 to SLIBEXTRAFLAGS so the shared library linker also targets x86_64 (LDFLAGS already receives this flag from the env var). Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> --- scripts/mk_unix_dist.py | 4 ++++ scripts/mk_util.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/scripts/mk_unix_dist.py b/scripts/mk_unix_dist.py index 4df68d4c7..4ec98db05 100644 --- a/scripts/mk_unix_dist.py +++ b/scripts/mk_unix_dist.py @@ -140,6 +140,10 @@ def mk_build_dir(path): opts.append('--python') if mk_util.IS_ARCH_ARM64: opts.append('--arm64=true') + elif HOST_IS_ARM64: + # Explicitly disable arm64 when cross-compiling from ARM64 host to x64; + # without this, mk_make.py detects the ARM64 host and adds -arch arm64 flags + opts.append('--arm64=false') if mk_util.IS_ARCH_ARM64 and LINUX_X64: # we are on x64 machine but build for arm64 # so we have to do cross compiling on Linux diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 1af384242..4ec3d5dbd 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -2756,6 +2756,11 @@ def mk_config(): CXXFLAGS = '%s -arch arm64' % CXXFLAGS LDFLAGS = '%s -arch arm64' % LDFLAGS SLIBEXTRAFLAGS = '%s -arch arm64' % SLIBEXTRAFLAGS + elif IS_OSX and os.uname()[4] == 'arm64': + # Cross-compiling from ARM64 host to x86_64: ensure the shared library + # linker also targets x86_64 (LDFLAGS already contains -arch x86_64 + # from the environment, but SLIBEXTRAFLAGS is independent) + SLIBEXTRAFLAGS = '%s -arch x86_64' % SLIBEXTRAFLAGS if IS_OSX: SLIBFLAGS += ' -Wl,-headerpad_max_install_names'