Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,6 @@ unstable_cli_options!(
gitoxide: Option<GitoxideFeatures> = ("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"),
Expand Down Expand Up @@ -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<Option<Vec<String>>, D::Error>
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)?,
Expand Down
30 changes: 12 additions & 18 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(())
Expand Down
17 changes: 16 additions & 1 deletion src/doc/src/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<name>] # registries other than crates.io
Expand Down Expand Up @@ -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: `<workspace_root>/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
Expand All @@ -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
Expand Down
38 changes: 4 additions & 34 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<workspace_root>/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`.
Expand Down Expand Up @@ -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 `<workspace_root>/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: `<workspace_root>/Cargo.lock`
* Environment: `CARGO_RESOLVER_LOCKFILE_PATH`

Specifies the path to the lockfile.
By default, the lockfile is written to `<workspace_root>/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)
Expand Down Expand Up @@ -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.
62 changes: 30 additions & 32 deletions tests/testsuite/cargo/z_help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading