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

Generate "Cargo.lock" for old Rust compiler #13503

Closed
P1119r1m opened this issue Feb 29, 2024 · 16 comments
Closed

Generate "Cargo.lock" for old Rust compiler #13503

P1119r1m opened this issue Feb 29, 2024 · 16 comments
Labels
A-lockfile Area: Cargo.lock issues C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-generate-lockfile S-triage Status: This issue is waiting on initial triage.

Comments

@P1119r1m
Copy link

Problem

I have a project written in Rust.
It was compiled without problems using the Rust compiler version "1.64.0".
At some point I decided to do:

cargo update

As a result, the "Cargo.lock" file was updated and now I can't build the project:

error: package regex-syntax v0.8.2 cannot be built because it

requires rustc 1.65 or newer... ... error: package home v0.5.9

cannot be built because it requires rustc 1.70.0 or newer...

Previous version of the "Cargo.lock" file wasn't saved.

Also I don't want (cannot) update my Rust compiler. It is written by 3rd-party vendor.

Is it possible to:

  • recover the possibility to build my project using old Rust "1.64.0"?
  • generate a "Cargo.lock" file for a specific version of the Rust compiler?

If yes, then how?
If no - that's the matter of the current feature request.

Proposed Solution

cargo generate-lockfile --rustc-version=1.64.0

Notes

No response

@P1119r1m P1119r1m added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Feb 29, 2024
@epage
Copy link
Contributor

epage commented Feb 29, 2024

#12861 made the cargo lock version package.rust-version aware.

Does that satisfy the need?

@epage epage added A-lockfile Area: Cargo.lock issues Command-generate-lockfile labels Feb 29, 2024
@weihanglo
Copy link
Member

@epage
From the description it sounds like about MSRV aware resolution, not lockfile version.

For the MSRV aware dependency resolver, see #9930.

@epage
Copy link
Contributor

epage commented Feb 29, 2024

You're right, I went off the title.

See also #5221 for the time traveling resolver.

@epage
Copy link
Contributor

epage commented Feb 29, 2024

For the MSRV aware dependency resolver, see #9930.

Note that this is available in nightly. Run cargo +nightly generate-lockfile -Zmsrv-policy

@weihanglo
Copy link
Member

@P1119r1m

If you really want to use an older lockfile version (which is rare and you normally won't do that), you can edit the topmost version field in Cargo.lock to an older version.

Since we already have -Zmsrv-policy and other aforementioned tracking issues, I am going to close this as a duplicate. Thank you.

@weihanglo weihanglo closed this as not planned Won't fix, can't repro, duplicate, stale Feb 29, 2024
@P1119r1m
Copy link
Author

For the MSRV aware dependency resolver, see #9930.

Note that this is available in nightly. Run cargo +nightly generate-lockfile -Zmsrv-policy

Thank you for such a fast reply!
Unfortunately, this command seems unavailable (old cargo?):

$ cargo --version
cargo 1.64.0-nightly (387270bc7 2022-09-16)

$ cargo +nightly generate-lockfile -Zmsrv-policy
error: no such subcommand: `+nightly`

$ cargo generate-lockfile -Zmsrv-policy
error: unknown `-Z` flag specified: msrv-policy

@epage
Copy link
Contributor

epage commented Feb 29, 2024

+nightly is a directive to rustup to tell it to use a different toolchain version (from the "nightly" release channel). Sounds like you are running Rust directly without rustup, the Rust toolchain version manager.

Are you running Debian? Generally, we recommend Debian's toolchain only be used for packaging of Debian packages and people should use rustup for their own development.

@P1119r1m
Copy link
Author

+nightly is a directive to rustup to tell it to use a different toolchain version (from the "nightly" release channel). Sounds like you are running Rust directly without rustup, the Rust toolchain version manager.

Unfortunately, I don't have rustup in this 3rd-party toolchain.

@P1119r1m
Copy link
Author

P1119r1m commented Feb 29, 2024

@P1119r1m

If you really want to use an older lockfile version (which is rare and you normally won't do that), you can edit the topmost version field in Cargo.lock to an older version.

Since we already have -Zmsrv-policy and other aforementioned tracking issues, I am going to close this as a duplicate. Thank you.

As far as I understand, the features mentioned in the comments do not cover the original idea of the current feature request.
In short - "generate Cargo.lock for a predefined version of the rustc compiler", for example:

cargo generate-lockfile --rustc-version=1.64.0

@weihanglo

IMHO, this is an extremely useful feature in many situations - from testing to development.

Please reopen this feature request.

@epage
Copy link
Contributor

epage commented Feb 29, 2024

The MSRV RFC opens with

  • Generate for MSRV, if set
  • Generate for rustc --version, otherwise

So you can get this by either changing your MSRV or changing your toolchain.

Is that sufficient? If not, could you expand on why?

@P1119r1m
Copy link
Author

@epage

Frankly, I don't really understand what I need to do to compile my Rust project with the old (1.64.0) Rust toolkit.
That project that was compiled without problems until the moment when "Cargo.lock" was removed.

Am I understanding you correctly that this will be possible in the future (after/if the MSRV RFC will be merged into the master), but not for older Rust tools (eg 1.64.0, 1.72.0, etc.)?

@epage
Copy link
Contributor

epage commented Feb 29, 2024

You will need to be running a newer toolchain to get access to the feature, yes.

We generally recommend people develop with the latest toolchain so they get features like this, regardless of what version they do official testing and deployment with.

@epage
Copy link
Contributor

epage commented Feb 29, 2024

Even if we added a --rust-version flag, it would only be available on those newer toolchains anyways.

@P1119r1m
Copy link
Author

@epage

Ok. I got your idea.
If I understand correctly, I should use the "nightly, latest" Rust toolchain to be able to generate "Cargo.lock" for my old (1.64.0) third-party Rust toolchain.

Thank you very much for your help and tips!

@P1119r1m
Copy link
Author

P1119r1m commented Feb 29, 2024

Even if we added a --rust-version flag, it would only be available on those newer toolchains anyways.

BTW, it would be nice and clear feature anyway.

JFYI.
Even now I'm not sure I can "downgrade" "Cargo.lock" for "1.64.0" using the latest "nigtly" toolchain with:

cargo +nightly generate-lockfile -Zmsrv-policy

In other words, I tried but failed.
Generated "Cargo.lock" contains version = 3 anyway.
It seems that it ignores "Cargo.toml":

[workspace]
resolver = "2"
version = 2

UPD.

$ cargo +nightly --version
cargo 1.78.0-nightly (8964c8ccf 2024-02-27)

@epage
Copy link
Contributor

epage commented Feb 29, 2024

The lockfile format version is different than the resolver algorithm version. #12861 (mentioned earlier) made the lockfile format version auto-selected by MSRV, rather than always "latest" for situations like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lockfile Area: Cargo.lock issues C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-generate-lockfile S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

3 participants