Skip to content

Commit deab78d

Browse files
committed
fix: Filter out directories that do not contain dylibs
This is an optimization to reduce the amount for paths that get added to the dylib search path. This is especially important for Windows as it has issues when PATH gets too long. With the new Cargo build-dir we increased the number of paths being passed.
1 parent 862d0a6 commit deab78d

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

  • src/bootstrap/src/core/build_steps

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,8 +1622,9 @@ impl Builder<'_> {
16221622
//
16231623
// Notably this munges the dynamic library lookup path to point to the
16241624
// right location to run `compiler`.
1625-
let mut lib_paths: Vec<PathBuf> =
1626-
discover_out_dirs(self.cargo_out(compiler, Mode::ToolBootstrap, *host).join("build"));
1625+
let mut lib_paths: Vec<PathBuf> = discover_out_dirs_with_dylibs(
1626+
self.cargo_out(compiler, Mode::ToolBootstrap, *host).join("build"),
1627+
);
16271628

16281629
// On MSVC a tool may invoke a C compiler (e.g., compiletest in run-make
16291630
// mode) and that C compiler may need some extra PATH modification. Do
@@ -1653,18 +1654,21 @@ impl Builder<'_> {
16531654
}
16541655

16551656
/// Gets all of the `out` dirs in a given Cargo `build-dir/<profile>/build` dir.
1656-
fn discover_out_dirs(dir: PathBuf) -> Vec<PathBuf> {
1657+
fn discover_out_dirs_with_dylibs(dir: PathBuf) -> Vec<PathBuf> {
16571658
if !dir.exists() {
16581659
return Vec::new();
16591660
}
1660-
16611661
let read_dir = |path: &Path| path.read_dir().ok().into_iter().flatten().filter_map(Result::ok);
1662+
let has_dylib = |path: &Path| {
1663+
read_dir(path)
1664+
.any(|e| e.path().extension().is_some_and(|ext| ext == std::env::consts::DLL_EXTENSION))
1665+
};
16621666
dir.read_dir()
16631667
.unwrap_or_else(|e| panic!("Couldn't read {}: {}", dir.display(), e))
16641668
.map(|e| e.unwrap())
16651669
.flat_map(|e| read_dir(&e.path()))
16661670
.flat_map(|e| read_dir(&e.path()))
16671671
.map(|e| e.path())
1668-
.filter(|path| path.ends_with("out"))
1672+
.filter(|path| path.ends_with("out") && has_dylib(path))
16691673
.collect::<Vec<_>>()
16701674
}

0 commit comments

Comments
 (0)