address review comments
This commit is contained in:
parent
eb74f21f5a
commit
a0911cf95d
@ -69,18 +69,13 @@ pub fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> (PathB
|
||||
// This worked historically but is needed manually since #42436 (regression
|
||||
// was tagged as #42791) and some more info can be found on #44443 for
|
||||
// emscripten itself.
|
||||
let mut cmd = (|| {
|
||||
if let Some(linker) = linker.to_str() {
|
||||
if cfg!(windows) && linker.ends_with(".bat") {
|
||||
return Command::bat_script(linker)
|
||||
}
|
||||
}
|
||||
match flavor {
|
||||
let mut cmd = match linker.to_str() {
|
||||
Some(linker) if cfg!(windows) && linker.ends_with(".bat") => Command::bat_script(linker),
|
||||
_ => match flavor {
|
||||
LinkerFlavor::Lld(f) => Command::lld(linker, f),
|
||||
_ => Command::new(linker),
|
||||
|
||||
}
|
||||
})();
|
||||
};
|
||||
|
||||
let msvc_tool = windows_registry::find_tool(&sess.opts.target_triple.triple(), "link.exe");
|
||||
|
||||
@ -600,33 +595,26 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLibrary]) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn linker_and_flavor(sess: &Session) -> Result<(PathBuf, LinkerFlavor), ()> {
|
||||
fn from<F>(
|
||||
pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
|
||||
fn infer_from(
|
||||
sess: &Session,
|
||||
linker: Option<PathBuf>,
|
||||
flavor: Option<LinkerFlavor>,
|
||||
otherwise: F,
|
||||
) -> Result<(PathBuf, LinkerFlavor), ()>
|
||||
where
|
||||
F: FnOnce() -> Result<(PathBuf, LinkerFlavor), ()>
|
||||
{
|
||||
) -> Option<(PathBuf, LinkerFlavor)> {
|
||||
match (linker, flavor) {
|
||||
(Some(linker), Some(flavor)) => Ok((linker, flavor)),
|
||||
(Some(linker), Some(flavor)) => Some((linker, flavor)),
|
||||
// only the linker flavor is known; use the default linker for the selected flavor
|
||||
(None, Some(flavor)) => Ok((PathBuf::from(match flavor {
|
||||
LinkerFlavor::Em => "emcc",
|
||||
(None, Some(flavor)) => Some((PathBuf::from(match flavor {
|
||||
LinkerFlavor::Em => if cfg!(windows) { "emcc.bat" } else { "emcc" },
|
||||
LinkerFlavor::Gcc => "gcc",
|
||||
LinkerFlavor::Ld => "ld",
|
||||
LinkerFlavor::Msvc => "link.exe",
|
||||
LinkerFlavor::Lld(_) => "lld",
|
||||
}), flavor)),
|
||||
// infer the linker flavor from the linker name
|
||||
(Some(linker), None) => {
|
||||
let stem = linker.file_stem().and_then(|stem| stem.to_str()).ok_or_else(|| {
|
||||
sess
|
||||
.struct_err(&format!("couldn't extract file stem from specified linker"))
|
||||
.emit();
|
||||
})?.to_owned();
|
||||
let stem = linker.file_stem().and_then(|stem| stem.to_str()).unwrap_or_else(|| {
|
||||
sess.fatal("couldn't extract file stem from specified linker");
|
||||
}).to_owned();
|
||||
|
||||
let flavor = if stem == "emcc" {
|
||||
LinkerFlavor::Em
|
||||
@ -637,32 +625,35 @@ pub fn linker_and_flavor(sess: &Session) -> Result<(PathBuf, LinkerFlavor), ()>
|
||||
} else if stem == "link" || stem == "lld-link" {
|
||||
LinkerFlavor::Msvc
|
||||
} else {
|
||||
sess
|
||||
.struct_err(&format!("couldn't infer linker flavor from specified linker"))
|
||||
.emit();
|
||||
return Err(());
|
||||
// fall back to the value in the target spec
|
||||
sess.target.target.linker_flavor
|
||||
};
|
||||
|
||||
Ok((linker, flavor))
|
||||
Some((linker, flavor))
|
||||
},
|
||||
(None, None) => otherwise(),
|
||||
(None, None) => None,
|
||||
}
|
||||
}
|
||||
|
||||
// linker and linker flavor specified via command line have precedence over what the target
|
||||
// specification specifies
|
||||
from(sess, sess.opts.cg.linker.clone(), sess.opts.debugging_opts.linker_flavor, || {
|
||||
from(
|
||||
sess,
|
||||
sess.target.target.options.linker.clone().map(PathBuf::from),
|
||||
Some(sess.target.target.linker_flavor),
|
||||
|| {
|
||||
sess
|
||||
.struct_err(&format!("no linker or linker flavor information provided"))
|
||||
.emit();
|
||||
Err(())
|
||||
})
|
||||
})
|
||||
if let Some(ret) = infer_from(
|
||||
sess,
|
||||
sess.opts.cg.linker.clone(),
|
||||
sess.opts.debugging_opts.linker_flavor,
|
||||
) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if let Some(ret) = infer_from(
|
||||
sess,
|
||||
sess.target.target.options.linker.clone().map(PathBuf::from),
|
||||
Some(sess.target.target.linker_flavor),
|
||||
) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
sess.fatal("Not enough information provided to determine how to invoke the linker");
|
||||
}
|
||||
|
||||
// Create a dynamic library or executable
|
||||
@ -675,12 +666,7 @@ fn link_natively(sess: &Session,
|
||||
codegen_results: &CodegenResults,
|
||||
tmpdir: &Path) {
|
||||
info!("preparing {:?} to {:?}", crate_type, out_filename);
|
||||
let (linker, flavor) = if let Ok((linker, flavor)) = linker_and_flavor(sess) {
|
||||
(linker, flavor)
|
||||
} else {
|
||||
sess.abort_if_errors();
|
||||
return;
|
||||
};
|
||||
let (linker, flavor) = linker_and_flavor(sess);
|
||||
|
||||
// The invocations of cc share some flags across platforms
|
||||
let (pname, mut cmd) = get_linker(sess, &linker, flavor);
|
||||
|
@ -1503,17 +1503,14 @@ fn start_executing_work(tcx: TyCtxt,
|
||||
|
||||
let assembler_cmd = if modules_config.no_integrated_as {
|
||||
// HACK: currently we use linker (gcc) as our assembler
|
||||
if let Ok((linker, flavor)) = link::linker_and_flavor(sess) {
|
||||
let (name, mut cmd) = get_linker(sess, &linker, flavor);
|
||||
cmd.args(&sess.target.target.options.asm_args);
|
||||
Some(Arc::new(AssemblerCommand {
|
||||
name,
|
||||
cmd,
|
||||
}))
|
||||
} else {
|
||||
sess.abort_if_errors();
|
||||
None
|
||||
}
|
||||
let (linker, flavor) = link::linker_and_flavor(sess);
|
||||
|
||||
let (name, mut cmd) = get_linker(sess, &linker, flavor);
|
||||
cmd.args(&sess.target.target.options.asm_args);
|
||||
Some(Arc::new(AssemblerCommand {
|
||||
name,
|
||||
cmd,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user