silk.wasm.bindgen.
Programmable build-graph integration for auto-generated core WebAssembly
(wasm32-unknown-unknown) TypeScript and Effect 4.x bindings.
When to use#
Call WasmBindings.prepare from src/tasks.silk to turn an ordinary Silk Compilation
into:
an analysis-only
emit = "interface"compilation (interface.json),a cached glue generator step (
abi.json,__silk_wasm_glue.silk) keyed only on the semantic ABI +TracingMode,a forked
standaloneWASM compilation whose root is the generated glue, anda parallel TypeScript/Effect code-generation step (
_core.ts,index.ts, and optionallyeffect.ts) that does not depend on the.wasmbinary.
Details#
WasmBindings.prepare composes only standard Compilation and Run steps, so tasks.silk
remains runner-free and silk plan never triggers WASM compilation or codegen.
Import as WasmBindings with import silk.wasm.bindgen { WasmBindings }.
Public declarations: 6.
BindingsMode#
pub enum BindingsModeWhich TypeScript / Effect facades to generate.
Ts#
TsPlain TypeScript only (_core.ts, index.ts).
Effect#
EffectEffect 4.x service/layer facade only (_core.ts, index.ts).
Both#
BothBoth Plain TypeScript (index.ts) and Effect 4.x (effect.ts) sharing one _core.ts.
ErrorStyle#
pub enum ErrorStyleHow declared Silk ! E errors surface in the Plain TypeScript facade.
Throw#
ThrowThrow typed Error subclasses (default).
Result#
ResultReturn discriminated { readonly ok: true; readonly value: A } | { readonly ok: false; readonly error: E }.
TracingMode#
pub enum TracingModeBidirectional OpenTelemetry span-bridging mode.
Off#
OffEmit no HostTracer or silk_trace imports (zero-cost TRACE-001 elision).
Live#
LiveBridge Effect Tracer <-> Silk silk.trace spans live across the WASM boundary.
BindingsOptions#
pub struct BindingsOptionsConfiguration for WasmBindings.prepare.
Field exportModule#
pub exportModule: string<'static>Module to export (e.g. "api" or "src/api.silk"). Empty string selects the compilation root.
Field mode#
pub mode: BindingsModeWhich facade(s) to emit.
Field errorStyle#
pub errorStyle: ErrorStyleError reporting style for Plain TypeScript (Throw or Result).
Field tracing#
pub tracing: TracingModeOpenTelemetry span bridging mode (Off or Live).
Field serviceId#
pub serviceId: string<'static>Effect Context.Service identifier (e.g. "@my-app/wasm/SceneModule").
Field emitDocs#
pub emitDocs: boolWhether to emit TSDoc comments translated from Silk /// / //! docs.
Field includeSilkExamples#
pub includeSilkExamples: boolWhether to include Silk # Examples blocks fenced as ```silk in TSDoc.
Implementation Copy for BindingsOptions#
impl Copy for BindingsOptionsImplementation BindingsOptions#
impl BindingsOptionsAssociated function defaults#
pub fn defaults(exportModule: string<'static>) -> BindingsOptionsReturns default options for exportModule: BindingsMode.Both, ErrorStyle.Throw,
TracingMode.Off, emitDocs = true, includeSilkExamples = false.
PreparedBindings#
pub struct PreparedBindingsPrepared build-graph steps and artifacts produced by WasmBindings.prepare.
Field interfaceCompilation#
pub interfaceCompilation: CompilationPhase 1: analysis-only emit = "interface" compilation producing interface.json.
Field glueStep#
pub glueStep: StepHandlePhase 2a: cached glue generator step (abi.json, __silk_wasm_glue.silk).
Field tsStep#
pub tsStep: StepHandlePhase 2b: cached parallel TypeScript / Effect generator step (_core.ts, index.ts, effect.ts).
Field wasmCompilation#
pub wasmCompilation: CompilationPhase 3: forked standalone WASM compilation whose root is the generated glue.
Field interfacePath#
pub interfacePath: Deferred<Path>Deferred path to the emitted interface.json.
Field abiPath#
pub abiPath: Deferred<Path>Deferred path to the semantic abi.json.
Field gluePath#
pub gluePath: Deferred<Path>Deferred path to the generated __silk_wasm_glue.silk.
Field corePath#
pub corePath: Deferred<Path>Deferred path to the generated _core.ts.
Field indexPath#
pub indexPath: Deferred<Path>Deferred path to the generated index.ts.
Field effectPath#
pub effectPath: Option<Deferred<Path>>Deferred path to effect.ts when BindingsMode.Both was selected.
Field mode#
pub mode: BindingsModeSelected bindings mode.
WasmBindings#
pub struct WasmBindingsNamespace for preparing and registering WebAssembly bindings in a Silk build graph.
Implementation WasmBindings#
impl WasmBindingsAssociated function prepare#
pub effect fn prepare(user: Compilation, options: BindingsOptions) -> PreparedBindings
! StepFailure
? &mut Allocator | &mut FileSystem | &mut HostInputForks user into the two-phase WebAssembly bindings graph (interface -> glue + parallel TS ->
standalone WASM compilation) without executing any step yet.
Associated function addTo#
pub effect fn addTo(build: Build, prepared: PreparedBindings) -> Build
! BuildError
? &mut AllocatorAdds the WASM compilation and all generated TypeScript/Effect output files (_core.ts,
index.ts, and effect.ts when BindingsMode.Both) as roots of build.
Category: WebAssembly.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.