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

Self contained rust boostrapping #2421

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

konstin
Copy link
Member

@konstin konstin commented Jan 1, 2025

Currently, maturin is not self-contained: You need to install rust on the machine in order to build a package. We can improve this by downloading a matching rustup, using it to install cargo and rustc into a temporary directory and using this rust for the build. As long as the platform is supported by rustup, we get a self-contained build that doesn't mess with the host system. You can for example use pip install ... in a fresh python3-slim docker container and any rust dependency with a missing wheel will build and install without additional setup (while it currently fails and prompts you to install rust).

To inject this cache installation, we need to set PATH, RUST_HOME and CARGO_HOME whenever we call cargo or rustc.

Since setuptools rejects supporting programmatically setting dependencies (pypa/setuptools#2854), we use their hack of an in-tree build backend that overrides some of setuptools' hooks. In this hook, we install https://github.com/konstin/puccinialin if rust is missing, and later (in setup.py) run it to install rust and run maturin with the right env vars already set.

There's an option to disable rust bootstrapping through an env vars for users that don't want this automatism (e.g. linux distros).

In effect, this now works (using the dev maturin for demonstration):

docker run --rm -it -v $(pwd):/io python:3.13 python -m pip install /io/ -v

I've only tested linux/windows/mac and x86_64/arm64 in puccinialin so far, but i hope to add all the other rustup supporter platforms and arches over time.

Needs PyO3/setuptools-rust#504

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant