-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·134 lines (120 loc) · 4.41 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·134 lines (120 loc) · 4.41 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
129
130
131
132
133
134
# 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 " -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 " -P enable DWARF debugging and panicking"
echo " -D also build rustdocs"
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 RUSTDOC;
QUIET=1;
while getopts 'dpWoszvhPD' c
do
case $c in
d) set_variable PROD 0 ;;
p) set_variable PROD 1 ;;
W) set_variable WASM 1 ;;
o) set_variable WOPT 0 ;;
s) set_variable WOPT 1 ;;
z) set_variable WOPT 2 ;;
P) set_variable DWARF 1 ;;
D) set_variable RUSTDOC 1;;
v) unset QUIET ;;
h|?) usage ;;
esac
done
[ -z $WASM ] && set_variable WASM 0;
if [ $WASM = "1" ]; then
[ -z $PROD ] && usage;
if [ -z DWARF ]; then
set_variable DWARF 0;
fi
fi
if [ -z $WOPT ]; then
if [[ "$PROD" = "1" ]]; then
set_variable WOPT 2;
else
set_variable WOPT 0;
fi
fi
[[ "$WASM" == "0" && "$WOPT" == "0" && "$RUSTDOC" != "1" ]] && 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
if [[ "$WASM" == "1" ]] || [[ "$WOPT" == "1" ]] || [[ "$WOPT" == "2" ]]; then
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
fi
if [[ "$RUSTDOC" == "1" ]]; then
echo building rust docs
# cargo doc --workspace --exclude sb3
RUSTDOCFLAGS="--html-in-header typst-header.html" cargo doc --no-deps --document-private-items
rm -rf playground/public/docs/internal
mkdir -p playground/public/docs/internal
cp -ra target/doc playground/public/docs/internal
fi
echo finished!