Skip to content

feat: configure WebAssembly port and Javascript bindings#53

Open
Codekill33 wants to merge 2 commits into
MindFlowInteractive:mainfrom
Codekill33:main
Open

feat: configure WebAssembly port and Javascript bindings#53
Codekill33 wants to merge 2 commits into
MindFlowInteractive:mainfrom
Codekill33:main

Conversation

@Codekill33

Copy link
Copy Markdown

🎯 Goal
Configure the quest-rust project to compile to WebAssembly so the game can run in a browser environment without any server-side execution, expanding the reach to players without requiring a local Rust binary.

🛠️ Changes Made
Cargo Configuration: Updated Cargo.toml to support the cdylib target and added a conditional wasm feature flag.
Time API Abstractions: Replaced hardcoded std::time::Instant and SystemTime calls with a new src/time.rs abstraction.
Native builds continue to use the standard library.
WASM builds use web_sys::window().performance().now() and js_sys::Date::now() to avoid standard library panics.
Persistence Layer: Created src/persistence.rs to abstract file operations.
Native builds use std::fs.
WASM builds read from and write to the browser's localStorage via web-sys.
JavaScript API Bindings: Introduced src/wasm.rs that maintains a thread-safe global GameState and exposes a clean API using wasm-bindgen:
startSession(puzzle_id, puzzle_json)
submitAnswer(answer)
revealHint()
getScore()
endSession()
Frontend Demo: Added a minimal web/index.html interface to demonstrate loading the WASM module and driving a complete game session purely in the browser.
CI/CD Integration: Updated .github/workflows/ci.yml to automatically verify both the native cargo build and the wasm-pack build --target web compilation on every push.
✅ Verification
Validated native builds (cargo check and cargo test) to ensure regressions were not introduced for existing targets.
Validated the WebAssembly compilation (cargo check --target wasm32-unknown-unknown --features wasm) ensuring that the feature flags correctly gate incompatible standard library APIs.
🚀 How to Test
Build the WebAssembly package:
bash
wasm-pack build --target web --features wasm
Serve the web/ directory using any local web server (e.g., python -m http.server 8000).
Open http://localhost:8000 in your browser and click "Start Session" to test the integration!

closes #49

@Mkalbani

Copy link
Copy Markdown
Contributor

@Codekill33 Please resolve conflict!!

@Codekill33

Codekill33 commented Jul 23, 2026

Copy link
Copy Markdown
Author

Done! @Mkalbani

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate WASM Compilation Target for Browser Play

2 participants