Skip to content

Commit b4dbde4

Browse files
committed
Update HTML5 export guide for Godot 3.5
Recommend building Godot export template yourself, always Remove mention of WASM_BIGINT as alternative to panic=abort
1 parent 1112ad9 commit b4dbde4

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

src/exporting/html5.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Exporting to HTML5 works just like exporting to other platforms, however there a
55
## What you need (to know)
66

77
The Godot HTML5 export templates are built with [Emscripten](https://emscripten.org/), so you need to build your Rust code for the `wasm32-unknown-emscripten` target (`wasm32-unknown-unknown` will not work).
8-
You need to build your code with a version of Emscripten that is compatible with your version of Rust and (ideally identical to) the version of Emscripten used to build the export template.
9-
In practice, this means you might have to:
8+
Since Emscripten does not offer a stable ABI between versions, your code and the Godot export template have to be built with the same Emscripten version, which also needs to be compatible with the Rust compiler version you are using.
9+
In practice, this means you probably have to do some or all of these things:
1010
* install a specific version of Emscripten
1111
* [build the HTML5 export template yourself](https://docs.godotengine.org/en/stable/development/compiling/compiling_for_web.html)
1212
* use a specific version of Rust
@@ -18,20 +18,23 @@ emcc -v
1818
rustc --version --verbose
1919
```
2020

21-
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`.
21+
A version mismatch between Rust and Emscripten will probably result in compiler errors, while using incompatible Emscripten versions between Rust and Godot will result in cryptic runtime errors.
22+
23+
Emscripten uses a cache to store build artifacts and header files. In some cases this means that the order in which steps are completed matters.
2224

2325
Also note that `wasm32-unknown-emscripten` is a 32-bit target, which can cause problems with crates incorrectly assuming that `usize` is 64 bits wide.
2426

25-
## Godot 3.4.4
27+
## Godot 3.5
2628

2729
**Disclaimer**: _Currently, the following steps are only tested and confirmed to work on Linux._
2830

29-
Godot 3.4.4's export template is built with a very old Emscripten version that doesn't play nice with Rust. You will have to build it yourself with a more recent version.
30-
As of 2022-07-02 you also need to use a Rust nightly build.
31+
[Godot 3.5's prebuilt HTML5 export template is built with Emscripten 3.1.10](https://github.com/godotengine/godot/blob/3.5/.github/workflows/javascript_builds.yml).
32+
It might be possible to use it if build your Rust code with that exact version, but extra compiler flags may be needed. This guide focuses on building the export template yourself with a recent version of Emscripten.
33+
As of 2022-09-04 you also need to use a Rust nightly build.
3134

3235
Confirmed working versions are:
33-
* rustc 1.64.0-nightly (f2d93935f 2022-07-02)
34-
* Emscripten 3.1.16-git (e026c0e22a986d92695b2563a1e8ef140b5d8a87)
36+
* rustc 1.65.0-nightly (8c6ce6b91 2022-09-02)
37+
* Emscripten 3.1.21-git (3ce1f726b449fd1b90803a6150a881fc8dc711da)
3538

3639

3740
### Installing and configuring Emscripten
@@ -75,8 +78,8 @@ In your project's `config.toml`, add the following:
7578
[target.wasm32-unknown-emscripten]
7679
rustflags = [
7780
"-Clink-arg=-sSIDE_MODULE=2", # build a side module that Godot can load
78-
"-Cpanic=abort", # panic unwinding is currently broken without -sWASM_BIGINT, see below
79-
#"-Clink-arg=-sWASM_BIGINT", # alternative to panic=abort, requires building godot with -sWASM_BIGINT also
81+
"-Zlink-native-libraries=no", # workaround for a wasm-ld error during linking
82+
"-Cpanic=abort", # workaround for a runtime error related to dyncalls
8083
]
8184
```
8285

@@ -91,11 +94,21 @@ cargo +nightly build --target=wasm32-unknown-emscripten --release
9194

9295
The result is a `.wasm` file that you add in your `GDNativeLibrary` properties under `entry/HTML5.wasm32`, just like you would add a `.so` or a `.dll` for Linux or Windows.
9396

97+
### Errors you might encounter
98+
99+
Compile time:
100+
* `failed to run custom build command for gdnative-sys v0.10.1`, `fatal error: 'wchar.h' file not found`: Emscripten cache not populated, build Godot export template first
101+
* `undefined symbol: __cxa_is_pointer_type`: You need to build with `-Clink-arg=-sSIDE_MODULE=2`
102+
103+
Runtime:
104+
* `indirect call signature mismatch`: Possibly due to Emscripten version mismatch between Godot and Rust
105+
* `need the dylink section to be first`: Same as above
106+
* `WebAssembly.Module(): Compiling function #1 failed: invalid local index`: You need to build with `-Cpanic=abort`
107+
94108
### Further reading
95109

96-
In the future, some/all of this will probably not be needed, for more info see:
110+
In the future, some of this will probably not be needed, for more info see:
97111
* [Tracking issue for godot-rust wasm support](https://github.com/godot-rust/godot-rust/issues/647)
112+
* [Rust](https://github.com/rust-lang/rust/issues/98155) and [Emscripten](https://github.com/rust-lang/rust/pull/98303#issuecomment-1162172132) issues that explain the need for `-Zlink-native-libraries=no`
113+
* [Emscripten PR that should have obsoleted `-Cpanic=abort`](https://github.com/emscripten-core/emscripten/pull/17328)
98114
* [Rust PR that would obsolete `-Clink-arg=-sSIDE_MODULE=2`](https://github.com/rust-lang/rust/pull/98358)
99-
* [Godot PR that updates Emscripten version for Godot 3.x](https://github.com/godotengine/godot/pull/61989)
100-
* [Godot PR that would obsolete `-Cpanic=abort` in favor of `-sWASM_BIGINT`](https://github.com/godotengine/godot/pull/62397)
101-
* [Emscripten PR that would obsolete `-Cpanic=abort` without requiring `-sWASM_BIGINT`](https://github.com/emscripten-core/emscripten/pull/17328)

0 commit comments

Comments
 (0)