Repository navigation
[#446 Tier 1 #5 follow-up] Zig FFI implementation for wasm_export_call dispatch #497
Description
Context
Closed #455 (the WASM-exports calling pattern kickoff) shipped via PR #467 with the Deno-ESM backend lowering: wasm_export_call(exports, name, args) + WasmValue opaque type + JS-side dispatch (__as_wasm_export_call).
Per the owner's Option-B scope breakdown, the Zig-side dispatch was deferred to a follow-up:
Zig FFI: implement the call dispatch (marshal args, find export by name, call, marshal return)
This issue tracks that.
Scope
The Zig-side counterpart to the Deno-ESM lowering. When wasm_export_call is invoked from an AffineScript program targeting the linear-memory WebAssembly backend (i.e. anywhere outside the Deno-ESM host), the host must supply a wasm_export_call symbol under the env import — and that symbol should be implementable in a canonical Zig crate so any embedder can pick it up.
What to ship
- A canonical Zig crate (in this repo's
tools/, or scaffolded as ahpm-wasm-export-rsrsibling — owner's choice) exporting anextern "C" fn wasm_export_call(exports_handle: *anyopaque, name_ptr: [*]const u8, name_len: usize, args_ptr: [*]const WasmValueRepr, args_len: usize) -> WasmValueRepr(or matching ABI). - Marshalling:
WasmValueRepr↔ the tagged scalar (i32/i64/f32/f64). - Export lookup: by name through a
WebAssembly.Instance.exports-like handle. - Recipe doc (or row in the existing
docs/specs/zig-ffi-patterns.adoc) showing how to wire this Zig dispatcher into a wasm-host configuration.
Acceptance
- Zig source compiles to a freestanding
.wasm(or a host-linkable.so) that satisfies theenv.wasm_export_callimport contract. - Round-trip exercised by a smoke-test (see [#446 Tier 1 #5] WASM-exports calling pattern (recommended kickoff) #455 follow-up "Zig-FFI smoke-test" sub-issue).
STDLIB-EXTERN-AUDIT.adocrow forwasm_export_callupdated to flag the Zig host as available.
Refs
- Closed kickoff: [#446 Tier 1 #5] WASM-exports calling pattern (recommended kickoff) #455
- Shipped surface: PR feat(stdlib): WasmValue + wasm_export_call typed wasm-exports binding (closes #455) #467 (Deno-ESM lowering + Deno.affine externs)
- Companion doc: PR Roadmap tracking + Zig-FFI doc (#19) + hex/base64 encoding (#25) + Int-division codegen fix (#478) #474 —
docs/specs/zig-ffi-patterns.adoc(general pattern doc) - Umbrella: [campaign] AffineScript top-50 framework bindings roadmap (UMBRELLA) #446 (Tier 1 — idaptik blockers)
- Tier sub-issue: [#446 STEP 2] Tier 1 — idaptik blockers (10 bindings) #450
- Estate directive: "Zig = APIs + FFIs"
This is the FFI implementation half; the Idris2-ABI proof-carrier doc is a separate follow-up under the "Idris2 = ABIs" directive.
Activity
security: standardize secret scanning on TruffleHog (+ ADR-023 draft …