Skip to content

Commit 1112ad9

Browse files
committed
Update HTML5 export guide to reflect current state of affairs
1 parent c1e206f commit 1112ad9

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

src/exporting/html5.md

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,41 @@
22

33
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.
44

5-
## General considerations
5+
## What you need (to know)
66

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:
915

1016
```bash
1117
emcc -v
1218
rustc --version --verbose
1319
```
1420

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+
1523
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.
1624

1725
## Godot 3.4.4
1826

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

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.
2331

2432
Confirmed working versions are:
25-
* rustc 1.63.0-nightly (dc80ca78b 2022-06-21)
26-
* Emscripten 3.1.15-git (4100960b42619b28f19baf4254d5db2097234b32)
33+
* rustc 1.64.0-nightly (f2d93935f 2022-07-02)
34+
* Emscripten 3.1.16-git (e026c0e22a986d92695b2563a1e8ef140b5d8a87)
2735

2836

29-
### Getting Emscripten
37+
### Installing and configuring Emscripten
3038

31-
We will be using Emscripten tip-of-tree:
39+
We will be using the most recent git version of Emscripten (tip-of-tree):
3240

3341
```bash
3442
# Get the emsdk repo
@@ -57,7 +65,7 @@ scons platform=javascript tools=no gdnative_enabled=yes target=release
5765
mv bin/godot.javascript.opt.gdnative.zip bin/webassembly_gdnative_release.zip
5866
```
5967

60-
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".
6169

6270
### Building your Rust code
6371

@@ -67,7 +75,6 @@ In your project's `config.toml`, add the following:
6775
[target.wasm32-unknown-emscripten]
6876
rustflags = [
6977
"-Clink-arg=-sSIDE_MODULE=2", # build a side module that Godot can load
70-
"-Crelocation-model=pic", # needed to prevent linker errors
7178
"-Cpanic=abort", # panic unwinding is currently broken without -sWASM_BIGINT, see below
7279
#"-Clink-arg=-sWASM_BIGINT", # alternative to panic=abort, requires building godot with -sWASM_BIGINT also
7380
]
@@ -79,14 +86,16 @@ Build like this:
7986
source "/path/to/emsdk-portable/emsdk_env.sh"
8087
export C_INCLUDE_PATH=$EMSDK/upstream/emscripten/cache/sysroot/include
8188

82-
cargo +nightly build --target=wasm32-unknown-emscripten --release -Zbuild-std=core,std,alloc,panic_abort
89+
cargo +nightly build --target=wasm32-unknown-emscripten --release
8390
```
8491

92+
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+
8594
### Further reading
8695

8796
In the future, some/all of this will probably not be needed, for more info see:
8897
* [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

Comments
 (0)