https://github.com/permutationlock/raylib_wasm_rs_example
A simple example showing how to make a Rust Raylib application cross platform with the web using emscripten.
https://github.com/permutationlock/raylib_wasm_rs_example
emscripten raylib rust wasm
Last synced: about 2 months ago
JSON representation
A simple example showing how to make a Rust Raylib application cross platform with the web using emscripten.
- Host: GitHub
- URL: https://github.com/permutationlock/raylib_wasm_rs_example
- Owner: permutationlock
- License: mit
- Created: 2022-11-27T14:44:24.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-02T11:48:43.000Z (over 2 years ago)
- Last Synced: 2025-01-14T15:42:03.091Z (4 months ago)
- Topics: emscripten, raylib, rust, wasm
- Language: Rust
- Homepage:
- Size: 437 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE.MIT
Awesome Lists containing this project
README
# Cross-platform Rust apps using Raylib and Emscripten
The goal of this repository is to create a simple graphical Rust
application that can be compiled to target native platforms and web
browsers.To cross-compile to wasm I use a
[Raylib](https://github.com/raysan5/raylib) library file compiled
with [emcc](https://emscripten.org), combined with a Rust wrapper
around the Raylib functionality needed in the project.A custom Cargo config file is needed to pass emcc
build flags via the EMCC_CFLAGS environment variable.Finally, in order to get applications to fill the browser window and
resize with it, we need to export an on_resize function from Rust to
JavaScript. This function is set as an event listener for the
Browser's window resize event.## Dependencies
In order to compile to native Unix and/or Windows systems it is
assumed that you have the
[Raylib](https://github.com/raysan5/raylib) C library installed.
The web server provided to test wasm builds requires
[Go](https://go.dev).## Building
Building native applications should work as normal:
```console
cargo build
```
To build for web:
```console
cargo build --target wasm32-unknown-emscripten
```
You can then test your web builds using the included Go server and shell
scripts.