Browser wasm: feature-detected module variants (relaxed-SIMD) + variant-aware runtime.js #25
No reviewers
Labels
No labels
bug
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Catcrafts/Crafter.Build!25
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "claude/issue-24"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds a general, feature-parameterized mechanism so a wasm32 browser target can ship multiple codegen variants and have the runtime serve each browser the most capable one it supports — without dropping engines that lack a feature. The motivating case is relaxed SIMD (Chrome 114+/Firefox 120+ enable it by default; Safari still flag-gates it as of mid-2026), but the plumbing is generic.
Both halves are owned in Crafter.Build, as the issue notes:
-msimd128was hardcoded for every wasm32 target (no way to produce a relaxed-SIMD variant or fallback).What changed
Configuration::wasmVariantsdeclares N codegen variants — each a{label, flags, probes}WasmVariant.Build()produces the baselineoutputName.wasmplus oneoutputName.<label>.wasmper variant, recompiling the whole build graph (incl. dep libs and the std PCM) with the variant's-mflags. Relaxed-SIMD is per-translation-unit codegen, not a link switch, so a full rebuild is the only correct way to produce it.wasmVariantFlagsfolds intoVariantId, so each variant's objects/PCMs land in their own build+bin dir and never clobber the baseline.EnableWasiBrowserRuntimenow emits avariants.jsonmanifest (label → url + probes), preferred-first with the baseline (empty probes) as the universal fallback.wasi-runtime/runtime.jsruns inlined wasm-feature-detect probes (relaxed-simd,simd,tail-call,bulk-memory,exception-handling,threads— no external dependency), picks the first variant whose probes all pass, and falls back to the single bakedCRAFTER_WASM_URLwhen no manifest is present (backward compatible with existing builds).EnableWasiRelaxedSimdVariant(cfg)registers the relaxed-SIMD variant in one call. Call it beforeEnableWasiBrowserRuntimeso the manifest includes it.Tests
crafter-build test— full suite green (13 passed).New
WasmVariantstest: variant registration/idempotency,VariantIdperturbation, andvariants.jsoncontents/ordering.WasiBrowserRuntimetest updated for the extra manifest file.End-to-end: built the
examples/wasiproject withEnableWasiRelaxedSimdVariantforwasm32-wasip1. It emits bothwasi-hello.wasmandwasi-hello.relaxed-simd.wasm+variants.json. Loaded in Firefox, the runtime logged:confirming the probe-driven selection picks and actually executes the relaxed-SIMD variant.
Resolves #24
🤖 Generated with Claude Code