forked from hacspec/hax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·97 lines (85 loc) · 2.77 KB
/
setup.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
set -eu
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
opam_jobs=4
# Parse command line arguments.
all_args=("$@")
while [ $# -gt 0 ]; do
case "$1" in
-j)
opam_jobs=$2
shift
;;
esac
shift
done
# Warns if we're building in a dirty checkout of hax: while hacking on
# hax, we should really be using the `./.utils/rebuild.sh`
warn_if_dirty() {
(
cd "$SCRIPTPATH"
if ! git diff-index --quiet HEAD -- >& /dev/null; then
printf '\e[33mWarning: This is a dirty checkout of hax!\n If you are hacking on hax, please use the \e[1m`./.utils/rebuild.sh`\e[0m\e[33m script.\e[0m\n\n'
fi
)
}
# Ensures a given binary is available in PATH
ensure_binary_available() {
command -v "$1" >/dev/null 2>&1 || {
printf '\e[31mError: binary \e[1m%s\e[0m\e[31m was not found.\e[0m\n' "$1"
printf '\e[37m(Did you look at \e[1mManual installation\e[0m\e[37m in \e[1mREADME.md\e[0m\e[37m?)\e[0m.\n'
exit 1
}
}
NODE_VERSION_MIN_MAJOR=17
ensure_node_is_recent_enough() {
function strip_first_char () {
cut -c2-
}
function get_major () {
cut -d'.' -f1
}
VERSION=$(node --version)
MAJOR=$(echo "$VERSION" | strip_first_char | get_major)
if [[ "$MAJOR" -lt "$NODE_VERSION_MIN_MAJOR" ]]; then
printf '\e[31mError: \e[1m%s\e[0m\e[31m appears to be too old.\e[0m\n' "NodeJS"
printf '\e[37m(the minimal version required is \e[1m%s\e[0m\e[37m, yours is \e[1m%s\e[0m\e[37m)\e[0m.\n' "v${NODE_VERSION_MIN_MAJOR}.*.*" "$VERSION"
exit 1
fi
}
# Installs the Rust CLI & frontend, providing `cargo-hax` and `driver-hax`
install_rust_binaries() {
for i in driver subcommands ../engine/names/extract; do
(
set -x
cargo install --locked --force --path "cli/$i"
)
done
}
# Provides the `hax-engine` binary
install_ocaml_engine() {
# Fixes out of memory issues (https://github.com/hacspec/hax/issues/197)
{
# Limit the number of thread spawned by opam
export OPAMJOBS=$opam_jobs
# Make the garbadge collector of OCaml more agressive (see
# https://discuss.ocaml.org/t/how-to-limit-the-amount-of-memory-the-ocaml-compiler-is-allowed-to-use/797)
export OCAMLRUNPARAM="o=20"
}
# Make opam show logs when an error occurs
export OPAMERRLOGLEN=0
# Make opam ignore system dependencies (it doesn't handle properly certain situations)
export OPAMASSUMEDEPEXTS=1
(
set -x
opam uninstall hax-engine || true
opam install --yes ./engine
)
}
warn_if_dirty
for binary in opam node rustup jq; do
ensure_binary_available $binary
done
ensure_node_is_recent_enough
install_rust_binaries
install_ocaml_engine