use flate;
use syntax::ast;
use syntax::attr;
-use syntax::symbol::Symbol;
use syntax_pos::Span;
/// The LLVM module name containing crate-metadata. This includes a `.` on
"rust_out".to_string()
}
-pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap,
- name: &str)
- -> LinkMeta {
+pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap) -> LinkMeta {
let r = LinkMeta {
- crate_name: Symbol::intern(name),
crate_hash: Svh::new(incremental_hashes_map[&DepNode::Krate].to_smaller_hash()),
};
info!("{:?}", r);
}
fn emit_metadata<'a>(sess: &'a Session, trans: &CrateTranslation, out_filename: &Path) {
- let result = fs::File::create(out_filename).and_then(|mut f| f.write_all(&trans.metadata));
+ let result = fs::File::create(out_filename).and_then(|mut f| {
+ f.write_all(&trans.metadata.raw_data)
+ });
+
if let Err(e) = result {
sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));
}
outputs: &OutputFilenames,
tmpdir: &Path) {
info!("preparing {:?} from {:?} to {:?}", crate_type, objects, out_filename);
+ let flavor = sess.linker_flavor();
// The invocations of cc share some flags across platforms
let (pname, mut cmd, extra) = get_linker(sess);
cmd.env("PATH", command_path(sess, extra));
let root = sess.target_filesearch(PathKind::Native).get_lib_path();
- cmd.args(&sess.target.target.options.pre_link_args);
+ if let Some(args) = sess.target.target.options.pre_link_args.get(&flavor) {
+ cmd.args(args);
+ }
let pre_link_objects = if crate_type == config::CrateTypeExecutable {
&sess.target.target.options.pre_link_objects_exe
}
{
- let mut linker = trans.linker_info.to_linker(&mut cmd, &sess);
+ let mut linker = trans.linker_info.to_linker(cmd, &sess);
link_args(&mut *linker, sess, crate_type, tmpdir,
objects, out_filename, outputs, trans);
+ cmd = linker.finalize();
+ }
+ if let Some(args) = sess.target.target.options.late_link_args.get(&flavor) {
+ cmd.args(args);
}
- cmd.args(&sess.target.target.options.late_link_args);
for obj in &sess.target.target.options.post_link_objects {
cmd.arg(root.join(obj));
}
- cmd.args(&sess.target.target.options.post_link_args);
+ if let Some(args) = sess.target.target.options.post_link_args.get(&flavor) {
+ cmd.args(args);
+ }
if sess.opts.debugging_opts.print_link_args {
println!("{:?}", &cmd);
}
});
- let pair = sess.cstore.used_libraries().into_iter().filter(|l| {
+ let relevant_libs = sess.cstore.used_libraries().into_iter().filter(|l| {
relevant_lib(sess, l)
- }).partition(|lib| {
- lib.kind == NativeLibraryKind::NativeStatic
});
- let (staticlibs, others): (Vec<_>, Vec<_>) = pair;
-
- // Some platforms take hints about whether a library is static or dynamic.
- // For those that support this, we ensure we pass the option if the library
- // was flagged "static" (most defaults are dynamic) to ensure that if
- // libfoo.a and libfoo.so both exist that the right one is chosen.
- cmd.hint_static();
let search_path = archive_search_paths(sess);
- for l in staticlibs {
- // Here we explicitly ask that the entire archive is included into the
- // result artifact. For more details see #15460, but the gist is that
- // the linker will strip away any unused objects in the archive if we
- // don't otherwise explicitly reference them. This can occur for
- // libraries which are just providing bindings, libraries with generic
- // functions, etc.
- cmd.link_whole_staticlib(&l.name.as_str(), &search_path);
- }
-
- cmd.hint_dynamic();
-
- for lib in others {
+ for lib in relevant_libs {
match lib.kind {
NativeLibraryKind::NativeUnknown => cmd.link_dylib(&lib.name.as_str()),
NativeLibraryKind::NativeFramework => cmd.link_framework(&lib.name.as_str()),
NativeLibraryKind::NativeStaticNobundle => cmd.link_staticlib(&lib.name.as_str()),
- NativeLibraryKind::NativeStatic => bug!(),
+ NativeLibraryKind::NativeStatic => cmd.link_whole_staticlib(&lib.name.as_str(),
+ &search_path)
}
}
}