Improve naming and path operations in crate loader
Simplify the path operation with `join`, clarify some of the names.
This commit is contained in:
parent
4c2b21a2ef
commit
b4c439c3de
3 changed files with 14 additions and 18 deletions
|
@ -41,17 +41,13 @@ const RUST_LIB_DIR: &str = "rustlib";
|
|||
///
|
||||
/// For example: `target_sysroot_path("/usr", "x86_64-unknown-linux-gnu")` =>
|
||||
/// `"lib*/rustlib/x86_64-unknown-linux-gnu"`.
|
||||
pub fn target_rustlib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
|
||||
let libdir = find_libdir(sysroot);
|
||||
PathBuf::from_iter([
|
||||
Path::new(libdir.as_ref()),
|
||||
Path::new(RUST_LIB_DIR),
|
||||
Path::new(target_triple),
|
||||
])
|
||||
pub fn relative_target_rustlib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
|
||||
let libdir = find_relative_libdir(sysroot);
|
||||
Path::new(libdir.as_ref()).join(RUST_LIB_DIR).join(target_triple)
|
||||
}
|
||||
|
||||
/// The name of the directory rustc expects libraries to be located.
|
||||
fn find_libdir(sysroot: &Path) -> std::borrow::Cow<'static, str> {
|
||||
fn find_relative_libdir(sysroot: &Path) -> std::borrow::Cow<'static, str> {
|
||||
// FIXME: This is a quick hack to make the rustc binary able to locate
|
||||
// Rust libraries in Linux environments where libraries might be installed
|
||||
// to lib64/lib32. This would be more foolproof by basing the sysroot off
|
||||
|
|
|
@ -3367,7 +3367,7 @@ impl Target {
|
|||
|
||||
// Additionally look in the sysroot under `lib/rustlib/<triple>/target.json`
|
||||
// as a fallback.
|
||||
let rustlib_path = crate::target_rustlib_path(sysroot, target_triple);
|
||||
let rustlib_path = crate::relative_target_rustlib_path(sysroot, target_triple);
|
||||
let p = PathBuf::from_iter([
|
||||
Path::new(sysroot),
|
||||
Path::new(&rustlib_path),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue