Skip to content

Commit 424362a

Browse files
committed
Auto merge of #12279 - weihanglo:next-lockfile-bump, r=epage
feat: prepare for the next lockfile bump
2 parents 0d5370a + 0355605 commit 424362a

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

src/cargo/core/features.rs

+2
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ unstable_cli_options!(
741741
minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum"),
742742
msrv_policy: bool = ("Enable rust-version aware policy within cargo"),
743743
mtime_on_use: bool = ("Configure Cargo to update the mtime of used files"),
744+
next_lockfile_bump: bool = (HIDDEN),
744745
no_index_update: bool = ("Do not update the registry index even if the cache is outdated"),
745746
panic_abort_tests: bool = ("Enable support to run tests with -Cpanic=abort"),
746747
profile_rustflags: bool = ("Enable the `rustflags` option in profiles in .cargo/config.toml file"),
@@ -1110,6 +1111,7 @@ impl CliUnstable {
11101111
"host-config" => self.host_config = parse_empty(k, v)?,
11111112
"jobserver-per-rustc" => self.jobserver_per_rustc = parse_empty(k, v)?,
11121113
"lints" => self.lints = parse_empty(k, v)?,
1114+
"next-lockfile-bump" => self.next_lockfile_bump = parse_empty(k, v)?,
11131115
"minimal-versions" => self.minimal_versions = parse_empty(k, v)?,
11141116
"msrv-policy" => self.msrv_policy = parse_empty(k, v)?,
11151117
// can also be set in .cargo/config or with and ENV

src/cargo/core/resolver/encode.rs

+9
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,18 @@ impl EncodableResolve {
154154
/// primary uses is to be used with `resolve_with_previous` to guide the
155155
/// resolver to create a complete Resolve.
156156
pub fn into_resolve(self, original: &str, ws: &Workspace<'_>) -> CargoResult<Resolve> {
157+
let unstable_lockfile_version_allowed = ws.config().cli_unstable().next_lockfile_bump;
157158
let path_deps = build_path_deps(ws)?;
158159
let mut checksums = HashMap::new();
159160

160161
let mut version = match self.version {
162+
Some(4) => {
163+
if unstable_lockfile_version_allowed {
164+
ResolveVersion::V4
165+
} else {
166+
anyhow::bail!("lock file version 4 requires `-Znext-lockfile-bump`",)
167+
}
168+
}
161169
Some(3) => ResolveVersion::V3,
162170
Some(n) => bail!(
163171
"lock file version `{}` was found, but this version of Cargo \
@@ -612,6 +620,7 @@ impl ser::Serialize for Resolve {
612620
metadata,
613621
patch,
614622
version: match self.version() {
623+
ResolveVersion::V4 => Some(4),
615624
ResolveVersion::V3 => Some(3),
616625
ResolveVersion::V2 | ResolveVersion::V1 => None,
617626
},

src/cargo/core/resolver/resolve.rs

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ pub enum ResolveVersion {
8080
/// V3 by default staring in 1.53.
8181
#[default]
8282
V3,
83+
/// Unstable. Will collect a certain amount of changes and then go.
84+
///
85+
/// Changes made:
86+
V4,
8387
}
8488

8589
impl Resolve {

src/cargo/ops/lockfile.rs

+8
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes
6969
if resolve.version() < ResolveVersion::default() {
7070
resolve.set_version(ResolveVersion::default());
7171
out = serialize_resolve(resolve, orig.as_deref());
72+
} else if resolve.version() > ResolveVersion::default()
73+
&& !ws.config().cli_unstable().next_lockfile_bump
74+
{
75+
// The next version hasn't yet stabilized.
76+
anyhow::bail!(
77+
"lock file version `{:?}` requires `-Znext-lockfile-bump`",
78+
resolve.version()
79+
)
7280
}
7381

7482
// Ok, if that didn't work just write it out

tests/testsuite/lockfile_compat.rs

+63
Original file line numberDiff line numberDiff line change
@@ -888,3 +888,66 @@ perhaps a crate was updated and forgotten to be re-vendored?
888888
)
889889
.run();
890890
}
891+
892+
#[cargo_test]
893+
fn v4_is_unstable() {
894+
let p = project()
895+
.file(
896+
"Cargo.toml",
897+
&format!(
898+
r#"
899+
[package]
900+
name = "foo"
901+
version = "0.0.1"
902+
"#,
903+
),
904+
)
905+
.file("src/lib.rs", "")
906+
.file("Cargo.lock", "version = 4")
907+
.build();
908+
909+
p.cargo("fetch")
910+
.with_status(101)
911+
.with_stderr(
912+
"\
913+
error: failed to parse lock file at: [CWD]/Cargo.lock
914+
915+
Caused by:
916+
lock file version 4 requires `-Znext-lockfile-bump`
917+
",
918+
)
919+
.run();
920+
}
921+
922+
#[cargo_test]
923+
fn v4_cannot_be_created_from_scratch() {
924+
let p = project()
925+
.file(
926+
"Cargo.toml",
927+
&format!(
928+
r#"
929+
[package]
930+
name = "foo"
931+
version = "0.0.1"
932+
"#,
933+
),
934+
)
935+
.file("src/lib.rs", "")
936+
.build();
937+
938+
p.cargo("fetch -Znext-lockfile-bump")
939+
.masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"])
940+
.run();
941+
942+
let lockfile = r#"# This file is automatically @generated by Cargo.
943+
# It is not intended for manual editing.
944+
version = 3
945+
946+
[[package]]
947+
name = "foo"
948+
version = "0.0.1"
949+
"#;
950+
951+
let lock = p.read_lockfile();
952+
assert_match_exact(lockfile, &lock);
953+
}

0 commit comments

Comments
 (0)