Implement -L builtin:$path
This commit is contained in:
parent
35936c4839
commit
91547573af
4 changed files with 68 additions and 28 deletions
|
@ -2795,11 +2795,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
|
|||
let debuginfo = select_debuginfo(matches, &cg);
|
||||
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 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)
|
||||
};
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
let working_dir = std::env::current_dir().unwrap_or_else(|e| {
|
||||
early_dcx.early_fatal(format!("Current directory is invalid: {e}"));
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::filesearch::make_target_lib_path;
|
||||
use crate::EarlyDiagCtxt;
|
||||
use rustc_target::spec::TargetTriple;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -46,7 +47,12 @@ impl PathKind {
|
|||
}
|
||||
|
||||
impl SearchPath {
|
||||
pub fn from_cli_opt(early_dcx: &EarlyDiagCtxt, path: &str) -> Self {
|
||||
pub fn from_cli_opt(
|
||||
sysroot: Option<&Path>,
|
||||
triple: &TargetTriple,
|
||||
early_dcx: &EarlyDiagCtxt,
|
||||
path: &str,
|
||||
) -> Self {
|
||||
let (kind, path) = if let Some(stripped) = path.strip_prefix("native=") {
|
||||
(PathKind::Native, stripped)
|
||||
} else if let Some(stripped) = path.strip_prefix("crate=") {
|
||||
|
@ -57,6 +63,27 @@ impl SearchPath {
|
|||
(PathKind::Framework, stripped)
|
||||
} 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);
|
||||
if !path.is_dir() {
|
||||
early_dcx.early_fatal(format!("builtin:{stripped} does not exist"));
|
||||
}
|
||||
|
||||
return Self::new(PathKind::All, path);
|
||||
} else {
|
||||
(PathKind::All, path)
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue