Skip to content

Commit 56c1718

Browse files
committed
Address review
1 parent 2a4fcf7 commit 56c1718

File tree

1 file changed

+45
-44
lines changed
  • src/librustc_codegen_ssa/back

1 file changed

+45
-44
lines changed

src/librustc_codegen_ssa/back/link.rs

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -978,58 +978,59 @@ fn get_crt_libs_path(sess: &Session) -> Option<PathBuf> {
978978
where
979979
P: AsRef<Path>,
980980
{
981-
env::var_os("PATH").and_then(|paths| {
982-
env::split_paths(&paths)
983-
.filter_map(|dir| {
984-
let full_path = dir.join(&exe_name);
985-
if full_path.is_file() {
986-
Some(fix_windows_verbatim_for_gcc(&full_path))
987-
} else {
988-
None
989-
}
990-
})
991-
.next()
992-
})
981+
for dir in env::split_paths(&env::var_os("PATH")?) {
982+
let full_path = dir.join(&exe_name);
983+
if full_path.is_file() {
984+
return Some(fix_windows_verbatim_for_gcc(&full_path));
985+
}
986+
}
987+
None
988+
}
989+
990+
fn probe(sess: &Session) -> Option<PathBuf> {
991+
if let (linker, LinkerFlavor::Gcc) = linker_and_flavor(&sess) {
992+
let linker_path = if cfg!(windows) && !linker.extension().is_some() {
993+
linker.with_extension("exe")
994+
} else {
995+
linker
996+
};
997+
if let Some(linker_path) = find_exe_in_path(linker_path) {
998+
let mingw_arch = match &sess.target.target.arch {
999+
x if x == "x86" => "i686",
1000+
x => x,
1001+
};
1002+
let mingw_dir = format!("{}-w64-mingw32", mingw_arch);
1003+
// Here we have path/bin/gcc but we need path/
1004+
let mut path = linker_path;
1005+
path.pop();
1006+
path.pop();
1007+
// Based on Clang MinGW driver
1008+
let probe_path = path.join(&mingw_dir).join("lib");
1009+
if probe_path.exists() {
1010+
*SYSTEM_LIBS.lock().unwrap() = Some(Some(probe_path.clone()));
1011+
return Some(probe_path);
1012+
};
1013+
let probe_path = path.join(&mingw_dir).join("sys-root/mingw/lib");
1014+
if probe_path.exists() {
1015+
*SYSTEM_LIBS.lock().unwrap() = Some(Some(probe_path.clone()));
1016+
return Some(probe_path);
1017+
};
1018+
};
1019+
};
1020+
*SYSTEM_LIBS.lock().unwrap() = Some(None);
1021+
None
9931022
}
9941023

9951024
use std::sync::Mutex;
9961025
lazy_static::lazy_static! {
997-
static ref SYSTEM_LIBS: Mutex<Option<Result<PathBuf, ()>>> = Mutex::new(None);
1026+
static ref SYSTEM_LIBS: Mutex<Option<Option<PathBuf>>> = Mutex::new(None);
9981027
}
9991028

10001029
let system_libs = SYSTEM_LIBS.lock().unwrap().clone();
10011030
match system_libs {
1002-
Some(Ok(compiler_libs_path)) => Some(compiler_libs_path),
1003-
Some(Err(_)) => None,
1004-
_ => {
1005-
if let (linker, LinkerFlavor::Gcc) = linker_and_flavor(&sess) {
1006-
let linker_path = if cfg!(windows) { linker.with_extension("exe") } else { linker };
1007-
if let Some(linker_path) = find_exe_in_path(linker_path) {
1008-
let mingw_arch = match &sess.target.target.arch {
1009-
x if x == "x86" => "i686",
1010-
x => x,
1011-
};
1012-
let mingw_dir = [mingw_arch, "-w64-mingw32"].concat();
1013-
// Here we have path/bin/gcc but we need path/
1014-
let mut path = linker_path;
1015-
path.pop();
1016-
path.pop();
1017-
// Based on Clang MinGW driver
1018-
let probe_path = path.join([&mingw_dir, "lib"].concat());
1019-
if probe_path.exists() {
1020-
*SYSTEM_LIBS.lock().unwrap() = Some(Ok(probe_path.clone()));
1021-
return Some(probe_path);
1022-
};
1023-
let probe_path = path.join([&mingw_dir, "sys-root/mingw/lib"].concat());
1024-
if probe_path.exists() {
1025-
*SYSTEM_LIBS.lock().unwrap() = Some(Ok(probe_path.clone()));
1026-
return Some(probe_path);
1027-
};
1028-
};
1029-
};
1030-
*SYSTEM_LIBS.lock().unwrap() = Some(Err(()));
1031-
None
1032-
}
1031+
Some(Some(compiler_libs_path)) => Some(compiler_libs_path),
1032+
Some(None) => None,
1033+
None => probe(sess),
10331034
}
10341035
}
10351036

0 commit comments

Comments
 (0)