jamsinclair / jSquash

Browser & Web Worker focussed image codec wasm bundles derived from the Squoosh App.
Apache License 2.0
240 stars 16 forks source link

Codec Request: Jpegtran #64

Open jahed opened 1 week ago

jahed commented 1 week ago

Is your feature request related to a problem? Please describe. I'd like to be able to optimise existing JPGs without re-encoding them and losing quality.

Describe the solution you'd like jpegtran is a popular program to optimise JPGs. It's a part of libjpeg-turbo, so it's also available under mozjpeg. mozjpeg is already used in @jsquash/jpeg. So adding an optimise function export would make sense, similar to @jsquash/oxipng.

https://github.com/mozilla/mozjpeg/blob/master/jpegtran.c

jpegtran has a bunch of options, I typically use -optimize -copy none -progressive.

https://github.com/mozilla/mozjpeg/blob/master/jpegtran.1

Describe alternatives you've considered jSquash is the only actively maintained library I've found that provides oxipng WASM builds with web browser support. It'd be perfect if it also provided a way to optimise JPGs. As far as I can tell, there's no actively maintained package for jpegtran WASM builds or any other package that can optimise JPGs like it can.

Additional context n/a

jamsinclair commented 5 days ago

Brilliant suggestion @jahed.

I don't have time to work on this myself. I'd welcome someone to look into providing one and I am happy to help where I can! 🙇

jahed commented 5 days ago

Tried building the current jpeg codecs from a default GitHub Codespace, switched to Node 20 to match CI.

nvm use 20
cd packages/jpeg/codec
npm run build

WASM files are created, but terser via empscripten hits a null pointer.

TypeError: Cannot read property 'print' of undefined

Could be due to https://github.com/emscripten-core/emscripten/issues/14525 which is fixed. https://github.com/emscripten-core/emscripten/issues/13297#issuecomment-1167602986

I noticed there are few old/deprecated versions, like emsdk using Node 14. emsdk@v3 is out. So some version upgrades might help.

I'll take another look when I'm ready to integrate this feature. If anyone else wants to, feel free. I'm not familiar with C++/Emscripten or mozjpeg's source so I'd appreciate it.

Full build logs (click here) ``` > build > ../../../tools/build-cpp.sh BUILD_DIR: /workspaces/jSquash/packages/jpeg/codec SCRIPTDIR: ../../../tools [+] Building 285.3s (10/10) FINISHED docker:default => [internal] load build definition from Dockerfile 0.2s => => transferring dockerfile: 650B 0.0s => [internal] load metadata for docker.io/emscripten/emsdk:2.0.34 1.3s => [auth] emscripten/emsdk:pull token for registry-1.docker.io 0.0s => [internal] load .dockerignore 0.2s => => transferring context: 2B 0.0s => [1/5] FROM docker.io/emscripten/emsdk:2.0.34@sha256:3a5cec571c533e448f1d2bcba9757382f9122771e74394106c4acd6235b026f5 33.3s => => resolve docker.io/emscripten/emsdk:2.0.34@sha256:3a5cec571c533e448f1d2bcba9757382f9122771e74394106c4acd6235b026f5 0.1s => => sha256:3a5cec571c533e448f1d2bcba9757382f9122771e74394106c4acd6235b026f5 1.37kB / 1.37kB 0.0s => => sha256:0ac9bde0a632e05abca555563b3491dbf27ab0b2804d9c9ae59e85a6e6f5af0b 5.46kB / 5.46kB 0.0s => => sha256:f28b8bbe013da5b9c9a890722f2a251107522a2f24bfb02bcb48722f52e8e5f2 229.39MB / 229.39MB 8.2s => => sha256:7b1a6ab2e44dbac178598dabe7cff59bd67233dba0b27e4fbd1f9d4b3c877a54 28.57MB / 28.57MB 1.2s => => sha256:e7ace8f8ceef2c779e9d25e50b0535b3f561b4352f46c6af6106d4c63054b7fe 5.15kB / 5.15kB 0.4s => => sha256:98819ffb6ec3d18d7a2414aa93f6532afb62d368c69dce0f37c3c9e2e0d47008 213.42MB / 213.42MB 9.3s => => extracting sha256:7b1a6ab2e44dbac178598dabe7cff59bd67233dba0b27e4fbd1f9d4b3c877a54 1.1s => => sha256:1b912d00c70ed554e076aca86b945c925a62573686228eb22a9f57aec2ea68b3 126B / 126B 1.7s => => extracting sha256:f28b8bbe013da5b9c9a890722f2a251107522a2f24bfb02bcb48722f52e8e5f2 7.0s => => extracting sha256:e7ace8f8ceef2c779e9d25e50b0535b3f561b4352f46c6af6106d4c63054b7fe 0.0s => => extracting sha256:98819ffb6ec3d18d7a2414aa93f6532afb62d368c69dce0f37c3c9e2e0d47008 7.0s => => extracting sha256:1b912d00c70ed554e076aca86b945c925a62573686228eb22a9f57aec2ea68b3 0.0s => [2/5] RUN apt-get update && apt-get install -qqy autoconf libtool pkg-config 11.1s => [3/5] RUN emcc -O3 -flto -std=c++17 -O3 -flto -s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency -s FILESYSTEM=0 -s ALLOW_MEMORY_GROWTH=1 -s TEXTDECODER=0 115.7s => [4/5] RUN emcc -O3 -flto -std=c++17 -O3 -flto -s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency -s FILESYSTEM=0 -s ALLOW_MEMORY_GROWTH=1 -s TEXTDECODER=0 119.6s => [5/5] WORKDIR /src 0.3s => exporting to image 3.2s => => exporting layers 3.0s => => writing image sha256:d94f2f5d29261dd08e52907b263a44361a19e2a9818dcf717ab37e3528ae8500 0.0s => => naming to docker.io/library/jsquash-cpp-build 0.0s make: make -j2 mkdir -p node_modules/mozjpeg curl -sL https://github.com/mozilla/mozjpeg/archive/v3.3.1.tar.gz | tar xz --strip 1 -C node_modules/mozjpeg cd node_modules/mozjpeg && autoreconf -iv autoreconf: Entering directory `.' autoreconf: configure.ac: not using Gettext autoreconf: running: aclocal autoreconf: configure.ac: tracing autoreconf: running: libtoolize --copy libtoolize: putting auxiliary files in '.'. libtoolize: copying file './ltmain.sh' libtoolize: Consider adding 'AC_CONFIG_MACRO_DIRS([m4])' to configure.ac, libtoolize: and rerunning libtoolize and aclocal. libtoolize: Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am. autoreconf: running: /usr/bin/autoconf autoreconf: running: /usr/bin/autoheader autoreconf: running: automake --add-missing --copy --no-force configure.ac:18: installing './ar-lib' configure.ac:16: installing './compile' configure.ac:23: installing './config.guess' configure.ac:23: installing './config.sub' configure.ac:8: installing './install-sh' configure.ac:8: installing './missing' Makefile.am: installing './depcomp' autoreconf: Leaving directory `.' cd node_modules/mozjpeg && ./configure \ --disable-shared \ --without-turbojpeg \ --without-simd \ --without-arith-enc \ --without-arith-dec \ --with-build-date=jsquash checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for gawk... no checking for mawk... mawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking whether make supports nested variables... (cached) yes checking whether make supports the include directive... yes (GNU style) checking for gcc... /emsdk/upstream/emscripten/emcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether /emsdk/upstream/emscripten/emcc accepts -g... yes checking for /emsdk/upstream/emscripten/emcc option to accept ISO C89... none needed checking whether /emsdk/upstream/emscripten/emcc understands -c and -o together... yes checking dependency style of /emsdk/upstream/emscripten/emcc... gcc3 checking how to run the C preprocessor... /emsdk/upstream/emscripten/emcc -E checking for gcc... (cached) /emsdk/upstream/emscripten/emcc checking whether we are using the GNU C compiler... (cached) yes checking whether /emsdk/upstream/emscripten/emcc accepts -g... (cached) yes checking for /emsdk/upstream/emscripten/emcc option to accept ISO C89... (cached) none needed checking whether /emsdk/upstream/emscripten/emcc understands -c and -o together... (cached) yes checking dependency style of /emsdk/upstream/emscripten/emcc... (cached) gcc3 checking the archiver (/emsdk/upstream/emscripten/emar) interface... ar checking dependency style of /emsdk/upstream/emscripten/emcc... gcc3 checking the archiver (/emsdk/upstream/emscripten/emar) interface... (cached) ar checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking how to print strings... printf checking for a sed that does not truncate output... /usr/bin/sed checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for fgrep... /usr/bin/grep -F checking for ld used by /emsdk/upstream/emscripten/emcc... /emsdk/upstream/emscripten/emcc checking if the linker (/emsdk/upstream/emscripten/emcc) is GNU ld... yes checking for BSD- or MS-compatible name lister (nm)... /emsdk/upstream/bin/llvm-nm checking the name lister (/emsdk/upstream/bin/llvm-nm) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 1572864 checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop checking for /emsdk/upstream/emscripten/emcc option to reload object files... -r checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for dlltool... no checking how to associate runtime and link libraries... printf %s\n checking for archiver @FILE support... @ checking for strip... strip checking for ranlib... /emsdk/upstream/emscripten/emranlib checking command to parse /emsdk/upstream/bin/llvm-nm output from /emsdk/upstream/emscripten/emcc object... ok checking for sysroot... no checking for a working dd... /usr/bin/dd checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1 checking for mt... no checking if : is a manifest tool... no checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for dlfcn.h... yes checking for objdir... .libs checking if /emsdk/upstream/emscripten/emcc supports -fno-rtti -fno-exceptions... yes checking for /emsdk/upstream/emscripten/emcc option to produce PIC... -fPIC -DPIC checking if /emsdk/upstream/emscripten/emcc PIC flag -fPIC -DPIC works... yes checking if /emsdk/upstream/emscripten/emcc static flag -static works... yes checking if /emsdk/upstream/emscripten/emcc supports -c -o file.o... yes checking if /emsdk/upstream/emscripten/emcc supports -c -o file.o... (cached) yes checking whether the /emsdk/upstream/emscripten/emcc linker (/emsdk/upstream/emscripten/emcc) supports shared libraries... emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 2.0.34 (0d24418f0eac4828f096ee070dae8472d427edaa) clang version 14.0.0 (https://github.com/llvm/llvm-project 3d39612b3dd3f6b67ee63da305d30606abbe7287) Target: wasm32-unknown-emscripten Thread model: posix InstalledDir: /emsdk/upstream/bin yes checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... no checking whether to build static libraries... yes checking whether ln -s works... yes checking for pkg-config... /usr/bin/pkg-config checking pkg-config is at least version 0.9.0... yes checking size of size_t... 0 checking whether compiler supports pointers to undefined structures... yes checking whether __SUNPRO_C is declared... no checking for pow in -lm... yes checking for libpng... no checking for libpng... no checking for ANSI C header files... (cached) yes checking stddef.h usability... yes checking stddef.h presence... yes checking for stddef.h... yes checking for stdlib.h... (cached) yes checking locale.h usability... yes checking locale.h presence... yes checking for locale.h... yes checking for string.h... (cached) yes checking for sys/types.h... (cached) yes checking for an ANSI C-conforming const... yes checking whether char is unsigned... no checking for inline... inline checking for size_t... yes checking for unsigned char... yes checking for unsigned short... yes checking if right shift is signed... yes checking for memset... yes checking for memcpy... yes checking libjpeg API version... 6.2 checking whether to include in-memory source/destination managers... yes checking libjpeg shared library version... 62.2.0 checking whether the linker supports version scripts... yes (GNU style) checking whether to use version script when building mozjpeg... yes checking for inline... inline __attribute__((always_inline)) checking whether to include arithmetic encoding support... no checking whether to include arithmetic decoding support... no checking whether to use 12-bit samples... no checking whether to build TurboJPEG C wrapper... no checking whether to build TurboJPEG Java wrapper... no checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating pkgscripts/mozjpeg.spec.tmpl config.status: creating pkgscripts/makecygwinpkg.tmpl config.status: creating pkgscripts/makedpkg.tmpl config.status: creating pkgscripts/makemacpkg.tmpl config.status: creating pkgscripts/uninstall.tmpl config.status: creating pkgscripts/libjpeg.pc config.status: creating pkgscripts/libturbojpeg.pc config.status: creating libjpeg.map config.status: creating Makefile config.status: creating simd/Makefile config.status: creating java/Makefile config.status: creating md5/Makefile config.status: creating config.h config.status: creating jconfig.h config.status: creating jconfigint.h config.status: executing depfiles commands config.status: executing libtool commands # ^ If not provided with a dummy value, MozJPEG includes a build date in the # binary as part of the version string, making binaries different each time. make -C node_modules/mozjpeg libjpeg.la make -C node_modules/mozjpeg rdswitch.o make[1]: Entering directory '/src/node_modules/mozjpeg' make[1]: Entering directory '/src/node_modules/mozjpeg' CC jcapimin.lo CC rdswitch.o make[1]: Leaving directory '/src/node_modules/mozjpeg' CC jcapistd.lo CC jccoefct.lo CC jccolor.lo CC jcdctmgr.lo CC jcext.lo CC jchuff.lo CC jcinit.lo CC jcmainct.lo CC jcmarker.lo CC jcmaster.lo CC jcomapi.lo CC jcparam.lo CC jcphuff.lo CC jcprepct.lo CC jcsample.lo CC jctrans.lo CC jdapimin.lo CC jdapistd.lo CC jdatadst.lo CC jdatasrc.lo CC jdcoefct.lo CC jdcolor.lo CC jddctmgr.lo CC jdhuff.lo CC jdinput.lo CC jdmainct.lo CC jdmarker.lo CC jdmaster.lo CC jdmerge.lo CC jdphuff.lo CC jdpostct.lo CC jdsample.lo CC jdtrans.lo CC jerror.lo CC jfdctflt.lo CC jfdctfst.lo CC jfdctint.lo CC jidctflt.lo CC jidctfst.lo CC jidctint.lo CC jidctred.lo CC jquant1.lo CC jquant2.lo CC jutils.lo CC jmemmgr.lo CC jmemnobs.lo CC jsimd_none.lo CCLD libjpeg.la make[1]: Leaving directory '/src/node_modules/mozjpeg' /emsdk/upstream/emscripten/em++ \ -I node_modules/mozjpeg \ -O3 -flto -std=c++17 \ -O3 -flto -s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency -s FILESYSTEM=0 -s ALLOW_MEMORY_GROWTH=1 -s TEXTDECODER=0 \ --pre-js pre.js \ --bind \ -s ENVIRONMENT=web,worker \ -s EXPORT_ES6=1 \ -s DYNAMIC_EXECUTION=0 \ -s MODULARIZE=1 \ -o enc/mozjpeg_enc.js \ node_modules/mozjpeg/.libs/libjpeg.a node_modules/mozjpeg/rdswitch.o enc/mozjpeg_enc.cpp /emsdk/upstream/emscripten/em++ \ -I node_modules/mozjpeg \ -O3 -flto -std=c++17 \ -O3 -flto -s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency -s FILESYSTEM=0 -s ALLOW_MEMORY_GROWTH=1 -s TEXTDECODER=0 \ --pre-js pre.js \ --bind \ -s ENVIRONMENT=web,worker \ -s EXPORT_ES6=1 \ -s DYNAMIC_EXECUTION=0 \ -s MODULARIZE=1 \ -o dec/mozjpeg_dec.js \ node_modules/mozjpeg/.libs/libjpeg.a node_modules/mozjpeg/rdswitch.o dec/mozjpeg_dec.cpp /emsdk/upstream/emscripten/third_party/terser/terser.js:6892 expr.print(output); ^ TypeError: Cannot read property 'print' of undefined at /emsdk/upstream/emscripten/third_party/terser/terser.js:6892:14 at doit (/emsdk/upstream/emscripten/third_party/terser/terser.js:5999:13) at AST_Dot. (/emsdk/upstream/emscripten/third_party/terser/terser.js:6006:13) at /emsdk/upstream/emscripten/third_party/terser/terser.js:6934:19 at doit (/emsdk/upstream/emscripten/third_party/terser/terser.js:5999:13) at AST_Binary. (/emsdk/upstream/emscripten/third_party/terser/terser.js:6006:13) at /emsdk/upstream/emscripten/third_party/terser/terser.js:6605:28 at Object.with_parens (/emsdk/upstream/emscripten/third_party/terser/terser.js:5765:19) at /emsdk/upstream/emscripten/third_party/terser/terser.js:6604:16 at doit (/emsdk/upstream/emscripten/third_party/terser/terser.js:5999:13) em++: error: '/emsdk/node/14.15.5_64bit/bin/node /emsdk/upstream/emscripten/tools/acorn-optimizer.js /tmp/emscripten_temp_gopivn_d/mozjpeg_dec.js.pp.js AJSDCE minifyWhitespace --exportES6' failed (returned 1) make: *** [Makefile:20: dec/mozjpeg_dec.js] Error 1 make: *** Waiting for unfinished jobs.... /emsdk/upstream/emscripten/third_party/terser/terser.js:6892 expr.print(output); ^ TypeError: Cannot read property 'print' of undefined at /emsdk/upstream/emscripten/third_party/terser/terser.js:6892:14 at doit (/emsdk/upstream/emscripten/third_party/terser/terser.js:5999:13) at AST_Dot. (/emsdk/upstream/emscripten/third_party/terser/terser.js:6006:13) at /emsdk/upstream/emscripten/third_party/terser/terser.js:6934:19 at doit (/emsdk/upstream/emscripten/third_party/terser/terser.js:5999:13) at AST_Binary. (/emsdk/upstream/emscripten/third_party/terser/terser.js:6006:13) at /emsdk/upstream/emscripten/third_party/terser/terser.js:6605:28 at Object.with_parens (/emsdk/upstream/emscripten/third_party/terser/terser.js:5765:19) at /emsdk/upstream/emscripten/third_party/terser/terser.js:6604:16 at doit (/emsdk/upstream/emscripten/third_party/terser/terser.js:5999:13) em++: error: '/emsdk/node/14.15.5_64bit/bin/node /emsdk/upstream/emscripten/tools/acorn-optimizer.js /tmp/emscripten_temp_y_at9g0h/mozjpeg_enc.js.pp.js AJSDCE minifyWhitespace --exportES6' failed (returned 1) make: *** [Makefile:20: enc/mozjpeg_enc.js] Error 1 emmake: error: 'make -j2' failed (returned 2) ```
jamsinclair commented 5 days ago

Thanks I believe that error is actually caused by --pre-js option. You can comment out the follow line and it should compile: https://github.com/jamsinclair/jSquash/blob/9e7eb888a707cb0f8bb951f24bf2ea4a839f9225/packages/jpeg/codec/Makefile#L24

We can probably use a later emscripten version to bypass that 🤔

Edit: Confirmed Emscripten 3.1.57 seems to work on my local codespace.

jamsinclair commented 5 days ago

Thanks for taking a look @jahed.

Looks like we both added similar fixes at the same time. I've also gone ahead and updated the scripts in the main branch to build it with Emscripten 3.1.57.

After playing around further, one observation is that jpegtran is a command line tool. Some extra care will be needed to make this work. One alternative would be to do the transformations ourselves by using the transupp.c api.

jahed commented 4 days ago

Looks like emsdk@v3 can't clean compile mozjpeg. Downgrading back to emsdk@v2 works (with the terser error).

config.log shows a permission error which is caused by caches created during the docker build RUN emcc steps.

Fixed by setting permissions to the cache files immediately after as suggested here: https://github.com/emscripten-core/emsdk/issues/535#issuecomment-651849416

RUN chmod -R 777 ${EMSDK}/upstream/emscripten/cache

Next, it was failing at ./conftest with no obvious errors. There's some [emcc](emcc: error: no input files) errors logged but I'm guessing they're fine as one of them passes.

Click for full config.log. ``` This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by mozjpeg configure 3.3.1, which was generated by GNU Autoconf 2.71. Invocation command line was $ ./configure --disable-shared --without-turbojpeg --without-simd --without-arith-enc --without-arith-dec --with-build-date=jsquash ## --------- ## ## Platform. ## ## --------- ## hostname = 8c8f3e52771f uname -m = x86_64 uname -r = 6.5.0-1025-azure uname -s = Linux uname -v = #26~22.04.1-Ubuntu SMP Thu Jul 11 22:33:04 UTC 2024 /usr/bin/uname -p = x86_64 /bin/uname -X = unknown /bin/arch = x86_64 /usr/bin/arch -k = unknown /usr/convex/getsysinfo = unknown /usr/bin/hostinfo = unknown /bin/machine = unknown /usr/bin/oslevel = unknown /bin/universe = unknown PATH: /emsdk/upstream/emscripten/cache/sysroot/bin/ PATH: /emsdk/ PATH: /emsdk/upstream/emscripten/ PATH: /emsdk/node/20.18.0_64bit/bin/ PATH: /usr/local/sbin/ PATH: /usr/local/bin/ PATH: /usr/sbin/ PATH: /usr/bin/ PATH: /sbin/ PATH: /bin/ ## ----------- ## ## Core tests. ## ## ----------- ## configure:2884: looking for aux files: config.guess config.sub ltmain.sh ar-lib compile missing install-sh configure:2897: trying ./ configure:2926: ./config.guess found configure:2926: ./config.sub found configure:2926: ./ltmain.sh found configure:2926: ./ar-lib found configure:2926: ./compile found configure:2926: ./missing found configure:2908: ./install-sh found configure:3057: checking for a BSD-compatible install configure:3130: result: /usr/bin/install -c configure:3141: checking whether build environment is sane configure:3196: result: yes configure:3355: checking for a race-free mkdir -p configure:3399: result: /usr/bin/mkdir -p configure:3406: checking for gawk configure:3441: result: no configure:3406: checking for mawk configure:3427: found /usr/bin/mawk configure:3438: result: mawk configure:3449: checking whether make sets $(MAKE) configure:3472: result: yes configure:3502: checking whether make supports nested variables configure:3520: result: yes configure:3670: checking whether make supports nested variables configure:3688: result: yes configure:3716: checking whether make supports the include directive configure:3731: make -f confmf.GNU && cat confinc.out make[1]: Entering directory '/src/node_modules/mozjpeg' make[1]: Leaving directory '/src/node_modules/mozjpeg' this is the am__doit target configure:3734: $? = 0 configure:3753: result: yes (GNU style) configure:3829: checking for gcc configure:3861: result: /emsdk/upstream/emscripten/emcc configure:4214: checking for C compiler version configure:4223: /emsdk/upstream/emscripten/emcc --version >&5 emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.70 (b53978ee3f540dc74761eba127aa7f1b8761a125) Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt) This is free and open source software under the MIT license. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. configure:4234: $? = 0 configure:4223: /emsdk/upstream/emscripten/emcc -v >&5 emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.70 (b53978ee3f540dc74761eba127aa7f1b8761a125) clang version 20.0.0git (https:/github.com/llvm/llvm-project f52b89561f2d929c0c6f37fd818229fbcad3b26c) Target: wasm32-unknown-emscripten Thread model: posix InstalledDir: /emsdk/upstream/bin configure:4234: $? = 0 configure:4223: /emsdk/upstream/emscripten/emcc -V >&5 emcc: error: no input files configure:4234: $? = 1 configure:4223: /emsdk/upstream/emscripten/emcc -qversion >&5 emcc: error: no input files configure:4234: $? = 1 configure:4223: /emsdk/upstream/emscripten/emcc -version >&5 emcc: error: no input files configure:4234: $? = 1 configure:4254: checking whether the C compiler works configure:4276: /emsdk/upstream/emscripten/emcc -O3 -flto -O3 -flto -s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency -s FILESYSTEM=0 -s ALLOW_MEMORY_GROWTH=1 -s TEXTDECODER=0 conftest.c >&5 cache:INFO: generating system asset: symbol_lists/2ec2788ddffdb0c849fa5f91b6fa4e6b11ec216b.json... (this will be cached in "/emsdk/upstream/emscripten/cache/symbol_lists/2ec2788ddffdb0c849fa5f91b6fa4e6b11ec216b.json" for subsequent builds) cache:INFO: - ok configure:4280: $? = 0 configure:4330: result: yes configure:4333: checking for C compiler default output file name configure:4335: result: a.out configure:4341: checking for suffix of executables configure:4348: /emsdk/upstream/emscripten/emcc -o conftest -O3 -flto -O3 -flto -s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency -s FILESYSTEM=0 -s ALLOW_MEMORY_GROWTH=1 -s TEXTDECODER=0 conftest.c >&5 configure:4352: $? = 0 configure:4375: result: configure:4397: checking whether we are cross compiling configure:4405: /emsdk/upstream/emscripten/emcc -o conftest -O3 -flto -O3 -flto -s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency -s FILESYSTEM=0 -s ALLOW_MEMORY_GROWTH=1 -s TEXTDECODER=0 conftest.c >&5 configure:4409: $? = 0 configure:4416: ./conftest configure:4420: $? = 1 configure:4427: error: in `/src/node_modules/mozjpeg': configure:4429: error: cannot run C compiled programs. If you meant to cross compile, use `--host'. See `config.log' for more details ## ---------------- ## ## Cache variables. ## ## ---------------- ## ac_cv_env_CCASFLAGS_set= ac_cv_env_CCASFLAGS_value= ac_cv_env_CCAS_set= ac_cv_env_CCAS_value= ac_cv_env_CC_set=set ac_cv_env_CC_value=/emsdk/upstream/emscripten/emcc ac_cv_env_CFLAGS_set=set ac_cv_env_CFLAGS_value='-O3 -flto' ac_cv_env_CPPFLAGS_set= ac_cv_env_CPPFLAGS_value= ac_cv_env_CPP_set= ac_cv_env_CPP_value= ac_cv_env_JAR_set= ac_cv_env_JAR_value= ac_cv_env_JAVACFLAGS_set= ac_cv_env_JAVACFLAGS_value= ac_cv_env_JAVAC_set= ac_cv_env_JAVAC_value= ac_cv_env_JAVA_set= ac_cv_env_JAVA_value= ac_cv_env_JNI_CFLAGS_set= ac_cv_env_JNI_CFLAGS_value= ac_cv_env_JPEG_LIB_VERSION_set= ac_cv_env_JPEG_LIB_VERSION_value= ac_cv_env_LDFLAGS_set=set ac_cv_env_LDFLAGS_value='-O3 -flto -s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency -s FILESYSTEM=0 -s ALLOW_MEMORY_GROWTH=1 -s TEXTDECODER=0 ' ac_cv_env_LIBS_set= ac_cv_env_LIBS_value= ac_cv_env_LT_SYS_LIBRARY_PATH_set= ac_cv_env_LT_SYS_LIBRARY_PATH_value= ac_cv_env_NASM_set= ac_cv_env_NASM_value= ac_cv_env_PKGNAME_set= ac_cv_env_PKGNAME_value= ac_cv_env_PKG_CONFIG_LIBDIR_set=set ac_cv_env_PKG_CONFIG_LIBDIR_value=/emsdk/upstream/emscripten/cache/sysroot/local/lib/pkgconfig:/emsdk/upstream/emscripten/cache/sysroot/lib/pkgconfig ac_cv_env_PKG_CONFIG_PATH_set=set ac_cv_env_PKG_CONFIG_PATH_value= ac_cv_env_PKG_CONFIG_set= ac_cv_env_PKG_CONFIG_value= ac_cv_env_SO_MAJOR_VERSION_set= ac_cv_env_SO_MAJOR_VERSION_value= ac_cv_env_SO_MINOR_VERSION_set= ac_cv_env_SO_MINOR_VERSION_value= ac_cv_env_build_alias_set= ac_cv_env_build_alias_value= ac_cv_env_host_alias_set= ac_cv_env_host_alias_value= ac_cv_env_libpng_CFLAGS_set= ac_cv_env_libpng_CFLAGS_value= ac_cv_env_libpng_LIBS_set= ac_cv_env_libpng_LIBS_value= ac_cv_env_target_alias_set= ac_cv_env_target_alias_value= ac_cv_path_install='/usr/bin/install -c' ac_cv_path_mkdir=/usr/bin/mkdir ac_cv_prog_AWK=mawk ac_cv_prog_ac_ct_CC=/emsdk/upstream/emscripten/emcc ac_cv_prog_make_make_set=yes am_cv_make_support_nested_variables=yes ## ----------------- ## ## Output variables. ## ## ----------------- ## ACLOCAL='${SHELL} '\''/src/node_modules/mozjpeg/missing'\'' aclocal-1.16' AMDEPBACKSLASH='\' AMDEP_FALSE='#' AMDEP_TRUE='' AMTAR='$${TAR-tar}' AM_BACKSLASH='\' AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' AM_DEFAULT_VERBOSITY='0' AM_V='$(V)' AR='/emsdk/upstream/emscripten/emar' AUTOCONF='${SHELL} '\''/src/node_modules/mozjpeg/missing'\'' autoconf' AUTOHEADER='${SHELL} '\''/src/node_modules/mozjpeg/missing'\'' autoheader' AUTOMAKE='${SHELL} '\''/src/node_modules/mozjpeg/missing'\'' automake-1.16' AWK='mawk' BUILD='20241028' CC='/emsdk/upstream/emscripten/emcc' CCAS='' CCASDEPMODE='' CCASFLAGS='' CCDEPMODE='' CFLAGS='-O3 -flto' CPP='' CPPFLAGS='' CROSS_COMPILING_FALSE='' CROSS_COMPILING_TRUE='' CSCOPE='cscope' CTAGS='ctags' CYGPATH_W='echo' DEBARCH='' DEFS='' DEPDIR='.deps' DLLTOOL='' DSYMUTIL='' DUMPBIN='' ECHO_C='' ECHO_N='-n' ECHO_T='' EGREP='' ETAGS='etags' EXEEXT='' FGREP='' GREP='' HAVE_LIBPNG_FALSE='' HAVE_LIBPNG_TRUE='' INSTALL_DATA='${INSTALL} -m 644' INSTALL_PROGRAM='${INSTALL}' INSTALL_SCRIPT='${INSTALL}' INSTALL_STRIP_PROGRAM='$(install_sh) -c -s' JAR='' JAVA='' JAVAC='' JAVACFLAGS='' JAVA_RPM_CONTENTS_1='' JAVA_RPM_CONTENTS_2='' JNI_CFLAGS='' JPEG_LIB_VERSION='' JPEG_LIB_VERSION_DECIMAL='' LD='/emsdk/upstream/emscripten/emcc' LDFLAGS='-O3 -flto -s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency -s FILESYSTEM=0 -s ALLOW_MEMORY_GROWTH=1 -s TEXTDECODER=0 ' LIBOBJS='' LIBS='' LIBTOOL='' LIBTOOL_CURRENT='' LIPO='' LN_S='' LTLIBOBJS='' LT_SYS_LIBRARY_PATH='' MAKEINFO='${SHELL} '\''/src/node_modules/mozjpeg/missing'\'' makeinfo' MANIFEST_TOOL='' MEM_SRCDST_FUNCTIONS='' MKDIR_P='/usr/bin/mkdir -p' NAFLAGS='' NASM='' NM='/emsdk/upstream/bin/llvm-nm' NMEDIT='' OBJDUMP='' OBJEXT='' OTOOL64='' OTOOL='' PACKAGE='mozjpeg' PACKAGE_BUGREPORT='' PACKAGE_NAME='mozjpeg' PACKAGE_STRING='mozjpeg 3.3.1' PACKAGE_TARNAME='mozjpeg' PACKAGE_URL='' PACKAGE_VERSION='3.3.1' PATH_SEPARATOR=':' PKGNAME='' PKG_CONFIG='' PKG_CONFIG_LIBDIR='/emsdk/upstream/emscripten/cache/sysroot/local/lib/pkgconfig:/emsdk/upstream/emscripten/cache/sysroot/lib/pkgconfig' PKG_CONFIG_PATH='' RANLIB='/emsdk/upstream/emscripten/emranlib' RPMARCH='' RPM_CONFIG_ARGS='' SED='' SET_MAKE='' SHELL='/bin/bash' SIMD_ARM_64_FALSE='' SIMD_ARM_64_TRUE='' SIMD_ARM_FALSE='' SIMD_ARM_TRUE='' SIMD_I386_FALSE='' SIMD_I386_TRUE='' SIMD_MIPS_FALSE='' SIMD_MIPS_TRUE='' SIMD_POWERPC_FALSE='' SIMD_POWERPC_TRUE='' SIMD_X86_64_FALSE='' SIMD_X86_64_TRUE='' SO_AGE='' SO_MAJOR_VERSION='' SO_MINOR_VERSION='' STRIP='' VERSION='3.3.1' VERSION_SCRIPT_FALSE='' VERSION_SCRIPT_FLAG='' VERSION_SCRIPT_TRUE='' WITH_12BIT_FALSE='' WITH_12BIT_TRUE='' WITH_ARITH_DEC_FALSE='' WITH_ARITH_DEC_TRUE='' WITH_ARITH_ENC_FALSE='' WITH_ARITH_ENC_TRUE='' WITH_ARITH_FALSE='' WITH_ARITH_TRUE='' WITH_JAVA='' WITH_JAVA_FALSE='' WITH_JAVA_TRUE='' WITH_SIMD_FALSE='' WITH_SIMD_TRUE='' WITH_SSE_FLOAT_DCT_FALSE='' WITH_SSE_FLOAT_DCT_TRUE='' WITH_TURBOJPEG_FALSE='' WITH_TURBOJPEG_TRUE='' X86_64_FALSE='' X86_64_TRUE='' ac_ct_AR='' ac_ct_CC='/emsdk/upstream/emscripten/emcc' ac_ct_DUMPBIN='' am__EXEEXT_FALSE='' am__EXEEXT_TRUE='' am__fastdepCCAS_FALSE='' am__fastdepCCAS_TRUE='' am__fastdepCC_FALSE='' am__fastdepCC_TRUE='' am__include='include' am__isrc='' am__leading_dot='.' am__nodep='_no' am__quote='' am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -' bindir='${exec_prefix}/bin' build='' build_alias='' build_cpu='' build_os='' build_vendor='' datadir='${datarootdir}' datarootdir='${prefix}/share' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' dvidir='${docdir}' exec_prefix='NONE' host='' host_alias='' host_cpu='' host_os='' host_vendor='' htmldir='${docdir}' includedir='${prefix}/include' infodir='${datarootdir}/info' install_sh='${SHELL} /src/node_modules/mozjpeg/install-sh' libdir='${exec_prefix}/lib' libexecdir='${exec_prefix}/libexec' libpng_CFLAGS='' libpng_LIBS='' localedir='${datarootdir}/locale' localstatedir='${prefix}/var' mandir='${datarootdir}/man' mkdir_p='$(MKDIR_P)' oldincludedir='/usr/include' pdfdir='${docdir}' prefix='NONE' program_transform_name='s,x,x,' psdir='${docdir}' runstatedir='${localstatedir}/run' sbindir='${exec_prefix}/sbin' sharedstatedir='${prefix}/com' sysconfdir='${prefix}/etc' target_alias='' ## ----------- ## ## confdefs.h. ## ## ----------- ## /* confdefs.h */ #define PACKAGE_NAME "mozjpeg" #define PACKAGE_TARNAME "mozjpeg" #define PACKAGE_VERSION "3.3.1" #define PACKAGE_STRING "mozjpeg 3.3.1" #define PACKAGE_BUGREPORT "" #define PACKAGE_URL "" #define PACKAGE "mozjpeg" #define VERSION "3.3.1" configure: exit 77 ```
jahed commented 4 days ago

The old version of terser in emsdk@2 is failing at this block (unsupported import.meta syntax):

https://github.com/jamsinclair/jSquash/blob/918efc3b5410872ae76923a7413148d39b864d63/packages/jpeg/codec/pre.js#L17-L19

If emsdk@v3 is too much effort to upgrade to right now, that block can be removed. Node 18 is the lowest maintained NodeJS version and it supports import.meta.url.

Created a PR for that if it's a viable option:

jamsinclair commented 4 days ago

I also commented in the merge request, but the import.meta.url hotfix is still needed to support cloudflare workers.

I think I have solved the compilation issues with emsdk@3 if you pull the latest main branch.