Skip to main content

hypen_engine/wasm/
mod.rs

1//! WASM/WASI interface for Hypen Engine
2//!
3//! This module provides bindings for running the engine in WASM environments.
4//! Two interface types are available:
5//!
6//! ## JavaScript Runtimes (`js` feature)
7//!
8//! For Node.js, Bun, Deno, and browsers. Uses wasm-bindgen for seamless JavaScript
9//! interop with native JS types and callbacks.
10//!
11//! ```toml
12//! [dependencies]
13//! hypen-engine = { features = ["js"] }
14//! ```
15//!
16//! ## WASI Runtimes (`wasi` feature)
17//!
18//! For Go (wazero, wasmtime-go), Python (wasmtime, wasmer), Rust, and other
19//! languages that embed WASM via WASI. Uses a C-compatible FFI with JSON
20//! serialization for data exchange.
21//!
22//! ```toml
23//! [dependencies]
24//! hypen-engine = { features = ["wasi"] }
25//! ```
26//!
27//! ## Feature Flags
28//!
29//! - `js` - Enable JavaScript bindings via wasm-bindgen (default for wasm-pack builds)
30//! - `wasi` - Enable WASI-compatible C FFI bindings
31//!
32//! These features are mutually exclusive. If both are enabled, `js` takes precedence.
33
34// Shared FFI utilities (available on all platforms for testing)
35pub mod ffi;
36
37// JavaScript bindings (wasm-bindgen)
38#[cfg(all(target_arch = "wasm32", feature = "js"))]
39pub mod js;
40
41// Re-export JS types at module root for backward compatibility
42#[cfg(all(target_arch = "wasm32", feature = "js"))]
43pub use js::*;
44
45// WASI bindings (C FFI)
46#[cfg(all(target_arch = "wasm32", feature = "wasi", not(feature = "js")))]
47pub mod wasi;
48
49// Re-export WASI functions at module root
50#[cfg(all(target_arch = "wasm32", feature = "wasi", not(feature = "js")))]
51pub use wasi::*;
52
53// If neither feature is enabled but we're on wasm32, provide a helpful error
54#[cfg(all(target_arch = "wasm32", not(feature = "js"), not(feature = "wasi")))]
55compile_error!(
56    "Either 'js' or 'wasi' feature must be enabled for WASM builds. \
57     Use --features js for JavaScript runtimes or --features wasi for WASI runtimes."
58);