-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·102 lines (95 loc) · 2.59 KB
/
build.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
98
99
100
101
102
# build script for hyperquark
# a lot of code here was adapted from https://www.shellscript.sh/examples/getopts/
trap "err" ERR # exit if any command returns a non-zero exit code
err()
{
echo;
echo Exiting early since previous build step failed!;
exit 1;
}
usage()
{
echo "Usage: $0 [options]"
echo "Options:"
echo " -h -? show this help screen"
echo " -d build for development"
echo " -p build for production"
echo " -V build the website with vite"
echo " -v do not build the website with vite"
echo " -W build wasm"
echo " -w do not build wasm"
echo " -o do not run wasm-opt"
echo " -O run wasm-opt"
echo " -s run wasm-opt with -Os"
echo " -z run wasm-opt with -Os"
exit 1
}
set_variable()
{
local varname=$1
shift
if [ -z "${!varname}" ]; then
eval "$varname=\"$@\""
else
echo "Error: $varname already set. This probably means that you've used two conflicting flags."
echo
usage
fi
}
unset PROD VITE WASM
QUIET=1
while getopts 'dpwvoWVOhi' c
while getopts 'dpwvoWVszhi' c
do
case $c in
d) set_variable PROD 0 ;;
p) set_variable PROD 1 ;;
v) set_variable VITE 0 ;;
w) set_variable WASM 0 ;;
V) set_variable VITE 1 ;;
W) set_variable WASM 1 ;;
o) set_variable WOPT 0 ;;
O) set_variable WOPT 1 ;;
s) set_variable WOPT 1 ;;
z) set_variable WOPT 2 ;;
i) unset QUIET ;;
h|?) usage ;;
esac
done
[ -z $PROD ] && usage
[ -z $VITE ] && usage
[ -z $WASM ] && usage
if [ -z $WOPT ]; then
if [ $PROD = "1" ]; then
set_variable WOPT 1;
else
set_variable WOPT 0;
fi
fi
[ $VITE = "0" ] && [ $WASM = "0" ] && [ $WOPT = "0" ] && echo "exiting (nothing to build)" && exit 0
if [ $WASM = "1" ]; then
if [ $PROD = "1" ]; then
echo building hyperquark for production...
cargo build --target=wasm32-unknown-unknown --release ${QUIET:+--quiet}
echo running wasm-bindgen...
wasm-bindgen target/wasm32-unknown-unknown/release/hyperquark.wasm --out-dir=js
else
echo building hyperquark for development...
cargo build --target=wasm32-unknown-unknown ${QUIET:+--quiet}
echo running wasm-bindgen...
wasm-bindgen target/wasm32-unknown-unknown/debug/hyperquark.wasm --out-dir=js
fi
fi
if [ $WOPT = "1" ]; then
echo running wasm-opt...
wasm-opt -Oz js/hyperquark_bg.wasm -o js/hyperquark_bg.wasm
wasm-opt -Os -g js/hyperquark_bg.wasm -o js/hyperquark_bg.wasm
fi
if [ $WOPT = "2" ]; then
echo running wasm-opt...
wasm-opt -Oz -g js/hyperquark_bg.wasm -o js/hyperquark_bg.wasm
fi
if [ $VITE = "1" ]; then
echo running npm build...
npm run build
fi