22
33if [[ -z ${EMSDK+z} ]]
44then
5- pushd ${SDKROOT}
6- . ${CONFIG:- config}
7- popd
5+
6+ . ${CONFIG:- config}
87
98 if [ -d emsdk ]
109 then
2322 ./emsdk install ${EMFLAVOUR:- latest}
2423 ./emsdk activate ${EMFLAVOUR:- latest}
2524
25+
2626 pushd upstream/emscripten
2727 echo " FIXME: applying stdio* are not const"
2828 sed -i ' s|extern FILE \*const|extern FILE \*|g' cache/sysroot/include/stdio.h
6565 # wget https://patch-diff.githubusercontent.com/raw/emscripten-core/emscripten/pull/18941.diff
6666 # patch -p1 < 18941.diff
6767 fi
68+ popd
69+
70+ # wget https://raw.githubusercontent.com/paradust7/minetest-wasm/main/emsdk_emcc.patch
71+ # patch -p1 < emsdk_emcc.patch
6872
73+ pushd upstream/emscripten
6974 echo " FIXME: Applying https://github.com/emscripten-core/emscripten/pull/21472 glfw3: gl level version major/minor hints"
7075 wget https://patch-diff.githubusercontent.com/raw/emscripten-core/emscripten/pull/21472.diff
7176 patch -p1 < 21472.diff
9297
9398
9499
95- # wget https://raw.githubusercontent.com/paradust7/minetest-wasm/main/emsdk_emcc.patch
96- # patch -p1 < emsdk_emcc.patch
97-
98-
99100 # https://github.com/paradust7/minetest-wasm/blob/main/emsdk_dirperms.patch
100101 patch -p1 << END
101102--- emsdk-orig/upstream/emscripten/system/lib/wasmfs/wasmfs.cpp 2022-07-29 17:22:28.000000000 +0000
172173
173174 export EMSDK_PYTHON=$SYS_PYTHON
174175
175- if [ -f $EMSDK /.complete ]
176+ if [ -f emsdk /.complete ]
176177 then
177178 echo "
178179 * emsdk prereq ok
204205 embuilder --pic build $one
205206 done
206207
207- export BUN_INSTALL=${SDKROOT} /bun
208208 curl -fsSL https://bun.sh/install | bash
209209
210210 npm install --prefix $ROOT /emsdk/node/?? .?? .* -g pnpm@^9.0.0
@@ -214,18 +214,255 @@ END
214214 cat > emsdk/upstream/emscripten/emcc << END
215215#!/bin/bash
216216
217- if \$ {EMCC_TRACE:-false}
217+ EMCC_TRACE=\$ {EMCC_TRACE:-false}
218+ if \$ EMCC_TRACE
218219then
219- echo "
220- \$ 0 \$ @" >> $SDKROOT /emcc.log
220+ echo "
221+ $@ " >> $SDKROOT /emcc.log
222+
221223fi
222224
223225unset _EMCC_CCACHE
226+
227+ #if [ -z "\$ _EMCC_CCACHE" ]
228+ #then
229+
224230unset _PYTHON_SYSCONFIGDATA_NAME
225231unset PYTHONHOME
226232unset PYTHONPATH
227233
228- $EMSDK_PYTHON -E $SDKROOT /emsdk-cc \$ 0.py "\$ @"
234+ # -Wwarn-absolute-paths
235+ # --valid-abspath ${SDKROOT}
236+
237+ # COMMON="-Wno-unsupported-floating-point-opt"
238+ COMMON="-Wno-limited-postlink-optimizations -Wno-unused-command-line-argument -Wno-unreachable-code-fallthrough -Wno-unused-function"
239+ SHARED=""
240+ IS_SHARED=false
241+ PY_MODULE=false
242+ MVP=\$ {MVP:true}
243+ WASM_PURE=\$ {WASM_PURE:true}
244+
245+
246+ if \$ MVP
247+ then
248+
249+ # turn of wasm ex (https://github.com/emscripten-core/emscripten/pull/20536)
250+ # -fno-wasm-exceptions -sEMSCRIPTEN_LONGJMP=0
251+
252+
253+ # -mcpu=generic would activate those https://reviews.llvm.org/D125728
254+ # https://github.com/emscripten-core/emscripten/pull/17689
255+
256+ # -fPIC not allowed with -mno-mutable-globals
257+ # -mno-sign-ext not allowed with pthread
258+
259+ #WASMOPTS="-fno-wasm-exceptions -sSUPPORT_LONGJMP=emscripten"
260+ #CPU="-mnontrapping-fptoint -mno-reference-types -mno-sign-ext -m32"
261+
262+ CPU="-D_FILE_OFFSET_BITS=64 -sSUPPORT_LONGJMP=emscripten -mnontrapping-fptoint -mno-reference-types -mno-sign-ext -m32"
263+
264+ else
265+ CPU="-D_FILE_OFFSET_BITS=64 -mcpu=bleeding-edge -m64"
266+ fi
267+
268+ # try to keep 32 but with 64 iface (bitint)
269+ WASMEXTRA="$WASM_EXTRA \$ WASMOPTS"
270+
271+
272+ LINKING=\$ {LINKING:-false}
273+
274+ if echo "\$ @ "|grep -q "\\ .so "
275+ then
276+ LINKING=true
277+ fi
278+
279+
280+ declare -A seen=( )
281+
282+ for arg do
283+ shift
284+
285+ if [ "\$ arg" = "-v" ]
286+ then
287+ $EMSDK_PYTHON -E \$ 0.py -v
288+ exit 0
289+ fi
290+
291+ if [ "\$ arg" = "--version" ]
292+ then
293+ $EMSDK_PYTHON -E \$ 0.py --version
294+ exit 0
295+ fi
296+
297+ if \$ LINKING
298+ then
299+ # prevent duplicates objects/archives files on cmdline when linking shared
300+ if echo \$ arg|grep -q \\\\ .o\$
301+ then
302+ [[ \$ {seen[\$ arg]} ]] && continue
303+ fi
304+ if echo \$ arg|grep -q \\\\ .a\$
305+ then
306+ [[ \$ {seen[\$ arg]} ]] && continue
307+ fi
308+ if echo \$ arg|grep -q ^-l
309+ then
310+ [[ \$ {seen[\$ arg]} ]] && continue
311+ fi
312+ seen[\$ arg]=1
313+ fi
314+
315+ arg_is_bad=false
316+
317+ for badarg in "-Wl,--as-needed" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-Wl,-znow" "-Wl,-zrelro" "-Wl,-zrelro,-znow"
318+ do
319+ if [ "\$ arg" = "\$ badarg" ]
320+ then
321+ arg_is_bad=true
322+ break
323+ fi
324+ done
325+
326+ if \$ arg_is_bad
327+ then
328+ continue
329+ fi
330+
331+ if [ "\$ arg" = "-c" ]
332+ then
333+ CPU_EXTRA=\$ WASM_EXTRA
334+ fi
335+
336+ if [ "\$ arg" = "-o" ]
337+ then
338+ CPU_EXTRA=\$ WASM_EXTRA
339+ fi
340+
341+ if [ "\$ arg" = "-fallow-argument-mismatch" ]
342+ then
343+ continue
344+ fi
345+
346+ if [ "\$ arg" = "-lutil" ]
347+ then
348+ continue
349+ fi
350+
351+ if [ "\$ arg" = "-O3" ]
352+ then
353+ continue
354+ fi
355+
356+ if [ "\$ arg" = "-g" ]
357+ then
358+ continue
359+ fi
360+
361+ if [ "\$ arg" = "-lgcc" ]
362+ then
363+ continue
364+ fi
365+
366+ if [ "\$ arg" = "-lgcc_s" ]
367+ then
368+ continue
369+ fi
370+
371+ if [ "\$ arg" = "-nomvp" ]
372+ then
373+ MVP=false
374+ continue
375+ fi
376+
377+ if [ "\$ arg" = "-pthread" ]
378+ then
379+ if echo \$ CPU|grep -q mno-sign-ext
380+ then
381+ continue
382+ fi
383+ fi
384+
385+
386+ # that is for some very bad setup.py behaviour regarding cross compiling.
387+ # should not be needed ..
388+ [ "\$ arg" = "-I/usr/include" ] && continue
389+ [ "\$ arg" = "-I/usr/include/SDL2" ] && continue
390+ [ "\$ arg" = "-L/usr/lib64" ] && continue
391+ [ "\$ arg" = "-L/usr/lib" ] && continue
392+ [ "\$ arg" = "-latomic" ] && continue
393+
394+ if [ "\$ arg" = "-shared" ]
395+ then
396+ IS_SHARED=true
397+ SHARED="\$ SHARED -sSIDE_MODULE"
398+ fi
399+
400+ if echo "\$ arg"|grep -q wasm32-emscripten.so\$
401+ then
402+ PY_MODULE=true
403+ SHARED_TARGET=\$ arg
404+ else
405+ if echo "\$ arg"|grep -q abi3.so\$
406+ then
407+ PY_MODULE=true
408+ SHARED_TARGET=\$ arg
409+ fi
410+ fi
411+
412+ if \$ PY_MODULE
413+ then
414+ if \$ IS_SHARED
415+ then
416+ true
417+ else
418+ IS_SHARED=true
419+ SHARED="\$ SHARED -shared -sSIDE_MODULE"
420+ fi
421+ else
422+ if \$ IS_SHARED
423+ then
424+ if echo "\$ arg"|grep \\\\ .so\$
425+ then
426+ PY_MODULE=true
427+ SHARED_TARGET=\$ arg
428+ SHARED="-sSIDE_MODULE"
429+ fi
430+ fi
431+ fi
432+
433+ set -- "\$ @" "\$ arg"
434+ done
435+
436+ if \$ IS_SHARED
437+ then
438+ # always pass CPU opts when linking
439+ $EMSDK_PYTHON -E \$ 0.py \$ SHARED $COPTS \$ CPU \$ WASM_EXTRA \$ LDFLAGS -sSIDE_MODULE -gsource-map --source-map-base / "\$ @" \$ COMMON
440+ if \$ MVP
441+ then
442+ if \$ WASM_PURE
443+ then
444+ SOTMP=\$ (mktemp).so
445+ mv \$ SHARED_TARGET \$ SOTMP
446+ # --memory64-lowering --signext-lowering
447+ $SDKROOT /emsdk/upstream/bin/wasm-emscripten-finalize -mvp \$ SOTMP -o \$ SHARED_TARGET
448+ [ -f \$ SHARED_TARGET.map ] && rm \$ SHARED_TARGET.map
449+ rm \$ SOTMP
450+ fi
451+ fi
452+ else
453+ # do not pass WASM opts when -c/-o but always PIC
454+ if echo $@ |grep -q MAIN_MODULE
455+ then
456+ $EMSDK_PYTHON -E \$ 0.py $COPTS \$ CPU \$ CPU_EXTRA \$ CPPFLAGS -DBUILD_STATIC "\$ @" \$ COMMON
457+ else
458+ $EMSDK_PYTHON -E \$ 0.py $COPTS \$ CPU_EXTRA \$ CPPFLAGS -DBUILD_STATIC "\$ @" \$ COMMON
459+ fi
460+ fi
461+ #else
462+ # unset _EMCC_CCACHE
463+ # exec ccache "\$ 0" "\$ @"
464+ #fi
465+
229466END
230467
231468 rm emsdk/upstream/emscripten/em++
0 commit comments