mitsuba-renderer / nanogui

Minimalistic C++/Python GUI library for OpenGL, GLES2/3, Metal, and WebAssembly/WebGL
Other
1.57k stars 196 forks source link

escripten/wasm example #56

Open DerThorsten opened 4 years ago

DerThorsten commented 4 years ago

Is there any example how to compile a gui to wasm. The mentioned https://github.com/rgl-epfl/tekari is not compiling with some complicated error

LLVM ERROR: malformed uleb128, extends past end
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
....
ghost commented 4 years ago

Same here, I would love to com[ile tekari.

svenevs commented 4 years ago

The warning message may not be accurate in terms of what the cause is. Can you both please share more information?

https://github.com/mitsuba-renderer/nanogui/blob/a6afde86f48bf2e3a00689c7145746c89fa474a3/CMakeLists.txt#L39

If you set your c++ compiler to emscripten, can you at least compile nanogui? What version of the compiler are you using? How did you install it? Platform?

We can probably just reuse one of the examples we already have assuming you can build nanogui

DerThorsten commented 4 years ago

I am able to compile an simple example with nano gui but it fails when I try to run the file. But I have the suspicion that I set some cmake-flags wrong.

Here is my code https://github.com/DerThorsten/nanofun/

I use the following emscripten version on Ubuntu 20.04 LTS

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 2.0.3
clang version 12.0.0 (/b/s/w/ir/cache/git/chromium.googlesource.com-external-github.com-llvm-llvm--project a39423084cbbeb59e81002e741190dccf08b5c82)
Target: x86_64-unknown-linux-gnu

I tried different values for NANOGUI_BACKEND I can only got it to compile when I set NANOGUI_BUILD_GLFW=1 and GLFW_USE_OSMESA=1 (without GLFW_USE_OSMESA=1 it fails already at cmake stage comlaining about some X11 libs missing)

The browser console showed me the following.

wasm streaming compile failed: TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.
(anonymous) @ index.js:1
Promise.then (async)
(anonymous) @ index.js:1
Promise.then (async)
instantiateAsync @ index.js:1
createWasm @ index.js:1
(anonymous) @ index.js:1
index.js:1 falling back to ArrayBuffer instantiation
(anonymous) @ index.js:1
Promise.then (async)
(anonymous) @ index.js:1
Promise.then (async)
instantiateAsync @ index.js:1
createWasm @ index.js:1
(anonymous) @ index.js:1
index.js:1 GLFW error 65542: Null: EGL not available
put_char @ index.js:1
write @ index.js:1
write @ index.js:1
doWritev @ index.js:1
_fd_write @ index.js:1
(anonymous) @ 00395f2e:1
(anonymous) @ 00395f2e:1
(anonymous) @ 00395f2e:1
(anonymous) @ 00395f2e:1
(anonymous) @ 00395f2e:1
(anonymous) @ 00395f2e:1
(anonymous) @ 00395f2e:1
(anonymous) @ 00395f2e:1
(anonymous) @ 00395f2e:1
(anonymous) @ 00395f2e:1
(anonymous) @ 00395f2e:1
(anonymous) @ 00395f2e:1
(anonymous) @ 00395f2e:1
main @ 00395f2e:1
Module._main @ index.js:1
callMain @ index.js:1
doRun @ index.js:1
run @ index.js:1
runCaller @ index.js:1
removeRunDependency @ index.js:1
receiveInstance @ index.js:1
receiveInstantiatedSource @ index.js:1
Promise.then (async)
instantiateArrayBuffer @ index.js:1
(anonymous) @ index.js:1
Promise.then (async)
(anonymous) @ index.js:1
Promise.then (async)
instantiateAsync @ index.js:1
createWasm @ index.js:1
(anonymous) @ index.js:1
index.js:1 exception thrown: 6065136
callMain @ index.js:1
doRun @ index.js:1
run @ index.js:1
runCaller @ index.js:1
removeRunDependency @ index.js:1
receiveInstance @ index.js:1
receiveInstantiatedSource @ index.js:1
Promise.then (async)
instantiateArrayBuffer @ index.js:1
(anonymous) @ index.js:1
Promise.then (async)
(anonymous) @ index.js:1
Promise.then (async)
instantiateAsync @ index.js:1
createWasm @ index.js:1
(anonymous) @ index.js:1
index.html:1 Uncaught (in promise) 6065136

any help is appreciated

DerThorsten commented 4 years ago

an absolute minimal example which compiles with emscripten would be so amazing

DerThorsten commented 3 years ago

any chance?

paulocoutinhox commented 3 years ago

??

jgm-ktg commented 2 years ago

Also pinging this ... "WebAssembly code generation works out of the box (requires Emscripten)" ... and yet I have no idea where to start

paulocoutinhox commented 2 years ago

Im getting this error:

python nativium.py target wasm build --dry-run
[INFO] Running "build" on target "wasm"...
[INFO] Running in dry mode...
[INFO] Building for: wasm/Debug...
Using lockfile: '/Users/paulo/Developer/workspaces/cpp/nativium-gui/nativium/build/wasm/Debug/wasm/conan/conan.lock'
Using cached profile from lockfile
[INFO] Nativium: Extending conan configuration with module app-core
conanfile.py (nativium/None): Calling build()
-- Nativium: Adding modules...
-- Nativium: Adding module app-core
-- CPM: adding package nanogui@ (master)
-- NanoGUI v0.1.4 
-- NanoGUI: using GLES 2 backend.
-- NanoGUI: building static library.
-- NanoGUI: not building the Python plugin.
-- Nativium: Adding module app-main
-- Nativium: Adding module support-lib
-- Nativium: Modules added
-- Conan: called by CMake conan helper
-- Conan: Adjusting output directories
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Conan: Adjusting fPIC flag (ON)
-- Conan: Compiler Clang>=8, checking major version 14
-- Conan: Checking correct version: 14
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/paulo/Developer/workspaces/cpp/nativium-gui/nativium/build/wasm/Debug/wasm/target
Consolidate compiler generated dependencies of target nanogui
[  1%] Building C object _deps/nanogui-build/CMakeFiles/nanogui.dir/ext/nanovg/src/nanovg.c.o
[  3%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/texture_gl.cpp.o
[  5%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/shader_gl.cpp.o
[  7%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/renderpass_gl.cpp.o
[  9%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/common.cpp.o
[ 11%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/nanogui_resources.cpp.o
[ 13%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/opengl.cpp.o
[ 17%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/theme.cpp.o
[ 17%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/widget.cpp.o
[ 19%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/screen.cpp.o
[ 21%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/layout.cpp.o
[ 23%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/label.cpp.o
[ 25%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/window.cpp.o
[ 26%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/popup.cpp.o
[ 28%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/checkbox.cpp.o
[ 30%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/button.cpp.o
[ 32%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/popupbutton.cpp.o
/Users/paulo/Developer/workspaces/cpp/nativium-gui/nativium/build/wasm/Debug/wasm/target/_deps/nanogui-src/src/screen.cpp:190:20: error: use of undeclared identifier 'GLFW_SCALE_TO_MONITOR'
    glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
                   ^
/Users/paulo/Developer/workspaces/cpp/nativium-gui/nativium/build/wasm/Debug/wasm/target/_deps/nanogui-src/src/common.cpp:312:22: warning: unused variable 'FILE_DIALOG_MAX_BUFFER' [-Wunused-variable]
    static const int FILE_DIALOG_MAX_BUFFER = 16384;
                     ^
/Users/paulo/Developer/workspaces/cpp/nativium-gui/nativium/build/wasm/Debug/wasm/target/_deps/nanogui-src/src/screen.cpp:380:5: error: use of undeclared identifier 'glfwSetWindowContentScaleCallback'
    glfwSetWindowContentScaleCallback(m_glfw_window,
    ^
[ 34%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/combobox.cpp.o
[ 36%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/progressbar.cpp.o
[ 38%] Building CXX object _deps/nanogui-build/CMakeFiles/nanogui.dir/src/slider.cpp.o
2 errors generated.
em++: error: '/Users/paulo/.conan/data/emsdk/3.1.0/_/_/package/cf186363a0bf37e3a91ee26c25ea5d664ac71fa5/bin/upstream/bin/clang++ -target wasm32-unknown-emscripten -DEMSCRIPTEN -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=1 -D__EMSCRIPTEN_tiny__=0 -D_LIBCPP_ABI_VERSION=2 -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/Users/paulo/.conan/data/emsdk/3.1.0/_/_/package/cf186363a0bf37e3a91ee26c25ea5d664ac71fa5/bin/.emscripten_cache/sysroot -Xclang -iwithsysroot/include/compat -DNANOGUI_BUILD -DNANOGUI_GLES_VERSION=2 -DNANOGUI_USE_GLES -DNVG_STB_IMAGE_IMPLEMENTATION -I/Users/paulo/Developer/workspaces/cpp/nativium-gui/nativium/build/wasm/Debug/wasm/target/_deps/nanogui-build -I/Users/paulo/Developer/workspaces/cpp/nativium-gui/nativium/build/wasm/Debug/wasm/target/_deps/nanogui-src/include -I/Users/paulo/Developer/workspaces/cpp/nativium-gui/nativium/build/wasm/Debug/wasm/target/_deps/nanogui-src/ext/nanovg/src -std=c++17 -Wall -std=c++17 -Wall -std=c++17 -Wall -std=c++17 -Wall -std=c++17 -Wall -std=c++17 -Wall -std=c++17 -Wall -std=c++17 -Wall -std=c++17 -Wall -std=c++17 -Wall -g -fvisibility=hidden -march=nehalem -std=gnu++17 -MD -MT _deps/nanogui-build/CMakeFiles/nanogui.dir/src/screen.cpp.o -MF CMakeFiles/nanogui.dir/src/screen.cpp.o.d -c /Users/paulo/Developer/workspaces/cpp/nativium-gui/nativium/build/wasm/Debug/wasm/target/_deps/nanogui-src/src/screen.cpp -o CMakeFiles/nanogui.dir/src/screen.cpp.o' failed (returned 1)
make[2]: *** [_deps/nanogui-build/CMakeFiles/nanogui.dir/src/screen.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
1 warning generated.
make[1]: *** [_deps/nanogui-build/CMakeFiles/nanogui.dir/all] Error 2
make: *** [all] Error 2