Skip to content

Commit 1878e85

Browse files
committed
feat(config): Stabilize resolver.lockfile-path
1 parent 019a9b0 commit 1878e85

File tree

6 files changed

+86
-142
lines changed

6 files changed

+86
-142
lines changed

src/cargo/core/features.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,6 @@ unstable_cli_options!(
887887
gitoxide: Option<GitoxideFeatures> = ("Use gitoxide for the given git interactions, or all of them if no argument is given"),
888888
host_config: bool = ("Enable the `[host]` section in the .cargo/config.toml file"),
889889
json_target_spec: bool = ("Enable `.json` target spec files"),
890-
lockfile_path: bool = ("Enable the `resolver.lockfile-path` config option"),
891890
minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum"),
892891
msrv_policy: bool = ("Enable rust-version aware policy within cargo"),
893892
mtime_on_use: bool = ("Configure Cargo to update the mtime of used files"),
@@ -1001,6 +1000,8 @@ const STABILIZED_BUILD_DIR: &str = "build.build-dir is now always enabled.";
10011000

10021001
const STABILIZED_CONFIG_INCLUDE: &str = "The `include` config key is now always available";
10031002

1003+
const STABILIZED_LOCKFILE_PATH: &str = "The `lockfile-path` config key is now always available";
1004+
10041005
fn deserialize_comma_separated_list<'de, D>(
10051006
deserializer: D,
10061007
) -> Result<Option<Vec<String>>, D::Error>
@@ -1389,6 +1390,7 @@ impl CliUnstable {
13891390
"package-workspace" => stabilized_warn(k, "1.89", STABILIZED_PACKAGE_WORKSPACE),
13901391
"build-dir" => stabilized_warn(k, "1.91", STABILIZED_BUILD_DIR),
13911392
"config-include" => stabilized_warn(k, "1.93", STABILIZED_CONFIG_INCLUDE),
1393+
"lockfile-path" => stabilized_warn(k, "1.95", STABILIZED_LOCKFILE_PATH),
13921394

13931395
// Unstable features
13941396
// Sorted alphabetically:
@@ -1427,7 +1429,6 @@ impl CliUnstable {
14271429
}
14281430
"host-config" => self.host_config = parse_empty(k, v)?,
14291431
"json-target-spec" => self.json_target_spec = parse_empty(k, v)?,
1430-
"lockfile-path" => self.lockfile_path = parse_empty(k, v)?,
14311432
"next-lockfile-bump" => self.next_lockfile_bump = parse_empty(k, v)?,
14321433
"minimal-versions" => self.minimal_versions = parse_empty(k, v)?,
14331434
"msrv-policy" => self.msrv_policy = parse_empty(k, v)?,

src/cargo/core/workspace.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,9 @@ impl<'gctx> Workspace<'gctx> {
368368
};
369369

370370
if let Some(lockfile_path) = config.lockfile_path {
371-
if self.gctx().cli_unstable().lockfile_path {
372-
// Reserve the ability to add templates in the future.
373-
let replacements: [(&str, &str); 0] = [];
374-
let path = lockfile_path
371+
// Reserve the ability to add templates in the future.
372+
let replacements: [(&str, &str); 0] = [];
373+
let path = lockfile_path
375374
.resolve_templated_path(self.gctx(), replacements)
376375
.map_err(|e| match e {
377376
context::ResolveTemplateError::UnexpectedVariable {
@@ -393,21 +392,16 @@ impl<'gctx> Workspace<'gctx> {
393392
)
394393
}
395394
})?;
396-
if !path.ends_with(LOCKFILE_NAME) {
397-
bail!("the `resolver.lockfile-path` must be a path to a {LOCKFILE_NAME} file");
398-
}
399-
if path.is_dir() {
400-
bail!(
401-
"`resolver.lockfile-path` `{}` is a directory but expected a file",
402-
path.display()
403-
);
404-
}
405-
self.requested_lockfile_path = Some(path);
406-
} else {
407-
self.gctx().shell().warn(
408-
"ignoring `resolver.lockfile-path`, pass `-Zlockfile-path` to enable it",
409-
)?;
395+
if !path.ends_with(LOCKFILE_NAME) {
396+
bail!("the `resolver.lockfile-path` must be a path to a {LOCKFILE_NAME} file");
397+
}
398+
if path.is_dir() {
399+
bail!(
400+
"`resolver.lockfile-path` `{}` is a directory but expected a file",
401+
path.display()
402+
);
410403
}
404+
self.requested_lockfile_path = Some(path);
411405
}
412406

413407
Ok(())

src/doc/src/reference/config.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ rpath = false # Sets the rpath linking option.
149149
# Same keys for a normal profile (minus `panic`, `lto`, and `rpath`).
150150

151151
[resolver]
152+
lockfile-path = "" # Overrides the path used for
152153
incompatible-rust-versions = "allow" # Specifies how resolver reacts to these
153154

154155
[registries.<name>] # registries other than crates.io
@@ -1098,7 +1099,19 @@ See [strip](profiles.md#strip).
10981099

10991100
### `[resolver]`
11001101

1101-
The `[resolver]` table overrides [dependency resolution behavior](resolver.md) for local development (e.g. excludes `cargo install`).
1102+
The `[resolver]` table overrides [dependency resolution behavior](resolver.md).
1103+
1104+
#### `resolver.lockfile-path`
1105+
* Type: string (path)
1106+
* Default: `<workspace_root>/Cargo.lock`
1107+
* Environment: `CARGO_RESOLVER_LOCKFILE_PATH`
1108+
1109+
Specifies the path to the lockfile to use when resolving dependencies.
1110+
This option is useful when working with read-only source directories.
1111+
1112+
The path must end with `Cargo.lock`.
1113+
1114+
> **MSRV:** Requires 1.95+
11021115
11031116
#### `resolver.incompatible-rust-versions`
11041117
* Type: string
@@ -1121,6 +1134,8 @@ See the [resolver](resolver.md#rust-version) chapter for more details.
11211134
> - `allow` is supported on any version
11221135
> - `fallback` is respected as of 1.84
11231136
1137+
> **Note:** this is for local development (e.g. excludes `cargo install`)
1138+
11241139
### `[registries]`
11251140

11261141
The `[registries]` table is used for specifying additional [registries]. It

src/doc/src/reference/unstable.md

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ Each new feature described below should explain how to use it.
130130
* Other
131131
* [gitoxide](#gitoxide) --- Use `gitoxide` instead of `git2` for a set of operations.
132132
* [script](#script) --- Enable support for single-file `.rs` packages.
133-
* [lockfile-path](#lockfile-path) --- Allows to specify a path to lockfile other than the default path `<workspace_root>/Cargo.lock`.
134133
* [native-completions](#native-completions) --- Move cargo shell completions to native completions.
135134
* [warnings](#warnings) --- controls warning behavior; options for allowing or denying warnings.
136135
* [Package message format](#package-message-format) --- Message format for `cargo package`.
@@ -1765,39 +1764,6 @@ will prefer the value in the configuration. The allows Cargo to add new built-in
17651764
path bases without compatibility issues (as existing uses will shadow the
17661765
built-in name).
17671766

1768-
## lockfile-path
1769-
1770-
* Original Issue: [#5707](https://github.com/rust-lang/cargo/issues/5707)
1771-
* Tracking Issue: [#14421](https://github.com/rust-lang/cargo/issues/14421)
1772-
1773-
The `-Zlockfile-path` flag enables the `resolver.lockfile-path` configuration option,
1774-
which allows you to specify the path of the lockfile `Cargo.lock`.
1775-
1776-
By default, lockfile is written into `<workspace_root>/Cargo.lock`.
1777-
However, when sources are stored in read-only directory,
1778-
most of the cargo commands would fail when trying to write a lockfile.
1779-
This configuration makes it easier to work with readonly sources.
1780-
1781-
Note, that currently path must end with `Cargo.lock`.
1782-
If you want to use this feature in multiple projects,
1783-
lockfiles should be stored in different directories.
1784-
1785-
### Documentation updates
1786-
1787-
*as a new `resolver.lockfile-path` entry in config.md*
1788-
1789-
#### `resolver.lockfile-path`
1790-
1791-
* Type: string (path)
1792-
* Default: `<workspace_root>/Cargo.lock`
1793-
* Environment: `CARGO_RESOLVER_LOCKFILE_PATH`
1794-
1795-
Specifies the path to the lockfile.
1796-
By default, the lockfile is written to `<workspace_root>/Cargo.lock`.
1797-
This option is useful when working with read-only source directories.
1798-
1799-
The path must end with `Cargo.lock`.
1800-
18011767
## native-completions
18021768
* Original Issue: [#6645](https://github.com/rust-lang/cargo/issues/6645)
18031769
* Tracking Issue: [#14520](https://github.com/rust-lang/cargo/issues/14520)
@@ -2348,3 +2314,7 @@ See the [`include` config documentation](config.md#include) for more.
23482314
## pubtime
23492315

23502316
The `pubtime` index field has been stabilized in Rust 1.94.0.
2317+
2318+
## lockfile-path
2319+
2320+
Support for `resolver.lockfile-path` config field has been stabilized in Rust 1.95.0.

tests/testsuite/cargo/z_help/stdout.term.svg

Lines changed: 30 additions & 32 deletions
Loading

0 commit comments

Comments
 (0)