Skip to content

Commit 008e3e7

Browse files
committed
feat(compile-time-deps): Add cli flag --compile-time-deps and adjust docs
1 parent ea09591 commit 008e3e7

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
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 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+
```sh
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: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ fn non_comp_time_dep() {
4646
.file("bar/src/lib.rs", r#"pub fn bar() {}"#)
4747
.build();
4848

49-
p.cargo("check")
49+
p.cargo("-Zcompile-time-deps check")
50+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
5051
.with_stderr_data(str![[r#"
5152
[LOCKING] 1 package to latest compatible version
52-
[CHECKING] bar v0.0.1 ([ROOT]/foo/bar)
53-
[CHECKING] foo v0.0.1 ([ROOT]/foo)
5453
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
5554
5655
"#]])
@@ -142,22 +141,21 @@ fn proc_macro_dep() {
142141
.file("baz/src/lib.rs", r#"pub fn baz() {}"#)
143142
.build();
144143

145-
p.cargo("check --package foo")
144+
p.cargo("-Zunstable-options check --package foo --compile-time-deps")
145+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
146146
.with_stderr_data(str![[r#"
147147
[COMPILING] baz v0.0.1 ([ROOT]/foo/baz)
148148
[COMPILING] bar v0.0.1 ([ROOT]/foo/bar)
149-
[CHECKING] foo v0.0.1 ([ROOT]/foo/foo)
150149
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
151150
152151
"#]])
153152
.run();
154153

155154
p.cargo("clean").run();
156155

157-
p.cargo("check --package bar")
156+
p.cargo("-Zunstable-options check --package bar --compile-time-deps")
157+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
158158
.with_stderr_data(str![[r#"
159-
[CHECKING] baz v0.0.1 ([ROOT]/foo/baz)
160-
[CHECKING] bar v0.0.1 ([ROOT]/foo/bar)
161159
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
162160
163161
"#]])
@@ -221,7 +219,8 @@ fn build_dep() {
221219
.file("bar/baz/src/lib.rs", r#"pub fn baz() {}"#)
222220
.build();
223221

224-
p.cargo("check")
222+
p.cargo("-Zunstable-options check --compile-time-deps")
223+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
225224
.with_stderr_data(str![[r#"
226225
[LOCKING] 2 packages to latest compatible versions
227226
[COMPILING] baz v0.0.1 ([ROOT]/foo/bar/baz)
@@ -294,12 +293,12 @@ fn indirect_comp_time_dep() {
294293
.file("bar/baz/src/lib.rs", r#"pub fn baz() {}"#)
295294
.build();
296295

297-
p.cargo("check")
296+
p.cargo("-Zunstable-options check --compile-time-deps")
297+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
298298
.with_stderr_data(str![[r#"
299299
[LOCKING] 2 packages to latest compatible versions
300300
[COMPILING] baz v0.0.1 ([ROOT]/foo/bar/baz)
301301
[COMPILING] bar v0.0.1 ([ROOT]/foo/bar)
302-
[CHECKING] foo v0.0.1 ([ROOT]/foo)
303302
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
304303
305304
"#]])
@@ -359,21 +358,21 @@ fn tests_target() {
359358
)
360359
.build();
361360

362-
p.cargo("check --tests")
361+
p.cargo("-Zunstable-options check --tests --compile-time-deps")
363362
.with_stderr_data(str![[r#"
364363
[LOCKING] 1 package to latest compatible version
365364
[COMPILING] bar v0.0.1 ([ROOT]/foo/bar)
366-
[CHECKING] foo v0.0.1 ([ROOT]/foo)
367365
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
368366
369367
"#]])
368+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
370369
.run();
371370

372371
p.cargo("clean").run();
373372

374-
p.cargo("check")
373+
p.cargo("-Zunstable-options check --compile-time-deps")
374+
.masquerade_as_nightly_cargo(&["compile-time-deps"])
375375
.with_stderr_data(str![[r#"
376-
[CHECKING] foo v0.0.1 ([ROOT]/foo)
377376
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
378377
379378
"#]])

0 commit comments

Comments
 (0)