#!/usr/bin/env python3 # file: scripts/build_reflex_tauri_wasm.py # version: 2 """Build the dedicated Reflex WASM adapter for the Vite/Tauri frontend.""" from __future__ import annotations import pathlib import subprocess import sys def main() -> int: """Build the WASM crate and generate browser bindings inside the Tauri frontend.""" root = pathlib.Path(__file__).resolve().parent.parent target_dir = root.parent / "builds" / "sasedev-games" / "target" wasm_path = target_dir / "wasm32-unknown-unknown" / "debug" / "game_reflex_poc_wasm.wasm" output_dir = root / "crates" / "apps" / "game-reflex-poc-tauri" / "frontend" / "wasm" build = subprocess.run( ["cargo", "build", "-p", "game-reflex-poc-wasm", "--target", "wasm32-unknown-unknown"], cwd=root, check=False, ) if build.returncode != 0: return build.returncode if not wasm_path.is_file(): print(f"WASM artifact not found: {wasm_path}", file=sys.stderr) return 2 output_dir.mkdir(parents=True, exist_ok=True) bindings = subprocess.run( [ "wasm-bindgen", str(wasm_path), "--target", "web", "--out-dir", str(output_dir), "--out-name", "game_reflex_poc_wasm", ], cwd=root, check=False, ) if bindings.returncode != 0: return bindings.returncode print(f"Reflex WASM bindings generated in {output_dir}") return 0 if __name__ == "__main__": raise SystemExit(main())