-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
cross compilation issue with PyO3 for macOS from linux #375
Comments
I think the best solution would be checking for the |
I've successfully cross-compiled a PyO3 "abi3" extension wheel for Windows from Linux by using the following python "interpreter" saved as
Maturin command line:
When targeting abi3 on Windows, it seems like the only relevant piece of information the interpreter provides to maturin is It would be nice if maturin could recognize |
I've successfully compiled my extension with the latest master. Everything seems to work, but this comment has caught my attention. PyO3 defines it as follows
On my system it is But running Windows python in WINE yields:
There is no I believe 9177092 is not semantically correct in its "base_prefix" handling, yet it seems to work just fine. |
Ok, I think I've figured it out. Linking appeared to work because I moved
As expected, Line 70 in cbf3c93
|
Thank you for investigating! I've changed it so that |
I've retested with the latest master. Both Thank you for supporting this valuable edge case. Having to use WINE on the build system to run the Windows python executable to cross-compile a python module just didn't feel right to me. Now cross-compiling python extensions for Windows is as simple as cross-compiling pure Rust programs. |
@ravenexp I'm very interested in cross compiling to windows too. Would you mind posting the necessary steps to have a environment ready to cross compile (I will be using centos7 if this is relevant)? Something like a Dockerfile would be great! I understand this is probably out of scope from maturin but I bet lot of people will find it useful. |
Here is my version:
mypython:
main script:
|
Why are you installing a Windows toolchain on linux? It can only be used in Windows or via WINE.
Non-abi3 extensions seem much more difficult to cross-compile because of the python interpreter ABI zoo. I hope maturin-0.9.1 will be released in the nearest future solving the Windows cross-compilation case for good. |
Thanks @Agile86 I've successfully managed to cross compile too! On wsl, I've used a windows conda ( |
Cross compilation has been improved with #454 , for example maturin/.github/workflows/test.yml Lines 147 to 166 in 4b928f0
|
Any news here on cross-compiling to Mac OS X? To me, the workaround looks quite nasty and I am looking for a proper solution. Thanks. |
I've verified that cross compile for macOS from linux using osxcross works now. |
#817 added support for cross compiling to macOS with the |
I've finally got around to put my Windows cross-compilation hacks into a rust crate and publish it: https://github.com/ravenexp/python3-dll-a It generates abi3-compatible Python DLL import libraries for the MinGW compiler without going through the pains of cross-compiling CPython itself using MinGW. |
@ravenexp That looks interesting, I wonder does it work with MSVC targets? |
No, MinGW and MSVC use different import library formats even though they both use MSCOFF object files. AFAIK, MSVC does not have anything like MinGW This crate is a hack for cross-compiling Windows extension modules from Linux. When building on Windows, you can just use the host Python interpreter as usual. |
@ravenexp What about llvm-dlltool? |
That looks feasible, but is Also, there is rust-lang/rust#58713, which will probably make the whole import library thing obsolete. |
No, it's not installed by default.
We can enable lld for Windows cross compiling in maturin if we want, but it'd only work for pure Rust projects.
Great! Will it work for both Windows msvc and gnu targets? |
I'll try to add basic
Yes, it will work for all Windows targets and will allow importing DLL symbols by name without any import libraries. PyO3 has to be modified to support this feature, though. |
I've added
@messense Thank you for suggesting |
My goal is to cross compile a python library made with Py03 for macOS from linux.
My Setup
/pythons/p3.9.0
).cargo/config.toml
(instructions on how to do it loosely adapted from https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html)cross building the library works, I can copy it manually to a macOS machine and use it:
My Issue
just replacing cargo by maturin doesn't work:
it seems maturin is calling python to get the current architecture, which makes it impossible to cross compile as a macOS python won't reply the correct arch on linux as it just won't run:
My Workaround
My first idea was to setup a false python that will reply whatever maturin is expecting. After some investigation, it seems maturin just want the result of https://github.com/PyO3/maturin/blob/master/src/get_interpreter_metadata.py. I ran this script on a macOS and created my custom python interpreter:
It seems PyO3 doesn't build the same way when called from maturin. Some more investigation later, Py03 is now executing a python script to parse the _sysconfigdata of the target python: https://github.com/PyO3/pyo3/blob/master/build.rs#L236
Now, with my new and improved custom python, it works 🎉:
This
mypython
script, when called by maturin, will reply the expected architecture, and when called by PyO3 will use the local python3 to interpret the target python header.Better Fix?
This is a very hacky fix, and not one I would want to use long term... From my understandings of PyO3 and maturin, I see three possible fixes:
--trust-me-dont-verify-my-arch
Thank you for reading this far!
The text was updated successfully, but these errors were encountered: