From 8285ab5c99db166e2137fb4b92fedd03b56acaa0 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Thu, 1 Dec 2016 16:26:47 -0600 Subject: [PATCH 1/3] convert --print options to a vector To allow manipulation of the options that appear in --print, convert it to a vector. Signed-off-by: Doug Goldstein --- src/librustc/session/config.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 26dafed7019ed..9dd341c767480 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1138,6 +1138,10 @@ mod opt { /// including metadata for each option, such as whether the option is /// part of the stable long-term interface for rustc. pub fn rustc_short_optgroups() -> Vec { + let mut print_opts = vec!["crate-name", "file-names", "sysroot", "cfg", + "target-list", "target-cpus", "target-features", + "relocation-models", "code-models"]; + vec![ opt::flag_s("h", "help", "Display this message"), opt::multi_s("", "cfg", "Configure the compilation environment", "SPEC"), @@ -1157,9 +1161,7 @@ pub fn rustc_short_optgroups() -> Vec { the compiler to emit", "[asm|llvm-bc|llvm-ir|obj|link|dep-info]"), opt::multi_s("", "print", "Comma separated list of compiler information to \ - print on stdout", - "[crate-name|file-names|sysroot|cfg|target-list|target-cpus|\ - target-features|relocation-models|code-models]"), + print on stdout", &print_opts.join("|")), opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"), opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"), opt::opt_s("o", "", "Write output to ", "FILENAME"), From ff112644defc6a982bfd6a793afbeb3155173742 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Thu, 7 Apr 2016 16:36:35 -0500 Subject: [PATCH 2/3] rustc: add --print target-spec option This option provides the user the ability to dump the configuration that is in use by rustc for the target they are building for. Signed-off-by: Doug Goldstein --- src/librustc/session/config.rs | 6 ++++++ src/librustc_driver/lib.rs | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 9dd341c767480..478b6b80414a3 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -308,6 +308,7 @@ pub enum PrintRequest { TargetFeatures, RelocationModels, CodeModels, + TargetSpec, } pub enum Input { @@ -1141,6 +1142,9 @@ pub fn rustc_short_optgroups() -> Vec { let mut print_opts = vec!["crate-name", "file-names", "sysroot", "cfg", "target-list", "target-cpus", "target-features", "relocation-models", "code-models"]; + if nightly_options::is_nightly_build() { + print_opts.push("target-spec-json"); + } vec![ opt::flag_s("h", "help", "Display this message"), @@ -1471,6 +1475,8 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches) "target-features" => PrintRequest::TargetFeatures, "relocation-models" => PrintRequest::RelocationModels, "code-models" => PrintRequest::CodeModels, + "target-spec-json" if nightly_options::is_unstable_enabled(matches) + => PrintRequest::TargetSpec, req => { early_error(error_format, &format!("unknown print request `{}`", req)) } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index b79eca0c22d7e..f84622c2f0285 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -80,6 +80,8 @@ use rustc_metadata::locator; use rustc_metadata::cstore::CStore; use rustc::util::common::time; +use serialize::json::ToJson; + use std::cmp::max; use std::cmp::Ordering::Equal; use std::default::Default; @@ -584,6 +586,7 @@ impl RustcDefaultCalls { println!("{}", targets.join("\n")); }, PrintRequest::Sysroot => println!("{}", sess.sysroot().display()), + PrintRequest::TargetSpec => println!("{}", sess.target.target.to_json().pretty()), PrintRequest::FileNames | PrintRequest::CrateName => { let input = match input { From 7151b5ad7821dc7c1990af0bd2850fcbcbe100e7 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Sun, 10 Apr 2016 22:17:27 -0500 Subject: [PATCH 3/3] rustc: add basic test for --print target-spec This is a very basic test of the --print target-spec feature. Signed-off-by: Doug Goldstein --- src/test/run-make/target-specs/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/run-make/target-specs/Makefile b/src/test/run-make/target-specs/Makefile index 0c9a0169c1abb..6b58ad7b6dff0 100644 --- a/src/test/run-make/target-specs/Makefile +++ b/src/test/run-make/target-specs/Makefile @@ -6,3 +6,4 @@ all: $(RUSTC) foo.rs --target=my-incomplete-platform.json 2>&1 | grep 'Field llvm-target' RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=my-awesome-platform --crate-type=lib --emit=asm RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=x86_64-unknown-linux-gnu --crate-type=lib --emit=asm + $(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 -