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:

  1. an analysis-only emit = "interface" compilation (interface.json),

  2. a cached glue generator step (abi.json, __silk_wasm_glue.silk) keyed only on the semantic ABI + TracingMode,

  3. a forked standalone WASM compilation whose root is the generated glue, and

  4. a parallel TypeScript/Effect code-generation step (_core.ts, index.ts, and optionally effect.ts) that does not depend on the .wasm binary.

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#

silk
pub enum BindingsMode

Which TypeScript / Effect facades to generate.

Ts#

silk
Ts

Plain TypeScript only (_core.ts, index.ts).

Effect#

silk
Effect

Effect 4.x service/layer facade only (_core.ts, index.ts).

Both#

silk
Both

Both Plain TypeScript (index.ts) and Effect 4.x (effect.ts) sharing one _core.ts.

ErrorStyle#

silk
pub enum ErrorStyle

How declared Silk ! E errors surface in the Plain TypeScript facade.

Throw#

silk
Throw

Throw typed Error subclasses (default).

Result#

silk
Result

Return discriminated { readonly ok: true; readonly value: A } | { readonly ok: false; readonly error: E }.

TracingMode#

silk
pub enum TracingMode

Bidirectional OpenTelemetry span-bridging mode.

Off#

silk
Off

Emit no HostTracer or silk_trace imports (zero-cost TRACE-001 elision).

Live#

silk
Live

Bridge Effect Tracer <-> Silk silk.trace spans live across the WASM boundary.

BindingsOptions#

silk
pub struct BindingsOptions

Configuration for WasmBindings.prepare.

Field exportModule#

silk
pub exportModule: string<'static>

Module to export (e.g. "api" or "src/api.silk"). Empty string selects the compilation root.

Field mode#

silk
pub mode: BindingsMode

Which facade(s) to emit.

Field errorStyle#

silk
pub errorStyle: ErrorStyle

Error reporting style for Plain TypeScript (Throw or Result).

Field tracing#

silk
pub tracing: TracingMode

OpenTelemetry span bridging mode (Off or Live).

Field serviceId#

silk
pub serviceId: string<'static>

Effect Context.Service identifier (e.g. "@my-app/wasm/SceneModule").

Field emitDocs#

silk
pub emitDocs: bool

Whether to emit TSDoc comments translated from Silk /// / //! docs.

Field includeSilkExamples#

silk
pub includeSilkExamples: bool

Whether to include Silk # Examples blocks fenced as ```silk in TSDoc.

Implementation Copy for BindingsOptions#

silk
impl Copy for BindingsOptions

Implementation BindingsOptions#

silk
impl BindingsOptions

Associated function defaults#

silk
pub fn defaults(exportModule: string<'static>) -> BindingsOptions

Returns default options for exportModule: BindingsMode.Both, ErrorStyle.Throw, TracingMode.Off, emitDocs = true, includeSilkExamples = false.

PreparedBindings#

silk
pub struct PreparedBindings

Prepared build-graph steps and artifacts produced by WasmBindings.prepare.

Field interfaceCompilation#

silk
pub interfaceCompilation: Compilation

Phase 1: analysis-only emit = "interface" compilation producing interface.json.

Field glueStep#

silk
pub glueStep: StepHandle

Phase 2a: cached glue generator step (abi.json, __silk_wasm_glue.silk).

Field tsStep#

silk
pub tsStep: StepHandle

Phase 2b: cached parallel TypeScript / Effect generator step (_core.ts, index.ts, effect.ts).

Field wasmCompilation#

silk
pub wasmCompilation: Compilation

Phase 3: forked standalone WASM compilation whose root is the generated glue.

Field interfacePath#

silk
pub interfacePath: Deferred<Path>

Deferred path to the emitted interface.json.

Field abiPath#

silk
pub abiPath: Deferred<Path>

Deferred path to the semantic abi.json.

Field gluePath#

silk
pub gluePath: Deferred<Path>

Deferred path to the generated __silk_wasm_glue.silk.

Field corePath#

silk
pub corePath: Deferred<Path>

Deferred path to the generated _core.ts.

Field indexPath#

silk
pub indexPath: Deferred<Path>

Deferred path to the generated index.ts.

Field effectPath#

silk
pub effectPath: Option<Deferred<Path>>

Deferred path to effect.ts when BindingsMode.Both was selected.

Field mode#

silk
pub mode: BindingsMode

Selected bindings mode.

WasmBindings#

silk
pub struct WasmBindings

Namespace for preparing and registering WebAssembly bindings in a Silk build graph.

Implementation WasmBindings#

silk
impl WasmBindings

Associated function prepare#

silk
pub effect fn prepare(user: Compilation, options: BindingsOptions) -> PreparedBindings
    ! StepFailure
    ? &mut Allocator | &mut FileSystem | &mut HostInput

Forks user into the two-phase WebAssembly bindings graph (interface -> glue + parallel TS -> standalone WASM compilation) without executing any step yet.

Associated function addTo#

silk
pub effect fn addTo(build: Build, prepared: PreparedBindings) -> Build
    ! BuildError
    ? &mut Allocator

Adds 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.

View the source of this page