Skip to content

Commit bc9822a

Browse files
committed
Auto merge of #42784 - tlively:wasm-bot, r=alexcrichton
Make wasm32 buildbot test LLVM backend This adds the experimental targets option to configure so it can be used by the builders and changes the wasm32 Dockerfile accordingly. Instead of using LLVM from the emsdk, the builder's emscripten tools now uses the Rust in-tree LLVM, since this is the one built with wasm support.
2 parents c9bb935 + c130b83 commit bc9822a

File tree

9 files changed

+117
-12
lines changed

9 files changed

+117
-12
lines changed

configure

+1
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ valopt musl-root-armhf "" "arm-unknown-linux-musleabihf install directory"
490490
valopt musl-root-armv7 "" "armv7-unknown-linux-musleabihf install directory"
491491
valopt extra-filename "" "Additional data that is hashed and passed to the -C extra-filename flag"
492492
valopt qemu-armhf-rootfs "" "rootfs in qemu testing, you probably don't want to use this"
493+
valopt experimental-targets "" "experimental LLVM targets to build"
493494

494495
if [ -e ${CFG_SRC_DIR}.git ]
495496
then

src/bootstrap/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ impl Config {
497497
"CFG_TARGET" if value.len() > 0 => {
498498
self.target.extend(value.split(" ").map(|s| s.to_string()));
499499
}
500+
"CFG_EXPERIMENTAL_TARGETS" if value.len() > 0 => {
501+
self.llvm_experimental_targets = Some(value.to_string());
502+
}
500503
"CFG_MUSL_ROOT" if value.len() > 0 => {
501504
self.musl_root = Some(parse_configure_path(value));
502505
}

src/ci/docker/disabled/wasm32/Dockerfile

+12-10
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,22 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1111
cmake \
1212
sudo \
1313
gdb \
14-
xz-utils
14+
xz-utils \
15+
jq \
16+
bzip2
1517

1618
# dumb-init
1719
COPY scripts/dumb-init.sh /scripts/
1820
RUN sh /scripts/dumb-init.sh
1921

2022
# emscripten
21-
COPY scripts/emscripten.sh /scripts/
22-
RUN bash /scripts/emscripten.sh
23-
COPY wasm32/node.sh /usr/local/bin/node
23+
COPY scripts/emscripten-wasm.sh /scripts/
24+
RUN bash /scripts/emscripten-wasm.sh
25+
COPY disabled/wasm32/node.sh /usr/local/bin/node
26+
27+
# cache
28+
COPY scripts/sccache.sh /scripts/
29+
RUN sh /scripts/sccache.sh
2430

2531
# env
2632
ENV PATH=$PATH:/emsdk-portable
@@ -30,15 +36,11 @@ ENV EMSCRIPTEN=/emsdk-portable/emscripten/1.37.13/
3036
ENV BINARYEN_ROOT=/emsdk-portable/clang/e1.37.13_64bit/binaryen/
3137
ENV EM_CONFIG=/emsdk-portable/.emscripten
3238

33-
ENV TARGETS=wasm32-unknown-emscripten
39+
ENV TARGETS=wasm32-unknown-emscripten,wasm32-experimental-emscripten
3440

35-
ENV RUST_CONFIGURE_ARGS --target=$TARGETS
41+
ENV RUST_CONFIGURE_ARGS --target=$TARGETS --experimental-targets=WebAssembly
3642

3743
ENV SCRIPT python2.7 ../x.py test --target $TARGETS
3844

39-
# cache
40-
COPY scripts/sccache.sh /scripts/
41-
RUN sh /scripts/sccache.sh
42-
4345
# init
4446
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
# file at the top-level directory of this distribution and at
3+
# http://rust-lang.org/COPYRIGHT.
4+
#
5+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
# option. This file may not be copied, modified, or distributed
9+
# except according to those terms.
10+
11+
set -ex
12+
13+
hide_output() {
14+
set +x
15+
on_err="
16+
echo ERROR: An error was encountered with the build.
17+
cat /tmp/build.log
18+
exit 1
19+
"
20+
trap "$on_err" ERR
21+
bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
22+
PING_LOOP_PID=$!
23+
$@ &> /tmp/build.log
24+
trap - ERR
25+
kill $PING_LOOP_PID
26+
rm -f /tmp/build.log
27+
set -x
28+
}
29+
30+
# Download emsdk
31+
cd /
32+
curl -L https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz | \
33+
tar -xz
34+
35+
# Download last known good emscripten from WebAssembly waterfall
36+
BUILD=$(curl -L https://storage.googleapis.com/wasm-llvm/builds/linux/lkgr.json | \
37+
jq '.build | tonumber')
38+
curl -L https://storage.googleapis.com/wasm-llvm/builds/linux/$BUILD/wasm-binaries.tbz2 | \
39+
hide_output tar xvkj
40+
41+
# node 8 is required to run wasm
42+
cd /
43+
curl -L https://nodejs.org/dist/v8.0.0/node-v8.0.0-linux-x64.tar.xz | \
44+
tar -xJ
45+
46+
cd /emsdk-portable
47+
./emsdk update
48+
hide_output ./emsdk install sdk-1.37.13-64bit
49+
./emsdk activate sdk-1.37.13-64bit
50+
51+
# Make emscripten use wasm-ready node and LLVM tools
52+
echo "NODE_JS='/node-v8.0.0-linux-x64/bin/node'" >> /root/.emscripten
53+
echo "LLVM_ROOT='/wasm-install/bin'" >> /root/.emscripten
54+
55+
# Make emsdk usable by any user
56+
cp /root/.emscripten /emsdk-portable
57+
chmod a+rxw -R /emsdk-portable
58+
59+
# Compile and cache libc
60+
source ./emsdk_env.sh
61+
echo "main(){}" > a.c
62+
HOME=/emsdk-portable/ emcc a.c
63+
HOME=/emsdk-portable/ emcc -s WASM=1 a.c
64+
rm -f a.*

src/ci/docker/scripts/emscripten.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ chmod a+rxw -R /emsdk-portable
5050
# node 8 is required to run wasm
5151
cd /
5252
curl -L https://nodejs.org/dist/v8.0.0/node-v8.0.0-linux-x64.tar.xz | \
53-
tar -xJ
53+
tar -xJ

src/librustc_back/target/mod.rs

+32
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(),
@@ -620,6 +624,21 @@ impl Target {
620624
base.options.$key_name = args;
621625
}
622626
} );
627+
($key_name:ident, env) => ( {
628+
let name = (stringify!($key_name)).replace("_", "-");
629+
if let Some(a) = obj.find(&name[..]).and_then(|o| o.as_array()) {
630+
for o in a {
631+
if let Some(s) = o.as_string() {
632+
let p = s.split('=').collect::<Vec<_>>();
633+
if p.len() == 2 {
634+
let k = p[0].to_string();
635+
let v = p[1].to_string();
636+
base.options.$key_name.push((k, v));
637+
}
638+
}
639+
}
640+
}
641+
} );
623642
}
624643

625644
key!(is_builtin, bool);
@@ -631,6 +650,7 @@ impl Target {
631650
key!(late_link_args, link_args);
632651
key!(post_link_objects, list);
633652
key!(post_link_args, link_args);
653+
key!(link_env, env);
634654
key!(asm_args, list);
635655
key!(cpu);
636656
key!(features);
@@ -785,6 +805,17 @@ impl ToJson for Target {
785805
d.insert(name.to_string(), obj.to_json());
786806
}
787807
} );
808+
(env - $attr:ident) => ( {
809+
let name = (stringify!($attr)).replace("_", "-");
810+
if default.$attr != self.options.$attr {
811+
let obj = self.options.$attr
812+
.iter()
813+
.map(|&(ref k, ref v)| k.clone() + "=" + &v)
814+
.collect::<Vec<_>>();
815+
d.insert(name.to_string(), obj.to_json());
816+
}
817+
} );
818+
788819
}
789820

790821
target_val!(llvm_target);
@@ -806,6 +837,7 @@ impl ToJson for Target {
806837
target_option_val!(link_args - late_link_args);
807838
target_option_val!(post_link_objects);
808839
target_option_val!(link_args - post_link_args);
840+
target_option_val!(env - link_env);
809841
target_option_val!(asm_args);
810842
target_option_val!(cpu);
811843
target_option_val!(features);

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
@@ -789,6 +789,9 @@ fn link_natively(sess: &Session,
789789
if let Some(args) = sess.target.target.options.post_link_args.get(&flavor) {
790790
cmd.args(args);
791791
}
792+
for &(ref k, ref v) in &sess.target.target.options.link_env {
793+
cmd.env(k, v);
794+
}
792795

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

src/tools/compiletest/src/runtest.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,6 @@ actual:\n\
13381338
input)
13391339
}
13401340

1341-
13421341
fn compose_and_run(&self,
13431342
ProcArgs{ args, prog }: ProcArgs,
13441343
procenv: Vec<(String, String)> ,

0 commit comments

Comments
 (0)