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

Enable experimental wasm support #493

Merged
merged 1 commit into from
Nov 25, 2023

Conversation

zecozephyr
Copy link
Contributor

Instead of messing around with godot export templates or emscripten in order to either:

  1. dlopen the gdextension lib with global flag (which may come with unforeseen problems from broadly exposing miscellaneous new symbols from the dso).

  2. Reconsider the lookup scope of dynCall_<sig> in the generated invoke_<sig> methods (i.e. when an invoke_ is generated, also make it it remember the originating dso and fall back to lookup in the dso exports if the dynCall is not found globally)

I instead opt to simply promote the selected troublesome symbols from the dso to Module scope as early as possible at the gdextension entry point, whilst also searching for and executing the constructor methods which set up state for the subsequent class registrations.


Tested With:
Godot Engine v4.1.3.stable.official [f06b6836a]
(default export templates, dlink variant)
rustc 1.75.0-nightly (2f1bd0729 2023-10-27)
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.47 (431685f05c67f0424c11473cc16798b9587bb536)
Chrome Version 120.0.6093.0 (Official Build) canary (arm64)

@zecozephyr zecozephyr force-pushed the wasm-mvp-for-merge branch 2 times, most recently from 08c09d7 to 47aec42 Compare November 22, 2023 17:36
@zecozephyr zecozephyr changed the title Minimal proof-of-concept for running dodge-the-creeps targeting wasm Enable experimental wasm support Nov 22, 2023
@Bromeon Bromeon added the feature Adds functionality to the library label Nov 22, 2023
@GodotRust
Copy link

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-493

@zecozephyr zecozephyr force-pushed the wasm-mvp-for-merge branch 10 times, most recently from de7f73d to 1fbe196 Compare November 23, 2023 10:14
Copy link
Contributor

@PgBiel PgBiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking awesome 🚀 🦀 !!! Months of efforts from multiple contributors seem to have paid out 😄

Thank you very much @zecozephyr for the brilliant patch. Also thanks to everyone else involved, including @Esption for the recent 32-bit improvements and general help over at the WASM Discord thread, @Bromeon for all the support throughout, and the Godot contributors for all the recent work allowing GDExtension to work on WASM. 👍

@zecozephyr zecozephyr force-pushed the wasm-mvp-for-merge branch 3 times, most recently from 49c69e2 to 373bcea Compare November 25, 2023 09:06
@Bromeon
Copy link
Member

Bromeon commented Nov 25, 2023

Thanks a lot for this fantastic pull request, this is a great step towards WebAssembly support! ❤️

For future reference, I tested this PR as follows:

  1. Download emscripten
  2. Install emscripten
    • emsdk install latest
    • emsdk activate latest
      (not using --persistent as that might mess up env vars)
    • add directory with emcc manually to PATH
  3. Install Rust emscripten toolchain
    • rustup target add asmjs-unknown-emscripten --toolchain stable
    • rustup target add wasm32-unknown-emscripten --toolchain stable
    • you can also install for nightly instead
  4. Compile Rust for WASM and for Desktop (to open editor)
    • the build-wasm.sh script in this PR does this
  5. Open Godot editor in dodge-the-creeps/godot
    • Godot 4.1.3-stable
  6. Set up web export
    • in Project > Export, then enable Extensions Support option
    • alternatively, run $GODOT4_BIN --headless --path ../godot --export-debug Web from command line
  7. Launch game in browser
    • either from Godot grafik icon
    • or via URL http://localhost:8060/tmp_js_export.html

For me (Windows 10) it runs on Edge, but not on Firefox at the moment.

That's probably something we or Godot devs need to investigate in the future. For GDScript itself, Firefox definitely works (I recently released a LD54 game for Web). Either way, I'm super happy the Dodge-the-Creeps example already works with WASM ☺️

@Bromeon
Copy link
Member

Bromeon commented Nov 25, 2023

Regarding Firefox not working (loading forever, then freezing), I also tried with --release and
--release --features godot/lazy-function-tables, same result.

Seems to be a Godot/Emscripten issue, see also godotengine/godot-cpp#1247 (comment).

Instead of messing around with godot export templates or emscripten in
order to either:

 1. dlopen the gdextension lib with global flag (which may come with
    unforeseen problems from broadly exposing miscellaneous new symbols
    from the dso).

 2. Reconsider the lookup scope of `dynCall_<sig>` in the generated
    `invoke_<sig>` methods (i.e. when an invoke_<sig> is generated,
    also make it remember the originating dso and fall back to lookup
    in the dso exports if the `dynCall` is not found globally)

I instead opt to simply promote the selected troublesome symbols from
the dso to Module scope as early as possible at the gdextension entry
point, whilst also searching for and executing the constructor methods
which set up state for the subsequent class registrations.

-----------

Tested With:
    Godot Engine v4.1.3.stable.official [f06b6836a]
	(default export templates, dlink variant)
    rustc 1.75.0-nightly (2f1bd0729 2023-10-27)
    emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.47 (431685f05c67f0424c11473cc16798b9587bb536)
    Chrome Version 120.0.6093.0 (Official Build) canary (arm64)
@Bromeon Bromeon enabled auto-merge November 25, 2023 11:29
@Bromeon Bromeon added this pull request to the merge queue Nov 25, 2023
Merged via the queue into godot-rust:master with commit 9cca3e0 Nov 25, 2023
@zecozephyr zecozephyr deleted the wasm-mvp-for-merge branch November 25, 2023 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: wasm WebAssembly export target feature Adds functionality to the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants