xref: /rust-libc-0.2.174/ci/emscripten.sh (revision fe8470be)
1#!/usr/bin/env bash
2
3set -ex
4
5EMSDK_VERSION=1.39.20
6
7hide_output() {
8  set +x
9  on_err="
10echo ERROR: An error was encountered with the build.
11cat /tmp/build.log
12exit 1
13"
14  trap '$on_err' ERR
15  bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
16  PING_LOOP_PID=$!
17  "${@}" &> /tmp/build.log
18  trap - ERR
19  kill $PING_LOOP_PID
20  rm -f /tmp/build.log
21  set -x
22}
23
24git clone https://github.com/emscripten-core/emsdk.git /emsdk-portable
25cd /emsdk-portable
26hide_output ./emsdk install "${EMSDK_VERSION}"
27./emsdk activate "${EMSDK_VERSION}"
28
29# Compile and cache libc
30# shellcheck disable=SC1091
31source ./emsdk_env.sh
32echo "main(){}" > a.c
33HOME=/emsdk-portable/ emcc a.c
34rm -f a.*
35
36# Make emsdk usable by any user
37chmod a+rxw -R /emsdk-portable
38
39# node 8 is required to run wasm
40# NOTE: Do not forget to sync Node.js version with `emscripten-entry.sh`!
41cd /
42curl --retry 5 -L https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xz | \
43    tar -xJ
44