This directory is the publish-side of the
xeus-lean EXTRA_WASM_DIRS
extension contract. Running build-wasm.sh
produces a staging directory that xlean's CMake reads at build time
to whole-archive Sparkle's externs and oleans into xlean.wasm.
<staging>/
├── Sparkle.olean # umbrella olean
├── Sparkle/... # per-module olean tree
├── lib/
│ ├── libsparkle_wasm.a # whole-archived into xlean.wasm
│ └── sparkle_exports.txt # one symbol per line for emcc
├── xeus-lean-extra.json # manifest xlean's CMake reads
└── .xeus-auto-imports # pre-import Sparkle on REPL cell 1
libsparkle_wasm.a bundles:
c_src/sparkle_barrier.c— pure C, WASM-safe. Implements the Signal evaluator's memoization barriers (sparkle_cache_get/sparkle_eval_at).c_src/sparkle_jit_wasm_stub.c— replacessparkle_jit.cfor WASM. The native JIT loads compiled.sos viadlopen, which the xeus-lean WASM sandbox doesn't expose. The stub satisfies every@[extern "sparkle_jit_*"]at link time and throws a clearIO.userErrorat run time so notebook users see a helpful message instead of an opaque "missing symbol" failure.- Lake-generated
.cwrappers under.lake/build/ir/Sparkle/**.c. Lean's interpreter resolves the boxed entry points (lp_…___boxed) via dlsym; the wrappers must live in the same archive as the C externs.
IP.*(RV32, BitNet, YOLOv8, Video, …). Out-of-scope for the tutorials and would inflate the JupyterLite first-boot download by ~50 MB. If you want them, copy this script and addlake build IP.<lib>plus copy steps for the per-IP olean trees.Tools.SVParser. Useful for write-your-own-SoC work but tutorials don't import it.- Anything from
Examples/orTests/.
You need an emscripten-enabled shell — the easiest is the one xeus-lean's docs CI uses:
# Inside an xeus-lean checkout (peer to sparkle/):
cd /path/to/xeus-lean
pixi run -e wasm-build bash /path/to/sparkle/scripts/wasm/build-wasm.sh \
/tmp/sparkle-staging
# Then feed the staging dir to xlean's WASM build:
pixi run -e wasm-build emcmake cmake -S . -B wasm-build \
-DEXTRA_WASM_DIRS="/tmp/sparkle-staging"
pixi run -e wasm-build emmake make -C wasm-build -j$(nproc) xleanThe script bails out early if emcc, emar, or lake aren't on
PATH, so you don't waste a 30-minute WASM relink just to find out
one tool was missing.
If you add or remove an @[extern "sparkle_*"] declaration anywhere
under Sparkle/:
- The Lake-generated wrappers under
.lake/build/ir/Sparkle/**.cpick up the change automatically —build-wasm.shre-archives whatever is on disk. - The hand-written exports list in
sparkle_exports.txtis regenerated by scanningLEAN_EXPORTlines in those.cfiles, so it tracks the C side automatically too. - For new hand-written externs (something other than barrier or
JIT), add the implementation under
c_src/and add its.oto step 2 ofbuild-wasm.sh.
The native JIT externs (everything in c_src/sparkle_jit.c) are
WASM-incompatible by construction; if you ever add a new one, also
add a stub return in c_src/sparkle_jit_wasm_stub.c so the WASM
link doesn't break.
xeus-lean PR #13
moved every third-party Lean library out of the kernel repo.
xeus-lean now owns:
- the kernel binary (
xlean.wasm/js), - the JupyterLite glue,
- a vendor-agnostic mechanism (
EXTRA_WASM_DIRS+xeus-lean-extra.json)
and nothing else about any particular downstream library. This directory is Sparkle's matching plug for that mechanism.