From 8260b8325ca820ab9dc6b224c0db0ca06f1c2b91 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 16 May 2021 10:25:08 +0200 Subject: [PATCH 1/3] Use TargetTriple::from_path in rustdoc --- src/librustdoc/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index b75e98ae16c16..ac863a1b05bf0 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -565,7 +565,7 @@ impl Options { let target = matches.opt_str("target").map_or(TargetTriple::from_triple(host_triple()), |target| { if target.ends_with(".json") { - TargetTriple::TargetPath(PathBuf::from(target)) + TargetTriple::from_path(Path::new(&target)) } else { TargetTriple::TargetTriple(target) } From f22a80890a5e7245afccef0ab7f7ccc45105df4d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 16 May 2021 15:35:10 +0200 Subject: [PATCH 2/3] Use parse_target_triple in rustdoc --- compiler/rustc_session/src/config.rs | 5 ++++- src/librustdoc/config.rs | 15 +++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index f517c483758d2..1c6fad2ae8e1c 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1507,7 +1507,10 @@ fn collect_print_requests( prints } -fn parse_target_triple(matches: &getopts::Matches, error_format: ErrorOutputType) -> TargetTriple { +pub fn parse_target_triple( + matches: &getopts::Matches, + error_format: ErrorOutputType, +) -> TargetTriple { match matches.opt_str("target") { Some(target) if target.ends_with(".json") => { let path = Path::new(&target); diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index ac863a1b05bf0..6e1fdf67a652f 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -6,8 +6,10 @@ use std::path::PathBuf; use std::str::FromStr; use rustc_data_structures::fx::FxHashMap; -use rustc_session::config::{self, parse_crate_types_from_list, parse_externs, CrateType}; -use rustc_session::config::{get_cmd_lint_options, host_triple, nightly_options}; +use rustc_session::config::{ + self, parse_crate_types_from_list, parse_externs, parse_target_triple, CrateType, +}; +use rustc_session::config::{get_cmd_lint_options, nightly_options}; use rustc_session::config::{CodegenOptions, DebuggingOptions, ErrorOutputType, Externs}; use rustc_session::getopts; use rustc_session::lint::Level; @@ -562,14 +564,7 @@ impl Options { } } - let target = - matches.opt_str("target").map_or(TargetTriple::from_triple(host_triple()), |target| { - if target.ends_with(".json") { - TargetTriple::from_path(Path::new(&target)) - } else { - TargetTriple::TargetTriple(target) - } - }); + let target = parse_target_triple(matches, error_format); let show_coverage = matches.opt_present("show-coverage"); From 6afc1f45164b1c7fdbd7c70b1de603ce95c84446 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 16 May 2021 18:41:54 +0200 Subject: [PATCH 3/3] Add test --- .../rustdoc-target-spec-json-path/Makefile | 9 +++++ .../dummy_core.rs | 2 + .../rustdoc-target-spec-json-path/my_crate.rs | 3 ++ .../rustdoc-target-spec-json-path/target.json | 39 +++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 src/test/run-make-fulldeps/rustdoc-target-spec-json-path/Makefile create mode 100644 src/test/run-make-fulldeps/rustdoc-target-spec-json-path/dummy_core.rs create mode 100644 src/test/run-make-fulldeps/rustdoc-target-spec-json-path/my_crate.rs create mode 100644 src/test/run-make-fulldeps/rustdoc-target-spec-json-path/target.json diff --git a/src/test/run-make-fulldeps/rustdoc-target-spec-json-path/Makefile b/src/test/run-make-fulldeps/rustdoc-target-spec-json-path/Makefile new file mode 100644 index 0000000000000..6d0bc4186f229 --- /dev/null +++ b/src/test/run-make-fulldeps/rustdoc-target-spec-json-path/Makefile @@ -0,0 +1,9 @@ +include ../tools.mk + +# Test that rustdoc will properly canonicalize the target spec json path just like rustc + +OUTPUT_DIR := "$(TMPDIR)/rustdoc-target-spec-json-path" + +all: + $(RUSTC) --crate-type lib dummy_core.rs --target target.json + $(RUSTDOC) -o $(OUTPUT_DIR) -L $(TMPDIR) my_crate.rs --target target.json diff --git a/src/test/run-make-fulldeps/rustdoc-target-spec-json-path/dummy_core.rs b/src/test/run-make-fulldeps/rustdoc-target-spec-json-path/dummy_core.rs new file mode 100644 index 0000000000000..da27b7f3463da --- /dev/null +++ b/src/test/run-make-fulldeps/rustdoc-target-spec-json-path/dummy_core.rs @@ -0,0 +1,2 @@ +#![feature(no_core)] +#![no_core] diff --git a/src/test/run-make-fulldeps/rustdoc-target-spec-json-path/my_crate.rs b/src/test/run-make-fulldeps/rustdoc-target-spec-json-path/my_crate.rs new file mode 100644 index 0000000000000..12aa082208475 --- /dev/null +++ b/src/test/run-make-fulldeps/rustdoc-target-spec-json-path/my_crate.rs @@ -0,0 +1,3 @@ +#![feature(no_core)] +#![no_core] +extern crate dummy_core; diff --git a/src/test/run-make-fulldeps/rustdoc-target-spec-json-path/target.json b/src/test/run-make-fulldeps/rustdoc-target-spec-json-path/target.json new file mode 100644 index 0000000000000..58e924a9895c8 --- /dev/null +++ b/src/test/run-make-fulldeps/rustdoc-target-spec-json-path/target.json @@ -0,0 +1,39 @@ +{ + "arch": "x86_64", + "cpu": "x86-64", + "crt-static-respected": true, + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", + "dynamic-linking": true, + "env": "gnu", + "executables": true, + "has-elf-tls": true, + "has-rpath": true, + "is-builtin": true, + "linker-is-gnu": true, + "llvm-target": "x86_64-unknown-linux-gnu", + "max-atomic-width": 64, + "os": "linux", + "position-independent-executables": true, + "pre-link-args": { + "gcc": [ + "-m64" + ] + }, + "relro-level": "full", + "stack-probes": { + "kind": "inline-or-call", + "min-llvm-version-for-inline": [ + 11, + 0, + 1 + ] + }, + "supported-sanitizers": [ + "address", + "leak", + "memory", + "thread" + ], + "target-family": "unix", + "target-pointer-width": "64" +}