Skip to content

Commit f37caa7

Browse files
committed
Web: Refactor build script to run in parallel with full LTO
Fabio found that full LTO produces smaller binaries than ThinLTO, and that's quite important for the Web platform. But for an obscure reason LLVM's full LTO cannot linking with multiple threads, and so it's slow as heck (10-15 min per build). So we work it around by starting all builds in parallel so that they can all link at the same time. The code to do so is pretty ugly, could be refactored further.
1 parent 9aa0cb9 commit f37caa7

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

build-web/build.sh

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@ set -e
44

55
# Config
66

7-
export SCONS="scons -j${NUM_CORES} verbose=yes warnings=no progress=no"
7+
# To speed up builds with single-threaded full LTO linking,
8+
# we run all builds in parallel each from their own folder.
9+
export NUM_JOBS=5
10+
declare -a JOBS=(
11+
"tools=yes target=release_debug use_closure_compiler=yes"
12+
"tools=no target=release_debug"
13+
"tools=no target=release"
14+
"tools=no target=release_debug dlink_enabled=yes"
15+
"tools=no target=release dlink_enabled=yes"
16+
)
17+
18+
export SCONS="scons -j$(expr ${NUM_CORES} / ${NUM_JOBS}) verbose=yes warnings=no progress=no"
819
export OPTIONS="production=yes"
9-
export OPTIONS_MONO="module_mono_enabled=yes use_lto=no"
20+
export OPTIONS_MONO="module_mono_enabled=yes -j${NUM_CORES}"
1021
export TERM=xterm
1122

1223
source /root/emsdk/emsdk_env.sh
@@ -21,21 +32,25 @@ tar xf /root/godot.tar.gz --strip-components=1
2132
if [ "${CLASSICAL}" == "1" ]; then
2233
echo "Starting classical build for Web..."
2334

24-
$SCONS platform=web ${OPTIONS} target=release_debug tools=no
25-
$SCONS platform=web ${OPTIONS} target=release tools=no
35+
for i in {0..4}; do
36+
cp -r /root/godot /root/godot$i
37+
cd /root/godot$i
38+
echo "$SCONS platform=web ${OPTIONS} ${JOBS[$i]}"
39+
$SCONS platform=web ${OPTIONS} ${JOBS[$i]} &
40+
pids[$i]=$!
41+
done
2642

27-
$SCONS platform=web ${OPTIONS} target=release_debug tools=no dlink_enabled=yes
28-
$SCONS platform=web ${OPTIONS} target=release tools=no dlink_enabled=yes
29-
30-
mkdir -p /root/out/templates
31-
cp -rvp bin/*.zip /root/out/templates
32-
rm -f bin/*.zip
33-
34-
$SCONS platform=web ${OPTIONS} target=release_debug tools=yes use_closure_compiler=yes
43+
for pid in ${pids[*]}; do
44+
wait $pid
45+
done
3546

3647
mkdir -p /root/out/tools
37-
cp -rvp bin/*.zip /root/out/tools
38-
rm -f bin/*.zip
48+
cp -rvp /root/godot0/bin/*tools*.zip /root/out/tools
49+
50+
mkdir -p /root/out/templates
51+
for i in {1..4}; do
52+
cp -rvp /root/godot$i/bin/*.zip /root/out/templates
53+
done
3954
fi
4055

4156
# Mono

0 commit comments

Comments
 (0)