Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/platform/wasm/tools/build.sh @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 #!/bin/bash | |
| 2 # | |
| 3 # Script to build the WASM binary. | |
| 4 # | |
| 5 # The following environment variables can be used to configure the build: | |
| 6 # EMSDK, BUILD, SUFFIX, DEFINES, FEATURES | |
| 7 # | |
| 8 # EMSDK must point to the directory where emsdk is installed | |
| 9 # BUILD should be "small" or "memento" | |
| 10 # DEFINES should be a set of -D defines (e.g. "-DTOFU") | |
| 11 # FEATURES should be a list of "feature=no" (e.g. "brotli=no mujs=no extract=no xps=no svg=no html=no") | |
| 12 # SUFFIX should be a tag to keep build files for different configurations separate | |
| 13 # | |
| 14 | |
| 15 EMSDK=${EMSDK:-/opt/emsdk} | |
| 16 BUILD=${BUILD:-small} | |
| 17 DEFINES=${DEFINES:--DTOFU -DTOFU_CJK_EXT} | |
| 18 FEATURES=${FEATURES:-brotli=no mujs=no extract=no xps=no svg=no} | |
| 19 | |
| 20 if [ "$BUILD" = "memento" ] | |
| 21 then | |
| 22 MEMENTO="-DMEMENTO -DMEMENTO_STACKTRACE_METHOD=0" | |
| 23 fi | |
| 24 | |
| 25 export EMSDK_QUIET=1 | |
| 26 source $EMSDK/emsdk_env.sh | |
| 27 | |
| 28 emsdk install 4.0.8 >/dev/null || exit | |
| 29 emsdk activate 4.0.8 >/dev/null || exit | |
| 30 | |
| 31 mkdir -p dist | |
| 32 rm -f dist/* | |
| 33 | |
| 34 echo "COMPILING ($BUILD)" | |
| 35 | |
| 36 make --no-print-directory -j $(nproc) \ | |
| 37 -C ../.. \ | |
| 38 build=$BUILD \ | |
| 39 build_suffix=$SUFFIX \ | |
| 40 OS=wasm \ | |
| 41 XCFLAGS="$MEMENTO $DEFINES" \ | |
| 42 $FEATURES \ | |
| 43 libs | |
| 44 | |
| 45 echo "LINKING" | |
| 46 | |
| 47 emcc -o dist/mupdf-wasm.js \ | |
| 48 -I ../../include \ | |
| 49 -Os -g2 \ | |
| 50 $MEMENTO \ | |
| 51 --no-entry \ | |
| 52 -mno-nontrapping-fptoint \ | |
| 53 -fwasm-exceptions \ | |
| 54 -sSUPPORT_LONGJMP=wasm \ | |
| 55 -sMODULARIZE=1 \ | |
| 56 -sEXPORT_ES6=1 \ | |
| 57 -sEXPORT_NAME='"libmupdf_wasm"' \ | |
| 58 -sALLOW_MEMORY_GROWTH=1 \ | |
| 59 -sTEXTDECODER=2 \ | |
| 60 -sFILESYSTEM=0 \ | |
| 61 -sEXPORTED_RUNTIME_METHODS='["UTF8ToString","lengthBytesUTF8","stringToUTF8","HEAPU8","HEAP32","HEAPU32","HEAPF32"]' \ | |
| 62 lib/mupdf.c \ | |
| 63 ../../build/wasm/$BUILD$SUFFIX/libmupdf.a \ | |
| 64 ../../build/wasm/$BUILD$SUFFIX/libmupdf-third.a | |
| 65 | |
| 66 # remove executable bit from wasm-ld output | |
| 67 chmod -x dist/mupdf-wasm.wasm | |
| 68 | |
| 69 echo "TYPESCRIPT" | |
| 70 | |
| 71 sed < lib/mupdf.c '/#include/d' | emcc -E - | node tools/make-wasm-type.js > lib/mupdf-wasm.d.ts | |
| 72 cp lib/mupdf-wasm.d.ts dist/mupdf-wasm.d.ts | |
| 73 | |
| 74 npx tsc -p . | |
| 75 | |
| 76 # convert spaces to tabs | |
| 77 sed -i -e 's/ /\t/g' dist/mupdf.js | |
| 78 | |
| 79 echo "TERSER" | |
| 80 | |
| 81 npx terser --module -c -m -o dist/mupdf-wasm.js dist/mupdf-wasm.js | |
| 82 # npx terser --module -c -m -o dist/mupdf.min.js dist/mupdf.js |
