From 16da303209dc7d4ec84b10322c9f7d34f72b2985 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Thu, 22 Jun 2017 15:16:54 -0700 Subject: [PATCH] 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. --- src/librustc_back/target/mod.rs | 4 ++++ .../target/wasm32_experimental_emscripten.rs | 1 + src/librustc_trans/back/link.rs | 3 +++ src/tools/compiletest/src/runtest.rs | 10 ++-------- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 37d6a6b95d9..5c95868471e 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -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, @@ -451,6 +454,7 @@ fn default() -> 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(), diff --git a/src/librustc_back/target/wasm32_experimental_emscripten.rs b/src/librustc_back/target/wasm32_experimental_emscripten.rs index 1a95c93363a..053fab54250 100644 --- a/src/librustc_back/target/wasm32_experimental_emscripten.rs +++ b/src/librustc_back/target/wasm32_experimental_emscripten.rs @@ -30,6 +30,7 @@ pub fn target() -> Result { // 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, diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 1f88f90dbbb..a9af8b11f93 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -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); diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 3b3a94c6c58..0692e07253f 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1280,12 +1280,6 @@ fn compose_and_run_compiler(&self, args: ProcArgs, input: Option) -> Pro 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 @@ fn compose_and_run_compiler(&self, args: ProcArgs, input: Option) -> Pro }; 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 @@ fn compose_and_run_compiler(&self, args: ProcArgs, input: Option) -> Pro } 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) -- 2.44.0