Skip to content

Commit c5101b6

Browse files
committed
Revert "Auto merge of #57101 - o01eg:fix-57014, r=alexcrichton"
This reverts commit 6861426, reversing changes made to cae623c. Should fix tools on windows. Reopens #57014
1 parent 495fc5e commit c5101b6

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

src/librustc/session/filesearch.rs

-7
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,6 @@ pub fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
114114
sysroot.join(&relative_target_lib_path(sysroot, target_triple))
115115
}
116116

117-
pub fn target_lib_path(target_triple: &str) -> PathBuf {
118-
let mut p = PathBuf::from(RUST_LIB_DIR);
119-
p.push(target_triple);
120-
p.push("lib");
121-
p
122-
}
123-
124117
pub fn get_or_default_sysroot() -> PathBuf {
125118
// Follow symlinks. If the resolved path is relative, make it absolute.
126119
fn canonicalize(path: Option<PathBuf>) -> Option<PathBuf> {

src/librustc_driver/lib.rs

+21-19
Original file line numberDiff line numberDiff line change
@@ -269,35 +269,37 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
269269
}
270270

271271
let target = session::config::host_triple();
272-
// get target libdir path based on executable binary path
273-
let sysroot = filesearch::get_or_default_sysroot();
274-
let mut libdir_candidates = vec![filesearch::make_target_lib_path(&sysroot, &target)];
272+
let mut sysroot_candidates = vec![filesearch::get_or_default_sysroot()];
275273
let path = current_dll_path()
276274
.and_then(|s| s.canonicalize().ok());
277275
if let Some(dll) = path {
278-
// use `parent` once to chop off the file name
279-
if let Some(path) = dll.parent() {
276+
// use `parent` twice to chop off the file name and then also the
277+
// directory containing the dll which should be either `lib` or `bin`.
278+
if let Some(path) = dll.parent().and_then(|p| p.parent()) {
280279
// The original `path` pointed at the `rustc_driver` crate's dll.
281280
// Now that dll should only be in one of two locations. The first is
282-
// in the compiler's libdir, for example `$sysroot/$libdir/*.dll`. The
281+
// in the compiler's libdir, for example `$sysroot/lib/*.dll`. The
283282
// other is the target's libdir, for example
284-
// `$sysroot/$libdir/rustlib/$target/lib/*.dll`.
283+
// `$sysroot/lib/rustlib/$target/lib/*.dll`.
285284
//
286285
// We don't know which, so let's assume that if our `path` above
287-
// doesn't end in `$target` we *could* be in the main libdir, and always
288-
// assume that we may be in the target libdir.
289-
libdir_candidates.push(path.to_owned());
290-
291-
if !path.parent().map_or(false, |p| p.ends_with(target)) {
292-
libdir_candidates.push(path.join(filesearch::target_lib_path(target)));
286+
// ends in `$target` we *could* be in the target libdir, and always
287+
// assume that we may be in the main libdir.
288+
sysroot_candidates.push(path.to_owned());
289+
290+
if path.ends_with(target) {
291+
sysroot_candidates.extend(path.parent() // chop off `$target`
292+
.and_then(|p| p.parent()) // chop off `rustlib`
293+
.and_then(|p| p.parent()) // chop off `lib`
294+
.map(|s| s.to_owned()));
293295
}
294296
}
295297
}
296298

297-
let sysroot = libdir_candidates.iter()
298-
.map(|libdir| {
299-
debug!("Trying target libdir: {}", libdir.display());
300-
libdir.with_file_name(
299+
let sysroot = sysroot_candidates.iter()
300+
.map(|sysroot| {
301+
let libdir = filesearch::relative_target_lib_path(&sysroot, &target);
302+
sysroot.join(libdir).with_file_name(
301303
option_env!("CFG_CODEGEN_BACKENDS_DIR").unwrap_or("codegen-backends"))
302304
})
303305
.filter(|f| {
@@ -306,12 +308,12 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
306308
})
307309
.next();
308310
let sysroot = sysroot.unwrap_or_else(|| {
309-
let candidates = libdir_candidates.iter()
311+
let candidates = sysroot_candidates.iter()
310312
.map(|p| p.display().to_string())
311313
.collect::<Vec<_>>()
312314
.join("\n* ");
313315
let err = format!("failed to find a `codegen-backends` folder \
314-
in the libdir candidates:\n* {}", candidates);
316+
in the sysroot candidates:\n* {}", candidates);
315317
early_error(ErrorOutputType::default(), &err);
316318
});
317319
info!("probing {} for a codegen backend", sysroot.display());

0 commit comments

Comments
 (0)