mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
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 https://github.com/rust-lang/rust/pull/113780 (as insta-stable before being un-stablized in https://github.com/rust-lang/rust/pull/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\]](https://github.com/rust-lang/rust/pull/113780#issue-1807080607): > **Support --print KIND=PATH command line syntax** > > As is already done for `--emit KIND=PATH` and `-L KIND=PATH`. > > In the discussion of https://github.com/rust-lang/rust/pull/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](d43cf3a51a/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".31eda6f7c3/src/cargo/core/compiler/build_context/target_info.rs (L242)
----- cc `@dtolnay` r? `@jackh726`
This commit is contained in:
commit
f06b7c59a3
@ -2160,12 +2160,6 @@ fn collect_print_requests(
|
||||
prints.extend(matches.opt_strs("print").into_iter().map(|req| {
|
||||
let (req, out) = split_out_file_name(&req);
|
||||
|
||||
if out.is_some() && !unstable_opts.unstable_options {
|
||||
handler.early_error(
|
||||
"the `-Z unstable-options` flag must also be passed to \
|
||||
enable the path print option",
|
||||
);
|
||||
}
|
||||
let kind = match PRINT_KINDS.iter().find(|&&(name, _)| name == req) {
|
||||
Some((_, PrintKind::TargetSpec)) => {
|
||||
if unstable_opts.unstable_options {
|
||||
|
@ -260,6 +260,10 @@ The valid types of print values are:
|
||||
This returns rustc's minimum supported deployment target if no `*_DEPLOYMENT_TARGET` variable
|
||||
is present in the environment, or otherwise returns the variable's parsed value.
|
||||
|
||||
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.
|
||||
|
||||
[conditional compilation]: ../reference/conditional-compilation.html
|
||||
[deployment target]: https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html
|
||||
|
||||
|
@ -1,11 +0,0 @@
|
||||
# `--print` Options
|
||||
|
||||
The behavior of the `--print` flag can be modified by optionally be specifying a filepath
|
||||
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.
|
||||
|
||||
This is unstable feature, so you have to provide `-Zunstable-options` to enable it.
|
||||
|
||||
## Examples
|
||||
|
||||
`rustc main.rs -Z unstable-options --print cfg=cfgs.txt`
|
@ -13,19 +13,19 @@ all: default output_to_file
|
||||
|
||||
output_to_file:
|
||||
# Backend-independent, printed by rustc_driver_impl/src/lib.rs
|
||||
$(RUSTC) --target x86_64-pc-windows-gnu --print cfg=$(TMPDIR)/cfg.txt -Z unstable-options
|
||||
$(RUSTC) --target x86_64-pc-windows-gnu --print cfg=$(TMPDIR)/cfg.txt
|
||||
$(CGREP) windows < $(TMPDIR)/cfg.txt
|
||||
|
||||
# Printed from CodegenBackend trait impl in rustc_codegen_llvm/src/lib.rs
|
||||
$(RUSTC) --print relocation-models=$(TMPDIR)/relocation-models.txt -Z unstable-options
|
||||
$(RUSTC) --print relocation-models=$(TMPDIR)/relocation-models.txt
|
||||
$(CGREP) dynamic-no-pic < $(TMPDIR)/relocation-models.txt
|
||||
|
||||
# Printed by compiler/rustc_codegen_llvm/src/llvm_util.rs
|
||||
$(RUSTC) --target wasm32-unknown-unknown --print target-features=$(TMPDIR)/target-features.txt -Z unstable-options
|
||||
$(RUSTC) --target wasm32-unknown-unknown --print target-features=$(TMPDIR)/target-features.txt
|
||||
$(CGREP) reference-types < $(TMPDIR)/target-features.txt
|
||||
|
||||
# Printed by C++ code in rustc_llvm/llvm-wrapper/PassWrapper.cpp
|
||||
$(RUSTC) --target wasm32-unknown-unknown --print target-cpus=$(TMPDIR)/target-cpus.txt -Z unstable-options
|
||||
$(RUSTC) --target wasm32-unknown-unknown --print target-cpus=$(TMPDIR)/target-cpus.txt
|
||||
$(CGREP) generic < $(TMPDIR)/target-cpus.txt
|
||||
|
||||
ifdef IS_WINDOWS
|
||||
|
@ -1,2 +0,0 @@
|
||||
error: the `-Z unstable-options` flag must also be passed to enable the path print option
|
||||
|
@ -1,7 +0,0 @@
|
||||
// check-fail
|
||||
// revisions: cfg target-features target-cpus
|
||||
// [cfg]compile-flags: --print cfg=cfg.txt
|
||||
// [target-cpus]compile-flags: --print target-cpu=target_cpu.txt
|
||||
// [target-features]compile-flags: --print target-features=target_features.txt
|
||||
|
||||
fn main() {}
|
@ -1,2 +0,0 @@
|
||||
error: the `-Z unstable-options` flag must also be passed to enable the path print option
|
||||
|
@ -1,2 +0,0 @@
|
||||
error: the `-Z unstable-options` flag must also be passed to enable the path print option
|
||||
|
Loading…
Reference in New Issue
Block a user