-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·199 lines (171 loc) · 5.54 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
PROJECT_ROOT="$SCRIPT_DIR"
export TEXINPUTS=.:$PROJECT_ROOT/tex/:
echo "TEXINPUTS=$TEXINPUTS"
function show_result {
# if return code is zero, then echo "Done" else echo "Failed"
if [ $? -ne 0 ]; then
# echo a red "Failed"
echo -e "\033[0;31mFailed\033[0m"
else
# echo a gree "Done"
echo -e "\033[0;32mDone\033[0m"
fi
}
function show_lize_result {
# if return code is zero, then echo "Done" else echo "Failed"
if [ $? -ne 0 ]; then
# echo a red "Failed"
echo -e "\033[0;31mFailed\033[0m"
tail -n 50 build/$1.log
echo "open build/$1.log to see the log."
else
# echo a gree "Done"
echo -e "\033[0;32mDone\033[0m"
fi
echo "Open build/$1.log to see the log."
echo "Open build/$1.tex to see the LaTeX source."
echo "Open output/$1.pdf to see the result."
}
function prep_wasm {
mkdir -p lib
lib_name=$1
url=$2
hash=$3
lib_path=${4:-$lib_name}
if [ ! -d "lib/$lib_name" ]; then
git clone --depth 1 $url lib/$lib_name
if [ -n "$hash" ]; then
(cd lib/$lib_name && git fetch --depth 1 origin $hash && git checkout $hash)
fi
fi
# only run wasm-pack build in CI or for `dev.sh`, so other people would not need Rust dependencies
if [ -n "$CI" ] || [ -n "$UTS_DEV" ]; then
# Check if pkg directory exists and is not empty
if [ ! -d "lib/$lib_path/pkg" ] || [ -z "$(ls -A lib/$lib_path/pkg)" ]; then
echo "Building WASM package for $lib_name..."
(cd lib/$lib_path && bunx wasm-pack -v build --target web --release . --out-dir pkg)
else
echo "Using cached WASM package for $lib_name"
fi
else
# echo warning emoji
echo "🟡 Skipping wasm-pack build for $lib_name, some notes that used Rust and WASM might not work as epected."
fi
cp lib/$lib_path/pkg/*.wasm output/
}
function bun_build {
# don't run `bun install` for `dev.sh`
if [ -z "$UTS_DEV" ]; then
bun install
fi
mkdir -p output
prep_wasm wgputoy https://github.com/compute-toys/wgpu-compute-toy.git 3fee2f5d9441aa4c55ea9e7a0b6a1daa21e8e874
prep_wasm egglog https://github.com/egraphs-good/egglog.git 8d9b10ec712106b21d10b7bf45d10c0f9d1d09c7 egglog/web-demo
prep_wasm rhaiscript https://github.com/rhaiscript/playground 9fa80661bc9eb69363ac86879826dcd8ccb604af
# failed:
# prep_wasm nalgebra https://github.com/dimforge/nalgebra
# for each files in the directory `bun`, run bun build
for FILE in $(ls -1 bun); do
# if the file extension is .css
if [[ $FILE == *".css" ]]; then
echo "🚀 lightningcss"
just css bun/$FILE
# check result
# EXIT_CODE=$?
# if [ $EXIT_CODE -ne 0 ]; then
# echo "🚨 lightningcss failed with $EXIT_CODE"
# exit $EXIT_CODE
# fi
else
just js bun/$FILE
# bun build bun/$FILE --outdir output
fi
done
}
function copy_extra_assets {
mkdir -p output/shader/
cp -f assets/shader/*.glsl output/shader/
# ls output/shader/
# cp node_modules/@myriaddreamin/typst-ts-web-compiler/pkg/typst_ts_web_compiler_bg.wasm output/
# cp node_modules/@myriaddreamin/typst-ts-renderer/pkg/typst_ts_renderer_bg.wasm output/
# ls output/*.wasm
# cp node_modules/ginac-wasm/dist/ginac.wasm output/
}
function build_ssr {
echo "⭐ Rebuilding SSR assets"
echo >build/ssr.log
bunx roger trios assets/penrose/*.trio.json -o output 1>>build/ssr.log 2>>build/ssr.log
}
function backup_xml_files() {
echo "⭐ Backing up XML files"
mkdir -p output/.bak
cp output/*.xml output/.bak/ 2>/dev/null || true
}
function needs_update() {
local xml_file=$1
local html_file=$2
local backup_file="output/.bak/$(basename "$xml_file")"
# If HTML doesn't exist, needs update
if [ ! -f "$html_file" ]; then
return 0
fi
# If backup doesn't exist (first run), needs update
if [ ! -f "$backup_file" ]; then
return 0
fi
# Compare current XML with backup
if ! cmp -s "$xml_file" "$backup_file"; then
return 0
fi
# Check if XSL template is newer than HTML file
if [ "assets/html.xsl" -nt "$html_file" ]; then
return 0
fi
return 1
}
source convert_xml.sh
function build {
mkdir -p build
echo "⭐ Rebuilding bun"
bun_build
backup_xml_files
echo "⭐ Rebuilding forest"
just forest
show_result
# Check if index.xml was generated
if [ ! -f "output/index.xml" ]; then
echo -e "\033[0;31mError: index.xml not found in output directory. Forest build likely failed.\033[0m"
exit 1
fi
# echo "⭐ Copying assets"
copy_extra_assets
convert_xml_files true
show_result
# build_ssr
# show_result
# echo "Open build/forester.log to see the log."
}
function lize {
./lize.sh spin-0001 >/dev/null 2>&1
show_lize_result spin-0001
./lize.sh hopf-0001 >/dev/null 2>&1
show_lize_result hopf-0001
./lize.sh ca-0001 >/dev/null 2>&1
show_lize_result ca-0001
./lize.sh tt-0001 >/dev/null 2>&1
show_lize_result tt-0001
./lize.sh uts-000C >/dev/null 2>&1
show_lize_result uts-000C
# ./lize.sh uts-0001 > /dev/null 2>&1
# show_lize_result uts-0001
}
time build
echo
#if environment variable CI or LIZE is set
if [ -n "$CI" ] || [ -n "$LIZE" ]; then
echo "⭐ Rebuilding LaTeX"
time lize
echo
fi