-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·128 lines (117 loc) · 4.09 KB
/
build.sh
File metadata and controls
executable file
·128 lines (117 loc) · 4.09 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# 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 " -W build wasm"
echo " -o do not run wasm-opt"
echo " -s run wasm-opt with -Os"
echo " -z run wasm-opt with -Oz"
echo " -v verbose output"
echo " -D enable DWARF debuggin and panicking"
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 VITE WASM PROD;
QUIET=1;
while getopts 'dpVWoszvhD' c
do
case $c in
d) set_variable PROD 0 ;;
p) set_variable PROD 1 ;;
V) set_variable VITE 1 ;;
W) set_variable WASM 1 ;;
o) set_variable WOPT 0 ;;
s) set_variable WOPT 1 ;;
z) set_variable WOPT 2 ;;
D) set_variable DWARF 1 ;;
v) unset QUIET ;;
h|?) usage ;;
esac
done
[ -z $WASM ] && set_variable WASM 0;
[ -z $VITE ] && set_variable VITE 0;
[ -z $PROD ] && usage;
if [ -z $WOPT ]; then
if [ $PROD = "1" ]; then
set_variable WOPT 2;
else
set_variable WOPT 0;
fi
fi
if [ -z DWARF ]; then
if [ $PROD = "0" ]; then
set_variable DWARF 1;
else
set_variable DWARF 0;
fi
fi
[ $VITE = "0" ] && [ $WASM = "0" ] && [ $WOPT = "0" ] && echo "exiting (nothing to build)" && exit 0
if [ $WASM = "1" ]; then
mkdir -p /tmp/hq-build/js/compiler;
mkdir -p /tmp/hq-build/js/no-compiler;
if [ $PROD = "1" ]; then
echo "building hyperquark (compiler) for production..."
cargo build --target=wasm32-unknown-unknown --release ${QUIET:+--quiet} ${DWARF:+--features="compiler panic"}
echo running wasm-bindgen...
wasm-bindgen target/wasm32-unknown-unknown/release/hyperquark.wasm --out-dir=/tmp/hq-build/js/compiler ${DWARF:+--keep-debug}
echo "building hyperquark (no compiler) for production..."
cargo build --target=wasm32-unknown-unknown --release ${QUIET:+--quiet} --no-default-features ${DWARF:+--features=panic}
echo running wasm-bindgen...
wasm-bindgen target/wasm32-unknown-unknown/release/hyperquark.wasm --out-dir=/tmp/hq-build/js/no-compiler ${DWARF:+--keep-debug}
else
echo "building hyperquark (compiler) for development..."
cargo build --target=wasm32-unknown-unknown ${QUIET:+--quiet} ${DWARF:+--features="compiler panic"}
echo running wasm-bindgen...
wasm-bindgen target/wasm32-unknown-unknown/debug/hyperquark.wasm --out-dir=/tmp/hq-build/js/compiler ${DWARF:+--keep-debug}
echo "building hyperquark (no compiler) for development..."
cargo build --target=wasm32-unknown-unknown ${QUIET:+--quiet} --no-default-features ${DWARF:+--features=panic}
echo running wasm-bindgen...
wasm-bindgen target/wasm32-unknown-unknown/debug/hyperquark.wasm --out-dir=/tmp/hq-build/js/no-compiler ${DWARF:+--keep-debug}
fi
mv $(cargo outdir --no-names --quiet)/imports.ts /tmp/hq-build/js/imports.ts
node opcodes.mjs
fi
if [ $WOPT = "1" ]; then
echo running wasm-opt -Os...
wasm-opt -Os -g /tmp/hq-build/js/compiler/hyperquark_bg.wasm -o /tmp/hq-build/js/compiler/hyperquark_bg.wasm
wasm-opt -Os -g /tmp/hq-build/js/no-compiler/hyperquark_bg.wasm -o /tmp/hq-build/js/no-compiler/hyperquark_bg.wasm
fi
if [ $WOPT = "2" ]; then
echo running wasm-opt -Oz...
wasm-opt -Oz -g /tmp/hq-build/js/compiler/hyperquark_bg.wasm -o /tmp/hq-build/js/compiler/hyperquark_bg.wasm
wasm-opt -Oz -g /tmp/hq-build/js/no-compiler/hyperquark_bg.wasm -o /tmp/hq-build/js/no-compiler/hyperquark_bg.wasm
fi
mkdir -p /tmp/hq-build/js-new
cp -a js/* /tmp/hq-build/js-new/
cp -a /tmp/hq-build/js/* /tmp/hq-build/js-new/
rm -rf js
mv -fT /tmp/hq-build/js-new js
if [ $VITE = "1" ]; then
echo running npm build...
npm run build
fi
echo finished!