rustc: Simplify getting sysroot library directory
This commit is contained in:
parent
0f6e1ae678
commit
f62b9e0179
3 changed files with 14 additions and 45 deletions
|
@ -1317,11 +1317,9 @@ fn link_sanitizer_runtime(
|
|||
name: &str,
|
||||
) {
|
||||
fn find_sanitizer_runtime(sess: &Session, filename: &str) -> PathBuf {
|
||||
let session_tlib =
|
||||
filesearch::make_target_lib_path(&sess.sysroot, sess.opts.target_triple.triple());
|
||||
let path = session_tlib.join(filename);
|
||||
let path = sess.target_tlib_path.dir.join(filename);
|
||||
if path.exists() {
|
||||
return session_tlib;
|
||||
return sess.target_tlib_path.dir.clone();
|
||||
} else {
|
||||
let default_sysroot =
|
||||
filesearch::get_or_default_sysroot().expect("Failed finding sysroot");
|
||||
|
@ -1612,19 +1610,18 @@ fn print_native_static_libs(
|
|||
}
|
||||
|
||||
fn get_object_file_path(sess: &Session, name: &str, self_contained: bool) -> PathBuf {
|
||||
let fs = sess.target_filesearch(PathKind::Native);
|
||||
let file_path = fs.get_lib_path().join(name);
|
||||
let file_path = sess.target_tlib_path.dir.join(name);
|
||||
if file_path.exists() {
|
||||
return file_path;
|
||||
}
|
||||
// Special directory with objects used only in self-contained linkage mode
|
||||
if self_contained {
|
||||
let file_path = fs.get_self_contained_lib_path().join(name);
|
||||
let file_path = sess.target_tlib_path.dir.join("self-contained").join(name);
|
||||
if file_path.exists() {
|
||||
return file_path;
|
||||
}
|
||||
}
|
||||
for search_path in fs.search_paths() {
|
||||
for search_path in sess.target_filesearch(PathKind::Native).search_paths() {
|
||||
let file_path = search_path.dir.join(name);
|
||||
if file_path.exists() {
|
||||
return file_path;
|
||||
|
@ -2131,7 +2128,7 @@ fn add_library_search_dirs(
|
|||
| LinkSelfContainedComponents::UNWIND
|
||||
| LinkSelfContainedComponents::MINGW,
|
||||
) {
|
||||
let lib_path = sess.target_filesearch(PathKind::Native).get_self_contained_lib_path();
|
||||
let lib_path = sess.target_tlib_path.dir.join("self-contained");
|
||||
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
|
||||
}
|
||||
|
||||
|
@ -2146,8 +2143,7 @@ fn add_library_search_dirs(
|
|||
|| sess.target.os == "fuchsia"
|
||||
|| sess.target.is_like_osx && !sess.opts.unstable_opts.sanitizer.is_empty()
|
||||
{
|
||||
let lib_path = sess.target_filesearch(PathKind::Native).get_lib_path();
|
||||
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
|
||||
cmd.include_path(&fix_windows_verbatim_for_gcc(&sess.target_tlib_path.dir));
|
||||
}
|
||||
|
||||
// Mac Catalyst uses the macOS SDK, but to link to iOS-specific frameworks
|
||||
|
@ -2859,15 +2855,14 @@ fn add_upstream_native_libraries(
|
|||
//
|
||||
// The returned path will always have `fix_windows_verbatim_for_gcc()` applied to it.
|
||||
fn rehome_sysroot_lib_dir(sess: &Session, lib_dir: &Path) -> PathBuf {
|
||||
let sysroot_lib_path = sess.target_filesearch(PathKind::All).get_lib_path();
|
||||
let sysroot_lib_path = &sess.target_tlib_path.dir;
|
||||
let canonical_sysroot_lib_path =
|
||||
{ try_canonicalize(&sysroot_lib_path).unwrap_or_else(|_| sysroot_lib_path.clone()) };
|
||||
{ try_canonicalize(sysroot_lib_path).unwrap_or_else(|_| sysroot_lib_path.clone()) };
|
||||
|
||||
let canonical_lib_dir = try_canonicalize(lib_dir).unwrap_or_else(|_| lib_dir.to_path_buf());
|
||||
if canonical_lib_dir == canonical_sysroot_lib_path {
|
||||
// This path, returned by `target_filesearch().get_lib_path()`, has
|
||||
// already had `fix_windows_verbatim_for_gcc()` applied if needed.
|
||||
sysroot_lib_path
|
||||
// This path already had `fix_windows_verbatim_for_gcc()` applied if needed.
|
||||
sysroot_lib_path.clone()
|
||||
} else {
|
||||
fix_windows_verbatim_for_gcc(lib_dir)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue