You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/exporting/html5.md
+27-14Lines changed: 27 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,8 @@ Exporting to HTML5 works just like exporting to other platforms, however there a
5
5
## What you need (to know)
6
6
7
7
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:
10
10
* install a specific version of Emscripten
11
11
*[build the HTML5 export template yourself](https://docs.godotengine.org/en/stable/development/compiling/compiling_for_web.html)
12
12
* use a specific version of Rust
@@ -18,20 +18,23 @@ emcc -v
18
18
rustc --version --verbose
19
19
```
20
20
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.
22
24
23
25
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.
24
26
25
-
## Godot 3.4.4
27
+
## Godot 3.5
26
28
27
29
**Disclaimer**: _Currently, the following steps are only tested and confirmed to work on Linux._
28
30
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.
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.
93
96
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
+
94
108
### Further reading
95
109
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:
97
111
*[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)
98
114
*[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