1 //! Locating various executables part of a C toolchain. 2 3 use std::path::PathBuf; 4 5 use rustc_codegen_ssa::back::link::linker_and_flavor; 6 use rustc_session::Session; 7 8 /// Tries to infer the path of a binary for the target toolchain from the linker name. get_toolchain_binary(sess: &Session, tool: &str) -> PathBuf9pub(crate) fn get_toolchain_binary(sess: &Session, tool: &str) -> PathBuf { 10 let (mut linker, _linker_flavor) = linker_and_flavor(sess); 11 let linker_file_name = 12 linker.file_name().unwrap().to_str().expect("linker filename should be valid UTF-8"); 13 14 if linker_file_name == "ld.lld" { 15 if tool != "ld" { 16 linker.set_file_name(tool) 17 } 18 } else { 19 let tool_file_name = linker_file_name 20 .replace("ld", tool) 21 .replace("gcc", tool) 22 .replace("clang", tool) 23 .replace("cc", tool); 24 25 linker.set_file_name(tool_file_name) 26 } 27 28 linker 29 } 30