Skip to content

Commit cfea065

Browse files
authored
Always include Cargo.lock in published crates (#14815)
### What does this PR try to resolve? Originally it was only included for packages that have executables or examples for `cargo install`, however this causes inconsistencies and is kind of unexpected nowadays, e.g. with cdylib crates. Including it always only slightly increases the crate size and allows for all crates to know a set of dependency versions that were working, which can make regression tracking easier. Fixes #13447 ### How should we test and review this PR? The existing tests are covering this change in all kinds of various already, and one test that previously asserted that there is *no* Cargo.lock for library crates was changed to explicitly check for the new behaviour.
2 parents 3ad481e + dd698ff commit cfea065

15 files changed

+188
-135
lines changed

src/cargo/core/package.rs

-5
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,6 @@ impl Package {
186186
}
187187
}
188188

189-
/// Returns if package should include `Cargo.lock`.
190-
pub fn include_lockfile(&self) -> bool {
191-
self.targets().iter().any(|t| t.is_example() || t.is_bin())
192-
}
193-
194189
pub fn serialized(
195190
&self,
196191
unstable_flags: &CliUnstable,

src/cargo/ops/cargo_package.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -459,17 +459,16 @@ fn build_ar_list(
459459
))?;
460460
}
461461

462-
if pkg.include_lockfile() {
463-
let rel_str = "Cargo.lock";
464-
result
465-
.entry(UncasedAscii::new(rel_str))
466-
.or_insert_with(Vec::new)
467-
.push(ArchiveFile {
468-
rel_path: PathBuf::from(rel_str),
469-
rel_str: rel_str.to_string(),
470-
contents: FileContents::Generated(GeneratedFile::Lockfile),
471-
});
472-
}
462+
let rel_str = "Cargo.lock";
463+
result
464+
.entry(UncasedAscii::new(rel_str))
465+
.or_insert_with(Vec::new)
466+
.push(ArchiveFile {
467+
rel_path: PathBuf::from(rel_str),
468+
rel_str: rel_str.to_string(),
469+
contents: FileContents::Generated(GeneratedFile::Lockfile),
470+
});
471+
473472
if let Some(vcs_info) = vcs_info {
474473
let rel_str = VCS_INFO_FILE;
475474
result

src/cargo/sources/path.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,7 @@ fn _list_files(pkg: &Package, gctx: &GlobalContext) -> CargoResult<Vec<PathBuf>>
505505
};
506506

507507
let rel = relative_path.as_os_str();
508-
if rel == "Cargo.lock" {
509-
return pkg.include_lockfile();
510-
} else if rel == "Cargo.toml" {
508+
if rel == "Cargo.lock" || rel == "Cargo.toml" {
511509
return true;
512510
}
513511

tests/testsuite/artifact_dep.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,8 @@ fn publish_artifact_dep() {
22712271
.with_stderr_data(str![[r#"
22722272
[UPDATING] crates.io index
22732273
[PACKAGING] foo v0.1.0 ([ROOT]/foo)
2274-
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
2274+
[UPDATING] crates.io index
2275+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
22752276
[UPLOADING] foo v0.1.0 ([ROOT]/foo)
22762277
[UPLOADED] foo v0.1.0 to registry `crates-io`
22772278
[NOTE] waiting for `foo v0.1.0` to be available at registry `crates-io`.
@@ -2331,7 +2332,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
23312332
}
23322333
"#,
23332334
"foo-0.1.0.crate",
2334-
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
2335+
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs", "Cargo.lock"],
23352336
[(
23362337
"Cargo.toml",
23372338
str![[r##"

tests/testsuite/cargo_features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ fn publish_allowed() {
637637
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
638638
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
639639
[PACKAGING] a v0.0.1 ([ROOT]/foo)
640-
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
640+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
641641
[VERIFYING] a v0.0.1 ([ROOT]/foo)
642642
[COMPILING] a v0.0.1 ([ROOT]/foo/target/package/a-0.0.1)
643643
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

tests/testsuite/credential_process.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn publish() {
7575
[UPDATING] `alternative` index
7676
{"v":1,"registry":{"index-url":"[..]","name":"alternative","headers":[..]},"kind":"get","operation":"read"}
7777
[PACKAGING] foo v0.1.0 ([ROOT]/foo)
78-
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
78+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
7979
[UPLOADING] foo v0.1.0 ([ROOT]/foo)
8080
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"publish","name":"foo","vers":"0.1.0","cksum":"[..]"}
8181
[UPLOADED] foo v0.1.0 to registry `alternative`
@@ -528,7 +528,7 @@ fn token_caching() {
528528
let output = r#"[UPDATING] `alternative` index
529529
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"read"}
530530
[PACKAGING] foo v0.1.0 ([ROOT]/foo)
531-
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
531+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
532532
[UPLOADING] foo v0.1.0 ([ROOT]/foo)
533533
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"publish","name":"foo","vers":"0.1.0","cksum":"[..]"}
534534
[UPLOADED] foo v0.1.0 to registry `alternative`
@@ -547,7 +547,7 @@ You may press ctrl-c [..]
547547
let output_non_independent = r#"[UPDATING] `alternative` index
548548
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"read"}
549549
[PACKAGING] foo v0.1.1 ([ROOT]/foo)
550-
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
550+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
551551
[UPLOADING] foo v0.1.1 ([ROOT]/foo)
552552
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"publish","name":"foo","vers":"0.1.1","cksum":"[..]"}
553553
[UPLOADED] foo v0.1.1 to registry `alternative`

tests/testsuite/features2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,7 @@ path = "src/lib.rs"
18261826
validate_crate_contents(
18271827
f,
18281828
"a-0.1.0.crate",
1829-
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
1829+
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs", "Cargo.lock"],
18301830
[("Cargo.toml", rewritten_toml)],
18311831
);
18321832
}

tests/testsuite/features_namespaced.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,8 @@ fn publish_no_implicit() {
920920
.with_stderr_data(str![[r#"
921921
[UPDATING] crates.io index
922922
[PACKAGING] foo v0.1.0 ([ROOT]/foo)
923-
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
923+
[UPDATING] crates.io index
924+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
924925
[UPLOADING] foo v0.1.0 ([ROOT]/foo)
925926
[UPLOADED] foo v0.1.0 to registry `crates-io`
926927
[NOTE] waiting for `foo v0.1.0` to be available at registry `crates-io`.
@@ -975,7 +976,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
975976
}
976977
"#,
977978
"foo-0.1.0.crate",
978-
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
979+
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs", "Cargo.lock"],
979980
[(
980981
"Cargo.toml",
981982
str![[r##"
@@ -1060,9 +1061,9 @@ fn publish() {
10601061
.with_stderr_data(str![[r#"
10611062
[UPDATING] crates.io index
10621063
[PACKAGING] foo v0.1.0 ([ROOT]/foo)
1063-
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
1064-
[VERIFYING] foo v0.1.0 ([ROOT]/foo)
10651064
[UPDATING] crates.io index
1065+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
1066+
[VERIFYING] foo v0.1.0 ([ROOT]/foo)
10661067
[COMPILING] foo v0.1.0 ([ROOT]/foo/target/package/foo-0.1.0)
10671068
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
10681069
[UPLOADING] foo v0.1.0 ([ROOT]/foo)
@@ -1112,7 +1113,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
11121113
}
11131114
"#,
11141115
"foo-0.1.0.crate",
1115-
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
1116+
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs", "Cargo.lock"],
11161117
[(
11171118
"Cargo.toml",
11181119
str![[r##"

tests/testsuite/git.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2737,6 +2737,7 @@ fn include_overrides_gitignore() {
27372737
p.cargo("package --list --allow-dirty")
27382738
.with_stdout_data(str![[r#"
27392739
.cargo_vcs_info.json
2740+
Cargo.lock
27402741
Cargo.toml
27412742
Cargo.toml.orig
27422743
ignored.txt
@@ -4048,6 +4049,7 @@ fn git_worktree_with_original_repo_renamed() {
40484049
.cwd(&new)
40494050
.with_stdout_data(str![[r#"
40504051
.cargo_vcs_info.json
4052+
Cargo.lock
40514053
Cargo.toml
40524054
Cargo.toml.orig
40534055
README.md
@@ -4116,6 +4118,7 @@ fn git_worktree_with_bare_original_repo() {
41164118
.cwd(wt.path())
41174119
.with_stdout_data(str![[r#"
41184120
.cargo_vcs_info.json
4121+
Cargo.lock
41194122
Cargo.toml
41204123
Cargo.toml.orig
41214124
README.md

0 commit comments

Comments
 (0)