Support dylibs
This commit is contained in:
parent
3441f6b5ba
commit
bd4b307b42
3 changed files with 38 additions and 12 deletions
|
@ -267,7 +267,7 @@ fn codegen_fn_content<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>)
|
|||
drop_place.write_place_ref(fx, arg_place);
|
||||
match ty.sty {
|
||||
ty::Dynamic(..) => {
|
||||
unimpl!("Drop for trait object");
|
||||
fx.tcx.sess.warn("Drop for trait object");
|
||||
}
|
||||
_ => {
|
||||
let drop_fn_ty = drop_fn.ty(fx.tcx);
|
||||
|
|
|
@ -312,7 +312,9 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
|||
let output_name = out_filename(sess, crate_type, &outputs, &res.crate_name.as_str());
|
||||
match crate_type {
|
||||
CrateType::Rlib => link::link_rlib(sess, &res, output_name),
|
||||
CrateType::Executable => link::link_bin(sess, &res, &output_name),
|
||||
CrateType::Dylib | CrateType::Executable => {
|
||||
link::link_natively(sess, crate_type, &res, &output_name);
|
||||
}
|
||||
_ => sess.fatal(&format!("Unsupported crate type: {:?}", crate_type)),
|
||||
}
|
||||
}
|
||||
|
|
44
src/link.rs
44
src/link.rs
|
@ -1,7 +1,10 @@
|
|||
use std::ascii;
|
||||
use std::char;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str;
|
||||
|
||||
use tempfile::Builder as TempFileBuilder;
|
||||
|
||||
|
@ -65,13 +68,20 @@ pub(crate) fn link_rlib(sess: &Session, res: &CodegenResults, output_name: PathB
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn link_bin(sess: &Session, codegen_results: &CodegenResults, out_filename: &Path) {
|
||||
pub(crate) fn link_natively(
|
||||
sess: &Session,
|
||||
crate_type: CrateType,
|
||||
codegen_results: &CodegenResults,
|
||||
out_filename: &Path,
|
||||
) {
|
||||
let tmpdir = match TempFileBuilder::new().prefix("rustc").tempdir() {
|
||||
Ok(tmpdir) => tmpdir,
|
||||
Err(err) => sess.fatal(&format!("couldn't create a temp dir: {}", err)),
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
let root = sess.target_filesearch(PathKind::Native).get_lib_path();
|
||||
|
@ -88,11 +98,16 @@ pub(crate) fn link_bin(sess: &Session, codegen_results: &CodegenResults, out_fil
|
|||
}
|
||||
cmd.args(&sess.opts.debugging_opts.pre_link_arg);
|
||||
|
||||
for obj in &sess.target.target.options.pre_link_objects_exe {
|
||||
let pre_link_objects = if crate_type == config::CrateType::Executable {
|
||||
&sess.target.target.options.pre_link_objects_exe
|
||||
} else {
|
||||
&sess.target.target.options.pre_link_objects_dll
|
||||
};
|
||||
for obj in pre_link_objects {
|
||||
cmd.arg(root.join(obj));
|
||||
}
|
||||
|
||||
if sess.crt_static() {
|
||||
if crate_type == config::CrateType::Executable && sess.crt_static() {
|
||||
for obj in &sess.target.target.options.pre_link_objects_exe_crt {
|
||||
cmd.arg(root.join(obj));
|
||||
}
|
||||
|
@ -108,9 +123,9 @@ pub(crate) fn link_bin(sess: &Session, codegen_results: &CodegenResults, out_fil
|
|||
}
|
||||
|
||||
{
|
||||
let target_cpu = "x86_64-apple-darwin"; //::llvm_util::target_cpu(sess);
|
||||
let mut linker = codegen_results.linker_info.to_linker(cmd, &sess, flavor, target_cpu);
|
||||
link_args(&mut *linker, flavor, sess, CrateType::Executable, tmpdir.path(),
|
||||
let target_cpu = ::target_lexicon::HOST.to_string();
|
||||
let mut linker = codegen_results.linker_info.to_linker(cmd, &sess, flavor, &target_cpu);
|
||||
link_args(&mut *linker, flavor, sess, crate_type, tmpdir.path(),
|
||||
out_filename, codegen_results);
|
||||
cmd = linker.finalize();
|
||||
}
|
||||
|
@ -203,6 +218,16 @@ pub(crate) fn link_bin(sess: &Session, codegen_results: &CodegenResults, out_fil
|
|||
|
||||
match prog {
|
||||
Ok(prog) => {
|
||||
fn escape_string(s: &[u8]) -> String {
|
||||
str::from_utf8(s).map(|s| s.to_owned())
|
||||
.unwrap_or_else(|_| {
|
||||
let mut x = "Non-UTF-8 output: ".to_string();
|
||||
x.extend(s.iter()
|
||||
.flat_map(|&b| ascii::escape_default(b))
|
||||
.map(char::from));
|
||||
x
|
||||
})
|
||||
}
|
||||
if !prog.status.success() {
|
||||
let mut output = prog.stderr.clone();
|
||||
output.extend_from_slice(&prog.stdout);
|
||||
|
@ -210,7 +235,7 @@ pub(crate) fn link_bin(sess: &Session, codegen_results: &CodegenResults, out_fil
|
|||
pname.display(),
|
||||
prog.status))
|
||||
.note(&format!("{:?}", &cmd))
|
||||
.note(&String::from_utf8_lossy(&output))
|
||||
.note(&escape_string(&output))
|
||||
.emit();
|
||||
sess.abort_if_errors();
|
||||
}
|
||||
|
@ -251,9 +276,8 @@ pub(crate) fn link_bin(sess: &Session, codegen_results: &CodegenResults, out_fil
|
|||
if sess.target.target.options.is_like_osx &&
|
||||
sess.opts.debuginfo != DebugInfo::None
|
||||
{
|
||||
match Command::new("dsymutil").arg(out_filename).output() {
|
||||
Ok(..) => {}
|
||||
Err(e) => sess.fatal(&format!("failed to run dsymutil: {}", e)),
|
||||
if let Err(e) = Command::new("dsymutil").arg(out_filename).output() {
|
||||
sess.fatal(&format!("failed to run dsymutil: {}", e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue