-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
171 lines (154 loc) · 4.94 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
#!/bin/bash
# Function to build HTML
build_html() {
emcc src/cpp/gol.cpp -o build/gol.html
}
help() {
echo
echo "Usage: $0 [command]"
echo
echo "For building libraries with emcmake, see /src/library for an example."
echo
echo "Available commands:"
echo " html Build HTML"
echo " c-libs Build C with libraries"
echo " accessor Build accessor (see index.html)"
echo " simple Build simple WASM (see index.html)"
echo " wasm Build WASM"
echo " wasmtime Run WASM with Wasmtime, via EMCC emitted standalone WASM (C based)"
echo " wasi Build WASI example (C based)"
echo " wasiPure Build WASI example with emcc's experimental pure WASI (C based)"
echo " wasiClock Build WASI clock example using wat2wasm - run anywhere WASI bindings are available"
echo " wat Build WAT"
echo " watshared Build shared memory example - supports multiple threads"
echo " asc Build ASC (AssemblyScript)"
echo " vec Build VEC (see vectors.js)"
echo " vecs Build VEC Shared (see vectorsShared.js)"
echo " help Show a command list"
exit 1
}
build_wat2wasi() {
wat2wasm src/wasi/sysclock.wat -o build/wasiClock.wasm
}
build_wasi() {
emcc src/wasi/hello.c -o build/wasiExample.wasm -s STANDALONE_WASM=1
}
build_wasiPure() {
emcc src/wasi/hello.c -o build/wasiPure.wasm -s PURE_WASI=1
}
run_wasmtime() {
wasmtime build/clock.wasm
}
# Function to build the shared mem example
build_sm() {
wat2wasm src/wasm/shared_memory.wat -o build/shared_memory.wasm --enable-threads
}
# Function to build C with libraries
build_c_with_libs() {
emcc example.c -s LDFLAGS=['-lSDL2'] -o output.html
}
# Function to build accessor
build_accessor() {
emcc -o build/gol.js src/js/gol.cpp -s EXPORTED_RUNTIME_METHODS=['ccall'] -s EXPORTED_FUNCTIONS=_main,_myFunction
}
# Function to build WASM
build_wasm() {
emcc src/cpp/gol.cpp -o build/gol.wasm -s STANDALONE_WASM=1 -s EXPORTED_FUNCTIONS=[_main,_myFunction]
}
# Function to build simple WASM
build_simple() {
emcc src/c/simple.c -o build/simple.wasm -s STANDALONE_WASM=1 -s EXPORT_ALL=1
}
# Function to build WAT
build_wat() {
wat2wasm src/wasm/memory.wat -o build/memory.wasm
}
# Function to build ASC
build_asc() {
asc src/ts-asc/fib.ts --outFile build/assembly.wasm --optimize
}
# Function to build VEC
build_vec() {
emcc src/c/vectors.c -o build/vectors.wasm -s STANDALONE_WASM=1 -s EXPORTED_FUNCTIONS=_alloc_vector,_dealloc_vector,_add_vectors,_sub_vectors,_mul_scalar
}
build_vecs() {
emcc src/c/vectorsShared.c -o build/vectorsShared.wasm -s STANDALONE_WASM=1 -s EXPORT_ALL=1
}
print_header() {
echo -e "\033[1m\033[94m ____ ____ ____ ____ _________ ____ ____ ____ ____ \033[0m"
echo -e "\033[1m\033[94m||E |||M |||C |||C ||| |||W |||A |||S |||M ||\033[0m"
echo -e "\033[1m\033[94m||__|||__|||__|||__|||_______|||__|||__|||__|||__||\033[0m"
echo -e "\033[1m\033[94m|/__\|/__\|/__\|/__\|/_______\|/__\|/__\|/__\|/__\|\033[0m"
echo
echo -e "\033[1m\033[92mEMCC WASM\033[0m"
}
print_header
# Main execution block
case "$1" in
html)
build_html
;;
c-libs)
build_c_with_libs
;;
accessor)
build_accessor
;;
simple)
build_simple
;;
wasm)
build_wasm
;;
wasmtime)
run_wasmtime
;;
wasi)
build_wasi
;;
wasiPure)
build_wasiPure
;;
wasiClock)
build_wat2wasi
;;
wat)
build_wat
;;
watshared)
build_sm
;;
asc)
build_asc
;;
vec)
build_vec
;;
vecs)
build_vecs
;;
*)
echo
echo "Usage: $0 [command]"
echo
echo "For building libraries with emcmake, see /src/library for an example."
echo
echo "Available commands:"
echo " html Build HTML"
echo " c-libs Build C with libraries"
echo " accessor Build accessor (see index.html)"
echo " simple Build simple WASM (see index.html)"
echo " wasm Build WASM"
echo " wasmtime Run WASM with Wasmtime, via EMCC emitted standalone WASM (C based)"
echo " wasi Build WASI example (C based)"
echo " wasiPure Build WASI example with emcc's experimental pure WASI (C based)"
echo " wasiClock Build WASI clock example using wat2wasm - run anywhere WASI bindings are available"
echo " wat Build WAT"
echo " watshared Build shared memory example - supports multiple threads"
echo " asc Build ASC (AssemblyScript)"
echo " vec Build VEC (see vectors.js)"
echo " vecs Build VEC Shared (see vectorsShared.js)"
echo " help Show a command list"
exit 1
;;
esac