Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for macOS universal2 wheel #403

Merged
merged 1 commit into from
Jan 16, 2021

Conversation

messense
Copy link
Member

Closes #402

@messense messense requested a review from konstin January 16, 2021 05:41
@@ -193,6 +209,7 @@ impl Target {
(OS::Linux, _) => format!("{}_{}", manylinux, self.arch),
(OS::Macos, Arch::X86_64) => "macosx_10_7_x86_64".to_string(),
(OS::Macos, Arch::AARCH64) => "macosx_11_0_arm64".to_string(),
(OS::Macos, Arch::Universal2) => "macosx_10_9_universal2".to_string(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the lib section of your Cargo.toml?",
)
})?;
// Use lipo to create an universal dylib
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently Cargo does have builtin support creating macOS Universal/fat binaries: rust-lang/cargo#8875

@messense
Copy link
Member Author

I've successfully built https://github.com/messense/murmurhash2-py with this branch, producing an universal2 wheel.

❯ ../maturin/target/debug/maturin build --release
🔗 Found pyo3 bindings with abi3 support for Python ≥ 3.6
🐍 Not using a specific python interpreter (With abi3, an interpreter is only required on windows)
.cargo/config .cargo/config
.github/workflows/master.yml .github/workflows/master.yml
.github/workflows/release.yml .github/workflows/release.yml
.gitignore .gitignore
Cargo.toml Cargo.toml
Dockerfile Dockerfile
LICENSE LICENSE
README.md README.md
pyproject.toml pyproject.toml
src/lib.rs src/lib.rs
tests/test_murmurhash2.py tests/test_murmurhash2.py
📦 Built source distribution to /Users/messense/Projects/murmurhash2-py/target/wheels/murmurhash2-0.2.3.tar.gz
   Compiling proc-macro2 v1.0.24
   Compiling unicode-xid v0.2.1
   Compiling syn v1.0.58
   Compiling libc v0.2.82
   Compiling cfg-if v1.0.0
   Compiling smallvec v1.6.1
   Compiling scopeguard v1.1.0
   Compiling inventory v0.1.10
   Compiling pyo3 v0.13.1
   Compiling unindent v0.1.7
   Compiling paste v1.0.4
   Compiling byteorder v1.4.2
   Compiling lock_api v0.4.2
   Compiling instant v0.1.9
   Compiling indoc v1.0.3
   Compiling quote v1.0.8
   Compiling parking_lot_core v0.8.2
   Compiling parking_lot v0.11.1
   Compiling pyo3-macros-backend v0.13.1
   Compiling inventory-impl v0.1.10
   Compiling ghost v0.1.2
   Compiling ctor v0.1.18
   Compiling pyo3-macros v0.13.1
   Compiling murmurhash2 v0.2.3 (/Users/messense/Projects/murmurhash2-py)
    Finished release [optimized] target(s) in 12.04s
   Compiling cfg-if v1.0.0
   Compiling scopeguard v1.1.0
   Compiling smallvec v1.6.1
   Compiling unindent v0.1.7
   Compiling byteorder v1.4.2
   Compiling libc v0.2.82
   Compiling inventory v0.1.10
   Compiling pyo3 v0.13.1
   Compiling instant v0.1.9
   Compiling lock_api v0.4.2
   Compiling parking_lot_core v0.8.2
   Compiling parking_lot v0.11.1
   Compiling murmurhash2 v0.2.3 (/Users/messense/Projects/murmurhash2-py)
    Finished release [optimized] target(s) in 4.27s
📦 Built wheel for abi3 Python ≥ 3.6 to /Users/messense/Projects/murmurhash2-py/target/wheels/murmurhash2-0.2.3-cp36-abi3-macosx_10_9_universal2.whl

Unpack the.whl file and use file/lipo to check the dylib:

❯ file murmurhash2.abi3.so
murmurhash2.abi3.so: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit dynamically linked shared library x86_64] [arm64:Mach-O 64-bit dynamically linked shared library arm64]
murmurhash2.abi3.so (for architecture x86_64):	Mach-O 64-bit dynamically linked shared library x86_64
murmurhash2.abi3.so (for architecture arm64):	Mach-O 64-bit dynamically linked shared library arm64
❯ lipo -info murmurhash2.abi3.so
Architectures in the fat file: murmurhash2.abi3.so are: x86_64 arm64

Unfortunately pip requires pypa/packaging#380 to be able to use macosx_10_9_universal2 tag, but we can rename it to murmurhash2-0.2.3-cp36-abi3-macosx_11_0_universal2.whl to install and test the wheel.

❯ pip3 install murmurhash2-0.2.3-cp36-abi3-macosx_10_9_universal2.whl
ERROR: murmurhash2-0.2.3-cp36-abi3-macosx_10_9_universal2.whl is not a supported wheel on this platform.

❯ pip3 install murmurhash2-0.2.3-cp36-abi3-macosx_11_0_universal2.whl
Processing ./murmurhash2-0.2.3-cp36-abi3-macosx_11_0_universal2.whl
Installing collected packages: murmurhash2
Successfully installed murmurhash2-0.2.3
python3
Python 3.9.1 (default, Jan  8 2021, 12:11:08)
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from murmurhash2 import murmurhash2
>>> SEED = 3242157231
>>> print(murmurhash2(b'key', SEED))
970142460

@messense messense added the enhancement New feature or request label Jan 16, 2021
@messense messense marked this pull request as ready for review January 16, 2021 06:02
@konstin
Copy link
Member

konstin commented Jan 16, 2021

Thank you!

@konstin konstin merged commit d809b1a into PyO3:master Jan 16, 2021
@messense messense deleted the macos_universal2 branch January 16, 2021 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for macOS universal2 builds for ARM-based Macs
2 participants