Skip to content

Commit

Permalink
Auto merge of rust-lang#128370 - petrochenkov:libsearch, r=<try>
Browse files Browse the repository at this point in the history
linker: Pass fewer search directories to the linker

Work in progress.

try-job: dist-x86_64-musl
try-job: dist-x86_64-mingw
try-job: dist-x86_64-msvc
try-job: dist-x86_64-apple
try-job: dist-various-1
try-job: dist-various-2
  • Loading branch information
bors committed Jul 29, 2024
2 parents 612a33f + 79ac35b commit aad9548
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
31 changes: 15 additions & 16 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2065,16 +2065,16 @@ fn add_local_crate_metadata_objects(
}

/// Add sysroot and other globally set directories to the directory search list.
fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session, self_contained: bool) {
fn add_library_search_dirs(_cmd: &mut dyn Linker, sess: &Session, self_contained: bool) {
// The default library location, we need this to find the runtime.
// The location of crates will be determined as needed.
let lib_path = sess.target_filesearch(PathKind::All).get_lib_path();
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
let _lib_path = sess.target_filesearch(PathKind::All).get_lib_path();
// cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));

// Special directory with libraries used only in self-contained linkage mode
if self_contained {
let lib_path = sess.target_filesearch(PathKind::All).get_self_contained_lib_path();
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
let _lib_path = sess.target_filesearch(PathKind::All).get_self_contained_lib_path();
// cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
}
}

Expand Down Expand Up @@ -2638,14 +2638,13 @@ fn add_local_native_libraries(
link_output_kind: LinkOutputKind,
) {
if sess.opts.unstable_opts.link_native_libraries {
// User-supplied library search paths (-L on the command line). These are the same paths
// used to find Rust crates, so some of them may have been added already by the previous
// crate linking code. This only allows them to be found at compile time so it is still
// entirely up to outside forces to make sure that library can be found at runtime.
for search_path in sess.target_filesearch(PathKind::All).search_paths() {
match search_path.kind {
PathKind::Framework => cmd.framework_path(&search_path.dir),
_ => cmd.include_path(&fix_windows_verbatim_for_gcc(&search_path.dir)),
for search_path in sess.target_filesearch(PathKind::Native).cli_search_paths() {
cmd.include_path(&fix_windows_verbatim_for_gcc(&search_path.dir));
}
for search_path in sess.target_filesearch(PathKind::Framework).cli_search_paths() {
// Contrary to the `-L` docs only framework-specific paths are considered here.
if search_path.kind != PathKind::All {
cmd.framework_path(&search_path.dir);
}
}
}
Expand Down Expand Up @@ -3012,9 +3011,9 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
// search path.

// The flags are called `-L` and `-F` both in Clang, ld64 and ldd.
let sdk_root = Path::new(&sdk_root);
cmd.include_path(&sdk_root.join("System/iOSSupport/usr/lib"));
cmd.framework_path(&sdk_root.join("System/iOSSupport/System/Library/Frameworks"));
// let sdk_root = Path::new(&sdk_root);
// cmd.include_path(&sdk_root.join("System/iOSSupport/usr/lib"));
// cmd.framework_path(&sdk_root.join("System/iOSSupport/System/Library/Frameworks"));
}
}

Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_session/src/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ pub struct FileSearch<'a> {
}

impl<'a> FileSearch<'a> {
pub fn cli_search_paths(&self) -> impl Iterator<Item = &'a SearchPath> {
let kind = self.kind;
self.cli_search_paths.iter().filter(move |sp| sp.kind.matches(kind))
}

pub fn search_paths(&self) -> impl Iterator<Item = &'a SearchPath> {
let kind = self.kind;
self.cli_search_paths
Expand Down

0 comments on commit aad9548

Please sign in to comment.