Skip to content

Commit 0282cd8

Browse files
committed
Also cache case when there is no system linker
1 parent e834aaa commit 0282cd8

File tree

1 file changed

+23
-20
lines changed
  • src/librustc_codegen_ssa/back

1 file changed

+23
-20
lines changed

src/librustc_codegen_ssa/back/link.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -977,31 +977,34 @@ fn get_crt_libs_path(sess: &Session) -> Option<PathBuf> {
977977
use std::sync::Mutex;
978978

979979
lazy_static::lazy_static! {
980-
static ref SYSTEM_LIBS: Mutex<Option<PathBuf>> = Mutex::new(None);
980+
static ref SYSTEM_LIBS: Mutex<Option<Result<PathBuf, ()>>> = Mutex::new(None);
981981
}
982982

983983
let system_libs = SYSTEM_LIBS.lock().unwrap().clone();
984-
if let Some(compiler_libs_path) = system_libs {
985-
return Some(compiler_libs_path);
986-
} else {
987-
let compiler = if let Some(linker) = &sess.opts.cg.linker {
988-
linker.clone().into_os_string()
989-
} else if let Some(linker) = &sess.target.target.options.linker {
990-
linker.into()
991-
} else {
992-
return None;
993-
};
994-
if let Ok(output) = Command::new(compiler).arg("-print-file-name=crt2.o").output() {
995-
if let Some(compiler_libs_path) =
996-
PathBuf::from(std::str::from_utf8(&output.stdout).unwrap()).parent()
997-
{
998-
let compiler_libs_path = fix_windows_verbatim_for_gcc(compiler_libs_path);
999-
*SYSTEM_LIBS.lock().unwrap() = Some(compiler_libs_path.clone());
1000-
return Some(compiler_libs_path);
1001-
}
984+
match system_libs {
985+
Some(Ok(compiler_libs_path)) => Some(compiler_libs_path),
986+
Some(Err(_)) => None,
987+
_ => {
988+
let compiler = if let Some(linker) = &sess.opts.cg.linker {
989+
linker.clone().into_os_string()
990+
} else if let Some(linker) = &sess.target.target.options.linker {
991+
linker.into()
992+
} else {
993+
*SYSTEM_LIBS.lock().unwrap() = Some(Err(()));
994+
return None;
995+
};
996+
if let Ok(output) = Command::new(compiler).arg("-print-file-name=crt2.o").output() {
997+
if let Some(compiler_libs_path) =
998+
PathBuf::from(std::str::from_utf8(&output.stdout).unwrap()).parent()
999+
{
1000+
let compiler_libs_path = fix_windows_verbatim_for_gcc(compiler_libs_path);
1001+
*SYSTEM_LIBS.lock().unwrap() = Some(Ok(compiler_libs_path.clone()));
1002+
return Some(compiler_libs_path);
1003+
}
1004+
};
1005+
None
10021006
}
10031007
}
1004-
None
10051008
}
10061009

10071010
pub fn get_file_path(sess: &Session, name: &str) -> PathBuf {

0 commit comments

Comments
 (0)