implement --print=all-target-specs-json
This commit is contained in:
parent
e592aaa705
commit
ef2bf6d505
3 changed files with 28 additions and 4 deletions
|
@ -44,8 +44,10 @@ use rustc_session::{early_error, early_error_no_abort, early_warn};
|
||||||
use rustc_span::source_map::{FileLoader, FileName};
|
use rustc_span::source_map::{FileLoader, FileName};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_target::json::ToJson;
|
use rustc_target::json::ToJson;
|
||||||
|
use rustc_target::spec::{Target, TargetTriple};
|
||||||
|
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
|
use std::collections::BTreeMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
@ -648,6 +650,15 @@ fn print_crate_info(
|
||||||
TargetSpec => {
|
TargetSpec => {
|
||||||
println!("{}", serde_json::to_string_pretty(&sess.target.to_json()).unwrap());
|
println!("{}", serde_json::to_string_pretty(&sess.target.to_json()).unwrap());
|
||||||
}
|
}
|
||||||
|
AllTargetSpecs => {
|
||||||
|
let mut targets = BTreeMap::new();
|
||||||
|
for name in rustc_target::spec::TARGETS {
|
||||||
|
let triple = TargetTriple::from_triple(name);
|
||||||
|
let target = Target::expect_builtin(&triple);
|
||||||
|
targets.insert(name, target.to_json());
|
||||||
|
}
|
||||||
|
println!("{}", serde_json::to_string_pretty(&targets).unwrap());
|
||||||
|
}
|
||||||
FileNames | CrateName => {
|
FileNames | CrateName => {
|
||||||
let Some(attrs) = attrs.as_ref() else {
|
let Some(attrs) = attrs.as_ref() else {
|
||||||
// no crate attributes, print out an error and exit
|
// no crate attributes, print out an error and exit
|
||||||
|
|
|
@ -580,6 +580,7 @@ pub enum PrintRequest {
|
||||||
CodeModels,
|
CodeModels,
|
||||||
TlsModels,
|
TlsModels,
|
||||||
TargetSpec,
|
TargetSpec,
|
||||||
|
AllTargetSpecs,
|
||||||
NativeStaticLibs,
|
NativeStaticLibs,
|
||||||
StackProtectorStrategies,
|
StackProtectorStrategies,
|
||||||
LinkArgs,
|
LinkArgs,
|
||||||
|
@ -1439,8 +1440,8 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
|
||||||
"Compiler information to print on stdout",
|
"Compiler information to print on stdout",
|
||||||
"[crate-name|file-names|sysroot|target-libdir|cfg|calling-conventions|\
|
"[crate-name|file-names|sysroot|target-libdir|cfg|calling-conventions|\
|
||||||
target-list|target-cpus|target-features|relocation-models|code-models|\
|
target-list|target-cpus|target-features|relocation-models|code-models|\
|
||||||
tls-models|target-spec-json|native-static-libs|stack-protector-strategies|\
|
tls-models|target-spec-json|all-target-specs-json|native-static-libs|\
|
||||||
link-args]",
|
stack-protector-strategies|link-args]",
|
||||||
),
|
),
|
||||||
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
|
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
|
||||||
opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"),
|
opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"),
|
||||||
|
@ -1887,6 +1888,7 @@ fn collect_print_requests(
|
||||||
("native-static-libs", PrintRequest::NativeStaticLibs),
|
("native-static-libs", PrintRequest::NativeStaticLibs),
|
||||||
("stack-protector-strategies", PrintRequest::StackProtectorStrategies),
|
("stack-protector-strategies", PrintRequest::StackProtectorStrategies),
|
||||||
("target-spec-json", PrintRequest::TargetSpec),
|
("target-spec-json", PrintRequest::TargetSpec),
|
||||||
|
("all-target-specs-json", PrintRequest::AllTargetSpecs),
|
||||||
("link-args", PrintRequest::LinkArgs),
|
("link-args", PrintRequest::LinkArgs),
|
||||||
("split-debuginfo", PrintRequest::SplitDebuginfo),
|
("split-debuginfo", PrintRequest::SplitDebuginfo),
|
||||||
];
|
];
|
||||||
|
@ -1904,6 +1906,17 @@ fn collect_print_requests(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some((_, PrintRequest::AllTargetSpecs)) => {
|
||||||
|
if unstable_opts.unstable_options {
|
||||||
|
PrintRequest::AllTargetSpecs
|
||||||
|
} else {
|
||||||
|
early_error(
|
||||||
|
error_format,
|
||||||
|
"the `-Z unstable-options` flag must also be passed to \
|
||||||
|
enable the all-target-specs-json print option",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Some(&(_, print_request)) => print_request,
|
Some(&(_, print_request)) => print_request,
|
||||||
None => {
|
None => {
|
||||||
let prints =
|
let prints =
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
error: unknown print request `uwu`. Valid print requests are: `crate-name`, `file-names`, `sysroot`, `target-libdir`, `cfg`, `calling-conventions`, `target-list`, `target-cpus`, `target-features`, `relocation-models`, `code-models`, `tls-models`, `native-static-libs`, `stack-protector-strategies`, `target-spec-json`, `link-args`, `split-debuginfo`
|
error: unknown print request `uwu`. Valid print requests are: `crate-name`, `file-names`, `sysroot`, `target-libdir`, `cfg`, `calling-conventions`, `target-list`, `target-cpus`, `target-features`, `relocation-models`, `code-models`, `tls-models`, `native-static-libs`, `stack-protector-strategies`, `target-spec-json`, `all-target-specs-json`, `link-args`, `split-debuginfo`
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue