feat(android): add Rust cross-compilation setup for Android environment
Like platform windows
https://github.com/pypa/cibuildwheel/blob/c53e541c2de29c8bb0a8f6e3ff13d96046e8000c/cibuildwheel/platforms/windows.py#L206-L232
Add Rust cross-compilation setup for Android environment, it can fix the cross-compilation problem for the rust project built with setuptools-rust
For Rust projects built with Maturin, it currently does not work. Maturin has some cross-compilation issues on Android that still need to be fixed.
For details, please see https://github.com/PyO3/maturin/issues/2810
This looks nice and neat! Is there an example of it working in a real project that you've been testing it with?
I want to test, but I did not know how to run this without the github action,if you know how to do, you can tell me,and I will test it.
This commit is a modification I made based on the actual missing environment configuration built on Android using cbuildwheel.
Of course, I manually configured it externally in a non-isolated environment, and after the configuration, I built the wheel correctly and it can run on Android
You can test a project using something like this in a github workflow-
- name: Build wheels
uses: ririv/cibuildwheel@main
Thanks, I have tested it, and made some new commits. Now, it works.
- The
CARGO_TARGET_<triple>_LINKERmust be set. Otherwise, it will use the host's linkercc, which will result in an error. - The
PYO3_CROSS_LIB_DIRmust be set to link againstlibpython3.x.soexplicitly. See: https://peps.python.org/pep-0738/#linkage and https://pyo3.rs/v0.27.1/building-and-distribution.html#cross-compiling
The PYO3_CROSS_LIB_DIR environment variable should be set here rather than requiring users to specify it manually, for the following reasons:
- PYO3 has become the de facto standard for Python extension modules built with Rust. Both setuptools-rust and maturin are tools developed by the PYO3 team specifically to serve PYO3.
- The value set for
PYO3_CROSS_LIB_DIRrequires the directory path of target_python. This path is already configured within cbuildwheel'sandroid.pybut cannot be directly accessed externally. External configuration would necessitate manually constructing the path. - PYO3's documentation for Android cross-compilation is insufficiently detailed. If users attempt to set this variable manually, they are likely to become confused and unsure how to proceed.
https://github.com/ririv/android-wheels/blob/main/.github/workflows/cbuildweel-repair-test.yml This is the workflow file. It performed some conversions. For the maturin project, it was converted to a setuptools-rust project. This is because maturin has some bugs in Android cross-compilation. I've submitted a PR to fix it, but the maturin maintainer hasn't responded yet.
Here are some logs:
- pydantic-core | maturin convert to setuptools-rust https://github.com/ririv/android-wheels/actions/runs/19223626338/job/54946144941
- tiktoken | based on setuptools-rust https://github.com/ririv/android-wheels/actions/runs/19223649349/job/54946212372
Looks good to me! @mhsmith what do you think?
Sorry for the delay, I'll look at this as soon as I can.