Skip to content

Commit 807429e

Browse files
committed
Auto merge of #7026 - ehuss:publish-lockfile-stabilize, r=alexcrichton
Stabilize publish-lockfile. This stabilizes the publish-lockfile feature. Specifically: - Makes `Cargo.lock` included by default for packages with executables. - Deprecates the `publish-lockfile` manifest key. It is no longer used. Additional notes: - Fixed issue where if a `Cargo.lock` file didn't exist, `cargo package` would fail the VCS dirty check. - Changed it so that `cargo publish` or `cargo package` will now show manifest warnings. I believe this was an oversight. Closes #5654
2 parents 7be4ca2 + 34307c6 commit 807429e

File tree

20 files changed

+270
-218
lines changed

20 files changed

+270
-218
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ pub fn cli() -> App {
6868
)
6969
.after_help(
7070
"\
71-
This command manages Cargo's local set of installed binary crates. Only packages
72-
which have [[bin]] targets can be installed, and all binaries are installed into
73-
the installation root's `bin` folder. The installation root is determined, in
74-
order of precedence, by `--root`, `$CARGO_INSTALL_ROOT`, the `install.root`
75-
configuration key, and finally the home directory (which is either
76-
`$CARGO_HOME` if set or `$HOME/.cargo` by default).
71+
This command manages Cargo's local set of installed binary crates. Only
72+
packages which have executable [[bin]] or [[example]] targets can be
73+
installed, and all executables are installed into the installation root's
74+
`bin` folder. The installation root is determined, in order of precedence, by
75+
`--root`, `$CARGO_INSTALL_ROOT`, the `install.root` configuration key, and
76+
finally the home directory (which is either `$CARGO_HOME` if set or
77+
`$HOME/.cargo` by default).
7778
7879
There are multiple sources from which a crate can be installed. The default
79-
location is crates.io but the `--git`, `--path`, and `registry` flags can
80+
location is crates.io but the `--git`, `--path`, and `--registry` flags can
8081
change this source. If the source contains more than one package (such as
8182
crates.io or a git repository with multiple crates) the `<crate>` argument is
8283
required to indicate which crate should be installed.

src/cargo/core/features.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ features! {
186186
[stable] rename_dependency: bool,
187187

188188
// Whether a lock file is published with this crate
189+
// This is deprecated, and will likely be removed in a future version.
189190
[unstable] publish_lockfile: bool,
190191

191192
// Overriding profiles for dependencies.

src/cargo/core/manifest.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,6 @@ impl Manifest {
478478
pub fn publish(&self) -> &Option<Vec<String>> {
479479
&self.publish
480480
}
481-
pub fn publish_lockfile(&self) -> bool {
482-
self.publish_lockfile
483-
}
484481
pub fn replace(&self) -> &[(PackageIdSpec, Dependency)] {
485482
&self.replace
486483
}

src/cargo/core/package.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ impl Package {
240240

241241
/// Returns if package should include `Cargo.lock`.
242242
pub fn include_lockfile(&self) -> bool {
243-
self.manifest().publish_lockfile()
244-
&& self.targets().iter().any(|t| t.is_example() || t.is_bin())
243+
self.targets().iter().any(|t| t.is_example() || t.is_bin())
245244
}
246245
}
247246

src/cargo/ops/cargo_package.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ pub struct PackageOpts<'cfg> {
4242
static VCS_INFO_FILE: &'static str = ".cargo_vcs_info.json";
4343

4444
pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Option<FileLock>> {
45-
// Make sure the Cargo.lock is up-to-date and valid.
46-
ops::resolve_ws(ws)?;
45+
if ws.root().join("Cargo.lock").exists() {
46+
// Make sure the Cargo.lock is up-to-date and valid.
47+
ops::resolve_ws(ws)?;
48+
// If Cargo.lock does not exist, it will be generated by `build_lock`
49+
// below, and will be validated during the verification step.
50+
}
4751
let pkg = ws.current()?;
4852
let config = ws.config();
4953

@@ -615,7 +619,7 @@ fn run_verify(ws: &Workspace<'_>, tar: &FileLock, opts: &PackageOpts<'_>) -> Car
615619
};
616620

617621
let exec: Arc<dyn Executor> = Arc::new(DefaultExecutor);
618-
ops::compile_ws(
622+
ops::compile_with_exec(
619623
&ws,
620624
&ops::CompileOptions {
621625
config,

src/cargo/util/toml/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,11 @@ impl TomlManifest {
10341034
let publish_lockfile = match project.publish_lockfile {
10351035
Some(b) => {
10361036
features.require(Feature::publish_lockfile())?;
1037+
warnings.push(
1038+
"The `publish-lockfile` feature is deprecated and currently \
1039+
has no effect. It may be removed in a future version."
1040+
.to_string(),
1041+
);
10371042
b
10381043
}
10391044
None => features.is_enabled(Feature::publish_lockfile()),

src/doc/man/cargo-install.adoc

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ cargo-install - Build and install a Rust binary
1717

1818
== DESCRIPTION
1919

20-
This command manages Cargo's local set of installed binary crates. Only packages
21-
which have `\[[bin]]` targets can be installed, and all binaries are installed into
22-
the installation root's `bin` folder.
20+
This command manages Cargo's local set of installed binary crates. Only
21+
packages which have executable `\[[bin]]` or `\[[example]]` targets can be
22+
installed, and all executables are installed into the installation root's
23+
`bin` folder.
2324

2425
include::description-install-root.adoc[]
2526

2627
There are multiple sources from which a crate can be installed. The default
27-
location is crates.io but the `--git`, `--path`, and `registry` flags can
28+
location is crates.io but the `--git`, `--path`, and `--registry` flags can
2829
change this source. If the source contains more than one package (such as
2930
crates.io or a git repository with multiple crates) the _CRATE_ argument is
3031
required to indicate which crate should be installed.
@@ -42,6 +43,20 @@ specified by setting the `CARGO_TARGET_DIR` environment variable to a relative
4243
path. In particular, this can be useful for caching build artifacts on
4344
continuous integration systems.
4445

46+
By default, the `Cargo.lock` file that is included with the package will be
47+
ignored. This means that Cargo will recompute which versions of dependencies
48+
to use, possibly using newer versions that have been released since the
49+
package was published. The `--locked` flag can be used to force Cargo to use
50+
the packaged `Cargo.lock` file if it is available. This may be useful for
51+
ensuring reproducible builds, to use the exact same set of dependencies that
52+
were available when the package was published. It may also be useful if a
53+
newer version of a dependency is published that no longer builds on your
54+
system, or has other problems. The downside to using `--locked` is that you
55+
will not receive any fixes or updates to any dependency. Note that Cargo did
56+
not start publishing `Cargo.lock` files until version 1.37, which means
57+
packages published with prior versions will not have a `Cargo.lock` file
58+
available.
59+
4560
== OPTIONS
4661

4762
=== Install Options

src/doc/man/cargo-package.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ steps:
2525
- The original `Cargo.toml` file is rewritten and normalized.
2626
- `[patch]`, `[replace]`, and `[workspace]` sections are removed from the
2727
manifest.
28+
- `Cargo.lock` is automatically included if the package contains an
29+
executable binary or example target. man:cargo-install[1] will use the
30+
packaged lock file if the `--locked` flag is used.
2831
- A `.cargo_vcs_info.json` file is included that contains information
2932
about the current VCS checkout hash if available (not included with
3033
`--allow-dirty`).

src/doc/man/generated/cargo-install.html

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ <h2 id="cargo_install_synopsis">SYNOPSIS</h2>
1717
<h2 id="cargo_install_description">DESCRIPTION</h2>
1818
<div class="sectionbody">
1919
<div class="paragraph">
20-
<p>This command manages Cargo&#8217;s local set of installed binary crates. Only packages
21-
which have <code>[[bin]]</code> targets can be installed, and all binaries are installed into
22-
the installation root&#8217;s <code>bin</code> folder.</p>
20+
<p>This command manages Cargo&#8217;s local set of installed binary crates. Only
21+
packages which have executable <code>[[bin]]</code> or <code>[[example]]</code> targets can be
22+
installed, and all executables are installed into the installation root&#8217;s
23+
<code>bin</code> folder.</p>
2324
</div>
2425
<div class="paragraph">
2526
<p>The installation root is determined, in order of precedence:</p>
@@ -45,7 +46,7 @@ <h2 id="cargo_install_description">DESCRIPTION</h2>
4546
</div>
4647
<div class="paragraph">
4748
<p>There are multiple sources from which a crate can be installed. The default
48-
location is crates.io but the <code>--git</code>, <code>--path</code>, and <code>registry</code> flags can
49+
location is crates.io but the <code>--git</code>, <code>--path</code>, and <code>--registry</code> flags can
4950
change this source. If the source contains more than one package (such as
5051
crates.io or a git repository with multiple crates) the <em>CRATE</em> argument is
5152
required to indicate which crate should be installed.</p>
@@ -65,6 +66,21 @@ <h2 id="cargo_install_description">DESCRIPTION</h2>
6566
path. In particular, this can be useful for caching build artifacts on
6667
continuous integration systems.</p>
6768
</div>
69+
<div class="paragraph">
70+
<p>By default, the <code>Cargo.lock</code> file that is included with the package will be
71+
ignored. This means that Cargo will recompute which versions of dependencies
72+
to use, possibly using newer versions that have been released since the
73+
package was published. The <code>--locked</code> flag can be used to force Cargo to use
74+
the packaged <code>Cargo.lock</code> file if it is available. This may be useful for
75+
ensuring reproducible builds, to use the exact same set of dependencies that
76+
were available when the package was published. It may also be useful if a
77+
newer version of a dependency is published that no longer builds on your
78+
system, or has other problems. The downside to using <code>--locked</code> is that you
79+
will not receive any fixes or updates to any dependency. Note that Cargo did
80+
not start publishing <code>Cargo.lock</code> files until version 1.37, which means
81+
packages published with prior versions will not have a <code>Cargo.lock</code> file
82+
available.</p>
83+
</div>
6884
</div>
6985
</div>
7086
<div class="sect1">

src/doc/man/generated/cargo-package.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ <h2 id="cargo_package_description">DESCRIPTION</h2>
4444
manifest.</p>
4545
</li>
4646
<li>
47+
<p><code>Cargo.lock</code> is automatically included if the package contains an
48+
executable binary or example target. <a href="commands/cargo-install.html">cargo-install(1)</a> will use the
49+
packaged lock file if the <code>--locked</code> flag is used.</p>
50+
</li>
51+
<li>
4752
<p>A <code>.cargo_vcs_info.json</code> file is included that contains information
4853
about the current VCS checkout hash if available (not included with
4954
<code>--allow-dirty</code>).</p>

0 commit comments

Comments
 (0)