Skip to content

Commit

Permalink
Make sysroot mandatory for rustdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Mar 6, 2024
1 parent 7f1719f commit 2779d74
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ fn test_search_paths_tracking_hash_different_order() {

let push = |opts: &mut Options, search_path| {
opts.search_paths.push(SearchPath::from_cli_opt(
None,
"not-a-sysroot".as_ref(),
&opts.target_triple,
&early_dcx,
search_path,
Expand Down
10 changes: 3 additions & 7 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2860,13 +2860,9 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M

// Try to find a directory containing the Rust `src`, for more details see
// the doc comment on the `real_rust_source_base_dir` field.
let tmp_buf;
let sysroot = match &sysroot_opt {
Some(s) => s,
None => {
tmp_buf = crate::filesearch::get_or_default_sysroot().expect("Failed finding sysroot");
&tmp_buf
}
Some(s) => s.clone(),
None => crate::filesearch::get_or_default_sysroot().expect("Failed finding sysroot"),
};
let real_rust_source_base_dir = {
// This is the location used by the `rust-src` `rustup` component.
Expand All @@ -2888,7 +2884,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M

let mut search_paths = vec![];
for s in &matches.opt_strs("L") {
search_paths.push(SearchPath::from_cli_opt(Some(&sysroot), &target_triple, early_dcx, s));
search_paths.push(SearchPath::from_cli_opt(&sysroot, &target_triple, early_dcx, s));
}

let working_dir = std::env::current_dir().unwrap_or_else(|e| {
Expand Down
15 changes: 3 additions & 12 deletions compiler/rustc_session/src/search_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl PathKind {

impl SearchPath {
pub fn from_cli_opt(
sysroot: Option<&Path>,
sysroot: &Path,
triple: &TargetTriple,
early_dcx: &EarlyDiagCtxt,
path: &str,
Expand All @@ -64,21 +64,12 @@ impl SearchPath {
} else if let Some(stripped) = path.strip_prefix("all=") {
(PathKind::All, stripped)
} else if let Some(stripped) = path.strip_prefix("builtin:") {
let Some(sysroot) = sysroot else {
early_dcx.early_fatal("`-L builtin:` is not supported without a sysroot present");
};
let triple = match triple {
TargetTriple::TargetTriple(triple) => triple,
TargetTriple::TargetJson { .. } => {
early_dcx.early_fatal("`-L builtin:` is not supported with custom targets");
}
};

if stripped.contains(std::path::is_separator) {
early_dcx.early_fatal("`-L builtin:` does not accept paths");
}

let path = make_target_lib_path(sysroot, triple).join("builtin").join(stripped);
let path =
make_target_lib_path(sysroot, triple.triple()).join("builtin").join(stripped);
if !path.is_dir() {
early_dcx.early_fatal(format!("builtin:{stripped} does not exist"));
}
Expand Down
9 changes: 8 additions & 1 deletion src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,17 @@ impl Options {
let target = parse_target_triple(early_dcx, matches);
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);

let sysroot = match &maybe_sysroot {
Some(s) => s.clone(),
None => {
rustc_session::filesearch::get_or_default_sysroot().expect("Failed finding sysroot")
}
};

let libs = matches
.opt_strs("L")
.iter()
.map(|s| SearchPath::from_cli_opt(maybe_sysroot.as_deref(), &target, early_dcx, s))
.map(|s| SearchPath::from_cli_opt(&sysroot, &target, early_dcx, s))
.collect();

let show_coverage = matches.opt_present("show-coverage");
Expand Down

0 comments on commit 2779d74

Please sign in to comment.