Skip to content

Commit

Permalink
build: Get rid of logging, indenting, and unbuffering entirely
Browse files Browse the repository at this point in the history
The output looked nice, but too many things broke: Vagrant would randomly hand
and disconnect, emconfigure would sometimes hang, and emcc would crash entirely.
  • Loading branch information
cpitclaudel committed Apr 15, 2018
1 parent 24bd6a6 commit dbae91a
Showing 1 changed file with 22 additions and 33 deletions.
55 changes: 22 additions & 33 deletions z3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

: "${BASEDIR:=/vagrant}"
: "${VAGRANT:=false}"
export LOGFILE="$BASEDIR/provision.log"
export DEBIAN_FRONTEND=noninteractive

export JS_ROOT="$BASEDIR/z3-wasm/"
Expand All @@ -46,37 +45,27 @@ export EMSCRIPTEN_TEMPDIR="/tmp/emscripten"
export OPTLEVEL=3

function say() {
date >> "$LOGFILE"
echo "$1" >> "$LOGFILE"
printf "\033[1;32m%s\033[0m\n" "$1"
}

UNBUFFER="stdbuf -oL -eL"
function log() {
$UNBUFFER tee -a "$LOGFILE" | sed 's/^/ /'
}

echo "" > "$LOGFILE"
say "* Starting; see ${LOGFILE} for details."

say ""
say '*********************************'
say '*** Installing dependencies ***'
say '*********************************'

say '* apt-get update'; {
$UNBUFFER sudo apt-get -y -q update
} |& log
sudo apt-get -y -q update
}

if [ "$VAGRANT" = true ]; then
say '* apt-get install (VBox extensions)'; {
sudo apt-get -y -q install virtualbox-guest-dkms virtualbox-guest-utils
} |& log
}
fi

say '* apt-get install (Dependencies)'; {
$UNBUFFER sudo apt-get -y -q install git build-essential lzip python2.7 cmake autoconf libtool
} |& log
sudo apt-get -y -q install git build-essential lzip python2.7 cmake autoconf libtool
}

if [ "$VAGRANT" = true ]; then
[ ! -f /usr/bin/python ] && sudo ln -s /usr/bin/python2.7 /usr/bin/python
Expand All @@ -96,11 +85,11 @@ mkdir "$JS_ROOT"
say '* wget emscripten'; {
wget --quiet -O /tmp/emsdk-portable.tar.gz https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz
tar -xf /tmp/emsdk-portable.tar.gz -C "$JS_ROOT"
} |& log
}

say '* git clone z3'; {
git clone --depth 1 --quiet https://github.com/Z3Prover/z3.git "$Z3_ROOT"
} |& log
}

say ""
say '****************'
Expand All @@ -113,9 +102,9 @@ cd "$EMSDK_ROOT"
# https://github.com/kripken/emscripten/issues/4667

say '* Emscripten: setup'; {
$UNBUFFER ./emsdk update
$UNBUFFER ./emsdk install latest --build=Release
$UNBUFFER ./emsdk activate latest
./emsdk update
./emsdk install latest --build=Release
./emsdk activate latest

# Use incoming because of https://github.com/kripken/emscripten/pull/5239
# ./emsdk install emscripten-incoming-32bit --build=Release
Expand All @@ -129,34 +118,34 @@ say '* Emscripten: setup'; {

# Regenerate emsdk_set_env.sh
./emsdk construct_env ""
} |& log
}

# Don't source emsdk_env directly, as it produces output that can't be logged
# without creating a subshell (which would break `source`)
source "${EMSDK_ROOT}/emsdk_set_env.sh"

# emcc fails in all sorts of weird ways without this
# Adding $UNBUFFER to emcc also causes it to crash
ulimit -s unlimited

say '* Emscripten: stdlib (slow!)'; {
say '* Emscripten: stdlib (very slow!)'; {
mkdir -p "$EMSCRIPTEN_TEMPDIR"
cd "$EMSCRIPTEN_TEMPDIR"
printf '#include<stdio.h>\nint main() { return 0; }\n' > minimal.c
# Adding to emcc here causes it to crash
emcc -v minimal.c
} |& log
}

cd "$Z3_ROOT"

Z3_CONFIGURE_OPTS=(--staticlib --staticbin --noomp --x86)

say '* Z3: configure (slow!)'; {
emconfigure python scripts/mk_make.py "${Z3_CONFIGURE_OPTS[@]}"
} |& log
}

say '* Z3: make standalone (slow!)'; {
emmake make -C build -j4
} |& log
say '* Z3: make standalone (very slow!)'; {
emmake make -C build -j6
}

# Shared options
EMCC_OPTIONS=(
Expand Down Expand Up @@ -211,16 +200,16 @@ EMCC_WASM_OPTIONS=(
EMCC_Z3_JS_INPUTS=("${Z3_ROOT}/build/z3.bc")
EMCC_Z3_SMT2_JS_INPUTS=("${BASEDIR}/z3smt2.c" "${Z3_ROOT}/build/libz3.a")

say '* Z3: Linking'; {
say '* Z3: Linking (slow!)'; {
cp "${Z3_ROOT}/build/z3" "${Z3_ROOT}/build/z3.bc"
# emcc "${EMCC_Z3_OPTIONS[@]}" "${EMCC_Z3_JS_INPUTS[@]}" -o z3.js
emcc "${EMCC_Z3_OPTIONS[@]}" "${EMCC_WASM_OPTIONS[@]}" "${EMCC_Z3_JS_INPUTS[@]}" -o z3w.js
} |& log
}

say '* Z3 smt2 client: Linking'; {
say '* Z3 smt2 client: Linking (slow!)'; {
# emcc "${EMCC_Z3_SMT2_OPTIONS[@]}" "${EMCC_Z3_SMT2_JS_INPUTS[@]}" -o z3smt2.js
emcc "${EMCC_Z3_SMT2_OPTIONS[@]}" "${EMCC_WASM_OPTIONS[@]}" "${EMCC_Z3_SMT2_JS_INPUTS[@]}" -o z3smt2w.js
} |& log
}

say ""
say '*********************************'
Expand Down

0 comments on commit dbae91a

Please sign in to comment.