Skip to content

[#446 Tier 1 #5 follow-up] Zig FFI implementation for wasm_export_call dispatch #497

Description

@hyperpolymath

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 a hpm-wasm-export-rsr sibling — owner's choice) exporting an extern "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 the env.wasm_export_call import 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.adoc row for wasm_export_call updated to flag the Zig host as available.

Refs

This is the FFI implementation half; the Idris2-ABI proof-carrier doc is a separate follow-up under the "Idris2 = ABIs" directive.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bindingsABI, FFI, WASM, and cross-language interop surfacestier-1AS bindings top-50 Tier 1 (idaptik blockers)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions