forked from WebAssembly/binaryen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-js.sh
executable file
·186 lines (173 loc) · 7.1 KB
/
build-js.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
#
# This file builds the js components using emscripten. You normally don't need
# to run this, as the builds are bundled in the repo in bin/. Running this is
# useful if you are a developer and want to update those builds.
#
# Usage: build-js.sh
# Usage: EMSCRIPTEN=path/to/emscripten build-js.sh # explicit emscripten dir
#
# Emscripten's em++ and tools/webidl_binder.py will be accessed through the
# env var EMSCRIPTEN, e.g. ${EMSCRIPTEN}/em++
#
# You can get emscripten from
# http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html
#
set -e
if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$1" == "-help" ]; then
echo "usage: $0 [-g]" >&2
echo " -g produce debug build" >&2
echo ""
echo "If EMSCRIPTEN is set in the environment, emscripten will be loaded"
echo "from that directory. Otherwise the location of emscripten is resolved"
echo "through PATH."
exit 1
fi
if [ -z "$EMSCRIPTEN" ]; then
if (which emcc >/dev/null); then
# Found emcc in PATH -- set EMSCRIPTEN (we need this to access webidl_binder.py)
EMSCRIPTEN=$(dirname "$(which emcc)")
else
echo "$0: EMSCRIPTEN environment variable is not set and emcc was not found in PATH" >&2
exit 1
fi
elif [ ! -d "$EMSCRIPTEN" ]; then
echo "$0: \"$EMSCRIPTEN\" (\$EMSCRIPTEN) is not a directory" >&2
exit 1
fi
EMCC_ARGS="-std=gnu++14 --memory-init-file 0"
EMCC_ARGS="$EMCC_ARGS -s ALLOW_MEMORY_GROWTH=1"
EMCC_ARGS="$EMCC_ARGS -s DEMANGLE_SUPPORT=1"
EMCC_ARGS="$EMCC_ARGS -s NO_FILESYSTEM=0"
EMCC_ARGS="$EMCC_ARGS -s WASM=0"
EMCC_ARGS="$EMCC_ARGS -s BINARYEN_ASYNC_COMPILATION=0"
EMCC_ARGS="$EMCC_ARGS -s DISABLE_EXCEPTION_CATCHING=0" # Exceptions are thrown and caught when optimizing endless loops
OUT_FILE_SUFFIX=
if [ "$1" == "-g" ]; then
EMCC_ARGS="$EMCC_ARGS -O2" # need emcc js opts to be decently fast
EMCC_ARGS="$EMCC_ARGS --llvm-opts 0 --llvm-lto 0"
EMCC_ARGS="$EMCC_ARGS -profiling"
EMCC_ARGS="$EMCC_ARGS -s ASSERTIONS=0" # 0 as a temporary workaround for https://github.com/emscripten-core/emscripten/pull/9360
else
EMCC_ARGS="$EMCC_ARGS -Oz"
EMCC_ARGS="$EMCC_ARGS --llvm-lto 1"
EMCC_ARGS="$EMCC_ARGS -s ELIMINATE_DUPLICATE_FUNCTIONS=1"
EMCC_ARGS="$EMCC_ARGS --closure 1"
# Why these settings?
# See https://gist.github.com/rsms/e33c61a25a31c08260161a087be03169
fi
# input sources relative to this script
BINARYEN_SRC="$(dirname $0)/src"
# input sources relative to this script
BINARYEN_SCRIPTS="$(dirname $0)/scripts"
# output binaries relative to current working directory
OUT="$PWD/out"
echo "generate embedded intrinsics module"
python3 "$BINARYEN_SCRIPTS/embedwast.py" "$BINARYEN_SRC/passes/wasm-intrinsics.wast" "$BINARYEN_SRC/passes/WasmIntrinsics.cpp"
echo "compiling source files"
mkdir -p "$OUT"
"$EMSCRIPTEN/em++" \
$EMCC_ARGS \
"$BINARYEN_SRC/asmjs/asm_v_wasm.cpp" \
"$BINARYEN_SRC/asmjs/asmangle.cpp" \
"$BINARYEN_SRC/asmjs/shared-constants.cpp" \
"$BINARYEN_SRC/cfg/Relooper.cpp" \
"$BINARYEN_SRC/emscripten-optimizer/optimizer-shared.cpp" \
"$BINARYEN_SRC/emscripten-optimizer/parser.cpp" \
"$BINARYEN_SRC/emscripten-optimizer/simple_ast.cpp" \
"$BINARYEN_SRC/ir/ExpressionAnalyzer.cpp" \
"$BINARYEN_SRC/ir/ExpressionManipulator.cpp" \
"$BINARYEN_SRC/ir/LocalGraph.cpp" \
"$BINARYEN_SRC/ir/ReFinalize.cpp" \
"$BINARYEN_SRC/passes/pass.cpp" \
"$BINARYEN_SRC/passes/AlignmentLowering.cpp" \
"$BINARYEN_SRC/passes/Asyncify.cpp" \
"$BINARYEN_SRC/passes/AvoidReinterprets.cpp" \
"$BINARYEN_SRC/passes/CoalesceLocals.cpp" \
"$BINARYEN_SRC/passes/DeadArgumentElimination.cpp" \
"$BINARYEN_SRC/passes/CodeFolding.cpp" \
"$BINARYEN_SRC/passes/CodePushing.cpp" \
"$BINARYEN_SRC/passes/ConstHoisting.cpp" \
"$BINARYEN_SRC/passes/DataFlowOpts.cpp" \
"$BINARYEN_SRC/passes/DeadCodeElimination.cpp" \
"$BINARYEN_SRC/passes/Directize.cpp" \
"$BINARYEN_SRC/passes/DuplicateImportElimination.cpp" \
"$BINARYEN_SRC/passes/DuplicateFunctionElimination.cpp" \
"$BINARYEN_SRC/passes/ExtractFunction.cpp" \
"$BINARYEN_SRC/passes/Flatten.cpp" \
"$BINARYEN_SRC/passes/FuncCastEmulation.cpp" \
"$BINARYEN_SRC/passes/I64ToI32Lowering.cpp" \
"$BINARYEN_SRC/passes/Inlining.cpp" \
"$BINARYEN_SRC/passes/InstrumentLocals.cpp" \
"$BINARYEN_SRC/passes/InstrumentMemory.cpp" \
"$BINARYEN_SRC/passes/LegalizeJSInterface.cpp" \
"$BINARYEN_SRC/passes/LimitSegments.cpp" \
"$BINARYEN_SRC/passes/LocalCSE.cpp" \
"$BINARYEN_SRC/passes/LogExecution.cpp" \
"$BINARYEN_SRC/passes/LoopInvariantCodeMotion.cpp" \
"$BINARYEN_SRC/passes/MemoryPacking.cpp" \
"$BINARYEN_SRC/passes/MergeBlocks.cpp" \
"$BINARYEN_SRC/passes/MergeLocals.cpp" \
"$BINARYEN_SRC/passes/Metrics.cpp" \
"$BINARYEN_SRC/passes/MinifyImportsAndExports.cpp" \
"$BINARYEN_SRC/passes/NameList.cpp" \
"$BINARYEN_SRC/passes/NoExitRuntime.cpp" \
"$BINARYEN_SRC/passes/OptimizeAddedConstants.cpp" \
"$BINARYEN_SRC/passes/OptimizeInstructions.cpp" \
"$BINARYEN_SRC/passes/PickLoadSigns.cpp" \
"$BINARYEN_SRC/passes/PostEmscripten.cpp" \
"$BINARYEN_SRC/passes/Precompute.cpp" \
"$BINARYEN_SRC/passes/Print.cpp" \
"$BINARYEN_SRC/passes/PrintFeatures.cpp" \
"$BINARYEN_SRC/passes/PrintFunctionMap.cpp" \
"$BINARYEN_SRC/passes/PrintCallGraph.cpp" \
"$BINARYEN_SRC/passes/RedundantSetElimination.cpp" \
"$BINARYEN_SRC/passes/RelooperJumpThreading.cpp" \
"$BINARYEN_SRC/passes/RemoveNonJSOps.cpp" \
"$BINARYEN_SRC/passes/RemoveImports.cpp" \
"$BINARYEN_SRC/passes/RemoveMemory.cpp" \
"$BINARYEN_SRC/passes/RemoveUnusedBrs.cpp" \
"$BINARYEN_SRC/passes/RemoveUnusedModuleElements.cpp" \
"$BINARYEN_SRC/passes/RemoveUnusedNames.cpp" \
"$BINARYEN_SRC/passes/ReorderFunctions.cpp" \
"$BINARYEN_SRC/passes/ReorderLocals.cpp" \
"$BINARYEN_SRC/passes/ReReloop.cpp" \
"$BINARYEN_SRC/passes/SafeHeap.cpp" \
"$BINARYEN_SRC/passes/SimplifyGlobals.cpp" \
"$BINARYEN_SRC/passes/SimplifyLocals.cpp" \
"$BINARYEN_SRC/passes/Souperify.cpp" \
"$BINARYEN_SRC/passes/SpillPointers.cpp" \
"$BINARYEN_SRC/passes/SSAify.cpp" \
"$BINARYEN_SRC/passes/StackIR.cpp" \
"$BINARYEN_SRC/passes/Strip.cpp" \
"$BINARYEN_SRC/passes/StripTargetFeatures.cpp" \
"$BINARYEN_SRC/passes/TrapMode.cpp" \
"$BINARYEN_SRC/passes/Untee.cpp" \
"$BINARYEN_SRC/passes/Vacuum.cpp" \
"$BINARYEN_SRC/passes/WasmIntrinsics.cpp" \
"$BINARYEN_SRC/support/bits.cpp" \
"$BINARYEN_SRC/support/colors.cpp" \
"$BINARYEN_SRC/support/file.cpp" \
"$BINARYEN_SRC/support/safe_integer.cpp" \
"$BINARYEN_SRC/support/threads.cpp" \
"$BINARYEN_SRC/wasm/literal.cpp" \
"$BINARYEN_SRC/wasm/wasm-binary.cpp" \
"$BINARYEN_SRC/wasm/wasm-emscripten.cpp" \
"$BINARYEN_SRC/wasm/wasm-interpreter.cpp" \
"$BINARYEN_SRC/wasm/wasm-io.cpp" \
"$BINARYEN_SRC/wasm/wasm-s-parser.cpp" \
"$BINARYEN_SRC/wasm/wasm-stack.cpp" \
"$BINARYEN_SRC/wasm/wasm-type.cpp" \
"$BINARYEN_SRC/wasm/wasm-validator.cpp" \
"$BINARYEN_SRC/wasm/wasm.cpp" \
-I"$BINARYEN_SRC" \
-o "$OUT/shared.o"
echo "building binaryen.js"
"$EMSCRIPTEN/em++" \
$EMCC_ARGS \
"$BINARYEN_SRC/binaryen-c.cpp" \
"$OUT/shared.o" \
-I"$BINARYEN_SRC/" \
-o "$OUT/binaryen$OUT_FILE_SUFFIX.js" \
-s MODULARIZE_INSTANCE=1 \
-s 'EXPORT_NAME="Binaryen"' \
--post-js "$BINARYEN_SRC/js/binaryen.js-post.js"