Skip to content

Commit 8900854

Browse files
committed
Auto merge of #38061 - cardoe:target-spec, r=alexcrichton
print option to dump target spec as JSON This lets the user dump out the target spec that the compiler is using. This is useful to people defining their own target.json to compare it against existing targets or understand how different targets change internal settings. It is also potentially useful for Cargo to determine if something has changed with a target and it needs to rebuild things.
2 parents 9a101d8 + 7151b5a commit 8900854

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/librustc/session/config.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ pub enum PrintRequest {
308308
TargetFeatures,
309309
RelocationModels,
310310
CodeModels,
311+
TargetSpec,
311312
}
312313

313314
pub enum Input {
@@ -1138,6 +1139,13 @@ mod opt {
11381139
/// including metadata for each option, such as whether the option is
11391140
/// part of the stable long-term interface for rustc.
11401141
pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
1142+
let mut print_opts = vec!["crate-name", "file-names", "sysroot", "cfg",
1143+
"target-list", "target-cpus", "target-features",
1144+
"relocation-models", "code-models"];
1145+
if nightly_options::is_nightly_build() {
1146+
print_opts.push("target-spec-json");
1147+
}
1148+
11411149
vec![
11421150
opt::flag_s("h", "help", "Display this message"),
11431151
opt::multi_s("", "cfg", "Configure the compilation environment", "SPEC"),
@@ -1157,9 +1165,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
11571165
the compiler to emit",
11581166
"[asm|llvm-bc|llvm-ir|obj|link|dep-info]"),
11591167
opt::multi_s("", "print", "Comma separated list of compiler information to \
1160-
print on stdout",
1161-
"[crate-name|file-names|sysroot|cfg|target-list|target-cpus|\
1162-
target-features|relocation-models|code-models]"),
1168+
print on stdout", &print_opts.join("|")),
11631169
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
11641170
opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"),
11651171
opt::opt_s("o", "", "Write output to <filename>", "FILENAME"),
@@ -1469,6 +1475,8 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
14691475
"target-features" => PrintRequest::TargetFeatures,
14701476
"relocation-models" => PrintRequest::RelocationModels,
14711477
"code-models" => PrintRequest::CodeModels,
1478+
"target-spec-json" if nightly_options::is_unstable_enabled(matches)
1479+
=> PrintRequest::TargetSpec,
14721480
req => {
14731481
early_error(error_format, &format!("unknown print request `{}`", req))
14741482
}

src/librustc_driver/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ use rustc_metadata::locator;
8080
use rustc_metadata::cstore::CStore;
8181
use rustc::util::common::time;
8282

83+
use serialize::json::ToJson;
84+
8385
use std::cmp::max;
8486
use std::cmp::Ordering::Equal;
8587
use std::default::Default;
@@ -584,6 +586,7 @@ impl RustcDefaultCalls {
584586
println!("{}", targets.join("\n"));
585587
},
586588
PrintRequest::Sysroot => println!("{}", sess.sysroot().display()),
589+
PrintRequest::TargetSpec => println!("{}", sess.target.target.to_json().pretty()),
587590
PrintRequest::FileNames |
588591
PrintRequest::CrateName => {
589592
let input = match input {

src/test/run-make/target-specs/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ all:
66
$(RUSTC) foo.rs --target=my-incomplete-platform.json 2>&1 | grep 'Field llvm-target'
77
RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=my-awesome-platform --crate-type=lib --emit=asm
88
RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=x86_64-unknown-linux-gnu --crate-type=lib --emit=asm
9+
$(RUSTC) -Z unstable-options --target=my-awesome-platform.json --print target-spec-json > $(TMPDIR)/test-platform.json && $(RUSTC) -Z unstable-options --target=$(TMPDIR)/test-platform.json --print target-spec-json | diff -q $(TMPDIR)/test-platform.json -

0 commit comments

Comments
 (0)