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

Allow overriding python platform with _PYTHON_HOST_PLATFORM env var #2104

Closed
messense opened this issue Jun 6, 2024 · 4 comments · Fixed by #2122
Closed

Allow overriding python platform with _PYTHON_HOST_PLATFORM env var #2104

messense opened this issue Jun 6, 2024 · 4 comments · Fixed by #2122
Labels
cross-compile Something related to cross compilation enhancement New feature or request good first issue Good for newcomers

Comments

@messense
Copy link
Member

messense commented Jun 6, 2024

Useful for cross compilation.

See also

@messense messense added enhancement New feature or request good first issue Good for newcomers cross-compile Something related to cross compilation labels Jun 6, 2024
@FeodorFitsner
Copy link
Contributor

I've been about to post the same issue :)

TLDR: Despite _PYTHON_HOST_PLATFORM is kind of undocumented variable used in soon-to-be-deprecated-distutils I also think it could be the easiest way to fix tags for cross-compiled wheels.

Long version:

Re: #2102 (comment) and #2103.

According to PEP-730 and PEP-738 wheels tags should be:

Android:

  • android_21_arm64_v8a
  • android_21_armeabi_v7a
  • android_21_x86_64
  • android_21_x86

iOS:

  • ios_12_0_arm64_iphoneos
  • ios_12_0_arm64_iphonesimulator
  • ios_12_0_x86_64_iphonesimulator

This should be the value returned by sysconfig.get_platform() (with _ replaced to -).

After looking at Maturin code base I see there are at least two ways for that value to get into the program:

  • CARGO_BUILD_TARGET variable (or --target option).
  • target.detect_arch_from_python() method

CARGO_BUILD_TARGET expects a valid triple in the format {arch}-{vendor}-{os}[-env], so neither android_21_arm64_v8a, not ios_12_0_arm64_iphoneos won't work there.

On the other hand detect_arch_from_python() is currently tailored to macOS only (btw, python interpreter detection code refuses executable name without a version on the end - could be fixed as well). We could, potentially, add checks/parsing for iOS and Android, but Target structure would need to be extended with os_ver (or something) field to store 12.0 for iOS and 21 for Android. Also, build_context.get_platform_tag() would need to be improved to handle iOS and Android OSes.

So, checking _PYTHON_HOST_PLATFORM and using it for a wheel tag would be an easiest way to satisfy custom tags requirements :)

I can try implementing that and submit a PR.

@messense
Copy link
Member Author

Pull requests are welcome!

On the other hand detect_arch_from_python() is currently tailored to macOS only

Don't worry about this one, it's only for native macOS compilation.

@FeodorFitsner
Copy link
Contributor

@messense what do you think about #2122? I don't have much experience with Rust, please let me know if it could be made more elegantly.

The implementation is that easy indeed, worked like a charm for us.

@messense
Copy link
Member Author

#2122 looks good to me, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cross-compile Something related to cross compilation enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants