-
-
Notifications
You must be signed in to change notification settings - Fork 145
/
build.sh
executable file
·296 lines (256 loc) · 7.47 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/bin/bash
set -e
if [ ! -d .git ]; then
echo 'build.sh must be run from repository root' 1>&2
exit 1
fi
message() {
echo "[1;93mbuild.sh: ${*}[0m"
}
run_configure() {
local feature
if [[ "$VIM_FEATURE" == "" ]]; then
feature='normal'
else
feature="$VIM_FEATURE"
fi
message "Running ./configure: feature=${feature}"
CPP="gcc -E" emconfigure ./configure \
--enable-fail-if-missing \
--enable-gui=wasm \
"--with-features=${feature}" \
--with-x=no \
--with-vim-name=vim.bc \
--with-modified-by=rhysd \
--with-compiledby=rhysd \
--disable-darwin \
--disable-smack \
--disable-selinux \
--disable-xsmp \
--disable-xsmp-interact \
--disable-luainterp \
--disable-mzschemeinterp \
--disable-perlinterp \
--disable-pythoninterp \
--disable-python3interp \
--disable-tclinterp \
--disable-rubyinterp \
--disable-cscope \
--disable-netbeans \
--disable-channel \
--disable-terminal \
--disable-autoservername \
--disable-rightleft \
--disable-arabic \
--disable-hangulinput \
--disable-xim \
--disable-fontset \
--disable-gtk2-check \
--disable-gnome-check \
--disable-gtk3-check \
--disable-motif-check \
--disable-athena-check \
--disable-nextaw-check \
--disable-carbon-check \
--disable-gtktest \
--disable-icon-cache-update \
--disable-desktop-database-update \
--disable-largefile \
--disable-canberra \
--disable-acl \
--disable-gpm \
--disable-sysmouse \
--disable-nls
}
run_make() {
message "Running make"
local cflags
if [[ "$RELEASE" != "" ]]; then
cflags="-Os"
elif [[ "$PROFILING" != "" ]]; then
cflags="-Os -g2"
else
cflags="-O1 -g -DGUI_WASM_DEBUG"
fi
emmake make -j CFLAGS="$cflags"
message "Copying bitcode to wasm/"
cp src/vim.bc wasm/
}
run_emcc() {
emcc --version
local emcc_fullpath="$(which emcc)"
if [[ "$emcc_fullpath" != *"/emsdk/"* ]]; then
echo "'emcc' must be installed via emsdk for the latest emscripten" 1>&2
exit 1
fi
local feature
local feature_dir
local src_prefix
if [[ "$VIM_FEATURE" == "" ]]; then
feature='normal'
feature_dir='./wasm'
src_prefix=''
else
feature="$VIM_FEATURE"
feature_dir="./wasm/${VIM_FEATURE}"
src_prefix='../'
fi
local extraflags
if [[ "$RELEASE" != "" ]]; then
extraflags="-Os"
elif [[ "$PROFILING" != "" ]]; then
extraflags="-Os --profiling"
else
# On debug build.
# Note: -g4 generates sourcemap
extraflags="-O0 -g4 -s ASSERTIONS=1"
fi
message "Running emcc: feature=${feature} flags=${extraflags}"
cd "$feature_dir"
if [[ "$PRELOAD_HOME_DIR" != "" && -d ./home ]]; then
cp ${src_prefix}DEMO_USAGE.md "./home/web_user/README.md"
extraflags="${extraflags} --preload-file home"
fi
if [ ! -f tutor ]; then
cp "${src_prefix}../runtime/tutor/tutor" .
fi
# Note: ALLOW_MEMORY_GROWTH is necessary because 'normal' feature build requires larger memory size
emcc "${src_prefix}vim.bc" \
-v \
-o vim.js \
-lidbfs.js \
--pre-js "${src_prefix}pre.js" \
--js-library "${src_prefix}runtime.js" \
-s INVOKE_RUN=1 \
-s EXIT_RUNTIME=1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s "EXPORTED_FUNCTIONS=['_wasm_main','_gui_wasm_resize_shell','_gui_wasm_handle_keydown', '_gui_wasm_handle_drop', '_gui_wasm_set_clip_avail', '_gui_wasm_do_cmdline', '_gui_wasm_emsg']" \
-s "EXTRA_EXPORTED_RUNTIME_METHODS=['cwrap']" \
--preload-file usr \
--preload-file tutor \
$extraflags
if [[ "$RELEASE" != "" ]]; then
npm run minify:common
npm run "minify:${feature}"
fi
cd -
}
run_release() {
message "Cleaning built files"
rm -rf wasm/*
git checkout wasm/
message "Start release build"
RELEASE=true ./build.sh
message "Release build done"
}
# Build both normal feature and small feature
run_release-all() {
message "Release builds for all features: normal, small"
run_release
message "Start release build for small feature"
make clean
RELEASE=true VIM_FEATURE=small ./build.sh configure make emcc
message "Release build done for small feature"
}
run_build_runtime() {
message "Building runtime JavaScript sources"
cd wasm/
npm install
npm run build
cd -
}
run_check() {
message "Checking built artifacts"
cd wasm/
npm run lint
if [[ "$RELEASE" != "" ]]; then
npm test
fi
cd -
}
run_gh-pages() {
message "Preparing new commit on gh-pages branch"
local hash
hash="$(git rev-parse HEAD)"
cp wasm/style.css _style.css
cp wasm/main.js _main.js
cp wasm/vimwasm.js _vimwasm.js
cp wasm/index.html _index.html
cp -R wasm/images _images
mkdir _small
cp wasm/small/vim.* _small/
git checkout gh-pages
git pull --rebase
mv _style.css style.css
mv _main.js main.js
mv _vimwasm.js vimwasm.js
mv _index.html index.html
mv _images/vim-wasm-logo-16x16.png images/
mv _images/vim-wasm-logo-32x32.png images/
cp wasm/vim.* .
rm -rf vim.bc vim.wast vim.wasm.map _images
mkdir -p small
mv _small/* small/
rm -rf _small
# XXX: Hack for GitHub pages.
# GitHub pages does not compress binary data file vim.data on sending it to browser. To force
# GitHub pages to compress it with gzip encoding, vim.data is renamed to vim.data.bmp for fake.
# GitHub pages recognizes this file as BMP and compress it with gzip.
sed -i '' -E 's/"vim.data"/"vim.data.bmp"/g' vim.js
mv vim.data vim.data.bmp
git add vim.* index.html style.css main.js vimwasm.js images small
git commit -m "Deploy from ${hash}"
message "New commit created from ${hash}. Please check diff with 'git show' and deploy it with 'git push'"
}
run_deploy() {
message "Before deploying gh-pages, run release build"
export PRELOAD_HOME_DIR=true
run_release-all
message "Deploying gh-pages"
run_gh-pages
}
run_merge-upstream() {
message 'Running `tools/merge_upstream_for_wasm.bash`'
./tools/merge_upstream_for_wasm.bash
}
run_merge-finish() {
message 'Running `tools/merge_upstream_for_wasm.bash finish`'
./tools/merge_upstream_for_wasm.bash finish
}
run_prepare-preload() {
message "Running tools/prepare_preload_dirs.bash"
./tools/prepare_preload_dir.bash
}
run_watch() {
message 'Watch files and run build commands automatically'
message " emcc: $(which emcc)"
message " npm: $(which npm)"
message " node: $(which node)"
./wasm/node_modules/.bin/chokidar \
--verbose \
--ignore './wasm/node_modules/**' \
--silent \
--command './tools/watch_wasm_build.bash {path}' \
'./wasm/usr/**' \
'./wasm/home/**' \
'./wasm/vtest/*.js' \
'./wasm/test/*' \
'./wasm/*.js' \
'./wasm/.eslintrc.js' \
'./wasm/vim.bc' \
'./wasm/style.css' \
'./src/*.[ch]'
}
if [[ "$#" != "0" ]]; then
for task in "$@"; do
"run_${task}"
done
else
make distclean
run_configure
run_make
run_build_runtime
run_emcc
run_check
fi
message "Done."