Add target option for linker environment variables

This is used in wasm32-experimental-emscripten to ensure that emscripten
links against the libc bitcode files produced by the wasm LLVM backend,
instead of using fastcomp.
This commit is contained in:
Thomas Lively 2017-06-22 15:16:54 -07:00
parent 447297ce59
commit 16da303209
4 changed files with 10 additions and 8 deletions

View File

@ -282,6 +282,9 @@ pub struct TargetOptions {
/// user-defined libraries.
pub post_link_args: LinkArgs,
/// Environment variables to be set before invoking the linker.
pub link_env: Vec<(String, String)>,
/// Extra arguments to pass to the external assembler (when used)
pub asm_args: Vec<String>,
@ -451,6 +454,7 @@ impl Default for TargetOptions {
pre_link_objects_dll: Vec::new(),
post_link_objects: Vec::new(),
late_link_args: LinkArgs::new(),
link_env: Vec::new(),
archive_format: "gnu".to_string(),
custom_unwind_resume: false,
lib_allocation_crate: "alloc_system".to_string(),

View File

@ -30,6 +30,7 @@ pub fn target() -> Result<Target, String> {
// possibly interpret the wasm, and a .wasm file
exe_suffix: ".js".to_string(),
linker_is_gnu: true,
link_env: vec![("EMCC_WASM_BACKEND".to_string(), "1".to_string())],
allow_asm: false,
obj_is_bitcode: true,
is_like_emscripten: true,

View File

@ -785,6 +785,9 @@ fn link_natively(sess: &Session,
if let Some(args) = sess.target.target.options.post_link_args.get(&flavor) {
cmd.args(args);
}
for &(ref k, ref v) in &sess.target.target.options.link_env {
cmd.env(k, v);
}
if sess.opts.debugging_opts.print_link_args {
println!("{:?}", &cmd);

View File

@ -1280,12 +1280,6 @@ actual:\n\
let extra_link_args = vec!["-L".to_owned(),
aux_dir.to_str().unwrap().to_owned()];
let mut env = self.props.rustc_env.clone();
// Tell emscripten to link using libc produced with LLVM backend
if self.config.target.contains("wasm32") && self.config.target.contains("experimental") {
env.push(("EMCC_WASM_BACKEND".to_string(), "1".to_string()));
}
for rel_ab in &self.props.aux_builds {
let aux_testpaths = self.compute_aux_test_paths(rel_ab);
let aux_props = self.props.from_aux_file(&aux_testpaths.file,
@ -1325,7 +1319,7 @@ actual:\n\
};
let aux_args = aux_cx.make_compile_args(crate_type, &aux_testpaths.file, aux_output);
let auxres = aux_cx.compose_and_run(aux_args,
env.clone(),
Vec::new(),
aux_cx.config.compile_lib_path.to_str().unwrap(),
Some(aux_dir.to_str().unwrap()),
None);
@ -1338,7 +1332,7 @@ actual:\n\
}
self.compose_and_run(args,
env,
self.props.rustc_env.clone(),
self.config.compile_lib_path.to_str().unwrap(),
Some(aux_dir.to_str().unwrap()),
input)