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

fix: Change the defaults to always check-in Cargo.lock #12382

Merged
merged 5 commits into from
Aug 21, 2023

Conversation

epage
Copy link
Contributor

@epage epage commented Jul 19, 2023

What does this PR try to resolve?

Having libraries leave Cargo.lock "on the float" has been serving the ecosystem well, including

  • Encouraging people to validate that latest dependencies work
  • Encouraging ecosystem-wide health by acting as a "distributed crater"

These benefits are limited though. The policy is inconsistent between workspaces with or without [[bin]]s, reducing the affect of testing the latest. This is also subject to when CI last ran; for passively maintained projects, there is little coverage of new dependencies.

There are also costs associated with this policy

  • git bisect is using an unpredictable set of dependencies, affecting the ability to identify root cause
  • This is another potential cause for Red CI / broken local development if version is yanked or a bug is introduced
    • Impacting the perceived level of quality for a project
    • Confusing to new contributors who might not recognize why CI failed and assume its their fault
    • Requiring context switching from maintainers to get fixes in

In particular, since this policy was decided, there has been an increased interest in supporting an MSRV (as recently as v1.56.0, cargo gained support for specifying a package's MSRV). This has led to long discussions on what MSRV a package should use (e.g. rust-lang/libs-team#72,. time-rs/time#535). Worst, there has been a growing trend for people to set an non-semver upper bound on dependencies, making it so packages can't work well with other packages (see #12323). Tooling support would help with this (#9930) but the sooner we address this, the less entrenched bad practices will be.

On the positive side, since the policy was decided

So to get some of the benefit from not checking in Cargo.lock, we can recommend either automatically applying updates or having CI check the latest dependencies in a way to get this out of the critical path of PRs and releases.

Since there is no one right answer on how to solve all of these problems, we're documenting these trade offs so people can make the choice that is most appropriate for them. However, we are changing the default to a consistent "always check it in" as the answer for those who don't want to think about it.

Prior art

Fixes #8728

How should we test and review this PR?

Please review per-commit. I tried to minimize changes I made to the structure of the CI document

In #8728, I brought up having a CI reference page. I keep going back and forth on whether this is guide-level material or reference-level material. Obviously, right now I'm leaning towards it being guide-level.

Additional information

This changes cargo from telling people what to do to giving them a starting point, or default, and giving them the information to make their own choice, if needed.

So the question for defaults is who are we targeting? For a default path in documentation, it would be for new to intermediate users. As for cargo new, we've been prioritizing new users over those that run it frequently (boiler plate comment, bin is default, etc).

See #8728 for the FCP on this policy change

epage added 3 commits July 19, 2023 10:46
When the guide was written, it only included Travis CI.  For while, it
was *the* CI service people used.  However, since git hosting services
have been integrating CI support and with Travis CI's new owners, market
share has been going down.  One estimate I found said that Travis CI's
market share is 0.94%.  If we had a compelling reason to include it,
independent of that, I would.  However, including it and making it first
in the list is a distraction.  There are CI services in more common use
(e.g. CircleCI, Jenkins) to include at this point over Travis.
@rustbot
Copy link
Collaborator

rustbot commented Jul 19, 2023

r? @weihanglo

(rustbot has picked a reviewer for you, use r? to override)

@epage epage marked this pull request as draft July 19, 2023 16:49
@rustbot rustbot added A-documenting-cargo-itself Area: Cargo's documentation Command-new S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 19, 2023
@epage
Copy link
Contributor Author

epage commented Jul 19, 2023

I've marked this as a draft until the FCP is closed.

epage and others added 2 commits July 19, 2023 11:55
Before, we were fairly prescriptive of when to check-in the `Cargo.lock`
file.   The guidance has been updated to instead explain the trade offs
and to mostly leave it in users hands.  As a starting point, we do say
to check it in for those that want an "easy answer".
Following the default guidance to commit a lockfile, this updates
`cargo new` to do it by default.
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't really looked into it yet. Should we take care of source files traversal and cargo package as well?

  • if pkg.include_lockfile() {
    result.push(ArchiveFile {
    rel_path: PathBuf::from("Cargo.lock"),
    rel_str: "Cargo.lock".to_string(),
    contents: FileContents::Generated(GeneratedFile::Lockfile),
    });
    }
  • if rel == "Cargo.lock" {
    return pkg.include_lockfile();
    } else if rel == "Cargo.toml" {
    return true;
    }

@epage
Copy link
Contributor Author

epage commented Jul 19, 2023

I believe both of those cases are more about what your users have access to. In theory, users of a lib should not be affected by a Cargo.lock, so leaving it out should still be fine.

src/doc/src/faq.md Outdated Show resolved Hide resolved
src/doc/src/faq.md Outdated Show resolved Hide resolved
Copy link
Member

@Turbo87 Turbo87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I very much support everything in this PR! ❤️

src/doc/src/faq.md Outdated Show resolved Hide resolved
@epage
Copy link
Contributor Author

epage commented Jul 19, 2023

Forgot to add, this is not just a draft until the FCP window closes but the cargo team was also wanting to wait on this until after the next beta branch so we get 12 weeks of feedback before this hits stable.

@bors
Copy link
Contributor

bors commented Jul 24, 2023

☔ The latest upstream changes (presumably #12397) made this pull request unmergeable. Please resolve the merge conflicts.

@Nemo157
Copy link
Member

Nemo157 commented Jul 24, 2023

I believe both of those cases are more about what your users have access to. In theory, users of a lib should not be affected by a Cargo.lock, so leaving it out should still be fine.

There are some usecases that use packaged Cargo.lock when building a library, like docs.rs, we attempt to build with the provided lockfile as we assume that gives the best chance of success, then delete it and try again if it fails (for packages that contain both library and binary crates and so distribute their lockfile). I also semi-regularly download and extract packages source code to inspect issues before going to find a repo, having a lockfile there can be useful.

@epage epage marked this pull request as ready for review August 21, 2023 20:52
@epage
Copy link
Contributor Author

epage commented Aug 21, 2023

Looks like rust-1.73.0 has been branched so I assume we are good to merge.

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Aug 21, 2023
@bors
Copy link
Contributor

bors commented Aug 21, 2023

⌛ Testing commit 54ad4a0 with merge 3bb02f2...

@bors
Copy link
Contributor

bors commented Aug 21, 2023

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing 3bb02f2 to master...

@bors bors merged commit 3bb02f2 into rust-lang:master Aug 21, 2023
about why that is, see
["Why do binaries have `Cargo.lock` in version control, but not libraries?" in the
FAQ](../faq.md#why-do-binaries-have-cargolock-in-version-control-but-not-libraries).
When in doubt, check `Cargo.lock` into git.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just found this. We may use version control system instead.

Suggested change
When in doubt, check `Cargo.lock` into git.
When in doubt, check `Cargo.lock` into the version control system (e.g. Git).

@epage epage deleted the lock branch August 22, 2023 16:45
epage added a commit to epage/cargo that referenced this pull request Aug 22, 2023
bors added a commit that referenced this pull request Aug 22, 2023
docs(guide): Generalize over VCSs

This is a follow up to #12382
Copy link
Contributor

@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for adding a review this late; I hope the comments are useful nonetheless.

- Only uses the resources necessary
- Can configure the frequency to balance CI resources and coverage of dependency versions

An example CI job to verify latest dependencies, using Github Actions:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really minor but this should probably be "GitHub" (with capital "H"). That would also be consistent with the other references in this file.

@@ -1,25 +1,8 @@
## Continuous Integration

### Travis CI
### Getting Started
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this header here really needed? And also, in general maybe the header levels have to be adjusted to be semantically more useful?

Currently the header hierarchy looks like this:

  • Continuous Integration
    • Getting Started
    • GitHub Actions
    • GitLab CI
    • builds.sr.ht
    • Verifying Latest Dependencies

Maybe something like this would be better?

  • Continuous Integration
    • <no sure how to name this>
      • GitHub Actions
      • GitLab CI
      • builds.sr.ht
    • Verifying Latest Dependencies

@epage
Copy link
Contributor Author

epage commented Sep 6, 2023

Fixed these in #12630

bors added a commit that referenced this pull request Sep 6, 2023
docs(guide): Apply feedback on CI

See #12382
Marcono1234 added a commit to Marcono1234/struson that referenced this pull request Sep 23, 2023
Including Cargo.lock is recommended now to get reproducible builds, see
rust-lang/cargo#12382
@ehuss ehuss added this to the 1.74.0 milestone Oct 11, 2023
sonro added a commit to sonro/narrate that referenced this pull request Jul 12, 2024
The convention for rust crates is now to check in Cargo.lock

See rust-lang/cargo#12382
sboukortt added a commit to libjxl/jxl-rs that referenced this pull request Sep 16, 2024
This is the new recommendation, per
rust-lang/cargo#12382. See also the discussion
at: rust-lang/cargo#8728
sboukortt added a commit to libjxl/jxl-rs that referenced this pull request Sep 16, 2024
This is the new recommendation, per
rust-lang/cargo#12382. See also the discussion
at: rust-lang/cargo#8728
sboukortt added a commit to libjxl/jxl-rs that referenced this pull request Sep 16, 2024
This is the new recommendation, per
rust-lang/cargo#12382. See also the discussion
at: rust-lang/cargo#8728
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documenting-cargo-itself Area: Cargo's documentation Command-new S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check Cargo.lock in version control for libraries
10 participants