rust-sdl-canvas-wasm
Minimal example of animating the HTML5 canvas from Rust using SDL through WebAssembly. https://thibaultlemaire.gitlab.io/rust-sdl-canvas-wasm/
Summary
| Latest Version | Unknown |
|---|---|
| License | Unknown |
| CI Status | Failing |
| Stars | 2 |
| Forks | 0 |
| Open Issues | 0 |
| Last Commit | 2023-06-13 |
| Downloads | 0 |
| Last Indexed | 2026-09-06 06:05 |
Tags
Installation
nimble install rust-sdl-canvas-wasm
choosenim install rust-sdl-canvas-wasm
git clone https://gitlab.com/ThibaultLemaire/rust-sdl-canvas-wasm
OS Compatibility
| Platform | Linux | macOS | Windows | FreeBSD | OpenBSD | NetBSD | Android | iOS | WASM | Embedded |
|---|---|---|---|---|---|---|---|---|---|---|
| rust-sdl-canvas-wasm | - | - | - | - | - | - | - | - | ✓ | - |
Source
| Repository | https://gitlab.com/ThibaultLemaire/rust-sdl-canvas-wasm |
|---|---|
| Homepage | https://gitlab.com/ThibaultLemaire/rust-sdl-canvas-wasm |
| Registry Source | gitlab |
README
Rust SDL2 Canvas Webassembly
A minimal example of animating an HTML5 canvas from Rust using SDL2 through WebAssembly.
(If you want more sophisticated drawing than SDL can offer (e.g. 3D), then you should probably start here instead.)
Recommended Instructions
-
Install Nix. Nix is a functional package manager that simplifies the process of setting up a project environment.
-
Clone this repo:
``` sh git clone https://gitlab.com/ThibaultLemaire/rust-sdl-canvas-wasm
cd rust-sdl-canvas-wasm ```
-
Start a Nix shell. This will give you an environment with the required dependencies.
sh nix-shell -
Install the appropriate toolchain.
sh rustup override set 1.39.0 rustup target add wasm32-unknown-emscripten -
Install
cargo-web. This cargo sub-command makes it easy to build wasm projects with Rust.sh cargo install cargo-web -
Build and run the project.
sh cargo web start --use-system-emscripten -
Open the URL that was output by this last command (Usually localhost on port 8000). You should see a moving blue square in a red square:
Credits
This is a port of Tim Hutton's C++ example, sdl-canvas-wasm, to the Rust programming language. In my opinion, his work has the perfect balance of simplicity vs demonstrativity. I thought the Rust community could use an equivalent.
I also took some inspiration from the work of Valerio Santinelli and bokuweb for the use of cargo-web and the emscripten boilerplate code.
Here are their respective projects:
MIT license
Copyright (c) 2018 Tim Hutton
Copyright (c) 2019-2020 Thibault Lemaire
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.