facebook / igl

Intermediate Graphics Library (IGL) is a cross-platform library that commands the GPU. It provides a single low-level cross-platform interface on top of various graphics APIs (e.g. OpenGL, Metal and Vulkan).
Other
2.97k stars 172 forks source link

Issue compiling WebAssembly #57

Closed kalwalt closed 10 months ago

kalwalt commented 10 months ago

As described in the readme i run this command to build the wasm lib:

cd build
emcmake cmake .. -G Ninja
cmake --build .

configurations goes well:

emcmake cmake .. -G Ninja
configure: cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE=/home/kalwalt/kalwalt-github/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/home/kalwalt/kalwalt-github/emsdk/node/16.20.0_64bit/bin/node
-- IGL_WITH_SAMPLES  = ON
-- IGL_WITH_OPENGL    = OFF
-- IGL_WITH_OPENGLES  = OFF
-- IGL_WITH_VULKAN    = OFF
-- IGL_WITH_METAL     = OFF
-- IGL_WITH_WEBGL     = ON
-- IGL_WITH_IGLU      = ON
-- IGL_WITH_SHELL     = OFF
-- IGL_WITH_TESTS     = OFF
-- IGL_WITH_TRACY     = OFF
-- IGL_WITH_TRACY_GPU = OFF
-- IGL_WITH_OPENXR    = OFF
-- IGL_ENFORCE_LOGS   = ON
-- IGL_DEPLOY_DEPS    = ON
-- IGL generator : Ninja
-- IGL build type: 
-- Found Python3: /home/kalwalt/anaconda3/bin/python3.1 (found version "3.11.5") found components: Interpreter 
-- IGL_ROOT_DIR = /home/kalwalt/kalwalt-github/igl
WARNING: Please install the Python packages [paramiko, scp] for full script operation.
--- Using third-party/deps as base directory
--- Using main bootstrap file /home/kalwalt/kalwalt-github/igl/third-party/bootstrap-deps.json
--- WARNING: command hg not found, but required by script
--- WARNING: command svn not found, but required by script
--- Cached state for meshoptimizer equals expected state; skipping library
--- Cached state for glslang equals expected state; skipping library
--- Cached state for SPIRV-Headers equals expected state; skipping library
--- Cached state for tinyobjloader equals expected state; skipping library
--- Cached state for glfw equals expected state; skipping library
--- Cached state for glew equals expected state; skipping library
--- Cached state for stb equals expected state; skipping library
--- Cached state for 3D-Graphics-Rendering-Cookbook equals expected state; skipping library
--- Cached state for bc7enc equals expected state; skipping library
--- Cached state for glm equals expected state; skipping library
--- Cached state for taskflow equals expected state; skipping library
--- Cached state for fmt equals expected state; skipping library
--- Cached state for imgui equals expected state; skipping library
--- Cached state for volk equals expected state; skipping library
--- Cached state for vma equals expected state; skipping library
--- Cached state for tracy equals expected state; skipping library
--- Cached state for gtest equals expected state; skipping library
--- Cached state for EGL equals expected state; skipping library
--- Cached state for ios-cmake equals expected state; skipping library
--- Cached state for spark-sl equals expected state; skipping library
--- Cached state for ktx-software equals expected state; skipping library
--- Cached state for openxr-sdk equals expected state; skipping library
--- Finished
-- Configuring done
-- Generating done

but during the build process i got this error:

[93/119] Building CXX object IGLU/CMak...loader/ktx2/TextureLoaderFactory.cpp.o
FAILED: IGLU/CMakeFiles/IGLUtexture_loader.dir/texture_loader/ktx2/TextureLoaderFactory.cpp.o 
/home/kalwalt/kalwalt-github/emsdk/upstream/emscripten/em++ -DIGL_BACKEND_ENABLE_OPENGL=1 -DIGL_CMAKE_BUILD=1 -DIGL_FORCE_ENABLE_LOGS=1 -DIGL_WITH_IGLU=1 -I/home/kalwalt/kalwalt-github/igl/. -I/home/kalwalt/kalwalt-github/igl/third-party/deps/src/imgui -I/home/kalwalt/kalwalt-github/igl/build_em/IGLU/include -I/home/kalwalt/kalwalt-github/igl/build_em/IGLU/include_texture_loader -I/home/kalwalt/kalwalt-github/igl -I/home/kalwalt/kalwalt-github/igl/src -I/home/kalwalt/kalwalt-github/igl/third-party/deps/src/glm -I/home/kalwalt/kalwalt-github/igl/third-party/deps/src/stb -std=gnu++17 -MD -MT IGLU/CMakeFiles/IGLUtexture_loader.dir/texture_loader/ktx2/TextureLoaderFactory.cpp.o -MF IGLU/CMakeFiles/IGLUtexture_loader.dir/texture_loader/ktx2/TextureLoaderFactory.cpp.o.d -o IGLU/CMakeFiles/IGLUtexture_loader.dir/texture_loader/ktx2/TextureLoaderFactory.cpp.o -c /home/kalwalt/kalwalt-github/igl/IGLU/texture_loader/ktx2/TextureLoaderFactory.cpp
In file included from /home/kalwalt/kalwalt-github/igl/IGLU/texture_loader/ktx2/TextureLoaderFactory.cpp:8:
In file included from /home/kalwalt/kalwalt-github/igl/./IGLU/texture_loader/ktx2/TextureLoaderFactory.h:10:
/home/kalwalt/kalwalt-github/igl/./IGLU/texture_loader/ktx/TextureLoaderFactory.h:29:23: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
      const ktxTexture* texture) const noexcept = 0;
                      ^
/home/kalwalt/kalwalt-github/igl/./IGLU/texture_loader/ktx/TextureLoaderFactory.h:29:23: note: insert '_Nullable' if the pointer may be null
      const ktxTexture* texture) const noexcept = 0;
                      ^
                        _Nullable
/home/kalwalt/kalwalt-github/igl/./IGLU/texture_loader/ktx/TextureLoaderFactory.h:29:23: note: insert '_Nonnull' if the pointer should never be null
      const ktxTexture* texture) const noexcept = 0;
                      ^
                        _Nonnull
In file included from /home/kalwalt/kalwalt-github/igl/IGLU/texture_loader/ktx2/TextureLoaderFactory.cpp:8:
/home/kalwalt/kalwalt-github/igl/./IGLU/texture_loader/ktx2/TextureLoaderFactory.h:35:66: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
  [[nodiscard]] igl::TextureFormat textureFormat(const ktxTexture* texture) const noexcept final;
                                                                 ^
/home/kalwalt/kalwalt-github/igl/./IGLU/texture_loader/ktx2/TextureLoaderFactory.h:35:66: note: insert '_Nullable' if the pointer may be null
  [[nodiscard]] igl::TextureFormat textureFormat(const ktxTexture* texture) const noexcept final;
                                                                 ^
                                                                   _Nullable
/home/kalwalt/kalwalt-github/igl/./IGLU/texture_loader/ktx2/TextureLoaderFactory.h:35:66: note: insert '_Nonnull' if the pointer should never be null
  [[nodiscard]] igl::TextureFormat textureFormat(const ktxTexture* texture) const noexcept final;
                                                                 ^
                                                                   _Nonnull
/home/kalwalt/kalwalt-github/igl/IGLU/texture_loader/ktx2/TextureLoaderFactory.cpp:13:10: fatal error: 'ktx.h' file not found
#include <ktx.h>
         ^~~~~~~
2 warnings and 1 error generated.
em++: error: '/home/kalwalt/kalwalt-github/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN -I/home/kalwalt/kalwalt-github/emsdk/upstream/emscripten/cache/sysroot/include/SDL --sysroot=/home/kalwalt/kalwalt-github/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -DIGL_BACKEND_ENABLE_OPENGL=1 -DIGL_CMAKE_BUILD=1 -DIGL_FORCE_ENABLE_LOGS=1 -DIGL_WITH_IGLU=1 -I/home/kalwalt/kalwalt-github/igl/. -I/home/kalwalt/kalwalt-github/igl/third-party/deps/src/imgui -I/home/kalwalt/kalwalt-github/igl/build_em/IGLU/include -I/home/kalwalt/kalwalt-github/igl/build_em/IGLU/include_texture_loader -I/home/kalwalt/kalwalt-github/igl -I/home/kalwalt/kalwalt-github/igl/src -I/home/kalwalt/kalwalt-github/igl/third-party/deps/src/glm -I/home/kalwalt/kalwalt-github/igl/third-party/deps/src/stb -std=gnu++17 -MD -MT IGLU/CMakeFiles/IGLUtexture_loader.dir/texture_loader/ktx2/TextureLoaderFactory.cpp.o -MF IGLU/CMakeFiles/IGLUtexture_loader.dir/texture_loader/ktx2/TextureLoaderFactory.cpp.o.d -c /home/kalwalt/kalwalt-github/igl/IGLU/texture_loader/ktx2/TextureLoaderFactory.cpp -o IGLU/CMakeFiles/IGLUtexture_loader.dir/texture_loader/ktx2/TextureLoaderFactory.cpp.o' failed (returned 1)
[98/119] Building CXX object IGLU/CMak...ate_pool/RenderPipelineStatePool.cpp.o
ninja: build stopped: subcommand failed.

Maybe i missing some steps? Thank you, Walter.

I'm trying to build the WASM version with an Ubuntu 22-04 machine without Vulkan ( i have only an integrated GPU intel card)

kalwalt commented 10 months ago

As a side note i have also run the script:

python3 deploy_content.py
python3 deploy_deps.py

and all dependencies were installed and ktx-software too...

kalwalt commented 10 months ago

i added this line inside IGLU CMakeLists.txt: target_include_directories(IGLUtexture_loader PUBLIC "${IGL_ROOT_DIR}/third-party/deps/src/ktx-software/include") and that error went away, but i got another one:

[21/21] Linking CXX executable samples\wasm\Tiny_Mesh.html
FAILED: samples/wasm/Tiny_Mesh.html
cmd.exe /C "cd . && C:\Users\perda\emsdk\upstream\emscripten\em++.bat  -s USE_WEBGL2=1 -s USE_GLFW=3 -s GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS=1 -s GL_EMULATE_GLES_VERSION_STRING_FORMAT=1 -s ALLOW_MEMORY_GROWTH=1 -s SINGLE_FILE=1 -s LLD_REPORT_UNDEFINED --shell-file C:/Users/perda/kalwalt-github/igl/samples/wasm/igl.html samples/wasm/CMakeFiles/Tiny_Mesh.dir/Tiny_Mesh.cpp.o samples/wasm/CMakeFiles/Tiny_Mesh.dir/Common.cpp.o -o samples\wasm\Tiny_Mesh.html  src/igl/libIGLLibrary.a  src/igl/opengl/libIGLOpenGL.a  src/igl/libIGLLibrary.a  src/igl/opengl/libIGLOpenGL.a  -lfmt && cd ."
wasm-ld: error: unable to find library -lfmt
em++: error: 'C:/Users/perda/emsdk/upstream/bin\wasm-ld.exe -o samples\wasm\Tiny_Mesh.wasm samples/wasm/CMakeFiles/Tiny_Mesh.dir/Tiny_Mesh.cpp.o samples/wasm/CMakeFiles/Tiny_Mesh.dir/Common.cpp.o src/igl/libIGLLibrary.a src/igl/opengl/libIGLOpenGL.a src/igl/libIGLLibrary.a src/igl/opengl/libIGLOpenGL.a -lfmt -LC:\Users\perda\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten -lGL-webgl2 -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined-file=C:\Users\perda\AppData\Local\Temp\tmpar9lib4d.undefined --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=__main_argc_argv --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export=__get_temp_ret --export=__set_temp_ret --export=malloc --export=__cxa_is_pointer_type --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=2147483648 --stack-first' failed (returned 1)
ninja: build stopped: subcommand failed.
kalwalt commented 10 months ago

if you delete the -lfmt from build.ninja it will finally build and link the Triangle.html and Tiny_Mesh.html files, i can see a colored triangle in the Triangle.html and a set of rotating textured cubes in the second. Of course it is a hack but maybe can be useful to someone.

kalwalt commented 10 months ago

To solve these issues i made these modifications to src/igl/CMakeLists.txt:

//at line 25
if(NOT EMSCRIPTEN)
  target_link_libraries(IGLLibrary PUBLIC fmt)
endif()

and to src/igl/opengl/CMakeLists.txt :

-add_subdirectory("${IGL_ROOT_DIR}/third-party/deps/src/glew/build/cmake" glew)
+add_subdirectory("${IGL_ROOT_DIR}/third-party/deps/src/glew-2.2.0/build/cmake" glew)
-target_include_directories(IGLOpenGL PUBLIC "${IGL_ROOT_DIR}/third-party/deps/src/glew/include")
+target_include_directories(IGLOpenGL PUBLIC "${IGL_ROOT_DIR}/third-party/deps/src/glew-2.2.0/include")

but maybe this last depends on the python script deploy_deps.py

kalwalt commented 10 months ago

You can find my changes in this branch https://github.com/kalwalt/igl/tree/testing-wasm if you want i can send a PR.

rudybear commented 10 months ago

Please send a PR

kalwalt commented 10 months ago

@rudybear I just send PR #64 to fix this.