Skip to content

Commit 16da303

Browse files
committed
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.
1 parent 447297c commit 16da303

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

src/librustc_back/target/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ pub struct TargetOptions {
282282
/// user-defined libraries.
283283
pub post_link_args: LinkArgs,
284284

285+
/// Environment variables to be set before invoking the linker.
286+
pub link_env: Vec<(String, String)>,
287+
285288
/// Extra arguments to pass to the external assembler (when used)
286289
pub asm_args: Vec<String>,
287290

@@ -451,6 +454,7 @@ impl Default for TargetOptions {
451454
pre_link_objects_dll: Vec::new(),
452455
post_link_objects: Vec::new(),
453456
late_link_args: LinkArgs::new(),
457+
link_env: Vec::new(),
454458
archive_format: "gnu".to_string(),
455459
custom_unwind_resume: false,
456460
lib_allocation_crate: "alloc_system".to_string(),

src/librustc_back/target/wasm32_experimental_emscripten.rs

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

src/librustc_trans/back/link.rs

+3
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,9 @@ fn link_natively(sess: &Session,
785785
if let Some(args) = sess.target.target.options.post_link_args.get(&flavor) {
786786
cmd.args(args);
787787
}
788+
for &(ref k, ref v) in &sess.target.target.options.link_env {
789+
cmd.env(k, v);
790+
}
788791

789792
if sess.opts.debugging_opts.print_link_args {
790793
println!("{:?}", &cmd);

src/tools/compiletest/src/runtest.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1280,12 +1280,6 @@ actual:\n\
12801280
let extra_link_args = vec!["-L".to_owned(),
12811281
aux_dir.to_str().unwrap().to_owned()];
12821282

1283-
let mut env = self.props.rustc_env.clone();
1284-
// Tell emscripten to link using libc produced with LLVM backend
1285-
if self.config.target.contains("wasm32") && self.config.target.contains("experimental") {
1286-
env.push(("EMCC_WASM_BACKEND".to_string(), "1".to_string()));
1287-
}
1288-
12891283
for rel_ab in &self.props.aux_builds {
12901284
let aux_testpaths = self.compute_aux_test_paths(rel_ab);
12911285
let aux_props = self.props.from_aux_file(&aux_testpaths.file,
@@ -1325,7 +1319,7 @@ actual:\n\
13251319
};
13261320
let aux_args = aux_cx.make_compile_args(crate_type, &aux_testpaths.file, aux_output);
13271321
let auxres = aux_cx.compose_and_run(aux_args,
1328-
env.clone(),
1322+
Vec::new(),
13291323
aux_cx.config.compile_lib_path.to_str().unwrap(),
13301324
Some(aux_dir.to_str().unwrap()),
13311325
None);
@@ -1338,7 +1332,7 @@ actual:\n\
13381332
}
13391333

13401334
self.compose_and_run(args,
1341-
env,
1335+
self.props.rustc_env.clone(),
13421336
self.config.compile_lib_path.to_str().unwrap(),
13431337
Some(aux_dir.to_str().unwrap()),
13441338
input)

0 commit comments

Comments
 (0)