feat(workspace): R2.4 core runtime — lazy load, poison on trap, offline re-instantiation, per-generation sheet handles
packages/core-wasm: browser-safe CoreRuntime (synchronous calls once ready; a WebAssembly.RuntimeError poisons the instance, the call answers internal, a fresh instance comes from the kept compiled module and a glue record imported in advance; at most 3 recoveries per page; retry after a load failure), SheetSession (handle rebuilt per instance generation, never called on a dropped one; invalid_sheet without poisoning), Node source. crates/wasm: SheetHandle (sheet held in the module memory). Two builds: pkg/ shipped without trap exports (checked), pkg-proofs/ for the trap tests; BUILD_STAMP (hash of the Rust sources) refused when missing or stale by the vitest global setup instead of skipping. Failure envelope carries a numeric found version; compact JS-number output.
This commit is contained in:
1 parent
22fea8736d
commit
343d6f4c1f
22 files changed
+783
-180
No files matched your search
+24
-9
@@ -21,14 +21,29 @@ if [ "$lock_version" != "$cli_version" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# `proofs`: the R0 trap exports; dropped when R2 builds the module the application ships.
|
||||
cargo build -p faunosteo-wasm --release --target wasm32-unknown-unknown --locked --features proofs
|
||||
# Two modules from the same sources: pkg/ is the one the application ships (no trap export),
|
||||
# pkg-proofs/ adds the R0 trap exports for the poison-and-reinstantiate tests only (R2 plan P10).
|
||||
build_module() {
|
||||
local out="$1"
|
||||
shift
|
||||
cargo build -p faunosteo-wasm --release --target wasm32-unknown-unknown --locked "$@"
|
||||
rm -rf "$out"
|
||||
wasm-bindgen --target web --out-dir "$out" --out-name faunosteo_wasm \
|
||||
target/wasm32-unknown-unknown/release/faunosteo_wasm.wasm
|
||||
}
|
||||
|
||||
out=packages/core-wasm/pkg
|
||||
rm -rf packages/core-wasm/pkg
|
||||
wasm-bindgen --target web --out-dir "$out" --out-name faunosteo_wasm \
|
||||
target/wasm32-unknown-unknown/release/faunosteo_wasm.wasm
|
||||
stamp="$(node scripts/wasm-stamp.mjs)"
|
||||
build_module packages/core-wasm/pkg-proofs --features proofs
|
||||
echo "$stamp" > packages/core-wasm/pkg-proofs/BUILD_STAMP
|
||||
build_module packages/core-wasm/pkg
|
||||
echo "$stamp" > packages/core-wasm/pkg/BUILD_STAMP
|
||||
|
||||
raw=$(wc -c < "$out/faunosteo_wasm_bg.wasm")
|
||||
gz=$(gzip -9 -c "$out/faunosteo_wasm_bg.wasm" | wc -c)
|
||||
echo "faunosteo_wasm_bg.wasm: ${raw} bytes raw, ${gz} bytes gzip -9"
|
||||
# The shipped module must not carry a proof export.
|
||||
if grep -Eq 'panic_for_test|recurse_for_test' packages/core-wasm/pkg/faunosteo_wasm.d.ts; then
|
||||
echo "packages/core-wasm/pkg exports a proof function: refusing to ship it" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
raw=$(wc -c < packages/core-wasm/pkg/faunosteo_wasm_bg.wasm)
|
||||
gz=$(gzip -9 -c packages/core-wasm/pkg/faunosteo_wasm_bg.wasm | wc -c)
|
||||
echo "faunosteo_wasm_bg.wasm (shipped): ${raw} bytes raw, ${gz} bytes gzip -9"
|
||||
@@ -0,0 +1,41 @@
|
||||
// Build stamp of the browser module: sha256 over the sources that compile into it (the core
|
||||
// library, the wasm facade, the workspace manifests and lock, the cargo config). Written into
|
||||
// pkg/ and pkg-proofs/ by scripts/wasm-build.sh; packages/core-wasm/tests/global-setup.ts
|
||||
// recomputes it and refuses to run the suites on a missing or stale module.
|
||||
// Usage: node scripts/wasm-stamp.mjs → prints the stamp.
|
||||
import { createHash } from 'node:crypto'
|
||||
import { readdirSync, readFileSync, statSync } from 'node:fs'
|
||||
import { join, relative, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const ROOT = resolve(fileURLToPath(new URL('..', import.meta.url)))
|
||||
const INPUTS = [
|
||||
'Cargo.toml',
|
||||
'Cargo.lock',
|
||||
'.cargo/config.toml',
|
||||
'crates/core/Cargo.toml',
|
||||
'crates/core/src',
|
||||
'crates/wasm/Cargo.toml',
|
||||
'crates/wasm/src',
|
||||
]
|
||||
|
||||
function files(path) {
|
||||
const absolute = join(ROOT, path)
|
||||
if (!statSync(absolute).isDirectory()) return [path]
|
||||
return readdirSync(absolute).flatMap((name) => files(join(path, name)))
|
||||
}
|
||||
|
||||
export function wasmStamp() {
|
||||
const hash = createHash('sha256')
|
||||
const all = INPUTS.flatMap(files).map((f) => relative(ROOT, join(ROOT, f)))
|
||||
for (const file of all.sort()) {
|
||||
hash.update(`${file}\0`)
|
||||
hash.update(readFileSync(join(ROOT, file)))
|
||||
hash.update('\0')
|
||||
}
|
||||
return hash.digest('hex')
|
||||
}
|
||||
|
||||
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
||||
process.stdout.write(`${wasmStamp()}\n`)
|
||||
}
|
||||
Reference in new issue
Block a user