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

[HTML5] Optional GDNative Support #44076

Merged
merged 5 commits into from
Dec 7, 2020
Merged

Conversation

Faless
Copy link
Collaborator

@Faless Faless commented Dec 3, 2020

After months of works, refactoring, bloody tears, GDNative is finally working for HTML5 exports, with some quirks (see below).
Here is a working GDNative C++ demo running on the web.

demo

The demo was built with this godot-cpp, this demo projects and this 3.2 branch. I'll PR them in the respective repositories.

Building a version that support dynamic linking requires a very recent emscripten version, at the time of writing 2.0.10 has been tested.
You can build an HTML5 template with GDNative support via:

scons p=javascript gdnative_enabled=yes

(yes, this kinda clash with module_gdnative_enabled=yes, should I rename it to dlopen_enabled? dynamic_linking_enabled?)

In this PR:

  • ENet patch to workaround emscripten 2.0.9 issue. Removed, no longer needed
    (now fixed upstream, new version will hopefully be good, once released I'll remove this commit and the draft status).
  • Add function signatures to JavaScript libraries (which is supposed to be required in newer emscripten).
  • Add a new "Export Type" section that allows the user to select either Regular, Threads, GDNative build.
    Expected template names are: webassembly[_$FEATURE]_$TARGET].zip, e.g webassembly_gdnative_release.zip.
    When using custom export that option is only relevant for the GDNative build (otherwise the libraries won't be exported, but of course the selected template must be of the proper type).

gdnative

@Faless Faless added this to the 4.0 milestone Dec 3, 2020
@Faless Faless requested review from akien-mga and a team as code owners December 3, 2020 21:32
@Faless Faless changed the title [HTML5] Optional GDNative Support [WIP] [HTML5] Optional GDNative Support Dec 3, 2020
@Faless Faless marked this pull request as draft December 3, 2020 21:35
@DarkMessiah
Copy link
Contributor

Which browser is required?
image

@Faless
Copy link
Collaborator Author

Faless commented Dec 4, 2020

Which browser is required?

Firefox, but the latest version of chrome should also work.

@@ -109,6 +110,7 @@ const GodotRTCDataChannel = {
}
},

godot_js_rtc_datachannel_send__sig: 'iiiii',
Copy link
Member

Choose a reason for hiding this comment

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

That's actually v in Roman numerals ;)

EXPORT_MODE_GDNATIVE = 2,
};

String _get_template_name(ExportMode p_mode, bool p_debug) const {
Copy link
Member

Choose a reason for hiding this comment

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

I'll get started on updating my build scripts to build all those flavours :)

Copy link
Member

Choose a reason for hiding this comment

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

Though for the 3.2 branch it's going to be a bit tricky as the current Mono version goes with Emscripten 1.39.7 (patched to 1.39.9 because 1.39.7 is broken), which doesn't work for GDNative.

We could possibly make the standard builds with Emscripten 2.0.10+ (normal, threads, gdnative) and Mono builds with Emscripten 1.39.9 (normal, threads). Or work our way through upstream Mono patches to up support to Emscripten 2.0.10 in the Mono 6.12 branch.

@akien-mga
Copy link
Member

Looks great on a first review 👍

@Faless
Copy link
Collaborator Author

Faless commented Dec 4, 2020

@DarkMessiah thanks for the report, I fixed the Chrome issue and uploaded a new version.
It should work for you now.
Please make sure to clear your browser cache and reloading the page.
(I will fix the cache issues with exported games soon, I promise)

Working with emscripten >= 2.0.10
This "breaks" our loading bar logic (libraries are not counted).
Fixing it is non trivial and probably deserves investigating a different
strategy.
Available types:
- Regular
- GDNative (support dynamic linking and thus GDNative WASM files)
- Threads (uses WebAssembly Threads)
This is suboptimal as it requires adding an extra compile flag, but
rewriting how feature tags work is beyond the scope of this work.
@Faless Faless marked this pull request as ready for review December 5, 2020 02:17
@Faless Faless changed the title [WIP] [HTML5] Optional GDNative Support [HTML5] Optional GDNative Support Dec 5, 2020
@Faless
Copy link
Collaborator Author

Faless commented Dec 5, 2020

Emscripten 2.0.10 is out, I removed the ENet patch, and renamed the feature tag wasm to wasm32 (since wasm64 will be a thing).
This is ready for review.

@akien-mga
Copy link
Member

(since wasm64 will be a thing).

Exciting!

@akien-mga akien-mga merged commit e20011b into godotengine:master Dec 7, 2020
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

Should we add a version check in detect.py to abort gdnative_enabled=yes build if emcc < 2.0.10?

@Faless
Copy link
Collaborator Author

Faless commented Dec 7, 2020

Should we add a version check in detect.py to abort gdnative_enabled=yes build if emcc < 2.0.10?

I'll look into that

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

Successfully merging this pull request may close these issues.

3 participants