Skip to content

Commit 072b345

Browse files
committed
feat(compile-time-deps): Add cli flag --compile-time-deps and adjust docs
1 parent 5b178a8 commit 072b345

File tree

5 files changed

+47
-24
lines changed

5 files changed

+47
-24
lines changed

src/bin/cargo/commands/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub fn cli() -> Command {
3838
.arg_build_plan()
3939
.arg_unit_graph()
4040
.arg_timings()
41+
.arg_compile_time_deps()
4142
.arg_manifest_path()
4243
.arg_lockfile_path()
4344
.arg_ignore_rust_version()

src/bin/cargo/commands/check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub fn cli() -> Command {
3535
.arg_target_dir()
3636
.arg_unit_graph()
3737
.arg_timings()
38+
.arg_compile_time_deps()
3839
.arg_manifest_path()
3940
.arg_lockfile_path()
4041
.arg_ignore_rust_version()

src/cargo/util/command_prelude.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,10 @@ pub trait CommandExt: Sized {
521521
.hide(true),
522522
)
523523
}
524+
525+
fn arg_compile_time_deps(self) -> Self {
526+
self._arg(flag("compile-time-deps", "").hide(true))
527+
}
524528
}
525529

526530
impl CommandExt for Command {
@@ -806,6 +810,7 @@ Run `{cmd}` to see possible targets."
806810
build_config.build_plan = self.flag("build-plan");
807811
build_config.unit_graph = self.flag("unit-graph");
808812
build_config.future_incompat_report = self.flag("future-incompat-report");
813+
build_config.compile_time_deps_only = self.flag("compile-time-deps");
809814

810815
if self._contains("timings") {
811816
for timing_output in self._values_of("timings") {
@@ -840,6 +845,10 @@ Run `{cmd}` to see possible targets."
840845
gctx.cli_unstable()
841846
.fail_if_stable_opt("--unit-graph", 8002)?;
842847
}
848+
if build_config.compile_time_deps_only {
849+
gctx.cli_unstable()
850+
.fail_if_stable_opt("--compile-time-deps", 14434)?;
851+
}
843852

844853
let opts = CompileOptions {
845854
build_config,

src/doc/src/reference/unstable.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,3 +2190,17 @@ More information can be found in the [config chapter](config.md#cache).
21902190
## doctest-xcompile
21912191

21922192
Doctest cross-compiling is now unconditionally enabled starting in Rust 1.89. Running doctests with `cargo test` will now honor the `--target` flag.
2193+
2194+
## compile-time-deps
2195+
2196+
This permanently-unstable flag to only build proc-macros and build scripts (and their required dependencies),
2197+
as well as run the build scripts.
2198+
2199+
It is intended for use by tools like rust-analyzer and will never be stabilized.
2200+
2201+
Example:
2202+
2203+
```console
2204+
cargo +nightly build --compile-time-deps -Z unstable-options
2205+
cargo +nightly check --compile-time-deps --all-targets -Z unstable-options
2206+
```

tests/testsuite/compile_time_deps.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ fn gated_by_unstable_opts() {
88
.build();
99

1010
p.cargo("check --compile-time-deps")
11-
.with_status(1)
11+
.with_status(101)
1212
.with_stderr_data(str![[r#"
13-
[ERROR] unexpected argument '--compile-time-deps' found
14-
15-
Usage: cargo check [OPTIONS]
16-
17-
For more information, try '--help'.
13+
[ERROR] the `--compile-time-deps` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
14+
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
15+
See https://github.com/rust-lang/cargo/issues/14434 for more information about the `--compile-time-deps` flag.
1816
1917
"#]])
2018
.run();
@@ -55,11 +53,10 @@ fn non_comp_time_dep() {
5553
.file("bar/src/lib.rs", r#"pub fn bar() {}"#)
5654
.build();
5755

58-
p.cargo("check")
56+
p.cargo("-Zunstable-options check --compile-time-deps")
57+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
5958
.with_stderr_data(str![[r#"
6059
[LOCKING] 1 package to latest compatible version
61-
[CHECKING] bar v0.0.1 ([ROOT]/foo/bar)
62-
[CHECKING] foo v0.0.1 ([ROOT]/foo)
6360
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
6461
6562
"#]])
@@ -151,33 +148,33 @@ fn proc_macro_dep() {
151148
.file("baz/src/lib.rs", r#"pub fn baz() {}"#)
152149
.build();
153150

154-
p.cargo("check --package foo")
151+
p.cargo("-Zunstable-options check --package foo --compile-time-deps")
152+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
155153
.with_stderr_data(str![[r#"
156154
[COMPILING] baz v0.0.1 ([ROOT]/foo/baz)
157155
[COMPILING] bar v0.0.1 ([ROOT]/foo/bar)
158-
[CHECKING] foo v0.0.1 ([ROOT]/foo/foo)
159156
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
160157
161158
"#]])
162159
.run();
163160

164161
p.cargo("clean").run();
165162

166-
p.cargo("check --package bar")
163+
p.cargo("-Zunstable-options check --package bar --compile-time-deps")
164+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
167165
.with_stderr_data(str![[r#"
168-
[CHECKING] baz v0.0.1 ([ROOT]/foo/baz)
169-
[CHECKING] bar v0.0.1 ([ROOT]/foo/bar)
170166
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
171167
172168
"#]])
173169
.run();
174170

175171
p.cargo("clean").run();
176172

177-
p.cargo("check --package bar --all-targets")
173+
p.cargo("-Zunstable-options check --package bar --all-targets --compile-time-deps")
174+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
178175
.with_stderr_data(str![[r#"
179-
[CHECKING] baz v0.0.1 ([ROOT]/foo/baz)
180-
[CHECKING] bar v0.0.1 ([ROOT]/foo/bar)
176+
[COMPILING] baz v0.0.1 ([ROOT]/foo/baz)
177+
[COMPILING] bar v0.0.1 ([ROOT]/foo/bar)
181178
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
182179
183180
"#]])
@@ -241,7 +238,8 @@ fn build_dep() {
241238
.file("bar/baz/src/lib.rs", r#"pub fn baz() {}"#)
242239
.build();
243240

244-
p.cargo("check")
241+
p.cargo("-Zunstable-options check --compile-time-deps")
242+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
245243
.with_stderr_data(str![[r#"
246244
[LOCKING] 2 packages to latest compatible versions
247245
[COMPILING] baz v0.0.1 ([ROOT]/foo/bar/baz)
@@ -314,12 +312,12 @@ fn indirect_comp_time_dep() {
314312
.file("bar/baz/src/lib.rs", r#"pub fn baz() {}"#)
315313
.build();
316314

317-
p.cargo("check")
315+
p.cargo("-Zunstable-options check --compile-time-deps")
316+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
318317
.with_stderr_data(str![[r#"
319318
[LOCKING] 2 packages to latest compatible versions
320319
[COMPILING] baz v0.0.1 ([ROOT]/foo/bar/baz)
321320
[COMPILING] bar v0.0.1 ([ROOT]/foo/bar)
322-
[CHECKING] foo v0.0.1 ([ROOT]/foo)
323321
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
324322
325323
"#]])
@@ -379,21 +377,21 @@ fn tests_target() {
379377
)
380378
.build();
381379

382-
p.cargo("check --tests")
380+
p.cargo("-Zunstable-options check --tests --compile-time-deps")
383381
.with_stderr_data(str![[r#"
384382
[LOCKING] 1 package to latest compatible version
385383
[COMPILING] bar v0.0.1 ([ROOT]/foo/bar)
386-
[CHECKING] foo v0.0.1 ([ROOT]/foo)
387384
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
388385
389386
"#]])
387+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
390388
.run();
391389

392390
p.cargo("clean").run();
393391

394-
p.cargo("check")
392+
p.cargo("-Zunstable-options check --compile-time-deps")
393+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
395394
.with_stderr_data(str![[r#"
396-
[CHECKING] foo v0.0.1 ([ROOT]/foo)
397395
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
398396
399397
"#]])

0 commit comments

Comments
 (0)