-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add HTML5 export guide #71
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for the PR! This is a great guide that helps better define how godot-rust supports HTML5 exports.
I have included some minor nitpicks on structure. I will also give this process a go to test this from my end.
@Bromeon feel free to let me know if you have any additional thoughts or questions on this addition
src/exporting/html5.md
Outdated
|
||
Exporting to HTML5 works just like exporting to other platforms, however there are some things that can make the process a bit tricky and require extra attention. | ||
|
||
## General considerations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this export process doesn't have a trivial set up, I think this section can be called "Tooling Requirements", "Setup Requirements" or something like that. This would make it more obvious to users that there are very specific requirements for this export process.
|
||
## Godot 3.4.4 | ||
|
||
**Disclaimer**: _Currently, the following steps are only tested and confirmed to work on Linux._ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth making this disclaimer into it's own section where we can include all of the additional version requirements. In the future, more folks may be able to test this and confirm working versions so having a section could be useful for new users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect this whole section to become outdated very rapidly. What I said under "General Considerations" (matching emscripten versions) is fairly general, but building Godot will probably not be necessary with 3.6, and rust compiler flags could change any second now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. I think keeping a normal disclaimer is probably enough in that case.
src/exporting/html5.md
Outdated
* Emscripten 3.1.15-git (4100960b42619b28f19baf4254d5db2097234b32) | ||
|
||
|
||
### Getting Emscripten |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick, "Installing and configuring Emscripten" might be a more appropriate section title.
source ./emsdk_env.sh | ||
``` | ||
|
||
### Building Godot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this require building Godot from source? or only the export template? If the latter, can we change the title to "Building Godot export template"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell an export template is just a pre-built version of Godot, so these are the same thing. We are compiling the engine from source to wasm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you built Godot from source, did you use gdnative
with the custom-godot
Cargo feature?
src/exporting/html5.md
Outdated
mv bin/godot.javascript.opt.gdnative.zip bin/webassembly_gdnative_release.zip | ||
``` | ||
|
||
Set the newly built export template as a custom template in Godot and be sure to set the export type as GDNative. When exporting, uncheck "Export With Debug". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming that the export template requires installing from a file as per: https://docs.godotengine.org/en/stable/tutorials/export/exporting_basics.html#export-templates
Is that correct? If so, can I ask for you to add the above link for completeness?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an awesome addition, thank you very much! ❤️
Good that you highlighted that some of the guide might be obsolete soon. I think it's good to start somewhere, and update when needed. Hopefully, a smaller scale in updating also motivates more people to contribute 🙂
src/exporting/html5.md
Outdated
mv bin/godot.javascript.opt.gdnative.zip bin/webassembly_gdnative_release.zip | ||
``` | ||
|
||
Set the newly built export template as a custom template in Godot and be sure to set the export type as GDNative. When exporting, uncheck "Export With Debug". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me!
|
||
### Building your Rust code | ||
|
||
In your project's `config.toml`, add the following: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refers to the godot-rust crate which is compiled as a cdylib
? If yes, maybe quickly mention that to resolve ambiguities 🙂
source ./emsdk_env.sh | ||
``` | ||
|
||
### Building Godot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you built Godot from source, did you use gdnative
with the custom-godot
Cargo feature?
@Bromeon I don't use |
@derivator You should only need I'm not sure if using Emscripten has an effect here. You could run godot --gdnative-generate-json-api api.json and diff the generated file against the |
I have no idea how I would do that for a wasm build, but I suspect it's fine. It works for me after all 😆 |
src/exporting/html5.md
Outdated
[target.wasm32-unknown-emscripten] | ||
rustflags = [ | ||
"-Clink-arg=-sSIDE_MODULE=2", # build a side module that Godot can load | ||
"-Crelocation-model=pic", # needed to prevent linker errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed on nightly Rust:
rust-lang/rust#98149
src/exporting/html5.md
Outdated
rustflags = [ | ||
"-Clink-arg=-sSIDE_MODULE=2", # build a side module that Godot can load | ||
"-Crelocation-model=pic", # needed to prevent linker errors | ||
"-Cpanic=abort", # panic unwinding is currently broken without -sWASM_BIGINT, see below |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR to fix:
emscripten-core/emscripten#17328
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the guide to reflect the current state of affairs.
I initially had some problems where I still needed -Zbuild-std
(to fix missing __cxa_is_pointer_type
) and -Zlink-native-libraries=no
(to fix wasm-ld: error: unable to find library -lc
, but after cargo clean
it works without those flags so maybe rust was incorrectly reusing some old build artifact? @hoodmane can you confirm that these flags shouldn't be needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently Pyodide is using:
export RUSTFLAGS= \
-C link-arg=-sSIDE_MODULE=2 \
-C link-arg=-sWASM_BIGINT \
-Z link-native-libraries=no
https://github.com/pyodide/pyodide/blob/main/Makefile.envs#L159
The problem that -Zlink-native-libraries=no
fixes is not resolved either on the Rust side or on the Emscripten side. But if it works without it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to you both for the great writeup already! 😊
src/exporting/html5.md
Outdated
rustc --version --verbose | ||
``` | ||
|
||
A version mismatch between Rust and Emscripten will probably result in compiler errors, while incompatible Emscripten versions between Rust and Godot will result in cryptic runtime errors such as `indirect call signature mismatch`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will result in cryptic runtime errors such as
indirect call signature mismatch
It might be worth indicating that indirect call signature mismatch
does not necessarily mean that there is a version incompatibility: this error message is also the most likely outcome of memory corruption and several other problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@derivator any comment on this? 🙂
@derivator @hoodmane Any more comments before this is merged? 🙂 |
@Bromeon As far as I can tell at a glance, building Godot shouldn't be necessary anymore with Godot 3.5, as the commit that updates their emscripten version seems to have made it in, but I would still keep that information in the guide, in case the same kind of version mismatch happens in the future. I can try updating the guide this weekend. |
@derivator have you had a chance to look at it yet? 🙂 |
@Bromeon I'm having a look right now. Some steps will not be necessary anymore, however Emscripten makes no ABI stability promises, so while using the export template provided by godot might work coincidentally, I think it's probably best to always compile it yourself. I will update the guide to reflect this. |
Recommend building Godot export template yourself, always Remove mention of WASM_BIGINT as alternative to panic=abort
I have it working with Godot 3.5 following the steps in the guide. I believe |
Thanks a lot to everyone involved! It's great to finally have a bit more resources on the topic of HTML5 exports ❤️ |
I was able to run on emscripten 3.1.14, Godot 3.5.1, rust nightly 0.65.0 (2022-09-03). I was unable to run as suggested on the latest versions of rust and emscripten, or even 3.1.21 as in the tutorial. A runtime error came out with similar text:
all because I understood different versions of llvm, so I am puzzled how you could run with the latest version of emscripten, as nightly rust builds still have 15.0, not 16.0. |
@Bromeon as discussed in #647 this should cover most of the current problems with HTML5 exports.