Skip to content

Commit 6b0b81b

Browse files
Rollup merge of #85361 - bjorn3:rustdoc_target_json_path_canonicalize, r=jyn514
Use TargetTriple::from_path in rustdoc This fixes the problem reported in Rust-for-Linux/linux#272 where rustdoc requires the absolute path of a target spec json instead of accepting a relative path like rustc.
2 parents a7890c7 + 6afc1f4 commit 6b0b81b

File tree

6 files changed

+62
-11
lines changed

6 files changed

+62
-11
lines changed

Diff for: compiler/rustc_session/src/config.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,10 @@ fn collect_print_requests(
15071507
prints
15081508
}
15091509

1510-
fn parse_target_triple(matches: &getopts::Matches, error_format: ErrorOutputType) -> TargetTriple {
1510+
pub fn parse_target_triple(
1511+
matches: &getopts::Matches,
1512+
error_format: ErrorOutputType,
1513+
) -> TargetTriple {
15111514
match matches.opt_str("target") {
15121515
Some(target) if target.ends_with(".json") => {
15131516
let path = Path::new(&target);

Diff for: src/librustdoc/config.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ use std::path::PathBuf;
66
use std::str::FromStr;
77

88
use rustc_data_structures::fx::FxHashMap;
9-
use rustc_session::config::{self, parse_crate_types_from_list, parse_externs, CrateType};
10-
use rustc_session::config::{get_cmd_lint_options, host_triple, nightly_options};
9+
use rustc_session::config::{
10+
self, parse_crate_types_from_list, parse_externs, parse_target_triple, CrateType,
11+
};
12+
use rustc_session::config::{get_cmd_lint_options, nightly_options};
1113
use rustc_session::config::{CodegenOptions, DebuggingOptions, ErrorOutputType, Externs};
1214
use rustc_session::getopts;
1315
use rustc_session::lint::Level;
@@ -562,14 +564,7 @@ impl Options {
562564
}
563565
}
564566

565-
let target =
566-
matches.opt_str("target").map_or(TargetTriple::from_triple(host_triple()), |target| {
567-
if target.ends_with(".json") {
568-
TargetTriple::TargetPath(PathBuf::from(target))
569-
} else {
570-
TargetTriple::TargetTriple(target)
571-
}
572-
});
567+
let target = parse_target_triple(matches, error_format);
573568

574569
let show_coverage = matches.opt_present("show-coverage");
575570

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
include ../tools.mk
2+
3+
# Test that rustdoc will properly canonicalize the target spec json path just like rustc
4+
5+
OUTPUT_DIR := "$(TMPDIR)/rustdoc-target-spec-json-path"
6+
7+
all:
8+
$(RUSTC) --crate-type lib dummy_core.rs --target target.json
9+
$(RUSTDOC) -o $(OUTPUT_DIR) -L $(TMPDIR) my_crate.rs --target target.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#![feature(no_core)]
2+
#![no_core]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![feature(no_core)]
2+
#![no_core]
3+
extern crate dummy_core;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"arch": "x86_64",
3+
"cpu": "x86-64",
4+
"crt-static-respected": true,
5+
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
6+
"dynamic-linking": true,
7+
"env": "gnu",
8+
"executables": true,
9+
"has-elf-tls": true,
10+
"has-rpath": true,
11+
"is-builtin": true,
12+
"linker-is-gnu": true,
13+
"llvm-target": "x86_64-unknown-linux-gnu",
14+
"max-atomic-width": 64,
15+
"os": "linux",
16+
"position-independent-executables": true,
17+
"pre-link-args": {
18+
"gcc": [
19+
"-m64"
20+
]
21+
},
22+
"relro-level": "full",
23+
"stack-probes": {
24+
"kind": "inline-or-call",
25+
"min-llvm-version-for-inline": [
26+
11,
27+
0,
28+
1
29+
]
30+
},
31+
"supported-sanitizers": [
32+
"address",
33+
"leak",
34+
"memory",
35+
"thread"
36+
],
37+
"target-family": "unix",
38+
"target-pointer-width": "64"
39+
}

0 commit comments

Comments
 (0)