-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomposition-cli-sqlite-lib.wac
More file actions
66 lines (62 loc) · 2.98 KB
/
Copy pathcomposition-cli-sqlite-lib.wac
File metadata and controls
66 lines (62 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Compose `sqlite-cli-command` with `sqlite-library` (sqlite-lib)
// so the cli's `sqlite:extension/spi*` imports get satisfied by
// sqlite-lib's exports, producing a single component that
// exports `wasi:cli/run` AND `sqlink:wasm/dispatch-bridge` and
// contains SQLite + the multi-memory cold-tier substrate.
//
// Run with:
//
// wac compose composition-cli-sqlite-lib.wac \
// -d sqlite:wasm-lib=sqlite-wasm/target/wasm32-wasip2/release/sqlite_lib.component.wasm \
// -d sqlite:cli=target/wasm32-wasip2/release/sqlite_cli.component.wasm \
// -o target/wasm32-wasip2/release/cli_with_sqlite.component.wasm
//
// `wac plug` is no longer sufficient: it auto-strips exports the
// outer world doesn't declare, which silently drops sqlite-lib's
// `dispatch-bridge`. Compose-with-recipe lets us explicitly re-
// export the bridge so the JS host's spi-loader.register-scalar
// impl can call into it.
//
// Imports the output STILL needs the embedder to satisfy:
//
// * sqlite:extension/{http, policy, types, metadata}@0.1.0
// (host-side capability gates the cli + extensions consume)
// * sqlink:wasm/extension-loader@0.1.0
// * sqlink:wasm/dispatch@0.1.0
// (host the JS host implements this; sqlite-lib's
// dispatch-bridge trampoline re-enters via this import)
// * sqlite:extension/spi-loader@0.1.0
// * the wasi:cli + wasi:io + wasi:clocks + wasi:filesystem +
// wasi:random preview-2 set
//
// Production wiring of those (browser polyfill, embedded
// extensions, …) lives in scripts/build-composed-runtime.sh.
package sqlite:composed-runtime@0.1.0;
let lib = new sqlite:wasm-lib { ... };
let cli = new sqlite:cli {
// Explicit cli lib wiring. `wac plug` auto-strips the
// dispatch-bridge export when there's no matching cli import,
// and `wac compose`'s `...` form left `sqlite:extension/spi`
// unwired in our setup. Spell out the spi handoff explicitly
// so the composed binary internally satisfies it from sqlite-
// lib's export rather than re-importing from the host.
"sqlite:extension/spi@0.1.0": lib["sqlite:extension/spi@0.1.0"],
...
};
export cli["wasi:cli/run@0.2.6"];
// Re-export sqlite-lib's dispatch-bridge so the JS host's
// `spi-loader.register-scalar` impl can install a sqlite3 scalar
// trampoline on sqlite-lib's connection. Without this, the
// composed binary's outer world wouldn't expose the bridge
// (the cli's own world doesn't declare it).
//
// dispatch-bridge.bridged-execute (v1.4) uses `sql-value` and
// `query-result` from `sqlite:extension/types`. Also re-export
// the types interface from sqlite-lib so the composed binary's
// outer-world type graph reaches them via an exported instance —
// without this, wac compose validation rejects the dispatch-bridge
// alias-export with "instance not valid to be used as export"
// because the referenced types aren't reachable through the
// exported component's type space.
export lib["sqlite:extension/types@0.1.0"];
export lib["sqlink:wasm/dispatch-bridge@0.1.0"];