-
-
Notifications
You must be signed in to change notification settings - Fork 271
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
Implement new sdist feature to download rust toolchain #2177
base: main
Are you sure you want to change the base?
Implement new sdist feature to download rust toolchain #2177
Conversation
Initial draft to implement downloading rust toolchain during sdist
✅ Deploy Preview for maturin-guide ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
@messense Can you review this PR ? I'm not sure if I'm heading to the right direction so I'd like to get some feedback before proceeding to polish it |
src/build_context.rs
Outdated
@@ -1132,6 +1148,19 @@ impl BuildContext { | |||
} | |||
Ok(wheels) | |||
} | |||
/// Check if user requires to install rust toolchain | |||
/// | |||
/// Loop over `build-system.requires` defined in pyproject.toml and see if `rust-toolchain` is provided |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't going to work because pip
will try to install rust-toolchain
package from pypi
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't have rust-toolchain
on pypi yet, we can try to use rust-toolchain.toml
/ legacy rust-toolchain
file or rust-version
in Cargo.toml
of the binding crate, then fallback to Rust stable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@messense Thanks. So it means like if user provides a rust-toolchain.toml
file in the project directory, that would be indicating that user wants to install rust-toolchain ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To put my two cents in, I think that the rust toolchain should be present for the build, even if rust-toolchain.toml
is missing in which case a default toolchain would be used. Bonus points if [toolchain]
can be specified directly in the pyproject.toml
as e.g [tool.maturin.toolchain]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about an additional command line flag such as maturin sdist --install-rust-toolchain
? (Or maybe when env variable MATURIN_INSTALL_RUST
is set to true? ). This will be backward-compatible while keeping maturin flexible for users .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would only be suitable in the case the user of the package knows what Maturin, Rust etc. is. However, the reason I brought up issue #2120, is that a typical user just wants to use a package and would probably do not like to think about the build backend of this package.
In other words, it would be nice in my opinion, if a user can install a source distribution of a package that uses maturin
as build-system
simply via pip install
without knowing such internals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@messense @padix-key I've modified prepare_metadata_for_build_wheel
to remove the check for rust-toolchain, and add logic in maturin pep517 write-dist-info
command to check for toolchain from there ( and install from rustup if not present). Let me know what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have actually barely insight into the maturin
internals, I only know the user side 😃.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think automatically downloading an installation script and running it for the user and installing to non-standard locations is undesirable. I would not be happy if this took place on my system without any confirmation at least. I could also see it causing problems for CI systems which may accidentally install rustup each build if misconfigured.
An opt-in command line flag or environment variable seems like a good approach to me. If not passed it could print
rust toolchain (cargo) not found.
Please install it manually or pass `maturin sdist --auto-install-toolchain`
so discoverability wouldn't be an issue for the 'typical user' described as not being aware of what they need to have installed
@@ -382,7 +382,7 @@ fn http_agent() -> Result<ureq::Agent, UploadError> { | |||
|
|||
#[cfg(feature = "rustls")] | |||
#[allow(clippy::result_large_err)] | |||
fn http_agent() -> Result<ureq::Agent, UploadError> { | |||
pub fn http_agent() -> Result<ureq::Agent, UploadError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a http_agent
below that also need to be made public.
src/build_context.rs
Outdated
.to_str() | ||
.context("Fail to construct target path for installing rust toolchain")?; | ||
|
||
download_and_execute_rustup(target_path_str, target_path_str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip download if there is already a working rust toolchain (probably need to validate version with rust-version
in Cargo.toml
and Cargo.toml
of every crate dependencies, I think we can get that from cargo metadata
output).
cc @padix-key since you requested this feature. |
for more information, see https://pre-commit.ci
…st_toolchain' into impl_sdist_feature_to_install_rust_toolchain
Initial draft to implement downloading rust toolchain during sdist
for more information, see https://pre-commit.ci
908bec0
to
e06953f
Compare
…//github.com/Owen-CH-Leung/maturin into impl_sdist_feature_to_install_rust_toolchain
(sorry for the further delay, i was on this but got thrown off again by #2268) |
… to test pip install without toolchain
I was trying to create a CI test to verify that pip install will work even without toolchain but no luck :( |
Why are rustup and cargo being installed to non-standard locations? the code seems to be using |
Would it be sensible to install |
Solves #2120
This PR implements feature to download rust toolchain when trying to pip install a python package built by maturin. Specifically, when maturin execute
WriteDistInfo
, when compiling with therustls
feature, it will try to check if toolchain is installed, and proceed to install the rustup installer and download the stable toolchain if toolchain is absent