1# jgenesis-web 2 3Minimal web frontend that compiles to WASM and runs in the browser. Requires a browser with [WebGPU](https://webgpu.org) support. 4 5## Dependencies 6 7### Rust Nightly 8 9The web frontend's audio implementation requires sharing memory between the main thread and the 10audio worklet thread, which is not supported in stable Rust when compiling to WASM. Even in nightly, 11this requires rebuilding the standard library with atomics support. 12 13Assuming you already have the basic Rust toolchain installed: 14``` 15rustup toolchain add nightly --component rust-src 16``` 17 18### wasm-pack 19 20wasm-pack is used to build and package the WASM/JS files. Here it's used mainly just as a convenience 21wrapper around wasm-bindgen-cli and wasm-opt. 22 23To install: 24``` 25cargo install wasm-pack 26``` 27 28## Build 29 30The following incantation builds the required WASM/JS files into the `pkg` directory: 31 32``` 33rustup run nightly \ 34wasm-pack build --target web . -- -Z build-std=panic_abort,std 35``` 36 37The provided `build.sh` script runs this command for you: 38``` 39./build.sh 40``` 41 42For development, the `--dev` flag can be used to disable LTOs and wasm-opt, which gives 43significantly shorter compile times at the cost of larger file size and worse performance: 44``` 45./build.sh --dev 46``` 47 48## Run 49 50Copy `index.html`, the `js` directory, and the `pkg` directory into the webserver of your choice. 51 52The webserver must set the following HTTP headers on every request or the application may not work 53properly in some browsers: 54``` 55Cross-Origin-Opener-Policy: same-origin 56Cross-Origin-Embedder-Policy: require-corp 57``` 58 59The provided `webserver.py` runs a local webserver that automatically sets these headers on every request. 60 61``` 62# Binds to localhost:8080 by default 63./webserver.py 64``` 65``` 66# Binds to a specific address:port 67./webserver.py localhost:9000 68```