Skip to content

Commit caa2216

Browse files
fix(snif): make Wasmex an optional, absence-guarded dependency (#46)
## Why `Burble.Coprocessor.SNIFBackend` referenced `Wasmex.start_link/1` and `Wasmex.call_function/3` directly while `:wasmex` is not even a declared dependency, and `available?/0` only checked the `.wasm` file existed. That produced a compile-time `Wasmex … is undefined` warning and the wrong runtime failure mode (rescued exception per call instead of clean degradation). ## What Applies the accepted `:quicer` / `Burble.Bolt.Quic` pattern from **ADR-0004** to `:wasmex`: * **`server/mix.exs`** — `:wasmex` documented in the existing optional-NIF block (Rust/wasmtime toolchain), commented like `quicer`/`elmdb`. * **`snif_backend.ex`** — `@wasmex Wasmex` alias; calls via `apply/3` so the compiler does not warn when absent; `available?/0` now also requires `Code.ensure_loaded?(@wasmex)` + `function_exported?`, so the existing `if available?()` guards transparently fall back to `ZigBackend`. * **CHANGELOG** — Fixed entry. ## Verification `mix compile --force --no-deps-check` → no `Wasmex` warning, no new unused/undefined warnings in `snif_backend.ex`. Pure consistency/bugfix; no behaviour change when Wasmex *is* present. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5286eea commit caa2216

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- `prim__registerCallback` made module-private (unsafe boundary, awaits idris2#3182)
2222
- `docs/developer/wsl-mirrored-networking.adoc` rewritten — NAT + host forwarder is the recommended WSL2 Bolt path; mirrored networking demoted to last-resort (Win11 24H2/Insider `Wsl/Service/E_UNEXPECTED` instability)
2323

24+
### Fixed
25+
- SNIF: `Burble.Coprocessor.SNIFBackend` no longer emits a compile warning for the optional `Wasmex` runtime and no longer mis-fails when it is absent — `Wasmex` is referenced via `apply/3` and `available?/0` now gates on it loadable, so kernels degrade cleanly to `ZigBackend` (mirrors the `:quicer` pattern, ADR-0004)
26+
2427
### Removed
2528
- TODO.md (superseded by CLAUDE-WORK.md — 0 TODOs remain in codebase)
2629

server/lib/burble/coprocessor/snif_backend.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,17 @@ defmodule Burble.Coprocessor.SNIFBackend do
157157
3. Verify configuration in `config/runtime.exs`
158158
4. Check `BURBLE_SNIF_PATH` environment variable
159159
"""
160+
# Optional WASM runtime. Referenced via apply/3 (see call_snif_module/3)
161+
# so the compiler does not warn when :wasmex is absent at build time —
162+
# mirrors the Burble.Bolt.Quic / :quicer pattern (ADR-0004). When absent,
163+
# available?/0 is false so every kernel transparently uses ZigBackend.
164+
@wasmex Wasmex
165+
160166
@impl true
161167
def available? do
162-
File.exists?(@snif_path)
168+
File.exists?(@snif_path) and
169+
Code.ensure_loaded?(@wasmex) and
170+
function_exported?(@wasmex, :start_link, 1)
163171
end
164172

165173
# ---------------------------------------------------------------------------
@@ -512,9 +520,9 @@ defmodule Burble.Coprocessor.SNIFBackend do
512520
# `{:error, reason}` so the caller can fall back gracefully.
513521
defp call_snif_module(path, function, args) do
514522
try do
515-
case Wasmex.start_link(%{bytes: File.read!(path)}) do
523+
case apply(@wasmex, :start_link, [%{bytes: File.read!(path)}]) do
516524
{:ok, pid} ->
517-
result = Wasmex.call_function(pid, function, args)
525+
result = apply(@wasmex, :call_function, [pid, function, args])
518526
GenServer.stop(pid, :normal)
519527
result
520528
{:error, reason} -> {:error, {:wasm_load_failed, reason}}

server/mix.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,14 @@ defmodule Burble.MixProject do
196196
# quicer — needs msquic (Microsoft QUIC C library)
197197
# elmdb — links liberl_interface which was dropped in OTP 23+
198198
# ex_lmdb — depends on elmdb
199+
# wasmex — Rust NIF (wasmtime); needs a Rust toolchain. SNIF
200+
# (Burble.Coprocessor.SNIFBackend) transparently degrades
201+
# to ZigBackend when absent — available?/0 gates on it.
199202
#
200203
# {:quicer, github: "emqx/quic", tag: "0.2.15", submodules: true, optional: true},
201204
# {:elmdb, "~> 0.4", optional: true},
202205
# {:ex_lmdb, "~> 0.1", optional: true},
206+
# {:wasmex, "~> 0.9", optional: true},
203207

204208
# Media plane — ex_webrtc SFU (audio-only, Opus)
205209
{:ex_webrtc, "~> 0.16"},

0 commit comments

Comments
 (0)