Skip to main content

Module wasm_builder

Module wasm_builder 

Source
Expand description

WebAssembly component builder with multi-language support

This module provides functionality to build WebAssembly components from various source languages, with support for both WASI Preview 1 and Preview 2 (component model) targets.

§Supported Languages

  • Rust: cargo build --target wasm32-wasip1 or cargo component build
  • Go: TinyGo compiler with WASI target
  • Python: componentize-py for component model
  • TypeScript/JavaScript: jco/componentize-js
  • AssemblyScript: asc compiler
  • C: Clang with WASI SDK
  • Zig: Native WASI support

§Usage

use std::path::Path;
use zlayer_builder::wasm_builder::{build_wasm, WasmBuildConfig, WasiTarget};

let config = WasmBuildConfig {
    language: None,  // Auto-detect
    target: WasiTarget::Preview2,
    optimize: true,
    ..Default::default()
};

let result = build_wasm(Path::new("./my-plugin"), config).await?;
println!("Built {} WASM at {}", result.language, result.wasm_path.display());

Structs§

WasmBuildConfig
Configuration for building a WASM component
WasmBuildResult
Result of a successful WASM build

Enums§

WasiTarget
WASI target version
WasmBuildError
Error types for WASM build operations
WasmLanguage
Supported source languages for WASM compilation

Functions§

build_wasm
Build a WASM component from source
detect_language
Detect the source language from files in the given directory
get_build_command
Get the build command for a specific language and target
get_build_command_with_config
Get the build command with full config support (world, features, etc.)
optimize_wasm
Optimize a WASM binary using wasm-opt.

Type Aliases§

Result
Result type for WASM build operations