Skip to content

Commit 8b387d8

Browse files
committed
Deduplicate -L paths passed to rustc
1 parent be00ea1 commit 8b387d8

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2828,16 +2828,27 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28282828
// This is the location used by the `rustc-dev` `rustup` component.
28292829
real_source_base_dir("lib/rustlib/rustc-src/rust", "compiler/rustc/src/main.rs");
28302830

2831-
let mut search_paths = vec![];
2832-
for s in &matches.opt_strs("L") {
2833-
search_paths.push(SearchPath::from_cli_opt(
2834-
sysroot.path(),
2835-
&target_triple,
2836-
early_dcx,
2837-
s,
2838-
unstable_opts.unstable_options,
2839-
));
2840-
}
2831+
// We eagerly scan all files in each passed -L path. If the same directory is passed multiple
2832+
// times, and the directory contains a lot of files, this can take a lot of time.
2833+
// So we remove -L paths that were passed multiple times, and keep only the first occurrence.
2834+
// We still have to keep the original order of the -L arguments.
2835+
let search_paths: Vec<SearchPath> = {
2836+
let mut seen_search_paths = FxHashSet::default();
2837+
let search_path_matches: Vec<String> = matches.opt_strs("L");
2838+
search_path_matches
2839+
.iter()
2840+
.filter(|p| seen_search_paths.insert(*p))
2841+
.map(|path| {
2842+
SearchPath::from_cli_opt(
2843+
sysroot.path(),
2844+
&target_triple,
2845+
early_dcx,
2846+
&path,
2847+
unstable_opts.unstable_options,
2848+
)
2849+
})
2850+
.collect()
2851+
};
28412852

28422853
let working_dir = std::env::current_dir().unwrap_or_else(|e| {
28432854
early_dcx.early_fatal(format!("Current directory is invalid: {e}"));

0 commit comments

Comments
 (0)