Skip to content

Commit ef2bf6d

Browse files
committed
implement --print=all-target-specs-json
1 parent e592aaa commit ef2bf6d

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ use rustc_session::{early_error, early_error_no_abort, early_warn};
4444
use rustc_span::source_map::{FileLoader, FileName};
4545
use rustc_span::symbol::sym;
4646
use rustc_target::json::ToJson;
47+
use rustc_target::spec::{Target, TargetTriple};
4748

4849
use std::cmp::max;
50+
use std::collections::BTreeMap;
4951
use std::env;
5052
use std::ffi::OsString;
5153
use std::fs;
@@ -648,6 +650,15 @@ fn print_crate_info(
648650
TargetSpec => {
649651
println!("{}", serde_json::to_string_pretty(&sess.target.to_json()).unwrap());
650652
}
653+
AllTargetSpecs => {
654+
let mut targets = BTreeMap::new();
655+
for name in rustc_target::spec::TARGETS {
656+
let triple = TargetTriple::from_triple(name);
657+
let target = Target::expect_builtin(&triple);
658+
targets.insert(name, target.to_json());
659+
}
660+
println!("{}", serde_json::to_string_pretty(&targets).unwrap());
661+
}
651662
FileNames | CrateName => {
652663
let Some(attrs) = attrs.as_ref() else {
653664
// no crate attributes, print out an error and exit

compiler/rustc_session/src/config.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ pub enum PrintRequest {
580580
CodeModels,
581581
TlsModels,
582582
TargetSpec,
583+
AllTargetSpecs,
583584
NativeStaticLibs,
584585
StackProtectorStrategies,
585586
LinkArgs,
@@ -1439,8 +1440,8 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
14391440
"Compiler information to print on stdout",
14401441
"[crate-name|file-names|sysroot|target-libdir|cfg|calling-conventions|\
14411442
target-list|target-cpus|target-features|relocation-models|code-models|\
1442-
tls-models|target-spec-json|native-static-libs|stack-protector-strategies|\
1443-
link-args]",
1443+
tls-models|target-spec-json|all-target-specs-json|native-static-libs|\
1444+
stack-protector-strategies|link-args]",
14441445
),
14451446
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
14461447
opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"),
@@ -1887,6 +1888,7 @@ fn collect_print_requests(
18871888
("native-static-libs", PrintRequest::NativeStaticLibs),
18881889
("stack-protector-strategies", PrintRequest::StackProtectorStrategies),
18891890
("target-spec-json", PrintRequest::TargetSpec),
1891+
("all-target-specs-json", PrintRequest::AllTargetSpecs),
18901892
("link-args", PrintRequest::LinkArgs),
18911893
("split-debuginfo", PrintRequest::SplitDebuginfo),
18921894
];
@@ -1900,7 +1902,18 @@ fn collect_print_requests(
19001902
early_error(
19011903
error_format,
19021904
"the `-Z unstable-options` flag must also be passed to \
1903-
enable the target-spec-json print option",
1905+
enable the target-spec-json print option",
1906+
);
1907+
}
1908+
}
1909+
Some((_, PrintRequest::AllTargetSpecs)) => {
1910+
if unstable_opts.unstable_options {
1911+
PrintRequest::AllTargetSpecs
1912+
} else {
1913+
early_error(
1914+
error_format,
1915+
"the `-Z unstable-options` flag must also be passed to \
1916+
enable the all-target-specs-json print option",
19041917
);
19051918
}
19061919
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
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`
1+
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`
22

0 commit comments

Comments
 (0)