Skip to content

Commit

Permalink
feat(cargo-lock): support lockfile v4
Browse files Browse the repository at this point in the history
In 1.78.0 Cargo introduce v4 lockfile:

rust-lang/cargo#12852

The v3-to-v4 change is minimal: encode URL params with URL encoding.
However, roundtrip test failed because v4 we can only have one
serialization implementation at a time.

I don't know how to proceed. Maybe we could

* Make v4 serialization the default when it becomes the default in Cargo
* Provide API for people to generate different versions of lockfiles.
* Work with upstream Cargo with an in-tree pacakge for lock serialization.
  (This is on me?)

Opened this PR for discussion.
  • Loading branch information
weihanglo committed Jun 24, 2024
1 parent 972ac93 commit f0e2954
Show file tree
Hide file tree
Showing 2 changed files with 231 additions and 0 deletions.
221 changes: 221 additions & 0 deletions cargo-lock/tests/examples/Cargo.lock.v4

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

10 changes: 10 additions & 0 deletions cargo-lock/tests/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const V2_LOCKFILE_PATH: &str = "tests/examples/Cargo.lock.v2";
/// Path to a V3 `Cargo.lock` file.
const V3_LOCKFILE_PATH: &str = "tests/examples/Cargo.lock.v3";

/// Path to a V4 `Cargo.lock` file.
const V4_LOCKFILE_PATH: &str = "tests/examples/Cargo.lock.v4";

/// Load example V1 `Cargo.lock` file (from the Cargo project itself)
#[test]
fn load_example_v1_lockfile() {
Expand Down Expand Up @@ -68,6 +71,13 @@ fn serialize_v3() {
assert_eq!(lockfile2.packages, lockfile.packages);
}

/// Load example V4 `Cargo.lock` file
#[test]
fn load_example_v4_lockfile() {
let err = Lockfile::load(V4_LOCKFILE_PATH).unwrap_err();
assert_eq!(&err.to_string(), "parse error: parse error: invalid Cargo.lock format version: `4`\n");
}

/// Ensure we can serialize a V2 lockfile as a V1 lockfile
#[test]
fn serialize_v2_to_v1() {
Expand Down

0 comments on commit f0e2954

Please sign in to comment.