Skip to content

Commit f06b7c5

Browse files
committed
Auto merge of #114183 - Urgau:stabilize-print-with-path, r=oli-obk
Stabilize `PATH` option for `--print KIND=PATH` This PR propose stabilizing the `PATH` option for `--print KIND=PATH`. This option was previously added in #113780 (as insta-stable before being un-stablized in #114139). Description of the `PATH` option: > A filepath may optionally be specified for each requested information kind, in the format `--print KIND=PATH`, just like for `--emit`. When a path is specified, information will be written there instead of to stdout. ------ Description of the original PR [\[link\]](#113780 (comment)): > **Support --print KIND=PATH command line syntax** > > As is already done for `--emit KIND=PATH` and `-L KIND=PATH`. > > In the discussion of #110785, it was pointed out that `--print KIND=PATH` is nicer than trying to apply the single global `-o path` to `--print`'s output, because in general there can be multiple print requests within a single rustc invocation, and anyway `-o` would already be used for a different meaning in the case of `link-args` and `native-static-libs`. > > I am interested in using `--print cfg=PATH` in Buck2. Currently Buck2 works around the lack of support for `--print KIND=PATH` by [indirecting through a Python wrapper script](https://github.com/facebook/buck2/blob/d43cf3a51a31f00be2c2248e78271b0fef0452b4/prelude/rust/tools/get_rustc_cfg.py) to redirect rustc's stdout into the location dictated by the build system. > > From skimming Cargo's usages of `--print`, it definitely seems like it would benefit from `--print KIND=PATH` too. Currently it is working around the lack of this by inserting `--crate-name=___ --print=crate-name` so that it can look for a line containing `___` as a delimiter between the 2 other `--print` informations it actually cares about. This is commented as a "HACK" and "abuse". https://github.com/rust-lang/cargo/blob/31eda6f7c360d9911f853b3014e057db61238f3e/src/cargo/core/compiler/build_context/target_info.rs#L242 ----- cc `@dtolnay` r? `@jackh726`
2 parents c5775a7 + caf6ce5 commit f06b7c5

File tree

8 files changed

+8
-34
lines changed

8 files changed

+8
-34
lines changed

compiler/rustc_session/src/config.rs

-6
Original file line numberDiff line numberDiff line change
@@ -2160,12 +2160,6 @@ fn collect_print_requests(
21602160
prints.extend(matches.opt_strs("print").into_iter().map(|req| {
21612161
let (req, out) = split_out_file_name(&req);
21622162

2163-
if out.is_some() && !unstable_opts.unstable_options {
2164-
handler.early_error(
2165-
"the `-Z unstable-options` flag must also be passed to \
2166-
enable the path print option",
2167-
);
2168-
}
21692163
let kind = match PRINT_KINDS.iter().find(|&&(name, _)| name == req) {
21702164
Some((_, PrintKind::TargetSpec)) => {
21712165
if unstable_opts.unstable_options {

src/doc/rustc/src/command-line-arguments.md

+4
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ The valid types of print values are:
260260
This returns rustc's minimum supported deployment target if no `*_DEPLOYMENT_TARGET` variable
261261
is present in the environment, or otherwise returns the variable's parsed value.
262262

263+
A filepath may optionally be specified for each requested information kind, in
264+
the format `--print KIND=PATH`, just like for `--emit`. When a path is
265+
specified, information will be written there instead of to stdout.
266+
263267
[conditional compilation]: ../reference/conditional-compilation.html
264268
[deployment target]: https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html
265269

src/doc/unstable-book/src/compiler-flags/path-options.md

-11
This file was deleted.

tests/run-make/print-cfg/Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ all: default output_to_file
1313

1414
output_to_file:
1515
# Backend-independent, printed by rustc_driver_impl/src/lib.rs
16-
$(RUSTC) --target x86_64-pc-windows-gnu --print cfg=$(TMPDIR)/cfg.txt -Z unstable-options
16+
$(RUSTC) --target x86_64-pc-windows-gnu --print cfg=$(TMPDIR)/cfg.txt
1717
$(CGREP) windows < $(TMPDIR)/cfg.txt
1818

1919
# Printed from CodegenBackend trait impl in rustc_codegen_llvm/src/lib.rs
20-
$(RUSTC) --print relocation-models=$(TMPDIR)/relocation-models.txt -Z unstable-options
20+
$(RUSTC) --print relocation-models=$(TMPDIR)/relocation-models.txt
2121
$(CGREP) dynamic-no-pic < $(TMPDIR)/relocation-models.txt
2222

2323
# Printed by compiler/rustc_codegen_llvm/src/llvm_util.rs
24-
$(RUSTC) --target wasm32-unknown-unknown --print target-features=$(TMPDIR)/target-features.txt -Z unstable-options
24+
$(RUSTC) --target wasm32-unknown-unknown --print target-features=$(TMPDIR)/target-features.txt
2525
$(CGREP) reference-types < $(TMPDIR)/target-features.txt
2626

2727
# Printed by C++ code in rustc_llvm/llvm-wrapper/PassWrapper.cpp
28-
$(RUSTC) --target wasm32-unknown-unknown --print target-cpus=$(TMPDIR)/target-cpus.txt -Z unstable-options
28+
$(RUSTC) --target wasm32-unknown-unknown --print target-cpus=$(TMPDIR)/target-cpus.txt
2929
$(CGREP) generic < $(TMPDIR)/target-cpus.txt
3030

3131
ifdef IS_WINDOWS

tests/ui/feature-gates/print-with-path.cfg.stderr

-2
This file was deleted.

tests/ui/feature-gates/print-with-path.rs

-7
This file was deleted.

tests/ui/feature-gates/print-with-path.target-cpus.stderr

-2
This file was deleted.

tests/ui/feature-gates/print-with-path.target-features.stderr

-2
This file was deleted.

0 commit comments

Comments
 (0)