This project is a raycaster written in Rust WASM. See it live at https://xtrinch.github.io/wasm-raycaster/. It's also paralellized with rayon (uses a nightly Rust build).
Before you begin, ensure you have the following installed:
.
├── packages/
│ ├── app/ # Frontend application
│ └── wasm/ # Generated WASM output
├── src/ # Rust source code
│ └── lib.rs # Rust WASM module source
├── package.json # Workspace configuration
└── pnpm-workspace.yaml # PNPM workspace configuration
The project uses pnpm workspaces to organize the codebase into two main parts:
- Rust WASM module (root/src)
- Application (packages/app)
- Clone the repository:
git clone <repository-url>
cd <project-directory>- Install dependencies:
pnpm install- Build the project:
pnpm run buildThis command executes the following steps:
build:wasm: Compiles Rust code to WebAssemblybuild:app: Builds the application
- Run the script with node:
pnpm run startThe Rust code in src/lib.rs contains the WebAssembly module implementation. When you run build:wasm, wasm-pack compiles this code and generates:
- WebAssembly binary (
.wasm) - JavaScript bindings
- TypeScript type definitions
These files are output to packages/app/wasm/.
The frontend application in packages/app demonstrates:
- How to import and initialize the WASM module
- Integration with the TypeScript library
- Usage of WASM functions in a web application
pnpm run build: Build all componentspnpm run build:wasm: Build only the WASM modulepnpm run build:app: Build only the frontend applicationpnpm run start: Start the development server
pnpm run dev: Run development server, observe output athttp://localhost:5173