kleisauke / wasm-vips

libvips for the browser and Node.js, compiled to WebAssembly with Emscripten.
https://kleisauke.github.io/wasm-vips/
MIT License
463 stars 25 forks source link

Docker compilation error #49

Closed aW4KeNiNG closed 1 year ago

aW4KeNiNG commented 1 year ago

Hi.

I'm trying to compile the library using the docker file but I get the next error:

=============================================
Compiling JS bindings
=============================================
configure: cmake /src -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=/src/lib -DENVIRONMENT=web;node -DENABLE_MODULES=true -DENABLE_WASMFS=false -DCMAKE_TOOLCHAIN_FILE=/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/usr/bin/node
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.0")
-- Checking for module 'vips>=8.14'
--   Found vips, version 8.14.2
-- Configuring done
-- Generating done
-- Build files have been written to: /src/build/deps/wasm-vips
[ 10%] Building CXX object src/CMakeFiles/wasm-vips.dir/bindings/connection.cpp.o
[ 20%] Building CXX object src/CMakeFiles/wasm-vips.dir/bindings/image.cpp.o
[ 30%] Building CXX object src/CMakeFiles/wasm-vips.dir/bindings/interpolate.cpp.o
[ 40%] Building CXX object src/CMakeFiles/wasm-vips.dir/bindings/option.cpp.o
[ 50%] Building CXX object src/CMakeFiles/wasm-vips.dir/bindings/utils.cpp.o
[ 60%] Building CXX object src/CMakeFiles/wasm-vips.dir/vips-emscripten.cpp.o
/src/src/bindings/connection.cpp:41:9: error: use of undeclared identifier 'EM_FUNC_SIG_JPJ'
        EM_FUNC_SIG_JPJ, self->read_callback, buffer, length);
        ^
/src/src/bindings/connection.cpp:52:9: error: use of undeclared identifier 'EM_FUNC_SIG_JJI'
        EM_FUNC_SIG_JJI, self->seek_callback, offset, whence);
        ^
/src/src/bindings/connection.cpp:95:9: error: use of undeclared identifier 'EM_FUNC_SIG_JPJ'
        EM_FUNC_SIG_JPJ, self->write_callback, buffer, length);
        ^
/src/src/bindings/connection.cpp:109:9: error: use of undeclared identifier 'EM_FUNC_SIG_JPJ'
        EM_FUNC_SIG_JPJ, self->read_callback, buffer, length);
        ^
/src/src/bindings/connection.cpp:120:9: error: use of undeclared identifier 'EM_FUNC_SIG_JJI'
        EM_FUNC_SIG_JJI, self->seek_callback, offset, whence);
        ^
5 errors generated.
em++: error: '/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_SHARED_MEMORY__=1 -DEMSCRIPTEN --sysroot=/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -O3 -pthread -fexceptions -mnontrapping-fptoint -msimd128 -fPIC -O3 -std=c++11 -DG_DISABLE_ASSERT -DG_DISABLE_CAST_CHECKS -DG_DISABLE_CHECKS -I/src/build/target/include/glib-2.0 -I/src/build/target/lib/glib-2.0/include -I/src/build/target/include/webp -DWASM_SIMD_COMPAT_SLOW -DWASM_BIGINT -DNDEBUG -c -MD -MT src/CMakeFiles/wasm-vips.dir/bindings/connection.cpp.o -MF CMakeFiles/wasm-vips.dir/bindings/connection.cpp.o.d -matomics -mbulk-memory /src/src/bindings/connection.cpp -o CMakeFiles/wasm-vips.dir/bindings/connection.cpp.o' failed (returned 1)
make[2]: *** [src/CMakeFiles/wasm-vips.dir/build.make:77: src/CMakeFiles/wasm-vips.dir/bindings/connection.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:106: src/CMakeFiles/wasm-vips.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Do you know what the issue could be?

Thanks in advance.

kleisauke commented 1 year ago

Looks like the Emscripten patches have not been applied, especially commit https://github.com/kleisauke/emscripten/commit/8268dafaf5f5f55191fcd0ebdec97ded1eec0d3e. https://github.com/kleisauke/wasm-vips/blob/e1cc2ddaecff889d1d9f2b8fb12e53fab51ccfad/Dockerfile#L38-L41

Did you run npm run build? Issue #6 reported something similar, but I was never able to reproduce that.

Note that you might need to clean up existing cache with:

$ rm -rf build/{cargo-cache,ccache,deps,emcache,target}

This ensures that all dependencies are rebuilt.

aW4KeNiNG commented 1 year ago

Thanks for the help.

I have updated to the latest git version, remove the current cache and rebuild it again with the same issue.

I'm not sure if it can help, but here is the docker build and the compilation log:

https://www.dropbox.com/s/wj0rwp0e7h1kke4/docker-build-log.txt?dl=0

https://www.dropbox.com/s/xhkmvdg9m9rnazr/wasmvips-build-log.txt?dl=0

I'm using Windows, so the command I'm using is (disabling svg and jxl): docker build -t wasm-vips . && docker run -it --rm -v %cd%:/src wasm-vips ./build.sh --disable-svg --disable-jxl

Thanks in advance.

kleisauke commented 1 year ago

Looking at those build logs, it seems that it uses the default sysroot location (/emsdk/upstream/emscripten/cache/sysroot), rather than the one specified in the EM_CACHE env var. https://github.com/kleisauke/wasm-vips/blob/bb0b71b80d6ca886a76fc06371174dcba45c7687/Dockerfile#L11-L12

I get the same build failure when passing -e EM_CACHE= to the docker run command.

Perhaps it's unable to access the mounted /src/build/emcache volume within the Docker container? You can check this with:

$ docker run -it --rm -v %cd%:/src wasm-vips bash -c "printenv EM_CACHE && emcc --clear-cache"
/src/build/emcache
emcc:INFO: clearing cache as requested by --clear-cache: `/src/build/emcache`
shared:INFO: (Emscripten: Running sanity checks)
aW4KeNiNG commented 1 year ago

Thank you! I identified the problem with your assistance. On Windows, I couldn't execute build.sh directly in a single command with Docker. After the git clone operation, it was necessary to use the sed command to remove the \r characters from the file. Otherwise, the script wouldn't function properly. The issue was occurring when executing the Docker command and then the build.sh script separately. It worked correctly when combined into a single command after removing the \r characters in advance.

kleisauke commented 1 year ago

I'm glad it's working now! It sounds like you have core.autocrlf = true in your git configuration, commit 678ffd667a3ccef4bb575fe3df2b1552d7da688b should prevent this line ending mangling for shell scripts.

Perhaps we should also remove this line from the official emsdk Docker image: https://github.com/emscripten-core/emsdk/blob/e8b64774ff1a3ddb6a013203ced27a34e70c2d8b/docker/Dockerfile#L82

Since it causes the existing EM_CACHE and EMSDK_NODE environment variables to be cleared when running in a interactive shell:

$ docker run -it --rm -v %cd%:/src wasm-vips
...
Clearing existing environment variable: EM_CACHE
Clearing existing environment variable: EMSDK_NODE
kleisauke commented 1 year ago

Perhaps we should also remove this line from the official emsdk Docker image: https://github.com/emscripten-core/emsdk/blob/e8b64774ff1a3ddb6a013203ced27a34e70c2d8b/docker/Dockerfile#L82

I just opened PR https://github.com/emscripten-core/emsdk/pull/1220 for this.