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
+25-16Lines changed: 25 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -2,33 +2,41 @@
2
2
3
3
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.
4
4
5
-
## General considerations
5
+
## What you need (to know)
6
6
7
-
The Godot HTML5 export templates are built with [Emscripten](https://emscripten.org/), so you need to build your code for the `wasm32-unknown-emscripten` target, `wasm32-unknown-unknown` will not work. Furthermore, you need to use a version of emscripten that is compatible with both your version of Rust and the version of emscripten used to build the export template.
8
-
In practice, this means you might have to [build the HTML5 export template yourself](https://docs.godotengine.org/en/stable/development/compiling/compiling_for_web.html) and/or use a specific version of Rust. You can check which versions you are using like this:
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:
10
+
* install a specific version of Emscripten
11
+
*[build the HTML5 export template yourself](https://docs.godotengine.org/en/stable/development/compiling/compiling_for_web.html)
12
+
* use a specific version of Rust
13
+
14
+
You can check which versions of Emscripten/Rust you are using like this:
9
15
10
16
```bash
11
17
emcc -v
12
18
rustc --version --verbose
13
19
```
14
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`.
22
+
15
23
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.
16
24
17
25
## Godot 3.4.4
18
26
19
27
**Disclaimer**: _Currently, the following steps are only tested and confirmed to work on Linux._
20
28
21
-
Godot 3.4.4's export template is built with a very old Emscripten version that doesn't play nice with Rust. We will have to build it ourselves with a more recent version.
22
-
We also need to build the `std` crate ourselves, so we will have to use a nightly Rust build.
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.
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".
68
+
Set the newly built export template as a [custom template](https://user-images.githubusercontent.com/2171264/175822720-bcd2f1ff-0a1d-4495-9f9c-892d42e9bdcd.png) in Godot and be sure to set the export type as GDNative. When exporting, uncheck "Export With Debug".
61
69
62
70
### Building your Rust code
63
71
@@ -67,7 +75,6 @@ In your project's `config.toml`, add the following:
67
75
[target.wasm32-unknown-emscripten]
68
76
rustflags = [
69
77
"-Clink-arg=-sSIDE_MODULE=2", # build a side module that Godot can load
70
-
"-Crelocation-model=pic", # needed to prevent linker errors
71
78
"-Cpanic=abort", # panic unwinding is currently broken without -sWASM_BIGINT, see below
72
79
#"-Clink-arg=-sWASM_BIGINT", # alternative to panic=abort, requires building godot with -sWASM_BIGINT also
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
+
85
94
### Further reading
86
95
87
96
In the future, some/all of this will probably not be needed, for more info see:
88
97
*[Tracking issue for godot-rust wasm support](https://github.com/godot-rust/godot-rust/issues/647)
89
-
*[Rust PR that obsoletes -Clink-arg=-sSIDE_MODULE=2](https://github.com/rust-lang/rust/pull/98358)
90
-
*[Rust PR that obsoletes -Crelocation-model=pic and -Zbuild-std](https://github.com/rust-lang/rust/pull/98149)
91
-
*[Godot PR that updates Emscripten version](https://github.com/godotengine/godot/pull/61989)
92
-
*[Godot PR that would obsolete -Cpanic=abort in favor of -sWASM_BIGINT](https://github.com/godotengine/godot/pull/62397)
98
+
*[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