Rollup merge of #121843 - ferrocene:builtin-path, r=petrochenkov
Implement `-L KIND=@RUSTC_BUILTIN/...` Implements https://github.com/rust-lang/compiler-team/issues/659
This commit is contained in:
commit
2973f04076
4 changed files with 62 additions and 31 deletions
|
@ -315,30 +315,39 @@ fn test_search_paths_tracking_hash_different_order() {
|
||||||
json_rendered: HumanReadableErrorType::Default(ColorConfig::Never),
|
json_rendered: HumanReadableErrorType::Default(ColorConfig::Never),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let push = |opts: &mut Options, search_path| {
|
||||||
|
opts.search_paths.push(SearchPath::from_cli_opt(
|
||||||
|
"not-a-sysroot".as_ref(),
|
||||||
|
&opts.target_triple,
|
||||||
|
&early_dcx,
|
||||||
|
search_path,
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
// Reference
|
// Reference
|
||||||
v1.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "native=abc"));
|
push(&mut v1, "native=abc");
|
||||||
v1.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "crate=def"));
|
push(&mut v1, "crate=def");
|
||||||
v1.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "dependency=ghi"));
|
push(&mut v1, "dependency=ghi");
|
||||||
v1.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "framework=jkl"));
|
push(&mut v1, "framework=jkl");
|
||||||
v1.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "all=mno"));
|
push(&mut v1, "all=mno");
|
||||||
|
|
||||||
v2.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "native=abc"));
|
push(&mut v2, "native=abc");
|
||||||
v2.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "dependency=ghi"));
|
push(&mut v2, "dependency=ghi");
|
||||||
v2.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "crate=def"));
|
push(&mut v2, "crate=def");
|
||||||
v2.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "framework=jkl"));
|
push(&mut v2, "framework=jkl");
|
||||||
v2.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "all=mno"));
|
push(&mut v2, "all=mno");
|
||||||
|
|
||||||
v3.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "crate=def"));
|
push(&mut v3, "crate=def");
|
||||||
v3.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "framework=jkl"));
|
push(&mut v3, "framework=jkl");
|
||||||
v3.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "native=abc"));
|
push(&mut v3, "native=abc");
|
||||||
v3.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "dependency=ghi"));
|
push(&mut v3, "dependency=ghi");
|
||||||
v3.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "all=mno"));
|
push(&mut v3, "all=mno");
|
||||||
|
|
||||||
v4.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "all=mno"));
|
push(&mut v4, "all=mno");
|
||||||
v4.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "native=abc"));
|
push(&mut v4, "native=abc");
|
||||||
v4.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "crate=def"));
|
push(&mut v4, "crate=def");
|
||||||
v4.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "dependency=ghi"));
|
push(&mut v4, "dependency=ghi");
|
||||||
v4.search_paths.push(SearchPath::from_cli_opt(&early_dcx, "framework=jkl"));
|
push(&mut v4, "framework=jkl");
|
||||||
|
|
||||||
assert_same_hash(&v1, &v2);
|
assert_same_hash(&v1, &v2);
|
||||||
assert_same_hash(&v1, &v3);
|
assert_same_hash(&v1, &v3);
|
||||||
|
|
|
@ -2795,11 +2795,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
|
||||||
let debuginfo = select_debuginfo(matches, &cg);
|
let debuginfo = select_debuginfo(matches, &cg);
|
||||||
let debuginfo_compression = unstable_opts.debuginfo_compression;
|
let debuginfo_compression = unstable_opts.debuginfo_compression;
|
||||||
|
|
||||||
let mut search_paths = vec![];
|
|
||||||
for s in &matches.opt_strs("L") {
|
|
||||||
search_paths.push(SearchPath::from_cli_opt(early_dcx, s));
|
|
||||||
}
|
|
||||||
|
|
||||||
let libs = parse_libs(early_dcx, matches);
|
let libs = parse_libs(early_dcx, matches);
|
||||||
|
|
||||||
let test = matches.opt_present("test");
|
let test = matches.opt_present("test");
|
||||||
|
@ -2848,6 +2843,11 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
|
||||||
candidate.join("library/std/src/lib.rs").is_file().then_some(candidate)
|
candidate.join("library/std/src/lib.rs").is_file().then_some(candidate)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut search_paths = vec![];
|
||||||
|
for s in &matches.opt_strs("L") {
|
||||||
|
search_paths.push(SearchPath::from_cli_opt(&sysroot, &target_triple, early_dcx, s));
|
||||||
|
}
|
||||||
|
|
||||||
let working_dir = std::env::current_dir().unwrap_or_else(|e| {
|
let working_dir = std::env::current_dir().unwrap_or_else(|e| {
|
||||||
early_dcx.early_fatal(format!("Current directory is invalid: {e}"));
|
early_dcx.early_fatal(format!("Current directory is invalid: {e}"));
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::filesearch::make_target_lib_path;
|
use crate::filesearch::make_target_lib_path;
|
||||||
use crate::EarlyDiagCtxt;
|
use crate::EarlyDiagCtxt;
|
||||||
|
use rustc_target::spec::TargetTriple;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -46,7 +47,12 @@ impl PathKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SearchPath {
|
impl SearchPath {
|
||||||
pub fn from_cli_opt(early_dcx: &EarlyDiagCtxt, path: &str) -> Self {
|
pub fn from_cli_opt(
|
||||||
|
sysroot: &Path,
|
||||||
|
triple: &TargetTriple,
|
||||||
|
early_dcx: &EarlyDiagCtxt,
|
||||||
|
path: &str,
|
||||||
|
) -> Self {
|
||||||
let (kind, path) = if let Some(stripped) = path.strip_prefix("native=") {
|
let (kind, path) = if let Some(stripped) = path.strip_prefix("native=") {
|
||||||
(PathKind::Native, stripped)
|
(PathKind::Native, stripped)
|
||||||
} else if let Some(stripped) = path.strip_prefix("crate=") {
|
} else if let Some(stripped) = path.strip_prefix("crate=") {
|
||||||
|
@ -60,12 +66,17 @@ impl SearchPath {
|
||||||
} else {
|
} else {
|
||||||
(PathKind::All, path)
|
(PathKind::All, path)
|
||||||
};
|
};
|
||||||
if path.is_empty() {
|
let dir = match path.strip_prefix("@RUSTC_BUILTIN") {
|
||||||
|
Some(stripped) => {
|
||||||
|
make_target_lib_path(sysroot, triple.triple()).join("builtin").join(stripped)
|
||||||
|
}
|
||||||
|
None => PathBuf::from(path),
|
||||||
|
};
|
||||||
|
if dir.as_os_str().is_empty() {
|
||||||
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
|
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
|
||||||
early_dcx.early_fatal("empty search path given via `-L`");
|
early_dcx.early_fatal("empty search path given via `-L`");
|
||||||
}
|
}
|
||||||
|
|
||||||
let dir = PathBuf::from(path);
|
|
||||||
Self::new(kind, dir)
|
Self::new(kind, dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -460,8 +460,6 @@ impl Options {
|
||||||
&matches.free[0]
|
&matches.free[0]
|
||||||
});
|
});
|
||||||
|
|
||||||
let libs =
|
|
||||||
matches.opt_strs("L").iter().map(|s| SearchPath::from_cli_opt(early_dcx, s)).collect();
|
|
||||||
let externs = parse_externs(early_dcx, matches, &unstable_opts);
|
let externs = parse_externs(early_dcx, matches, &unstable_opts);
|
||||||
let extern_html_root_urls = match parse_extern_html_roots(matches) {
|
let extern_html_root_urls = match parse_extern_html_roots(matches) {
|
||||||
Ok(ex) => ex,
|
Ok(ex) => ex,
|
||||||
|
@ -625,6 +623,20 @@ impl Options {
|
||||||
}
|
}
|
||||||
|
|
||||||
let target = parse_target_triple(early_dcx, matches);
|
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(&sysroot, &target, early_dcx, s))
|
||||||
|
.collect();
|
||||||
|
|
||||||
let show_coverage = matches.opt_present("show-coverage");
|
let show_coverage = matches.opt_present("show-coverage");
|
||||||
|
|
||||||
|
@ -653,7 +665,6 @@ impl Options {
|
||||||
let bin_crate = crate_types.contains(&CrateType::Executable);
|
let bin_crate = crate_types.contains(&CrateType::Executable);
|
||||||
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
|
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
|
||||||
let playground_url = matches.opt_str("playground-url");
|
let playground_url = matches.opt_str("playground-url");
|
||||||
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
|
|
||||||
let module_sorting = if matches.opt_present("sort-modules-by-appearance") {
|
let module_sorting = if matches.opt_present("sort-modules-by-appearance") {
|
||||||
ModuleSorting::DeclarationOrder
|
ModuleSorting::DeclarationOrder
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue