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

Remove [root] section from Cargo.lock file #4563

Closed
matklad opened this issue Oct 2, 2017 · 21 comments
Closed

Remove [root] section from Cargo.lock file #4563

matklad opened this issue Oct 2, 2017 · 21 comments
Labels
E-easy Experience: Easy

Comments

@matklad
Copy link
Member

matklad commented Oct 2, 2017

Cargo.lock includes [root] section which is no longer used for anything, because it became obsolete when Cargo workspaces were implemented.

About a year ago, support for rootless lockfiles was implemented: 5e644df.

However, by default Cargo still adds an arbitrary root to be compatible with older Cargos. Given that we have a year's worth of new Cargos, I think we can safely switch to rootless lockfiles.

This code should be removed:

let use_root_key = if let Ok(ref orig) = orig {
!orig.starts_with("[[package]]")
} else {
true
};

However, we should make sure that Cargo is still able to read a lockfile with a root section (there's a test for this).

@matklad
Copy link
Member Author

matklad commented Oct 2, 2017

@alexcrichton do you also think that a year is a long enough grace period? To be clear, new Cargos will always read the old lockfiles, but a Cargo from a year ago will fail to read the new lockfile.

@alexcrichton
Copy link
Member

Whoa I had no idea that we had support for this! In that case I think we're probably in a pretty good situation. Although I think we may be missing one piece to flip the switch.

Right now while an older Cargo will parse a root-missing lockfile, will it also generate one? The problem we just want to avoid is that if you build with different verisons of Cargo the lock file oscillates between two different formats. If older Cargo though generates a lock file without [root] when reading a lock file without [root], sounds great!

@matklad
Copy link
Member Author

matklad commented Oct 3, 2017

If older Cargo though generates a lock file without [root] when reading a lock file without [root], sounds great!

This is exactly what was implemented back then, yeah!

@raytung
Copy link
Contributor

raytung commented Oct 3, 2017

@matklad Mind if I give this a go? :)

@matklad
Copy link
Member Author

matklad commented Oct 3, 2017

@raytung sure, it's yours :)

bors added a commit that referenced this issue Oct 4, 2017
Remove root from cargo lock

Removing [root] section from Cargo.lock for #4563

Tests of interest has been updated accordingly, especially [tests/lockfile-compat.rs#oldest_lockfile_still_works](https://github.com/rust-lang/cargo/compare/master...raytung:remove-root-from-cargo-lock?expand=1#diff-48866d1891f97cb799dd0ca7148d1eefR10)
@tamird
Copy link
Contributor

tamird commented Oct 12, 2017

Fixed in #4571?

@matklad
Copy link
Member Author

matklad commented Oct 12, 2017

Indeed!

@DanielKeep
Copy link

This is a problem for me. This means that the current nightly version of Cargo actively breaks compatibility with older versions of Rust. Every time I run cargo build, even if it doesn't need to change the lock file, it removes the [root] section. This means that if I want to test against older versions of Rust, I have to manually go and reset the lock file from source control.

Additionally, it means I can't work on changes in the new version of Rust, then back-port those changes; I have to work exclusively in an older version. So far as I'm aware, there's no way to prevent Cargo from messing with the lock file. If I make the file read-only, cargo build just fails outright (again, even if it doesn't need to modify it).

The question on this issue was "if we aren't using this, why not remove it?" My question is: "if it doesn't hurt anything, why remove it?"

@matklad
Copy link
Member Author

matklad commented Oct 29, 2017

Every time I run cargo build, even if it doesn't need to change the lock file, it removes the [root] section.

So even with --frozen the lockfile is modified? If this is the case, I think we should fix this.

Additionally, it means I can't work on changes in the new version of Rust, then back-port those changes; I have to work exclusively in an older version.

This is true: this change makes lockfiles generated by newer Cargos incompatible with older Cargos.
Please note that "older" here means "one year old or more": For about one year Cargo is able to read lockfiles without a [root] section, as a preparation for their eventual removal.

Could you elaborate what is the backwards compatibility story for your use case? Why do you need to publish updates,which are to be build with a year's old toolchain?

if it doesn't hurt anything, why remove it?

The main (not very strong) motivation here is to prevent the user from interpreting the [root] section of Cargo.lock as something meaningful. Just listing some package (what we do now) does cause confusion: #3704. So yeah, it kinda hurts a little now :)

@raytung
Copy link
Contributor

raytung commented Oct 30, 2017

At the moment we can't build old projects with --frozen. This is what I got:

$ cd old_project
$ rustup run nightly cargo build --frozen
error: the lock file needs to be updated but --frozen was passed to prevent this

@DanielKeep
Copy link

As noted, --frozen and --locked don't help; they just prevent building entirely. Cargo appears determined to remove the [root] section come hell or high water.

Could you elaborate what is the backwards compatibility story for your use case? Why do you need to publish updates,which are to be build with a year's old toolchain?

I said I'd support 1.11. I have no technical reason to break that promise: there is nothing my code is doing that can't be done in 1.11. (Even then, it's 1.11 due to dependencies.) I personally loathe it when people break back compat without a damn good reason for doing so, so I take my promises in this regard very seriously. It's not about needing to build on a year-old toolchain, it's about there being no reason to not build on a year-old toolchain.

So yeah, it kinda hurts a little now :)

This sounds more like "workspaces and [root] don't get along" combined with "that's not how you're supposed to interpret that", not that retaining [root] is itself a problem.

The problem here isn't that Cargo isn't writing [root] when it updates the lockfile any more, it's that I can't get it to stop updating the lockfile, even when it has no reason to do so. Incidentally, I'd be fine with maintaining two different, incompatible lock files if they were under different filenames (i.e. Cargo.lock, Cargo.lockv2, etc.).

bors added a commit that referenced this issue Oct 31, 2017
Don't update lockfiles from previous Cargo versions if `--locked` is passed

Recently, we've stopped outputting `[root]` section to Cargo.lock files. The problem with this is that somebody might want to have a Cargo.lock file with a `[root]` section for compatibility with older Cargos, but at the same time use newer Cargo to build the crate. In this case, newer Cargo would remove `[root]` from the lockfile. Such updating of the lockfiles to the latest versions is a reasonable behavior, but it might be useful to be able to override it with `--locked` flag.

Context: #4563 (comment)

r? @alexcrichton
isislovecruft added a commit to isislovecruft/tor-old that referenced this issue Dec 13, 2017
Newer versions of cargo recently removed the ability to understand the
`[root]` section of Cargo.lock files, which is particularly relevant when
either `cargo --frozen` and/or `cargo --locked` are specified, and the
failure/inability to download a new index will cause the whole build to fail
with "error: the lock file needs to be updated but --frozen was passed to
prevent this" (cf. rust-lang/cargo#4563).

 * REMOVE `[root]` section from our top-level `Cargo.lock` file.
 * FIXES #24608: https://bugs.torproject.org/24608
isislovecruft added a commit to isislovecruft/tor-old that referenced this issue Dec 13, 2017
Newer versions of cargo recently removed the ability to understand the
`[root]` section of Cargo.lock files, which is particularly relevant when
either `cargo --frozen` and/or `cargo --locked` are specified, and the
failure/inability to download a new index will cause the whole build to fail
with "error: the lock file needs to be updated but --frozen was passed to
prevent this" (cf. rust-lang/cargo#4563).

 * REMOVE `[root]` section from our top-level `Cargo.lock` file.
 * FIXES #24608: https://bugs.torproject.org/24608
@isislovecruft
Copy link

isislovecruft commented Dec 13, 2017

Hi!

We (The Tor Project) appear to be having the same bug as @DanielKeep (and reasoning for backwards compatibility with the lockfiles which are now in our older, maintenance-only branches). However, instead of with --locked, we're specifying --frozen, and newer cargo is desperately trying to update the lockfile, then bailing because it can't. Our bug for tracking this is https://bugs.torproject.org/24608, the description of which includes the logs of a TravisCI build which is failing (we suspect) for this reason.

Should I make a new ticket for this issue?

@carols10cents carols10cents reopened this Dec 13, 2017
@carols10cents
Copy link
Member

Reopening this seems like a good start :)

@carols10cents
Copy link
Member

My first thought was that we patched --locked but not --frozen (because PR #4684 only mentioned --locked in the subject), but I have now learned that --frozen implies --locked. I have learned that from adding a test to cargo that tests --frozen with an old lockfile in addition to the existing test that tests --locked with an old lockfile and the test i added passed.

Given that there was an additional fix for this issue for cases in which the [root] section was not the first crate in the sorted crate array, I'm now suspecting there's a similar edge case tor is hitting, something involving workspaces and the [root] section pointing to a non-arbitrary existing crate.

My next step is going to be attempting to reproduce and reduce the circumstances in which the failure tor is seeing in travisci occurs.

@matklad
Copy link
Member Author

matklad commented Dec 13, 2017

@isislovecruft , on Traivis I see

$ if [[ "$RUST_OPTIONS" != "" ]]; then rustc --version; fi

rustc 1.24.0-nightly (9fe7aa353 2017-12-11)

install.12

0.02s$ if [[ "$RUST_OPTIONS" != "" ]]; then cargo --version; fi

cargo 0.25.0-nightly (930f9d949 2017-12-05)

So this means that the test is using the fresh nightly version of Cargo. Does it mean that this is a fresh regression?

@matklad
Copy link
Member Author

matklad commented Dec 13, 2017

Hm, I am now remembering a PR which removes some checksum checking from the lockfile, I wonder if it is the culprit...

@carols10cents
Copy link
Member

@matklad I noticed cargo was updated in rust-lang/rust 8 days ago, which matches when tor started seeing travis fail ("This is ​causing build errors on Travis, which picked up the newest cargo nightly a week ago.")

@matklad
Copy link
Member Author

matklad commented Dec 13, 2017

Yep, the commit I am talking about is a0dfbb7

@carols10cents
Copy link
Member

Aaaahhh ok, that sounds like a new issue then?

@matklad
Copy link
Member Author

matklad commented Dec 13, 2017

@carols10cents seems so! If tor faced this issue and they are testing on nightly/beta, then they would have caught it ages ago.

@carols10cents
Copy link
Member

Ok I've opened a new issue: #4815

and I'm reclosing this one :)

kamalmarhubi added a commit to kamalmarhubi/rls-span that referenced this issue Feb 23, 2018
Support for reading rootless lock files was added in cargo PR 3031,
which landed in cargo 0.14, released in November of 2016.  Cargo stopped
generating the root section in cargo PR 4571, which landed in cargo
0.23.

refs rust-lang/cargo#3031
refs rust-lang/cargo#4563
refs rust-lang/cargo#4571
pablobm added a commit to pablobm/rust-experiments that referenced this issue Nov 24, 2018
shuhei pushed a commit to shuhei/colortty that referenced this issue Feb 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Experience: Easy
Projects
None yet
Development

No branches or pull requests

7 participants