Skip to content

Commit

Permalink
Auto merge of #14595 - weihanglo:lockfile-v4, r=epage
Browse files Browse the repository at this point in the history
feat: make lockfile v4 the default

### What does this PR try to resolve?

This commit makes lockfile version 4 the default version when Cargo
tries to write to a lockfile.

The lockfile version 4 has been stabilized since 1.78.0,
and will become default in 1.83.0.
the length of transition period is pretty similar as before.

One caveat is that in other output from Cargo,
e.g., `cargo metatada`, status messages,
`SourceID` will display in the v4 URL encoded format.
This shouldn't affect the majority of Rust users,
as `SourceId` representation should be opaque to them,
unless comparing `SourceId` across different version of toolchains.

### How should we test and review this PR?

Some of those tests don't really need to be `version = 4`.
They were updated for consistency.

### Additional information

This was discussed in Cargo meeting on 2024-09-24.
  • Loading branch information
bors committed Sep 25, 2024
2 parents 8fc3ff4 + 5dfdd59 commit 5626292
Show file tree
Hide file tree
Showing 32 changed files with 92 additions and 108 deletions.
40 changes: 18 additions & 22 deletions src/cargo/core/resolver/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ pub enum ResolveVersion {
/// branch specifiers.
///
/// * Introduced in 2020 in version 1.47.
/// * New lockfiles use V3 by default starting in 1.53.
/// * New lockfiles use V3 by default from in 1.53 to 1.82.
V3,
/// SourceId URL serialization is aware of URL encoding. For example,
/// `?branch=foo bar` is now encoded as `?branch=foo+bar` and can be decoded
/// back and forth correctly.
///
/// * Introduced in 2024 in version 1.78.
/// * New lockfiles use V4 by default starting in 1.83.
V4,
/// Unstable. Will collect a certain amount of changes and then go.
///
Expand All @@ -107,7 +108,7 @@ impl ResolveVersion {
/// Update this and the description of enum variants of [`ResolveVersion`]
/// when we're changing the default lockfile version.
fn default() -> ResolveVersion {
ResolveVersion::V3
ResolveVersion::V4
}

/// The maximum version of lockfile made into the stable channel.
Expand All @@ -125,28 +126,23 @@ impl ResolveVersion {
return ResolveVersion::default();
};

let rust_1_41 = PartialVersion {
major: 1,
minor: Some(41),
patch: None,
pre: None,
build: None,
}
.try_into()
.expect("PartialVersion 1.41");
let rust_1_53 = PartialVersion {
major: 1,
minor: Some(53),
patch: None,
pre: None,
build: None,
}
.try_into()
.expect("PartialVersion 1.53");
let rust = |major, minor| -> RustVersion {
PartialVersion {
major,
minor: Some(minor),
patch: None,
pre: None,
build: None,
}
.try_into()
.unwrap()
};

if rust_version >= &rust_1_53 {
if rust_version >= &rust(1, 83) {
ResolveVersion::V4
} else if rust_version >= &rust(1, 53) {
ResolveVersion::V3
} else if rust_version >= &rust_1_41 {
} else if rust_version >= &rust(1, 41) {
ResolveVersion::V2
} else {
ResolveVersion::V1
Expand Down
5 changes: 1 addition & 4 deletions src/cargo/core/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,7 @@ impl fmt::Display for SourceId {
// Don't replace the URL display for git references,
// because those are kind of expected to be URLs.
write!(f, "{}", self.inner.url)?;
// TODO(-Znext-lockfile-bump): set it to true when the default is
// lockfile v4, because we want Source ID serialization to be
// consistent with lockfile.
if let Some(pretty) = reference.pretty_ref(false) {
if let Some(pretty) = reference.pretty_ref(true) {
write!(f, "?{}", pretty)?;
}

Expand Down
6 changes: 1 addition & 5 deletions src/cargo/sources/git/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,8 @@ fn ident_shallow(id: &SourceId, is_shallow: bool) -> String {
impl<'gctx> Debug for GitSource<'gctx> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "git repo at {}", self.remote.url())?;

// TODO(-Znext-lockfile-bump): set it to true when the default is
// lockfile v4, because we want Source ID serialization to be
// consistent with lockfile.
match &self.locked_rev {
Revision::Deferred(git_ref) => match git_ref.pretty_ref(false) {
Revision::Deferred(git_ref) => match git_ref.pretty_ref(true) {
Some(s) => write!(f, " ({})", s),
None => Ok(()),
},
Expand Down
6 changes: 1 addition & 5 deletions src/cargo/util/toml_mut/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,11 +1002,7 @@ impl GitSource {
impl std::fmt::Display for GitSource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let git_ref = self.git_ref();

// TODO(-Znext-lockfile-bump): set it to true when the default is
// lockfile v4, because we want Source ID serialization to be
// consistent with lockfile.
if let Some(pretty_ref) = git_ref.pretty_ref(false) {
if let Some(pretty_ref) = git_ref.pretty_ref(true) {
write!(f, "{}?{}", self.git, pretty_ref)
} else {
write!(f, "{}", self.git)
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@ fn sparse_lockfile() {
str![[r##"
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "a"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/lockfile_updated/in/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/lockfile_updated/out/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_info/not_found/out/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_info/path_dependency/in/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_info/path_dependency/out/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_info/within_workspace.in/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_info/within_ws/out/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/cargo_remove/gc_patch/out/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ fn cargo_compile_git_dep_pull_request() {
.with_stderr_data(str![[r#"
[UPDATING] git repository `[ROOTURL]/dep1`
[LOCKING] 1 package to latest compatible version
[COMPILING] dep1 v0.5.0 ([ROOTURL]/dep1?rev=refs/pull/330/head#[..])
[COMPILING] dep1 v0.5.0 ([ROOTURL]/dep1?rev=refs%2Fpull%2F330%2Fhead#[..])
[COMPILING] foo v0.0.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
Expand Down
Loading

0 comments on commit 5626292

Please sign in to comment.