-
Notifications
You must be signed in to change notification settings - Fork 36
/
build-brotli.sh
executable file
·61 lines (48 loc) · 1.62 KB
/
build-brotli.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
#!/bin/bash
SRC=$(dirname $0)
BUILD="$1"
BROTLI_SRC="$2"
if [ "$BROTLI_SRC" == "" ]; then
BROTLI_SRC=$(pwd)/upstream/brotli
fi
if [ "$BUILD" == "" ]; then
BUILD=$(pwd)/build
fi
SRC=$(realpath "$SRC")
BUILD=$(realpath "$BUILD")
BROTLI_BUILD=$BUILD/brotli
# If we don't have a copy of binaryen, make one
if [ ! -d $BROTLI_SRC/ ]; then
git clone --depth 1 https://github.com/google/brotli.git "$BROTLI_SRC/"
pushd $BROTLI_SRC/
# This is the last tested commit of brotli.
# Feel free to try with a newer version
COMMIT=62662f87cdd96deda90ac817de94e3c4af75226a
git fetch origin $COMMIT
git reset --hard $COMMIT
popd
fi
if [ ! -d $BROTLI_BUILD/ ]; then
CFLAGS="-flto" \
LDFLAGS="\
-flto \
-s ALLOW_MEMORY_GROWTH=1 \
-s EXPORTED_FUNCTIONS=_main,_free,_malloc \
-s EXPORTED_RUNTIME_METHODS=FS,PROXYFS,ERRNO_CODES,allocateUTF8 \
-lproxyfs.js \
--js-library=$SRC/emlib/fsroot.js \
" emcmake cmake -G Ninja \
-S $BROTLI_SRC/ \
-B $BROTLI_BUILD/ \
-DCMAKE_BUILD_TYPE=Release
# Make sure we build js modules (.mjs).
sed -i -E 's/\.js/.mjs/g' $BROTLI_BUILD/build.ninja
# The mjs patching is over zealous, and patches some source JS files rather than just output files.
# Undo that.
sed -i -E 's/(pre|post|proxyfs|fsroot)\.mjs/\1.js/g' $BROTLI_BUILD/build.ninja
fi
cmake --build $BROTLI_BUILD/ -- brotli.mjs
# the build script for brotli doesn't create a `bin` folder like binaryen or llvm
# so lets create and populate one
mkdir -p $BROTLI_BUILD/bin
cp $BROTLI_BUILD/brotli.{mjs,wasm} $BROTLI_BUILD/bin