diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index d71d20619ef..e72f49adfa9 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -887,7 +887,6 @@ unstable_cli_options!( gitoxide: Option = ("Use gitoxide for the given git interactions, or all of them if no argument is given"), host_config: bool = ("Enable the `[host]` section in the .cargo/config.toml file"), json_target_spec: bool = ("Enable `.json` target spec files"), - lockfile_path: bool = ("Enable the `resolver.lockfile-path` config option"), minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum"), msrv_policy: bool = ("Enable rust-version aware policy within cargo"), 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."; const STABILIZED_CONFIG_INCLUDE: &str = "The `include` config key is now always available"; +const STABILIZED_LOCKFILE_PATH: &str = "The `lockfile-path` config key is now always available"; + fn deserialize_comma_separated_list<'de, D>( deserializer: D, ) -> Result>, D::Error> @@ -1389,6 +1390,7 @@ impl CliUnstable { "package-workspace" => stabilized_warn(k, "1.89", STABILIZED_PACKAGE_WORKSPACE), "build-dir" => stabilized_warn(k, "1.91", STABILIZED_BUILD_DIR), "config-include" => stabilized_warn(k, "1.93", STABILIZED_CONFIG_INCLUDE), + "lockfile-path" => stabilized_warn(k, "1.95", STABILIZED_LOCKFILE_PATH), // Unstable features // Sorted alphabetically: @@ -1427,7 +1429,6 @@ impl CliUnstable { } "host-config" => self.host_config = parse_empty(k, v)?, "json-target-spec" => self.json_target_spec = parse_empty(k, v)?, - "lockfile-path" => self.lockfile_path = parse_empty(k, v)?, "next-lockfile-bump" => self.next_lockfile_bump = parse_empty(k, v)?, "minimal-versions" => self.minimal_versions = parse_empty(k, v)?, "msrv-policy" => self.msrv_policy = parse_empty(k, v)?, diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index ae8a6b06968..02b7ce63645 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -368,10 +368,9 @@ impl<'gctx> Workspace<'gctx> { }; if let Some(lockfile_path) = config.lockfile_path { - if self.gctx().cli_unstable().lockfile_path { - // Reserve the ability to add templates in the future. - let replacements: [(&str, &str); 0] = []; - let path = lockfile_path + // Reserve the ability to add templates in the future. + let replacements: [(&str, &str); 0] = []; + let path = lockfile_path .resolve_templated_path(self.gctx(), replacements) .map_err(|e| match e { context::ResolveTemplateError::UnexpectedVariable { @@ -393,21 +392,16 @@ impl<'gctx> Workspace<'gctx> { ) } })?; - if !path.ends_with(LOCKFILE_NAME) { - bail!("the `resolver.lockfile-path` must be a path to a {LOCKFILE_NAME} file"); - } - if path.is_dir() { - bail!( - "`resolver.lockfile-path` `{}` is a directory but expected a file", - path.display() - ); - } - self.requested_lockfile_path = Some(path); - } else { - self.gctx().shell().warn( - "ignoring `resolver.lockfile-path`, pass `-Zlockfile-path` to enable it", - )?; + if !path.ends_with(LOCKFILE_NAME) { + bail!("the `resolver.lockfile-path` must be a path to a {LOCKFILE_NAME} file"); + } + if path.is_dir() { + bail!( + "`resolver.lockfile-path` `{}` is a directory but expected a file", + path.display() + ); } + self.requested_lockfile_path = Some(path); } Ok(()) diff --git a/src/doc/src/reference/config.md b/src/doc/src/reference/config.md index 716d13beef7..1b6c1dfabe6 100644 --- a/src/doc/src/reference/config.md +++ b/src/doc/src/reference/config.md @@ -149,6 +149,7 @@ rpath = false # Sets the rpath linking option. # Same keys for a normal profile (minus `panic`, `lto`, and `rpath`). [resolver] +lockfile-path = "…" # Overrides the path used for incompatible-rust-versions = "allow" # Specifies how resolver reacts to these [registries.] # registries other than crates.io @@ -1098,7 +1099,19 @@ See [strip](profiles.md#strip). ### `[resolver]` -The `[resolver]` table overrides [dependency resolution behavior](resolver.md) for local development (e.g. excludes `cargo install`). +The `[resolver]` table overrides [dependency resolution behavior](resolver.md). + +#### `resolver.lockfile-path` +* Type: string (path) +* Default: `/Cargo.lock` +* Environment: `CARGO_RESOLVER_LOCKFILE_PATH` + +Specifies the path to the lockfile to use when resolving dependencies. +This option is useful when working with read-only source directories. + +The path must end with `Cargo.lock`. + +> **MSRV:** Requires 1.95+ #### `resolver.incompatible-rust-versions` * Type: string @@ -1121,6 +1134,8 @@ See the [resolver](resolver.md#rust-version) chapter for more details. > - `allow` is supported on any version > - `fallback` is respected as of 1.84 +> **Note:** this is for local development (e.g. excludes `cargo install`) + ### `[registries]` The `[registries]` table is used for specifying additional [registries]. It diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index b3f03a17c3a..d56f1404d81 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -130,7 +130,6 @@ Each new feature described below should explain how to use it. * Other * [gitoxide](#gitoxide) --- Use `gitoxide` instead of `git2` for a set of operations. * [script](#script) --- Enable support for single-file `.rs` packages. - * [lockfile-path](#lockfile-path) --- Allows to specify a path to lockfile other than the default path `/Cargo.lock`. * [native-completions](#native-completions) --- Move cargo shell completions to native completions. * [warnings](#warnings) --- controls warning behavior; options for allowing or denying warnings. * [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 path bases without compatibility issues (as existing uses will shadow the built-in name). -## lockfile-path - -* Original Issue: [#5707](https://github.com/rust-lang/cargo/issues/5707) -* Tracking Issue: [#14421](https://github.com/rust-lang/cargo/issues/14421) - -The `-Zlockfile-path` flag enables the `resolver.lockfile-path` configuration option, -which allows you to specify the path of the lockfile `Cargo.lock`. - -By default, lockfile is written into `/Cargo.lock`. -However, when sources are stored in read-only directory, -most of the cargo commands would fail when trying to write a lockfile. -This configuration makes it easier to work with readonly sources. - -Note, that currently path must end with `Cargo.lock`. -If you want to use this feature in multiple projects, -lockfiles should be stored in different directories. - -### Documentation updates - -*as a new `resolver.lockfile-path` entry in config.md* - -#### `resolver.lockfile-path` - -* Type: string (path) -* Default: `/Cargo.lock` -* Environment: `CARGO_RESOLVER_LOCKFILE_PATH` - -Specifies the path to the lockfile. -By default, the lockfile is written to `/Cargo.lock`. -This option is useful when working with read-only source directories. - -The path must end with `Cargo.lock`. - ## native-completions * Original Issue: [#6645](https://github.com/rust-lang/cargo/issues/6645) * 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. ## pubtime The `pubtime` index field has been stabilized in Rust 1.94.0. + +## lockfile-path + +Support for `resolver.lockfile-path` config field has been stabilized in Rust 1.95.0. diff --git a/tests/testsuite/cargo/z_help/stdout.term.svg b/tests/testsuite/cargo/z_help/stdout.term.svg index e4f2d6ba0f4..22705655ed8 100644 --- a/tests/testsuite/cargo/z_help/stdout.term.svg +++ b/tests/testsuite/cargo/z_help/stdout.term.svg @@ -1,4 +1,4 @@ - +