|
| 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.* |
0 commit comments