juj / wasm_webgpu

System headers for interfacing WebGPU from C programs compiled via Emscripten to WebAssembly
BSD 3-Clause "New" or "Revised" License
331 stars 26 forks source link

Error when trying to compile samples #44

Closed nerdola-de-cartola closed 2 months ago

nerdola-de-cartola commented 7 months ago

Introduction

I'm trying to compile the samples in this repository in Ubuntu 22 using wsl 2. But when I try to compile I got several errors, the output is even to big to put here, so I have reduced to just the first error. If you guys need any more information about my problem please let me know

Neofetch

$ neofetch

OS: Ubuntu 22.04.4 LTS on Windows 10 x86_64 Kernel: 5.15.90.3-microsoft-standard-WSL2+ Uptime: 6 hours, 37 mins Packages: 717 (dpkg), 6 (snap) Shell: bash 5.1.16 Theme: Adwaita [GTK3] Icons: Adwaita [GTK3] Terminal: Windows Terminal CPU: 11th Gen Intel i5-1135G7 (8) @ 2.419GHz GPU: 9c96:00:00.0 Microsoft Corporation Device 008e Memory: 1299MiB / 9797MiB

Emscripten version

$ emcc --version

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.57 (1df9c1977b49926c1efca672c31414da45c0c7bb) 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.

Cmake

$ emcmake cmake ../samples -DCMAKE_BUILD_TYPE=Debug # Or MinSizeRel, RelWithDebInfo or Release

configure: cmake ../samples -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=/home/matheus-lucas/downloads/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/home/matheus-lucas/downloads/emsdk/node/16.20.0_64bit/bin/node -- Configuring done -- Generating done -- Build files have been written to: /home/matheus-lucas/tests/wasm_webgpu/build

Make

$ make -j

[ 4%] Building CXX object CMakeFiles/webgpu.dir/home/matheus-lucas/tests/wasm_webgpu/lib/lib_webgpu.cpp.o [ 9%] Building CXX object CMakeFiles/webgpu.dir/home/matheus-lucas/tests/wasm_webgpu/lib/lib_webgpu_cpp20.cpp.o [ 14%] Linking CXX static library libwebgpu.a [ 14%] Built target webgpu [ 19%] Building C object CMakeFiles/vertex_buffer.dir/vertex_buffer/vertex_buffer.c.o [ 23%] Building C object CMakeFiles/clear_screen.dir/clear_screen/clear_screen.c.o [ 28%] Building C object CMakeFiles/hello_triangle_minimal.dir/hello_triangle/hello_triangle_minimal.c.o [ 33%] Building C object CMakeFiles/texture.dir/texture/texture.c.o [ 38%] Building C object CMakeFiles/buffer_map_sync.dir/buffer_map_sync/buffer_map_sync.c.o [ 42%] Building C object CMakeFiles/clear_screen_sync.dir/clear_screen/clear_screen_sync.c.o [ 47%] Building C object CMakeFiles/gpu_oom.dir/gpu_oom/gpu_oom.c.o [ 52%] Building C object CMakeFiles/hello_triangle_verbose.dir/hello_triangle/hello_triangle_verbose.c.o [ 57%] Building C object CMakeFiles/failing_shader_compilation.dir/failing_shader_compilation/failing_shader_compilation.c.o [ 61%] Linking CXX executable gpu_oom.html [ 66%] Linking CXX executable hello_triangle_minimal.html [ 71%] Linking CXX executable clear_screen.html [ 76%] Linking CXX executable vertex_buffer.html [ 80%] Linking CXX executable buffer_map_sync.html [ 85%] Linking CXX executable failing_shader_compilation.html [ 90%] Linking CXX executable clear_screen_sync.html [ 95%] Linking CXX executable hello_triangle_verbose.html [100%] Linking CXX executable texture.html cache:INFO: generating system asset: symbol_lists/05e51aa93b189dc23e58af3996460d7cd9203a73.json... (this will be cached in "/home/matheus-lucas/downloads/emsdk/upstream/emscripten/cache/symbol_lists/05e51aa93b189dc23e58af3996460d7cd9203a73.json" for subsequent builds) em++: warning: -sASYNCIFY=2 (JSPI) is still experimental [-Wexperimental] error: /home/matheus-lucas/tests/wasm_webgpu/lib/lib_webgpu.js: failure to execute js library "/home/matheus-lucas/tests/wasm_webgpu/lib/lib_webgpu.js": error: /home/matheus-lucas/tests/wasm_webgpu/lib/lib_webgpu.js: use -sVERBOSE to see more details Internal compiler error in src/compiler.js! Please create a bug report at https://github.com/emscripten-core/emscripten/issues/ with a log of the build and the input files used to run. Exception message: "/home/matheus-lucas/tests/wasm_webgpu/lib/lib_webgpu.js:46 global.WEBGPU_DEBUG ^

ReferenceError: global is not defined at /home/matheus-lucas/tests/wasm_webgpu/lib/lib_webgpu.js:46:5 at Script.runInContext (node:vm:141:12) at Script.runInNewContext (node:vm:146:17) at Module.runInNewContext (node:vm:306:38) at runInMacroContext (file:///home/matheus-lucas/downloads/emsdk/upstream/emscripten/src/utility.mjs:331:13) at preprocess (file:///home/matheus-lucas/downloads/emsdk/upstream/emscripten/src/parseTools.mjs:115:28) at Object.load (file:///home/matheus-lucas/downloads/emsdk/upstream/emscripten/src/modules.mjs:244:35) at Module.runJSify (file:///home/matheus-lucas/downloads/emsdk/upstream/emscripten/src/jsifier.mjs:166:18) at file:///home/matheus-lucas/downloads/emsdk/upstream/emscripten/src/compiler.mjs:88:11 em++: error: '/home/matheus-lucas/downloads/emsdk/node/16.20.0_64bit/bin/node /home/matheus-lucas/downloads/emsdk/upstream/emscripten/src/compiler.mjs /tmp/tmpg7w2mesa.json --symbols-only' failed (returned 1) cache:INFO: generating system asset: symbol_lists/05e51aa93b189dc23e58af3996460d7cd9203a73.json... (this will be cached in "/home/matheus-lucas/downloads/emsdk/upstream/emscripten/cache/symbol_lists/05e51aa93b189dc23e58af3996460d7cd9203a73.json" for subsequent builds)

briangavin commented 6 months ago

Hello, I am on Windows but I am getting a very simalar error. I fixed it by switching to an older version of emscripten. I switched to 3.1.35

nerdola-de-cartola commented 6 months ago

Hello, I am on Windows but I am getting a very simalar error. I fixed it by switching to an older version of emscripten. I switched to 3.1.35

Thank you, this solution works for me as well

juj commented 6 months ago

Thanks for reporting! Got around to looking at this now and bisected this issue, and it looks like a breakage in upstream Emscripten:

77133ba8c52d69ba2b4dd1445c23d0c129497c79 is the first bad commit
commit 77133ba8c52d69ba2b4dd1445c23d0c129497c79
Author: Sam Clegg <sbc@chromium.org>
Date:   Mon Mar 18 22:16:25 2024 -0700

    Finish converting JS compiler to ES6 modules. NFC (#21542)

    The compiler itself is now purely JS modules.

    As part of this change I create a new global context object in which
    all library code is processed.  This allows is to have a clean
    separation between the compiler code itself and code being processed.
    Only symbols explicitly added to the macro context are available to JS
    library code.

 ChangeLog.md              |    4 +
 src/compiler.mjs          |   53 +--
 src/jsifier.js            |  747 -----------------------------
 src/jsifier.mjs           |  774 ++++++++++++++++++++++++++++++
 src/modules.js            |  514 --------------------
 src/modules.mjs           |  557 ++++++++++++++++++++++
 src/parseTools.js         | 1084 ------------------------------------------
 src/parseTools.mjs        | 1161 +++++++++++++++++++++++++++++++++++++++++++++
 src/parseTools_legacy.js  |  139 ------
 src/parseTools_legacy.mjs |  152 ++++++
 src/utility.js            |  263 ----------
 src/utility.mjs           |  345 ++++++++++++++
 tools/preprocessor.mjs    |   57 +--
 13 files changed, 3020 insertions(+), 2830 deletions(-)
 delete mode 100644 src/jsifier.js
 create mode 100644 src/jsifier.mjs
 delete mode 100644 src/modules.js
 create mode 100644 src/modules.mjs
 delete mode 100644 src/parseTools.js
 create mode 100644 src/parseTools.mjs
 delete mode 100644 src/parseTools_legacy.js
 create mode 100644 src/parseTools_legacy.mjs
 delete mode 100644 src/utility.js
 create mode 100644 src/utility.mjs

C:\emsdk\emscripten\main>git tag --contains 77133ba8c52d69ba2b4dd1445c23d0c129497c79
3.1.57
3.1.58
3.1.59

So Emscripten < 3.1.57 works. I'll report this upstream and figure out a clean solution for this.

juj commented 2 months ago

Took a bit of time to get to the mindset to come back to this (thanks to #46 bug report to help get in the context). Reported upstream regression and found there is a simple fix after all, posted a fix now.