mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Stabilize patch-in-config
This commit is contained in:
parent
d47c52e7c4
commit
1e0d564ff0
@ -648,7 +648,6 @@ unstable_cli_options!(
|
||||
panic_abort_tests: bool = ("Enable support to run tests with -Cpanic=abort"),
|
||||
host_config: bool = ("Enable the [host] section in the .cargo/config.toml file"),
|
||||
target_applies_to_host: bool = ("Enable the `target-applies-to-host` key in the .cargo/config.toml file"),
|
||||
patch_in_config: bool = ("Allow `[patch]` sections in .cargo/config.toml files"),
|
||||
rustdoc_map: bool = ("Allow passing external documentation mappings to rustdoc"),
|
||||
separate_nightlies: bool = (HIDDEN),
|
||||
terminal_width: Option<Option<usize>> = ("Provide a terminal width to rustc for error truncation"),
|
||||
@ -697,6 +696,8 @@ const STABILIZED_EXTRA_LINK_ARG: &str = "Additional linker arguments are now \
|
||||
|
||||
const STABILIZED_CONFIGURABLE_ENV: &str = "The [env] section is now always enabled.";
|
||||
|
||||
const STABILIZED_PATCH_IN_CONFIG: &str = "The patch-in-config feature is now always enabled.";
|
||||
|
||||
fn deserialize_build_std<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
@ -841,7 +842,6 @@ impl CliUnstable {
|
||||
"jobserver-per-rustc" => self.jobserver_per_rustc = parse_empty(k, v)?,
|
||||
"host-config" => self.host_config = parse_empty(k, v)?,
|
||||
"target-applies-to-host" => self.target_applies_to_host = parse_empty(k, v)?,
|
||||
"patch-in-config" => self.patch_in_config = parse_empty(k, v)?,
|
||||
"features" => {
|
||||
// For now this is still allowed (there are still some
|
||||
// unstable options like "compare"). This should be removed at
|
||||
@ -877,6 +877,7 @@ impl CliUnstable {
|
||||
"package-features" => stabilized_warn(k, "1.51", STABILIZED_PACKAGE_FEATURES),
|
||||
"extra-link-arg" => stabilized_warn(k, "1.56", STABILIZED_EXTRA_LINK_ARG),
|
||||
"configurable-env" => stabilized_warn(k, "1.56", STABILIZED_CONFIGURABLE_ENV),
|
||||
"patch-in-config" => stabilized_warn(k, "1.56", STABILIZED_PATCH_IN_CONFIG),
|
||||
"future-incompat-report" => self.future_incompat_report = parse_empty(k, v)?,
|
||||
_ => bail!("unknown `-Z` flag specified: {}", k),
|
||||
}
|
||||
|
@ -362,11 +362,6 @@ impl<'cfg> Workspace<'cfg> {
|
||||
BTreeMap<String, BTreeMap<String, TomlDependency<ConfigRelativePath>>>,
|
||||
> = self.config.get("patch")?;
|
||||
|
||||
if config_patch.is_some() && !self.config.cli_unstable().patch_in_config {
|
||||
self.config.shell().warn("`[patch]` in cargo config was ignored, the -Zpatch-in-config command-line flag is required".to_owned())?;
|
||||
return Ok(HashMap::new());
|
||||
}
|
||||
|
||||
let source = SourceId::for_path(self.root())?;
|
||||
|
||||
let mut warnings = Vec::new();
|
||||
|
@ -111,6 +111,9 @@ retry = 2 # network retries
|
||||
git-fetch-with-cli = true # use the `git` executable for git operations
|
||||
offline = false # do not access the network
|
||||
|
||||
[patch.<registry>]
|
||||
# Same keys as for [patch] in Cargo.toml
|
||||
|
||||
[profile.<name>] # Modify profile settings via config.
|
||||
opt-level = 0 # Optimization level.
|
||||
debug = true # Include debug info.
|
||||
@ -650,6 +653,31 @@ needed, and generate an error if it encounters a network error.
|
||||
|
||||
Can be overridden with the `--offline` command-line option.
|
||||
|
||||
#### `[patch]`
|
||||
|
||||
Just as you can override dependencies using [`[patch]` in
|
||||
`Cargo.toml`](overriding-dependencies.md#the-patch-section), you can
|
||||
override them in the cargo configuration file to apply those patches to
|
||||
any affected build. The format is identical to the one used in
|
||||
`Cargo.toml`.
|
||||
|
||||
Since `.cargo/config.toml` files are not usually checked into source
|
||||
control, you should prefer patching using `Cargo.toml` where possible to
|
||||
ensure that other developers can compile your crate in their own
|
||||
environments. Patching through cargo configuration files is generally
|
||||
only appropriate when the patch section is automatically generated by an
|
||||
external build tool.
|
||||
|
||||
If a given dependency is patched both in a cargo configuration file and
|
||||
a `Cargo.toml` file, the patch in the configuration file is used. If
|
||||
multiple configuration files patch the same dependency, standard cargo
|
||||
configuration merging is used, which prefers the value defined closest
|
||||
to the current directory, with `$HOME/.cargo/config.toml` taking the
|
||||
lowest precedence.
|
||||
|
||||
Relative `path` dependencies in such a `[patch]` section are resolved
|
||||
relative to the configuration file they appear in.
|
||||
|
||||
#### `[profile]`
|
||||
|
||||
The `[profile]` table can be used to globally change profile settings, and
|
||||
|
@ -100,7 +100,6 @@ Each new feature described below should explain how to use it.
|
||||
* Configuration
|
||||
* [config-cli](#config-cli) — Adds the ability to pass configuration options on the command-line.
|
||||
* [config-include](#config-include) — Adds the ability for config files to include other files.
|
||||
* [patch-in-config](#patch-in-config) — Adds support for specifying the `[patch]` table in config files.
|
||||
* [`cargo config`](#cargo-config) — Adds a new subcommand for viewing config files.
|
||||
* Registries
|
||||
* [credential-process](#credential-process) — Adds support for fetching registry tokens from an external authentication program.
|
||||
@ -1227,31 +1226,6 @@ The supported values for `FREQUENCY` are 'always` and 'never', which control
|
||||
whether or not a message is printed out at the end of `cargo build` / `cargo check`.
|
||||
|
||||
|
||||
### patch-in-config
|
||||
* Original Pull Request: [#9204](https://github.com/rust-lang/cargo/pull/9204)
|
||||
* Tracking Issue: [#9269](https://github.com/rust-lang/cargo/issues/9269)
|
||||
|
||||
The `-Z patch-in-config` flag enables the use of `[patch]` sections in
|
||||
cargo configuration files (`.cargo/config.toml`). The format of such
|
||||
`[patch]` sections is identical to the one used in `Cargo.toml`.
|
||||
|
||||
Since `.cargo/config.toml` files are not usually checked into source
|
||||
control, you should prefer patching using `Cargo.toml` where possible to
|
||||
ensure that other developers can compile your crate in their own
|
||||
environments. Patching through cargo configuration files is generally
|
||||
only appropriate when the patch section is automatically generated by an
|
||||
external build tool.
|
||||
|
||||
If a given dependency is patched both in a cargo configuration file and
|
||||
a `Cargo.toml` file, the patch in `Cargo.toml` is used. If multiple
|
||||
configuration files patch the same dependency, standard cargo
|
||||
configuration merging is used, which prefers the value defined closest
|
||||
to the current directory, with `$HOME/.cargo/config.toml` taking the
|
||||
lowest precedence.
|
||||
|
||||
Relative `path` dependencies in such a `[patch]` section are resolved
|
||||
relative to the configuration file they appear in.
|
||||
|
||||
### `cargo config`
|
||||
|
||||
* Original Issue: [#2362](https://github.com/rust-lang/cargo/issues/2362)
|
||||
|
@ -66,50 +66,6 @@ fn replace() {
|
||||
p.cargo("build").with_stderr("[FINISHED] [..]").run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn from_config_without_z() {
|
||||
Package::new("bar", "0.1.0").publish();
|
||||
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
|
||||
[dependencies]
|
||||
bar = "0.1.0"
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
".cargo/config.toml",
|
||||
r#"
|
||||
[patch.crates-io]
|
||||
bar = { path = 'bar' }
|
||||
"#,
|
||||
)
|
||||
.file("src/lib.rs", "")
|
||||
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1"))
|
||||
.file("bar/src/lib.rs", r#""#)
|
||||
.build();
|
||||
|
||||
p.cargo("build")
|
||||
.with_stderr(
|
||||
"\
|
||||
[WARNING] `[patch]` in cargo config was ignored, the -Zpatch-in-config command-line flag is required
|
||||
[UPDATING] `dummy-registry` index
|
||||
[DOWNLOADING] crates ...
|
||||
[DOWNLOADED] bar v0.1.0 ([..])
|
||||
[COMPILING] bar v0.1.0
|
||||
[COMPILING] foo v0.0.1 ([CWD])
|
||||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn from_config() {
|
||||
Package::new("bar", "0.1.0").publish();
|
||||
@ -139,8 +95,7 @@ fn from_config() {
|
||||
.file("bar/src/lib.rs", r#""#)
|
||||
.build();
|
||||
|
||||
p.cargo("build -Zpatch-in-config")
|
||||
.masquerade_as_nightly_cargo()
|
||||
p.cargo("build")
|
||||
.with_stderr(
|
||||
"\
|
||||
[UPDATING] `dummy-registry` index
|
||||
@ -181,8 +136,7 @@ fn from_config_relative() {
|
||||
.file("bar/src/lib.rs", r#""#)
|
||||
.build();
|
||||
|
||||
p.cargo("build -Zpatch-in-config")
|
||||
.masquerade_as_nightly_cargo()
|
||||
p.cargo("build")
|
||||
.with_stderr(
|
||||
"\
|
||||
[UPDATING] `dummy-registry` index
|
||||
@ -226,8 +180,7 @@ fn from_config_precedence() {
|
||||
.file("bar/src/lib.rs", r#""#)
|
||||
.build();
|
||||
|
||||
p.cargo("build -Zpatch-in-config")
|
||||
.masquerade_as_nightly_cargo()
|
||||
p.cargo("build")
|
||||
.with_stderr(
|
||||
"\
|
||||
[UPDATING] `dummy-registry` index
|
||||
@ -519,8 +472,7 @@ fn unused_from_config() {
|
||||
.file("bar/src/lib.rs", "not rust code")
|
||||
.build();
|
||||
|
||||
p.cargo("build -Zpatch-in-config")
|
||||
.masquerade_as_nightly_cargo()
|
||||
p.cargo("build")
|
||||
.with_stderr(
|
||||
"\
|
||||
[UPDATING] `dummy-registry` index
|
||||
@ -537,8 +489,7 @@ fn unused_from_config() {
|
||||
",
|
||||
)
|
||||
.run();
|
||||
p.cargo("build -Zpatch-in-config")
|
||||
.masquerade_as_nightly_cargo()
|
||||
p.cargo("build")
|
||||
.with_stderr(
|
||||
"\
|
||||
[WARNING] Patch `bar v0.2.0 ([CWD]/bar)` was not used in the crate graph.
|
||||
@ -733,8 +684,7 @@ fn add_patch_from_config() {
|
||||
"#,
|
||||
);
|
||||
|
||||
p.cargo("build -Zpatch-in-config")
|
||||
.masquerade_as_nightly_cargo()
|
||||
p.cargo("build")
|
||||
.with_stderr(
|
||||
"\
|
||||
[COMPILING] bar v0.1.0 ([CWD]/bar)
|
||||
@ -743,10 +693,7 @@ fn add_patch_from_config() {
|
||||
",
|
||||
)
|
||||
.run();
|
||||
p.cargo("build -Zpatch-in-config")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.with_stderr("[FINISHED] [..]")
|
||||
.run();
|
||||
p.cargo("build").with_stderr("[FINISHED] [..]").run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user