forked from hacspec/hax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebuild.sh
executable file
·83 lines (69 loc) · 2.35 KB
/
rebuild.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
# This is a small script to rebuild Hax (the Rust CLI & frontend and
# OCaml engine) quickly.
# Options:
# - the flag `--online` allow Cargo to look for updates on the internet;
# - the environment variable `DUNEJOBS` limits the number of jobs `dune`
# is allowed to spawn in parallel while building.
set -euo pipefail
OFFLINE_FLAG="--offline"
if [[ "${1:-}" == "--online" ]]; then
OFFLINE_FLAG=""
shift 1
fi
TARGETS="${1:-rust ocaml}"
DUNEJOBS=${DUNEJOBS:-} # required since `set -u`
YELLOW=43
GREEN=42
RED=41
BLACK=40
status () { echo -e "\033[1m[rebuild script] \033[30m\033[$1m$2\033[0m"; }
cd_rootwise () {
cd $(git rev-parse --show-toplevel)/$1
}
rust () {
cd_rootwise "cli"
for i in driver subcommands ../engine/names/extract; do
CURRENT="rust/$i"
cargo install --locked --quiet $OFFLINE_FLAG --debug --path $i
done
}
ocaml () {
cd_rootwise "engine"
CURRENT="ocaml"
dune build $([ -z $DUNEJOBS ] || echo "-j $DUNEJOBS")
CURRENT="ocaml/install"
# Small hack for those that are not using [opam] at all: by
# default install OCaml binaries in `~/.cargo` (which is supposed
# to be in PATH anyway).
INSTALL_PREFIX="${OPAM_SWITCH_PREFIX:-${DUNE_INSTALL_PREFIX:-$HOME/.cargo}}"
dune install --profile dev --prefix $INSTALL_PREFIX
if ( command -v "which" && command -v "sort" && command -v "wc" ) >/dev/null; then
case $(which -a hax-engine | sort -u | wc -l) in
0) status $YELLOW 'Warning: cannot detect `hax-engine` in PATH';;
1) :;;
*) status $YELLOW 'Warning: multiple `hax-engine` detected in PATH. Maybe you installed Hax with OPAM (i.e. via `setup.sh`)? Please uninstall it, otherwise you might use a stale engine!';;
esac
else
status $YELLOW 'Warning: cannot run sanity checks because `which`, `sort` or `wc` commands are not available. Please install them.'
fi
}
on_exit () {
if [ $? -ne 0 ]; then
status $RED "ERR: $CURRENT";
fi
}
trap on_exit EXIT ERR
trap "status $RED 'SIGINT'" SIGINT
CURRENT="none"
started() { [ -z ${QUIET+x} ] && status $BLACK "$1 build started" || true; }
if [[ "$TARGETS" == *rust* ]]; then
started rust
rust
status $GREEN "rust succeed"
fi
if [[ "$TARGETS" == *ml* ]]; then
started ocaml
ocaml
status $GREEN "ocaml succeed"
fi