Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ unstable_cli_options!(
#[serde(deserialize_with = "deserialize_gitoxide_features")]
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"),
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 @@ -1408,6 +1409,7 @@ impl CliUnstable {
)?
}
"host-config" => self.host_config = 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
46 changes: 46 additions & 0 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ use crate::lints::rules::blanket_hint_mostly_unused;
use crate::lints::rules::check_im_a_teapot;
use crate::lints::rules::implicit_minimum_version_req;
use crate::ops;
use crate::ops::lockfile::LOCKFILE_NAME;
use crate::sources::{CRATES_IO_INDEX, CRATES_IO_REGISTRY, PathSource, SourceConfigMap};
use crate::util::context;
use crate::util::context::{FeatureUnification, Value};
use crate::util::edit_distance;
use crate::util::errors::{CargoResult, ManifestError};
Expand Down Expand Up @@ -354,6 +356,49 @@ impl<'gctx> Workspace<'gctx> {
.warn("ignoring `resolver.feature-unification` without `-Zfeature-unification`")?;
};

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
.resolve_templated_path(self.gctx(), replacements)
.map_err(|e| match e {
context::ResolveTemplateError::UnexpectedVariable {
variable,
raw_template,
} => {
anyhow!(
"unexpected variable `{variable}` in resolver.lockfile-path `{raw_template}`"
)
}
context::ResolveTemplateError::UnexpectedBracket { bracket_type, raw_template } => {
let (btype, literal) = match bracket_type {
context::BracketType::Opening => ("opening", "{"),
context::BracketType::Closing => ("closing", "}"),
};

anyhow!(
"unexpected {btype} bracket `{literal}` in build.build-dir path `{raw_template}`"
)
}
})?;
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",
)?;
}
}

Ok(())
}

Expand Down Expand Up @@ -690,6 +735,7 @@ impl<'gctx> Workspace<'gctx> {
}
}

// NOTE: may be removed once the deprecated `--lockfile-path` CLI flag is removed
pub fn set_requested_lockfile_path(&mut self, path: Option<PathBuf>) {
self.requested_lockfile_path = path;
}
Expand Down
15 changes: 14 additions & 1 deletion src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,15 @@ pub trait ArgMatchesExt {
if gctx.cli_unstable().avoid_dev_deps {
ws.set_require_optional_deps(false);
}
ws.set_requested_lockfile_path(lockfile_path);
if lockfile_path.is_some() {
if ws.requested_lockfile_path().is_some() {
gctx.shell().warn(
"`--lockfile-path` is ignored because `resolver.lockfile-path` is set in config",
)?;
} else {
ws.set_requested_lockfile_path(lockfile_path);
}
}
Ok(ws)
}

Expand Down Expand Up @@ -1123,6 +1131,11 @@ pub fn lockfile_path(
)
}

gctx.shell().warn(
"the `--lockfile-path` flag is deprecated and will be removed in a future release, \
use `resolver.lockfile-path` config instead",
)?;

return Ok(Some(path));
}

Expand Down
5 changes: 4 additions & 1 deletion src/cargo/util/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ pub use config_value::ConfigValue;
use config_value::is_nonmergeable_list;

mod path;
pub use path::{ConfigRelativePath, PathAndArgs};
pub use path::BracketType;
pub use path::ConfigRelativePath;
pub use path::PathAndArgs;
pub use path::ResolveTemplateError;

mod target;
pub use target::{TargetCfgConfig, TargetConfig};
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/util/context/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,14 @@ impl BuildTargetConfig {
/// [resolver]
/// incompatible-rust-versions = "fallback"
/// feature-unification = "workspace"
/// lockfile-path = "my/Cargo.lock"
/// ```
#[derive(Debug, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct CargoResolverConfig {
pub incompatible_rust_versions: Option<IncompatibleRustVersions>,
pub feature_unification: Option<FeatureUnification>,
pub lockfile_path: Option<ConfigRelativePath>,
}

#[derive(Debug, Deserialize, PartialEq, Eq)]
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-add.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ Add dependencies to only the specified package.

{{> options-locked }}

{{> options-lockfile-path }}
{{/options}}

{{> section-options-common }}
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ passing `--no-capture` to the benchmark binaries:

{{> options-locked }}

{{> options-lockfile-path }}
{{/options}}

{{> section-options-common }}
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ See <https://github.com/rust-lang/cargo/issues/6790> for more information.

{{> options-locked }}

{{> options-lockfile-path }}
{{/options}}

{{> section-options-common }}
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ they have `required-features` that are missing.

{{> options-locked }}

{{> options-lockfile-path }}
{{/options}}

{{> section-options-common }}
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-clean.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ Remove all artifacts in the directory with the given profile name.

{{> options-locked }}

{{> options-lockfile-path }}
{{/options}}

{{> section-options-common }}
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ and supports common Unix glob patterns.

{{> options-locked }}

{{> options-lockfile-path }}
{{/options}}

{{> section-options-common }}
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ you plan to use Cargo without a network with the `--offline` flag.

{{> options-locked }}

{{> options-lockfile-path }}
{{/options}}

{{> section-options-common }}
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ When no target selection options are given, `cargo fix` will fix all targets

{{> options-locked }}

{{> options-lockfile-path }}
{{/options}}

{{> section-options-common }}
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-generate-lockfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ This is a best-effort filter on allowed packages, including:

{{> options-locked }}

{{> options-lockfile-path }}
{{/options}}

{{> section-options-common }}
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ reproduction of the information within `Cargo.toml`.

{{> options-locked }}

{{> options-lockfile-path }}
{{/options}}

{{> section-options-common }}
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ Valid output formats:

{{> options-locked }}

{{> options-lockfile-path }}

{{/options}}

Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-pkgid.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ Get the package ID for the given package instead of the current package.

{{> options-locked }}

{{> options-lockfile-path }}

{{/options}}

Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ which defaults to `crates-io`.

{{> options-locked }}

{{> options-lockfile-path }}

{{/options}}

Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ Don't actually write to the manifest.

{{> options-locked }}

{{> options-lockfile-path }}
{{/options}}

### Package Selection
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ Run the specified example.

{{> options-locked }}

{{> options-lockfile-path }}

{{/options}}

Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-rustc.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ This flag only works when building a `lib` or `example` library target.

{{> options-locked }}

{{> options-lockfile-path }}

{{/options}}

Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-rustdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ if its name is the same as the lib target. Binaries are skipped if they have

{{> options-locked }}

{{> options-lockfile-path }}
{{/options}}

{{> section-options-common }}
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ results readable. Test output can be recovered (e.g., for debugging) by passing

{{> options-locked }}

{{> options-lockfile-path }}

{{/options}}

Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ Sets how each line is displayed. The _prefix_ value can be one of:

{{> options-locked }}

{{> options-lockfile-path }}
{{/options}}

{{> section-features }}
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ Displays what would be updated, but doesn't actually write the lockfile.

{{> options-locked }}

{{> options-lockfile-path }}

{{/options}}

Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-vendor.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ only a subset of the packages have changed.

{{> options-locked }}

{{> options-lockfile-path }}

{{/options}}

Expand Down
15 changes: 0 additions & 15 deletions src/doc/man/generated_txt/cargo-add.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,6 @@ OPTIONS
--frozen
Equivalent to specifying both --locked and --offline.

--lockfile-path PATH
Changes the path of the lockfile from the default
(<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
(e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
providing --lockfile-path will ignore existing lockfile at the
default path, and instead will either use the lockfile from PATH, or
write a new lockfile into the provided PATH if it doesn’t exist.
This flag can be used to run most commands in read-only directories,
writing lockfile into the provided PATH.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #14421
<https://github.com/rust-lang/cargo/issues/14421>).

Common Options
+toolchain
If Cargo has been installed with rustup, and the first argument to
Expand Down
15 changes: 0 additions & 15 deletions src/doc/man/generated_txt/cargo-bench.txt
Original file line number Diff line number Diff line change
Expand Up @@ -373,21 +373,6 @@ OPTIONS
--frozen
Equivalent to specifying both --locked and --offline.

--lockfile-path PATH
Changes the path of the lockfile from the default
(<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
(e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
providing --lockfile-path will ignore existing lockfile at the
default path, and instead will either use the lockfile from PATH, or
write a new lockfile into the provided PATH if it doesn’t exist.
This flag can be used to run most commands in read-only directories,
writing lockfile into the provided PATH.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #14421
<https://github.com/rust-lang/cargo/issues/14421>).

Common Options
+toolchain
If Cargo has been installed with rustup, and the first argument to
Expand Down
15 changes: 0 additions & 15 deletions src/doc/man/generated_txt/cargo-build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,6 @@ OPTIONS
--frozen
Equivalent to specifying both --locked and --offline.

--lockfile-path PATH
Changes the path of the lockfile from the default
(<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
(e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
providing --lockfile-path will ignore existing lockfile at the
default path, and instead will either use the lockfile from PATH, or
write a new lockfile into the provided PATH if it doesn’t exist.
This flag can be used to run most commands in read-only directories,
writing lockfile into the provided PATH.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #14421
<https://github.com/rust-lang/cargo/issues/14421>).

Common Options
+toolchain
If Cargo has been installed with rustup, and the first argument to
Expand Down
15 changes: 0 additions & 15 deletions src/doc/man/generated_txt/cargo-check.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,21 +291,6 @@ OPTIONS
--frozen
Equivalent to specifying both --locked and --offline.

--lockfile-path PATH
Changes the path of the lockfile from the default
(<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
(e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
providing --lockfile-path will ignore existing lockfile at the
default path, and instead will either use the lockfile from PATH, or
write a new lockfile into the provided PATH if it doesn’t exist.
This flag can be used to run most commands in read-only directories,
writing lockfile into the provided PATH.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #14421
<https://github.com/rust-lang/cargo/issues/14421>).

Common Options
+toolchain
If Cargo has been installed with rustup, and the first argument to
Expand Down
Loading