]> git.lizzy.rs Git - rust.git/commitdiff
Add target option for linker environment variables
authorThomas Lively <tlively@google.com>
Thu, 22 Jun 2017 22:16:54 +0000 (15:16 -0700)
committerThomas Lively <tlively@google.com>
Fri, 23 Jun 2017 01:34:56 +0000 (18:34 -0700)
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
src/librustc_back/target/wasm32_experimental_emscripten.rs
src/librustc_trans/back/link.rs
src/tools/compiletest/src/runtest.rs

index 37d6a6b95d937dddcb24db02de531d792ca2f5e5..5c95868471e43b5aabec6ac35588e8abc104e422 100644 (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 @@ 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(),
index 1a95c93363adb9095ca88b6ed62cf8738600f16a..053fab54250194a9186a79ee3983cbb1238dd261 100644 (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,
index 1f88f90dbbb28048a2ead7f92146f1e4f2b948da..a9af8b11f93ad69ca85f699806a80f5de9a6df26 100644 (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);
index 3b3a94c6c58255f22eb8ee2b8259d1dd36337620..0692e07253fbeefc6bde8c4196f92b7083b89f43 100644 (file)
@@ -1280,12 +1280,6 @@ fn compose_and_run_compiler(&self, args: ProcArgs, input: Option<String>) -> 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<String>) -> 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<String>) -> 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)