{"id":20895119,"url":"https://github.com/topheman/bevy-rust-wasm-experiments","last_synced_at":"2025-05-12T23:31:32.472Z","repository":{"id":142192655,"uuid":"575359700","full_name":"topheman/bevy-rust-wasm-experiments","owner":"topheman","description":"🦀 A small video game developed in Rust with Bevy framework targeting both desktop and WebAssembly (browser)","archived":false,"fork":false,"pushed_at":"2023-05-19T15:53:24.000Z","size":697,"stargazers_count":39,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T13:37:10.534Z","etag":null,"topics":["bevy","rust","wasm","webassembly"],"latest_commit_sha":null,"homepage":"https://bevy-rust-wasm-experiments.vercel.app","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/topheman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-07T10:37:38.000Z","updated_at":"2024-11-29T09:05:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"ed461cf6-f82c-4a86-8a77-6bc71cf5b4a7","html_url":"https://github.com/topheman/bevy-rust-wasm-experiments","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topheman%2Fbevy-rust-wasm-experiments","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topheman%2Fbevy-rust-wasm-experiments/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topheman%2Fbevy-rust-wasm-experiments/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topheman%2Fbevy-rust-wasm-experiments/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/topheman","download_url":"https://codeload.github.com/topheman/bevy-rust-wasm-experiments/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253840415,"owners_count":21972477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bevy","rust","wasm","webassembly"],"created_at":"2024-11-18T10:25:01.445Z","updated_at":"2025-05-12T23:31:32.456Z","avatar_url":"https://github.com/topheman.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bevy-rust-wasm-experiments\n\n[![Demo](https://img.shields.io/badge/demo-online-blue.svg)](https://bevy-rust-wasm-experiments.vercel.app/)\n\n\u003cp style=\"text-align:center;\"\u003e\u003ca href=\"https://bevy-rust-wasm-experiments.vercel.app/\"\u003e\u003cimg src=\"www/public/bevy-rust-wasm-experiments-logo-445x380.png\" /\u003e\u003c/a\u003e\u003c/p\u003e\n\nThis project is a proof of concept that aims to demonstrate how to code a video game in rust that compiles both to:\n\n- a binary executable on OS desktop such as MacOS, Linux or Windows ...\n- a web site, that you could access with any browser (via WebAssembly)\n\nThe web version is shipping with some features in addition, such as accelerometer support (if you load it on your smartphone 📱), which should integrate seemlessly into the rust source code.\n\n## Previous work\n\nIn the last five years I've done a few projects involving rust and WebAssembly:\n\n- [topheman/webassembly-wasi-experiments](https://github.com/topheman/webassembly-wasi-experiments): Discover WebAssembly System Interface (WASI) with C/Rust targetting NodeJS, python, Wasmtime and the browser\n- [topheman/rust-wasm-experiments](https://github.com/topheman/rust-wasm-experiments): Discover how to use Rust to generate WebAssembly, called by JavaScript\n  - [📺🇫🇷 Utiliser WebAssembly, dès aujourd'hui - ParisJS #86](https://www.youtube.com/watch?v=F3wOfWIFzVc\u0026list=PLWhFHBFsRtquZ6hVXVjXmJ-l51ZXuSBtb)\n\nTen years ago, I made a small video game in JavaScript that you can play on your smartphone's browser: [topheman/bombs](https://topheman.github.io/bombs/) which inspired this current project.\n\n## Summary\n\n- [Contributing](#contributing)\n  - [Prerequisites](#prerequisites)\n  - [Setup](#setup)\n  - [Folder organization](#folder-organization)\n  - [Development](#development)\n    - [Desktop](#desktop)\n    - [WebAssembly](#webassembly)\n    - [Web part](#web-part)\n  - [Production](#production)\n- [CI/CD](#cicd)\n- [https](#https)\n- [Assets](#assets)\n- [Resources](#resources)\n\n## Contributing\n\nA [Makefile](Makefile) is available with a list of tasks.\n\n### Prerequisites\n\n- node@\u003e=18\n- rust@\u003e=1.67.0\n\n### Setup\n\n```sh\n# If you haven't yet, wasm support to your rust installation\nrustup target install wasm32-unknown-unknown\n\n# Mandatory crates\ncargo install wasm-bindgen-cli@0.2.86 # cli for wasm-bindgen implementation shipped in Cargo.toml\ncargo install wasm-opt # cli that optimizes wasm payload\n\n# Optional crates for development\ncargo install wasm-server-runner # https://github.com/jakobhellermann/wasm-server-runner\ncargo install cargo-watch # https://github.com/watchexec/cargo-watch\n```\n\n### Folder organization\n\n```\n├── assets (contains the images/fonts used in the app)\n├── dev.html (custom endpoint used for when running with wasm-server-runner)\n├── src (source code of the rust application)\n├── target\n└── www (source code of the web part)\n    ├── dist\n    ├── global.js (bindings exposed to wasm-bindgen, used by both dev.html and www/index.html)\n    ├── index.html (endpoint used in the final web server)\n    ├── public\n    │   ├── assets -\u003e ../../assets (symlink to the asset dir so that they will be picked by the bundler and expose to the browser)\n```\n\n### Development\n\n#### Desktop\n\n```sh\ncargo run\n# `make desktop-dev` is an alias for 👆\n```\n\nYou can compile in watch mode, thanks to [cargo-watch](https://github.com/watchexec/cargo-watch) and [bevy dynamic linking feature](https://bevy-cheatbook.github.io/setup/bevy-config.html#dynamic-linking):\n\n```sh\ncargo watch -q -c -x 'run --features bevy/dynamic'\n# `make desktop-dev-watch` is an alias for 👆\n```\n\n#### WebAssembly\n\nThe following will compile the project in WebAssembly and make it available at http://localhost:3000/dev.html\n\n```sh\nWASM_SERVER_RUNNER_ADDRESS=0.0.0.0:3000 cargo run --target wasm32-unknown-unknown\n# `make wasm-dev` is an alias for 👆\n```\n\n#### Web part\n\nWhen you need to customize the html/js/css that will end up on the server, you will code in `www`.\n\nThe following code will compile the WebAssembly version, generate wasm glue code, build the www artefact and launch a server on http://localhost:3000\n\n```sh\n# compile WebAssembly version + generate wasm glue code + build the www artefact + launch a server\nmake www-build \u0026\u0026 make www-preview\n```\n\nYou can launch a dev server for www:\n\n```sh\nmake www-dev\n```\n\n### Production\n\nSame as `make www-build`, but [wasm-opt](https://lib.rs/crates/wasm-opt) is run on the wasm payload to make it lighter.\n\n```sh\nmake www-build-opt\n```\n\n## CI/CD\n\nI'm using github-actions for the CI and I deploy to vercel from there (can't use vercel for the whole pipeline since we need the rust toolchain with WebAssembly).\n\nOn each pull request:\n\n1. the project is compiled from rust to WebAssembly\n2. the WebAssembly output goes through `wasm-bindgen` which generates the glue code between wasm and JavaScript (it also goes through `wasm-opt` to optimize the size of the wasm file)\n2. the output from the previous step is fed up to the vite pipeline which generates a static site\n4. finally, the website is automatically published to vercel\n5. a comment is left on the PR with the generated url of the deployment\n\n## https\n\nAcceleremeter only works on secure origins, so when you will try to access the app on your smartphone via your local ip (like 192.168.1.1), it won't work, since the domain will be recognized as unsecure.\n\nYou'll need to tunnel the app with a utility like [localhost.run](https://localhost.run/) or [ngrok](https://ngrok.com) that will open an ssh tunnel and forward traffic on https. Please run the following one time:\n\n```sh\nmake forward # with ngrok\nmake forward-fallback # with localhost.run\n```\n\nThe public https temporary address will be outputted on your terminal (keep in mind you won't access your website through your local network but through the internet, which can take longer - use that only to test accelerometer on mobile devices).\n\n## Assets\n\n- `assets/ball-steel-no-shadow.png`: https://github.com/topheman/gopher-ball/tree/master/assets/imgs\n- `assets/impactMetal_heavy_004.ogg`: https://www.kenney.nl/assets/impact-sounds\n- `assets/impactPlate_medium_000.ogg`: https://www.kenney.nl/assets/impact-sounds\n- `assets/ThaleahFat.ttf`: https://tinyworlds.itch.io/free-pixel-font-thaleah\n- `assets/m6x11.ttf`: https://managore.itch.io/m6x11\n\n## Resources\n\n- [rust book](https://doc.rust-lang.org/stable/book/)\n- [bevy cheatbook](https://bevy-cheatbook.github.io)\n- [Ball.rs](https://github.com/topheman/rust-wasm-experiments/blob/master/crate/src/ball.rs) / [Ball.js](https://github.com/topheman/Ball.js)\n- [jeremychone-channel/rust-invaders](https://github.com/jeremychone-channel/rust-invaders)\n- [Bevy Tutorial: Start Menu, Bevy UI, and NPCs](https://www.youtube.com/watch?v=qbeu0Mw1HLY\u0026list=PLT_D88-MTFOOh_S9YifHfo6KETvEmRmYh\u0026index=7)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftopheman%2Fbevy-rust-wasm-experiments","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftopheman%2Fbevy-rust-wasm-experiments","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftopheman%2Fbevy-rust-wasm-experiments/lists"}