Skip to content

Commit 0670b60

Browse files
committed
Use the rust-std manifest file in build_llvm_sysroot_for_triple
This is far more accurate than filtering based on filename and as such allows building the sysroot a bit quicker. In addition the code is a bit simpler.
1 parent 8ad6e38 commit 0670b60

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

build_system/build_sysroot.rs

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -161,35 +161,18 @@ fn build_sysroot_for_triple(
161161
fn build_llvm_sysroot_for_triple(compiler: Compiler) -> SysrootTarget {
162162
let default_sysroot = crate::rustc_info::get_default_sysroot(&compiler.rustc);
163163

164-
let mut target_libs = SysrootTarget { triple: compiler.triple, libs: vec![] };
165-
166-
for entry in fs::read_dir(
167-
default_sysroot.join("lib").join("rustlib").join(&target_libs.triple).join("lib"),
168-
)
169-
.unwrap()
170-
{
171-
let entry = entry.unwrap();
172-
if entry.file_type().unwrap().is_dir() {
173-
continue;
174-
}
175-
let file = entry.path();
176-
let file_name_str = file.file_name().unwrap().to_str().unwrap();
177-
if (file_name_str.contains("rustc_")
178-
&& !file_name_str.contains("rustc_std_workspace_")
179-
&& !file_name_str.contains("rustc_demangle")
180-
&& !file_name_str.contains("rustc_literal_escaper"))
181-
|| file_name_str.contains("chalk")
182-
|| file_name_str.contains("tracing")
183-
|| file_name_str.contains("regex")
184-
{
185-
// These are large crates that are part of the rustc-dev component and are not
186-
// necessary to run regular programs.
187-
continue;
188-
}
189-
target_libs.libs.push(file);
190-
}
191-
192-
target_libs
164+
let std_manifest_path = default_sysroot
165+
.join("lib")
166+
.join("rustlib")
167+
.join(format!("manifest-rust-std-{}", compiler.triple));
168+
169+
let libs = fs::read_to_string(std_manifest_path)
170+
.unwrap()
171+
.lines()
172+
.map(|entry| default_sysroot.join(entry.strip_prefix("file:").unwrap()))
173+
.collect();
174+
175+
SysrootTarget { triple: compiler.triple, libs }
193176
}
194177

195178
fn build_clif_sysroot_for_triple(

0 commit comments

Comments
 (0)