Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how do I build this project for WebAssembly #72

Open
The0Dev opened this issue Jan 24, 2025 · 1 comment
Open

Question: how do I build this project for WebAssembly #72

The0Dev opened this issue Jan 24, 2025 · 1 comment

Comments

@The0Dev
Copy link

The0Dev commented Jan 24, 2025

Hello. I wonder if it's possible to compile this example for WebAssembly.

Apparently, it's possible to use GDExtension on the web when building with Scons but I struggle to make it work with CMake

I can export my main project for web with Godot but when it loads it says:

ERROR: No GDExtension library found for current OS and architecture (web.wasm32) in configuration file: res://GDExtensionTemplate.gdextension

I tried to build the example using Emscripten and the following commands:

./emcmake cmake -S /home/user/GDExtensionTemplate -B /home/user/GDExtensionTemplate-build-web -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-sSIDE_MODULE -fPIC -msimd128 -std=c++17 -sNO_DISABLE_EXCEPTION_CATCHING -o3 -pthread --target=wasm32-unknown-emscripten" -DCMAKE_C_FLAGS="-fPIC" -DCMAKE_EXE_LINKER_FLAGS="-pthread -sINITIAL_MEMORY=104857600 -sALLOW_MEMORY_GROWTH=1"

./emmake make -C /home/user/GDExtensionTemplate-build-web -j 4

However, I got the following warning from CMake and it built a static library instead (GDExtensionTemplate.a)

ADD_LIBRARY called with SHARED option but the target platform does not
support dynamic linking

I would appreciate some help

@The0Dev
Copy link
Author

The0Dev commented Jan 25, 2025

I've had some progress resolving this issue by doing this:
emscripten-core/emscripten#15276 (comment)

It now builds a .so library that I can specify in the .gdextension file

[libraries]
web.wasm32 = "lib/Emscripten-x86/libGDExtensionTemplate.so"

However, at link time I get warnings like this:

wasm-ld: warning: function signature mismatch: _ZNK5godot4Mesh21_surface_get_materialEi
defined as () -> void in extern/godot-cpp/bin/libgodot-cpp.emscripten.release.32.a(mesh.cpp.o)
defined as (i32, i32, i32) -> void in lto.tmp

And in my browser I get a similar error:

Uncaught (in promise) LinkError: imported function 'env.strtoull' signature mismatch

I tried to solve this by specifying -flto/-fno-lto flags everywhere I could and clearing cache but it seems like it had no effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant