Skip to content

Commit 8bddb02

Browse files
committed
Add --direct flag to use -Z direct-minimal-versions instead of -Z minimal-versions
1 parent 5f69150 commit 8bddb02

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ jobs:
7474
- run: cargo install -f --path . --debug
7575
- run: cargo minimal-versions check --workspace --no-private --detach-path-deps=skip-exact --all-features -v
7676
- run: cargo minimal-versions build --workspace --no-private --detach-path-deps=skip-exact --all-features -v
77+
- run: cargo minimal-versions build --workspace --no-private --detach-path-deps=skip-exact --all-features -v --direct
7778
- run: cargo minimal-versions test --workspace --all-features -v
7879
- run: |
7980
set -eEuxo pipefail
8081
git clone --depth 1 https://github.com/taiki-e/portable-atomic.git
8182
cd portable-atomic
8283
rustup toolchain add 1.34 --no-self-update
8384
RUSTC_BOOTSTRAP=1 cargo +1.34 minimal-versions build --workspace --no-private -v
85+
RUSTC_BOOTSTRAP=1 cargo +1.34 minimal-versions build --workspace --no-private --detach-path-deps=all -v
8486
if: startsWith(matrix.rust, 'nightly')
8587
8688
test-no-rustup:
@@ -102,6 +104,7 @@ jobs:
102104
- run: cargo install -f --path . --debug
103105
- run: cargo minimal-versions check --workspace --no-private --detach-path-deps=skip-exact --all-features -v
104106
- run: cargo minimal-versions build --workspace --no-private --detach-path-deps=skip-exact --all-features -v
107+
- run: cargo minimal-versions build --workspace --no-private --detach-path-deps=skip-exact --all-features -v --direct
105108
- run: cargo minimal-versions test --workspace --all-features -v
106109

107110
miri:

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
1010

1111
## [Unreleased]
1212

13+
- Add `--direct` flag to use [`-Z direct-minimal-versions`](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#direct-minimal-versions) instead of `-Z minimal-versions`. ([#25](https://github.com/taiki-e/cargo-minimal-versions/pull/25))
14+
1315
## [0.1.20] - 2023-10-22
1416

1517
- Add `--detach-path-deps` flag to run minimal versions check with `path` fields removed from dependencies. ([#4](https://github.com/taiki-e/cargo-minimal-versions/pull/4))

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ keywords = ["cargo", "subcommand", "testing"]
99
categories = ["command-line-utilities", "development-tools::cargo-plugins", "development-tools::testing"]
1010
exclude = ["/.*", "/tools"]
1111
description = """
12-
Cargo subcommand for proper use of -Z minimal-versions.
12+
Cargo subcommand for proper use of -Z minimal-versions and -Z direct-minimal-versions.
1313
"""
1414

1515
[package.metadata.docs.rs]

README.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![license](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue?style=flat-square)](#license)
55
[![build status](https://img.shields.io/github/actions/workflow/status/taiki-e/cargo-minimal-versions/ci.yml?branch=main&style=flat-square&logo=github)](https://github.com/taiki-e/cargo-minimal-versions/actions)
66

7-
Cargo subcommand for proper use of [`-Z minimal-versions`][cargo#5657].
7+
Cargo subcommand for proper use of [`-Z minimal-versions`][cargo#5657] and [`-Z direct-minimal-versions`][direct-minimal-versions].
88

99
- [Usage](#usage)
1010
- [Details](#details)
@@ -22,7 +22,7 @@ Cargo subcommand for proper use of [`-Z minimal-versions`][cargo#5657].
2222
$ cargo minimal-versions --help
2323
cargo-minimal-versions
2424

25-
Cargo subcommand for proper use of -Z minimal-versions.
25+
Cargo subcommand for proper use of -Z minimal-versions and -Z direct-minimal-versions.
2626

2727
USAGE:
2828
cargo minimal-versions <CARGO_SUBCOMMAND> [OPTIONS] [CARGO_OPTIONS]
@@ -63,6 +63,18 @@ By using `--detach-path-deps=skip-exact` flag, you can skip the removal of path
6363

6464
[^1]: To exactly, when neither version, git, nor path is specified, an error will occur, so we will remove the path field of all of dependencies for which the version or git URL is specified.
6565

66+
### --direct (-Z direct-minimal-versions)
67+
68+
If there are dependencies that are incompatible with `-Z minimum-versions`, it is also reasonable to use [`-Z direct-minimal-versions`][direct-minimal-versions], since it is hard to maintain `-Z minimum-versions` compatibility in such situations.
69+
70+
By using `--direct` flag, cargo-minimal-versions uses `-Z direct-minimal-versions` instead of `-Z minimal-versions`.
71+
72+
```sh
73+
cargo minimal-versions check --direct
74+
```
75+
76+
Note that using `-Z direct-minimal-versions` may miss some of the problems that can be found when using `-Z minimal-versions`. However, if there is a problem only with a particular version of a dependency, a problem that was missed when using `-Z minimal-versions` may be found by using `-Z direct-minimal-versions` (because the resolved dependency version is different).
77+
6678
## Details
6779

6880
Using `-Z minimal-versions` in the usual way will not work properly in many cases. [To use `cargo check` with `-Z minimal-versions` properly, you need to run at least three processes.](https://github.com/tokio-rs/tokio/pull/3131#discussion_r521621961)
@@ -83,7 +95,7 @@ See [#1](https://github.com/taiki-e/cargo-minimal-versions/issues/1) and [#6](ht
8395
### Prerequisites
8496

8597
cargo-minimal-versions requires nightly
86-
toolchain (to run `cargo update -Z minimal-versions`) and [cargo-hack] (to run `cargo check` & `cargo build` proper):
98+
toolchain (to run `cargo update -Z minimal-versions` or `cargo update -Z direct-minimal-versions`) and [cargo-hack] (to run `cargo check` & `cargo build` proper):
8799

88100
```sh
89101
rustup toolchain add nightly
@@ -169,6 +181,7 @@ cargo binstall cargo-minimal-versions
169181
[cargo-hack]: https://github.com/taiki-e/cargo-hack
170182
[cargo-llvm-cov]: https://github.com/taiki-e/cargo-llvm-cov
171183
[cargo#5657]: https://github.com/rust-lang/cargo/issues/5657
184+
[direct-minimal-versions]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#direct-minimal-versions
172185
[tokio-rs/tokio#4376]: https://github.com/tokio-rs/tokio/pull/4376
173186
[tokio-rs/tokio#4490]: https://github.com/tokio-rs/tokio/pull/4490
174187

src/cli.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use lexopt::{
1111
use crate::term;
1212

1313
static USAGE: &str = "cargo-minimal-versions\n
14-
Cargo subcommand for proper use of -Z minimal-versions.
14+
Cargo subcommand for proper use of -Z minimal-versions and -Z direct-minimal-versions.
1515
\nUSAGE:
1616
cargo minimal-versions <CARGO_SUBCOMMAND> [OPTIONS] [CARGO_OPTIONS]
1717
\nCARGO_SUBCOMMANDS:
@@ -23,6 +23,7 @@ Cargo subcommand for proper use of -Z minimal-versions.
2323

2424
pub(crate) struct Args {
2525
pub(crate) no_private: bool,
26+
pub(crate) direct: bool,
2627
pub(crate) subcommand: Subcommand,
2728
pub(crate) manifest_path: Option<String>,
2829
pub(crate) detach_path_deps: Option<DetachPathDeps>,
@@ -108,6 +109,7 @@ impl Args {
108109
let mut verbose = 0;
109110
let mut detach_path_deps = None;
110111

112+
let mut direct = false;
111113
let mut no_private = false;
112114

113115
let mut parser = lexopt::Parser::from_args(args);
@@ -148,6 +150,8 @@ impl Args {
148150
}
149151
}
150152

153+
Long("direct") => parse_flag!(direct),
154+
151155
// cargo-hack flags
152156
// However, do not propagate to cargo-hack, as the same process
153157
// is done by cargo-minimal-versions.
@@ -212,7 +216,15 @@ impl Args {
212216
cargo_args.push(path.clone());
213217
}
214218

215-
Ok(Self { no_private, subcommand, manifest_path, detach_path_deps, cargo_args, rest })
219+
Ok(Self {
220+
no_private,
221+
direct,
222+
subcommand,
223+
manifest_path,
224+
detach_path_deps,
225+
cargo_args,
226+
rest,
227+
})
216228
}
217229
}
218230

src/main.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ fn try_main() -> Result<()> {
5353
manifest::with(&ws.metadata, &args, remove_dev_deps, || {
5454
// Update Cargo.lock to minimal version dependencies.
5555
let mut cargo = ws.cargo_nightly();
56-
cargo.args(["update", "-Z", "minimal-versions"]);
56+
if args.direct {
57+
cargo.args(["update", "-Z", "direct-minimal-versions"]);
58+
} else {
59+
cargo.args(["update", "-Z", "minimal-versions"]);
60+
}
5761
info!("running {cargo}");
5862
cargo.run()?;
5963

0 commit comments

Comments
 (0)