Skip to content

Commit df2945f

Browse files
committed
feat(config): Stabilize resolver.lockfile-path
1 parent 72d5b50 commit df2945f

File tree

6 files changed

+82
-143
lines changed

6 files changed

+82
-143
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.97", 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
@@ -369,10 +369,9 @@ impl<'gctx> Workspace<'gctx> {
369369
};
370370

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

414408
Ok(())

src/doc/src/reference/config.md

Lines changed: 13 additions & 0 deletions
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
@@ -1101,6 +1102,18 @@ See [strip](profiles.md#strip).
11011102

11021103
The `[resolver]` table overrides [dependency resolution behavior](resolver.md) for local development (e.g. excludes `cargo install`).
11031104

1105+
#### `resolver.lockfile-path`
1106+
* Type: string (path)
1107+
* Default: `<workspace_root>/Cargo.lock`
1108+
* Environment: `CARGO_RESOLVER_LOCKFILE_PATH`
1109+
1110+
Specifies the path to the lockfile to use when resolving dependencies.
1111+
This option is useful when working with read-only source directories.
1112+
1113+
The path must end with `Cargo.lock`.
1114+
1115+
> **MSRV:** Requires 1.97+
1116+
11041117
#### `resolver.incompatible-rust-versions`
11051118
* Type: string
11061119
* Default: See [`resolver`](resolver.md#resolver-versions) docs

src/doc/src/reference/unstable.md

Lines changed: 4 additions & 38 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`.
@@ -1766,43 +1765,6 @@ will prefer the value in the configuration. The allows Cargo to add new built-in
17661765
path bases without compatibility issues (as existing uses will shadow the
17671766
built-in name).
17681767

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

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

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

Lines changed: 30 additions & 32 deletions
Loading

0 commit comments

Comments
 (0)