Skip to main content

WasmCompiler

Struct WasmCompiler 

Source
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

Source

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.

Source

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.

Source

pub fn content_hash_wasm(bytes: &[u8]) -> String

Compute SHA-256 content hash for WASM bytes (for ModuleId).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more