Skip to content

Commit 928e47d

Browse files
authored
Unrolled build for rust-lang#121843
Rollup merge of rust-lang#121843 - ferrocene:builtin-path, r=petrochenkov Implement `-L KIND=@RUSTC_BUILTIN/...` Implements rust-lang/compiler-team#659
2 parents 0dcc130 + 3d65c92 commit 928e47d

File tree

4 files changed

+65
-34
lines changed

4 files changed

+65
-34
lines changed

compiler/rustc_interface/src/tests.rs

+32-23
Original file line numberDiff line numberDiff line change
@@ -315,30 +315,39 @@ fn test_search_paths_tracking_hash_different_order() {
315315
json_rendered: HumanReadableErrorType::Default(ColorConfig::Never),
316316
};
317317

318+
let push = |opts: &mut Options, search_path| {
319+
opts.search_paths.push(SearchPath::from_cli_opt(
320+
"not-a-sysroot".as_ref(),
321+
&opts.target_triple,
322+
&early_dcx,
323+
search_path,
324+
));
325+
};
326+
318327
// Reference
319-
v1.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "native=abc"));
320-
v1.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "crate=def"));
321-
v1.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "dependency=ghi"));
322-
v1.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "framework=jkl"));
323-
v1.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "all=mno"));
324-
325-
v2.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "native=abc"));
326-
v2.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "dependency=ghi"));
327-
v2.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "crate=def"));
328-
v2.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "framework=jkl"));
329-
v2.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "all=mno"));
330-
331-
v3.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "crate=def"));
332-
v3.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "framework=jkl"));
333-
v3.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "native=abc"));
334-
v3.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "dependency=ghi"));
335-
v3.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "all=mno"));
336-
337-
v4.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "all=mno"));
338-
v4.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "native=abc"));
339-
v4.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "crate=def"));
340-
v4.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "dependency=ghi"));
341-
v4.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "framework=jkl"));
328+
push(&mut v1, "native=abc");
329+
push(&mut v1, "crate=def");
330+
push(&mut v1, "dependency=ghi");
331+
push(&mut v1, "framework=jkl");
332+
push(&mut v1, "all=mno");
333+
334+
push(&mut v2, "native=abc");
335+
push(&mut v2, "dependency=ghi");
336+
push(&mut v2, "crate=def");
337+
push(&mut v2, "framework=jkl");
338+
push(&mut v2, "all=mno");
339+
340+
push(&mut v3, "crate=def");
341+
push(&mut v3, "framework=jkl");
342+
push(&mut v3, "native=abc");
343+
push(&mut v3, "dependency=ghi");
344+
push(&mut v3, "all=mno");
345+
346+
push(&mut v4, "all=mno");
347+
push(&mut v4, "native=abc");
348+
push(&mut v4, "crate=def");
349+
push(&mut v4, "dependency=ghi");
350+
push(&mut v4, "framework=jkl");
342351

343352
assert_same_hash(&v1, &v2);
344353
assert_same_hash(&v1, &v3);

compiler/rustc_session/src/config.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2795,11 +2795,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
27952795
let debuginfo = select_debuginfo(matches, &cg);
27962796
let debuginfo_compression = unstable_opts.debuginfo_compression;
27972797

2798-
let mut search_paths = vec![];
2799-
for s in &matches.opt_strs("L") {
2800-
search_paths.push(SearchPath::from_cli_opt(early_dcx, s));
2801-
}
2802-
28032798
let libs = parse_libs(early_dcx, matches);
28042799

28052800
let test = matches.opt_present("test");
@@ -2848,6 +2843,11 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28482843
candidate.join("library/std/src/lib.rs").is_file().then_some(candidate)
28492844
};
28502845

2846+
let mut search_paths = vec![];
2847+
for s in &matches.opt_strs("L") {
2848+
search_paths.push(SearchPath::from_cli_opt(&sysroot, &target_triple, early_dcx, s));
2849+
}
2850+
28512851
let working_dir = std::env::current_dir().unwrap_or_else(|e| {
28522852
early_dcx.early_fatal(format!("Current directory is invalid: {e}"));
28532853
});

compiler/rustc_session/src/search_paths.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::filesearch::make_target_lib_path;
22
use crate::EarlyDiagCtxt;
3+
use rustc_target::spec::TargetTriple;
34
use std::path::{Path, PathBuf};
45

56
#[derive(Clone, Debug)]
@@ -46,7 +47,12 @@ impl PathKind {
4647
}
4748

4849
impl SearchPath {
49-
pub fn from_cli_opt(early_dcx: &EarlyDiagCtxt, path: &str) -> Self {
50+
pub fn from_cli_opt(
51+
sysroot: &Path,
52+
triple: &TargetTriple,
53+
early_dcx: &EarlyDiagCtxt,
54+
path: &str,
55+
) -> Self {
5056
let (kind, path) = if let Some(stripped) = path.strip_prefix("native=") {
5157
(PathKind::Native, stripped)
5258
} else if let Some(stripped) = path.strip_prefix("crate=") {
@@ -60,12 +66,17 @@ impl SearchPath {
6066
} else {
6167
(PathKind::All, path)
6268
};
63-
if path.is_empty() {
69+
let dir = match path.strip_prefix("@RUSTC_BUILTIN") {
70+
Some(stripped) => {
71+
make_target_lib_path(sysroot, triple.triple()).join("builtin").join(stripped)
72+
}
73+
None => PathBuf::from(path),
74+
};
75+
if dir.as_os_str().is_empty() {
6476
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
6577
early_dcx.early_fatal("empty search path given via `-L`");
6678
}
6779

68-
let dir = PathBuf::from(path);
6980
Self::new(kind, dir)
7081
}
7182

src/librustdoc/config.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,6 @@ impl Options {
460460
&matches.free[0]
461461
});
462462

463-
let libs =
464-
matches.opt_strs("L").iter().map(|s| SearchPath::from_cli_opt(early_dcx, s)).collect();
465463
let externs = parse_externs(early_dcx, matches, &unstable_opts);
466464
let extern_html_root_urls = match parse_extern_html_roots(matches) {
467465
Ok(ex) => ex,
@@ -625,6 +623,20 @@ impl Options {
625623
}
626624

627625
let target = parse_target_triple(early_dcx, matches);
626+
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
627+
628+
let sysroot = match &maybe_sysroot {
629+
Some(s) => s.clone(),
630+
None => {
631+
rustc_session::filesearch::get_or_default_sysroot().expect("Failed finding sysroot")
632+
}
633+
};
634+
635+
let libs = matches
636+
.opt_strs("L")
637+
.iter()
638+
.map(|s| SearchPath::from_cli_opt(&sysroot, &target, early_dcx, s))
639+
.collect();
628640

629641
let show_coverage = matches.opt_present("show-coverage");
630642

@@ -653,7 +665,6 @@ impl Options {
653665
let bin_crate = crate_types.contains(&CrateType::Executable);
654666
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
655667
let playground_url = matches.opt_str("playground-url");
656-
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
657668
let module_sorting = if matches.opt_present("sort-modules-by-appearance") {
658669
ModuleSorting::DeclarationOrder
659670
} else {

0 commit comments

Comments
 (0)