pub struct WasmCompiler;Expand description
WASM module compiler.
Compiles generated Rust source code to .wasm binaries by creating a
temporary Cargo project and invoking cargo build.
§Examples
use converge_tool::compile::{WasmCompiler, CompileConfig};
let source = "/* generated Rust source */";
let wasm_bytes = WasmCompiler::compile(source, &CompileConfig::default())?;
assert_eq!(&wasm_bytes[0..4], b"\0asm");Implementations§
Source§impl WasmCompiler
impl WasmCompiler
Sourcepub fn compile(
source: &str,
config: &CompileConfig,
) -> Result<Vec<u8>, CompileError>
pub fn compile( source: &str, config: &CompileConfig, ) -> Result<Vec<u8>, CompileError>
Compile Rust source code to WASM bytes.
Creates a temporary Cargo project, writes the source as lib.rs,
and runs cargo build --target <target> --release.
§Errors
Returns CompileError::MissingTarget if the WASM target is not installed.
Returns CompileError::BuildFailed if cargo compilation fails.
Sourcepub fn compile_truth_file(path: &Path) -> Result<CompiledModule, CompileError>
pub fn compile_truth_file(path: &Path) -> Result<CompiledModule, CompileError>
Compile a .truth file end-to-end: parse → codegen → compile → hash.
Reads the truth file, parses Gherkin scenarios, extracts predicates,
generates Rust source, and compiles to WASM bytes. Returns a
CompiledModule containing the .wasm bytes, manifest, source hash,
and module name.
Currently compiles the first compilable scenario (non-test, with a kind tag). Future versions may compile all scenarios into a multi-invariant module.
§Errors
Returns errors for any stage of the pipeline.
Sourcepub fn content_hash_wasm(bytes: &[u8]) -> String
pub fn content_hash_wasm(bytes: &[u8]) -> String
Compute SHA-256 content hash for WASM bytes (for ModuleId).