Skip to content

Commit aad9548

Browse files
committed
Auto merge of #128370 - petrochenkov:libsearch, r=<try>
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
2 parents 612a33f + 79ac35b commit aad9548

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -2065,16 +2065,16 @@ fn add_local_crate_metadata_objects(
20652065
}
20662066

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

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

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

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

compiler/rustc_session/src/filesearch.rs

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ pub struct FileSearch<'a> {
1919
}
2020

2121
impl<'a> FileSearch<'a> {
22+
pub fn cli_search_paths(&self) -> impl Iterator<Item = &'a SearchPath> {
23+
let kind = self.kind;
24+
self.cli_search_paths.iter().filter(move |sp| sp.kind.matches(kind))
25+
}
26+
2227
pub fn search_paths(&self) -> impl Iterator<Item = &'a SearchPath> {
2328
let kind = self.kind;
2429
self.cli_search_paths

0 commit comments

Comments
 (0)