Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print option to dump target spec as JSON #38061

Merged
merged 3 commits into from
Dec 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ pub enum PrintRequest {
TargetFeatures,
RelocationModels,
CodeModels,
TargetSpec,
}

pub enum Input {
Expand Down Expand Up @@ -1138,6 +1139,13 @@ 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<RustcOptGroup> {
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"),
opt::multi_s("", "cfg", "Configure the compilation environment", "SPEC"),
Expand All @@ -1157,9 +1165,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
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>", "FILENAME"),
Expand Down Expand Up @@ -1469,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))
}
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/test/run-make/target-specs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 -