Skip to content

Enable yanked dependencies with an unstable flag #5967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
15 changes: 8 additions & 7 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ pub fn main(config: &mut Config) -> CliResult {
"
Available unstable (nightly-only) flags:

-Z avoid-dev-deps -- Avoid installing dev-dependencies if possible
-Z minimal-versions -- Install minimal dependency versions instead of maximum
-Z no-index-update -- Do not update the registry, avoids a network request for benchmarking
-Z offline -- Offline mode that does not perform network requests
-Z unstable-options -- Allow the usage of unstable options such as --registry
-Z config-profile -- Read profiles from .cargo/config files
-Z compile-progress -- Display a progress bar while compiling
-Z avoid-dev-deps -- Avoid installing dev-dependencies if possible
-Z minimal-versions -- Install minimal dependency versions instead of maximum
-Z no-index-update -- Do not update the registry, avoids a network request for benchmarking
-Z offline -- Offline mode that does not perform network requests
-Z unstable-options -- Allow the usage of unstable options such as --registry
-Z config-profile -- Read profiles from .cargo/config files
-Z compile-progress -- Display a progress bar while compiling
-Z allow-yanked-deps -- Allow depending on yanked crates

Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
);
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ pub struct CliUnstable {
pub advanced_env: bool,
pub config_profile: bool,
pub compile_progress: bool,
pub allow_yanked_deps: bool,
}

impl CliUnstable {
Expand Down Expand Up @@ -355,6 +356,7 @@ impl CliUnstable {
"advanced-env" => self.advanced_env = true,
"config-profile" => self.config_profile = true,
"compile-progress" => self.compile_progress = true,
"allow-yanked-deps" => self.allow_yanked_deps = true,
_ => bail!("unknown `-Z` flag specified: {}", k),
}

Expand Down
5 changes: 4 additions & 1 deletion src/cargo/sources/registry/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,15 @@ impl<'cfg> RegistryIndex<'cfg> {
load: &mut RegistryData,
f: &mut FnMut(Summary),
) -> CargoResult<()> {
let allow_yanked_deps = self.config.cli_unstable().allow_yanked_deps;
let source_id = self.source_id.clone();
let name = dep.package_name().as_str();
let summaries = self.summaries(name, load)?;
let summaries = summaries
.iter()
.filter(|&&(_, yanked)| dep.source_id().precise().is_some() || !yanked)
.filter(|&&(_, yanked)| {
dep.source_id().precise().is_some() || allow_yanked_deps || !yanked
})
.map(|s| s.0.clone());

// Handle `cargo update --precise` here. If specified, our own source
Expand Down
12 changes: 12 additions & 0 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ directory. Example:
cargo +nightly build --out-dir=out -Z unstable-options
```

## allow-yanked-deps
* Original Issue: [#4425](https://github.com/rust-lang/cargo/issues/4225)

This feature allows your project to depend on yanked crates.

The flag can be useful if you need to build an old project that relies on a
yanked dependency, and you can't update it. The flag should not be used on new
or maintained projects: remember that yanked crates are not meant to be used.

```
cargo +nightly build -Z allow-yanked-deps
```

### Edition
* Tracking Issue: [rust-lang/rust#44581](https://github.com/rust-lang/rust/issues/44581)
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,6 @@ fn explain() {
fn z_flags_help() {
cargo_process("-Z help")
.with_stdout_contains(
" -Z unstable-options -- Allow the usage of unstable options such as --registry",
" -Z unstable-options -- Allow the usage of unstable options such as --registry",
).run();
}
36 changes: 36 additions & 0 deletions tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,42 @@ required by package `bar v0.0.1`
).run();
}

#[test]
fn yanks_are_used_with_z_flag() {
let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.0.1"
authors = []

[dependencies]
bar = "*"
"#,
).file("src/main.rs", "fn main() {}")
.build();

Package::new("baz", "0.0.1").publish();
Package::new("baz", "0.0.2").yanked(true).publish();
Package::new("bar", "0.0.1").dep("baz", "=0.0.2").publish();

p.cargo("build -Zallow-yanked-deps")
.masquerade_as_nightly_cargo()
.with_stderr(&format!(
"\
[UPDATING] registry `[..]`
[DOWNLOADING] [..] (registry `file://[..]`)
[DOWNLOADING] [..] (registry `file://[..]`)
[COMPILING] baz v0.0.2
[COMPILING] bar v0.0.1
[COMPILING] foo v0.0.1 (CWD)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
",
)).run();
}

#[test]
fn yanks_in_lockfiles_are_ok() {
let p = project()
Expand Down