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 cargo +rust-version build|test|... #2925

Open
imp opened this issue Dec 10, 2021 · 3 comments
Open

Allow cargo +rust-version build|test|... #2925

imp opened this issue Dec 10, 2021 · 3 comments

Comments

@imp
Copy link

imp commented Dec 10, 2021

Problem you are trying to solve

Now that rust-version is stable it makes sense to have a CI task/job that asserts this commitment. In that case, one would need to set up a CI config that runs tests on the selected Rust version. Usually, it means that the specific version will be specified twice

  1. rust-version in Cargo.toml
  2. Somewhere in CI configuration.

And they need to be in sync to make sense. This is where extra work is required and that may be avoided.

Solution you'd like

I suggest teaching cargo to understand the +rust-version parameter, alongside the +stable, +nightly, and friends. When specified it will cause cargo to use the Rust toolchain referenced in the rust-version parameter. (And installing it on demand as it does today when used with other +toolchain parameters).
If used for crates that lack rust-version parameter it will fall back to otherwise default toolchain configured for this crate.

As a result, the potential disagreement between CI and rust-version will be avoided completely, better usability, less time wasted, etc

Notes

This issue was originally opened as rust-lang/cargo#10012, but rustup is the right place to solve it

@kinnison
Copy link
Contributor

This is an interesting idea. Doing this would "reserve" the toolchain name "rust-version" but perhaps we can come up with some other term if that annoys anyone.

To make this work, Rustup would have to parse Cargo.toml which means it has to find it, and replicate Cargo's algorithms for that.

We'd have to very forgivingly parse Cargo.toml once found, and only then if we find a rust version, attempt to consider that an override.

None of this is particularly hard, but it's certainly non-trivial.

https://github.com/rust-lang/rustup/blob/master/src/config.rs#L555 has the function which finds the overrides. Starting here whoever implements this will want to understand how we find and report overrides, and then add support for this functionality.

@ongchi
Copy link
Contributor

ongchi commented Jul 24, 2023

Thank you for your explanation.
I'm working on this issue, but not sure if it's make sense to put rust-version form Cargo.toml as version override after rust-toolchain.
I would appreciate it if someone could point me out. Many thanks.

@ongchi
Copy link
Contributor

ongchi commented Jul 25, 2023

I just realized that I've been misunderstood.

The cargo will check the rust-version field in Cargo.toml, if the installed version is older than the version specified, then exit with an error message or just execute the command when the installed version is newer.

Then the following behavior should be implemented:

  • If the user pass +rust-version to cargo, then rustup should check if the exact version specified has been installed. If not, exit with an error message.
  • If the field rust-version is not found in Cargo.toml, then exit with an error message.
  • Set toolchain as version specified from Cargo.toml.

Please correct me if I got anything wrong.

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

Successfully merging a pull request may close this issue.

3 participants