From b3a75fe2987e84584c2fefe8de6c85d8f1df1e33 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 13 Jun 2025 16:14:10 +0700 Subject: [PATCH] Make libankihelper a universal library We were shipping a single arch library in a purelib, leading to breakages when running on a different platform. --- qt/mac/helper_build.py | 43 +++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/qt/mac/helper_build.py b/qt/mac/helper_build.py index 4edbd05c1..a119a7fe3 100644 --- a/qt/mac/helper_build.py +++ b/qt/mac/helper_build.py @@ -11,19 +11,32 @@ out_dylib, *src_files = sys.argv[1:] out_dir = Path(out_dylib).parent.resolve() src_dir = Path(src_files[0]).parent.resolve() -if platform.machine() == "arm64" and not os.environ.get("MAC_X86"): - target = "arm64-apple-macos11" -else: - target = "x86_64-apple-macos10.14" +# Build for both architectures +architectures = ["arm64", "x86_64"] +temp_files = [] -args = [ - "swiftc", - "-target", - target, - "-emit-library", - "-module-name", - "ankihelper", - "-O", -] -args.extend(src_dir / Path(file).name for file in src_files) -subprocess.run(args, check=True, cwd=out_dir) +for arch in architectures: + target = f"{arch}-apple-macos11" + temp_out = out_dir / f"temp_{arch}.dylib" + temp_files.append(temp_out) + + args = [ + "swiftc", + "-target", + target, + "-emit-library", + "-module-name", + "ankihelper", + "-O", + ] + args.extend(src_dir / Path(file).name for file in src_files) + args.extend(["-o", str(temp_out)]) + subprocess.run(args, check=True, cwd=out_dir) + +# Create universal binary +lipo_args = ["lipo", "-create", "-output", out_dylib] + [str(f) for f in temp_files] +subprocess.run(lipo_args, check=True) + +# Clean up temporary files +for temp_file in temp_files: + temp_file.unlink()