@threadedstack/wmd-web 0.1.45 → 0.1.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/RELEASE.json +12 -9
- package/package.json +3 -3
- package/src/boot.js +35 -7
- package/src/edge/auto.js +26 -9
- package/src/edge/pins.gen.js +1 -1
- package/src/edge/python-look.js +23 -0
- package/src/edge/setup.js +4 -1
- package/src/gowasm/boot-setup.js +6 -4
- package/src/host/chan-service-entry.js +21 -0
- package/src/host/chan-service.js +10 -1
- package/src/workers.json +12 -0
- package/wmdpack.wasm +0 -0
package/README.md
CHANGED
|
@@ -69,6 +69,7 @@ The interface this host implements is in [docs/host-interface.md](docs/host-inte
|
|
|
69
69
|
| `src/host/stdio.js` | stdout/stderr rings in a SharedArrayBuffer. Workers write into them under a spin lock, and the page drains them every 16 ms. |
|
|
70
70
|
| `src/host/layout.js` | Cell layout of the shared control block: tid counter, exit flag and code, pool slots, fd table, clock base, stub host-call counters. |
|
|
71
71
|
| `src/host/monitor.js` | Page-side monitors: the kernel-panic scanner, the progress watchdog and the throttle meter. |
|
|
72
|
+
| `src/workers.json` | Every file wmd-web starts a Worker from (`new URL('./x.js', import.meta.url)`), as package paths; exported as `@threadedstack/wmd-web/workers.json`. A page that copies wmd-web's files by a list (a site build that does not follow `new Worker(new URL(...))`) reads this list, so a new Worker file in a release is not a 404 on its site. `test/unit/workers-list.test.js` keeps it equal to the source. |
|
|
72
73
|
| `src/calib-worker.js` | The throttle detector's Worker: times a fixed integer loop and a 10 ms `Atomics.wait` every 2 s. |
|
|
73
74
|
| `page/` | A small test page. `?case=arm64\|amd64\|hello\|wfi\|prog\|loop\|flush\|smpflush\|smc&mode=interp\|jit&auto=1` boots on load (other options: `arg=`, `env=`, `prog=`, `jitc=`, `brk=`, `share=`, `door=0`, `watchdog=`; see the head of `page/main.js`). State is on `window.wmd`, and the JIT counters are in a table on the page. `page/smc-initrd.js` builds the self-modifying-code initramfs. `page/jit-stress.html` is the multi-Worker JIT door stress test, and `page/wasm-mini.js` encodes its block-shaped test modules. `page/idb-bytes.js` is the IndexedDB byte store behind `?jitcache=1` (`=fresh` empties it first), on this page and the wmn test page. |
|
|
74
75
|
| `src/fs/` | P-B4, the 9P2000.L file server (no browser wiring yet): the pack reader (`pack.js`), the overlay of pack lowers under an in-memory upper (`overlay.js`), the codec and server (`9p/codec.js`, `9p/server.js`) and Linux errno values (`errno.js`). See [docs/9p.md](docs/9p.md). |
|
|
@@ -3022,6 +3023,6 @@ attributes the guest has seen across a cache drop (the page's `ck.dropNames()`),
|
|
|
3022
3023
|
|
|
3023
3024
|
## The Go compiler's Wasm twin (X6; off until a base url is set)
|
|
3024
3025
|
|
|
3025
|
-
An embedder does nothing to get the twin: update the package and call `containerBundle` and `bootWmd` as before, with no line of twin code. `bootWmd` reads the pins (`src/gowasm/pins-data.js`, a JS module that ships in the package, no request), adds the stub mounts to the bundle's spec and sets the service's `gowasm` field from it; the image decides (an image with no Go compile, or a Go release with no pin, runs as before and downloads nothing). The twin's module (41 to 53 MB per Go release) is fetched by the twin's Worker on first use from an ordered list of sources (`GOWASM_SOURCES_DEFAULT` in `src/gowasm/setup.js`: the npm registry, then jsDelivr, then unpkg; `gowasm: false` turns the twin off): the first that gives the pinned sha256 and size wins, a source that fails, stalls, is too big, refuses the file or has a wrong hash is left for the next (jsDelivr refuses files over 50 MB, so for the largest twin the working sources are the registry tarball and unpkg: each release needs only one source that works), and when all fail the guest compiles, with one `gowasm-off` event that names each source. Source kinds: `{ kind: 'tgz', url }` (an npm registry tarball) and `{ kind: 'file', base }` (`<base>/<file>`); only the pins name the package. The module is kept in Cache Storage of the page's origin under a key that holds its hash (checked again at each boot).
|
|
3026
|
+
An embedder does nothing to get the twin: update the package and call `containerBundle` and `bootWmd` as before, with no line of twin code. `bootWmd` reads the pins (`src/gowasm/pins-data.js`, a JS module that ships in the package, no request), adds the stub mounts to the bundle's spec and sets the service's `gowasm` field from it; the image decides (an image with no Go compile, or a Go release with no pin, runs as before and downloads nothing). The twin's module (41 to 53 MB per Go release) is fetched by the twin's Worker on first use from an ordered list of sources (`GOWASM_SOURCES_DEFAULT` in `src/gowasm/setup.js`: the npm registry, then jsDelivr, then unpkg; `gowasm: false` turns the twin off): the first that gives the pinned sha256 and size wins, a source that fails, stalls, is too big, refuses the file or has a wrong hash is left for the next (jsDelivr refuses files over 50 MB, so for the largest twin the working sources are the registry tarball and unpkg: each release needs only one source that works), and when all fail the guest compiles, with one `gowasm-off` event that names each source. Source kinds: `{ kind: 'tgz', url }` (an npm registry tarball) and `{ kind: 'file', base }` (`<base>/<file>`); only the pins name the package. The module is kept in Cache Storage of the page's origin under a key that holds its hash (checked again at each boot). The twin is on in Chromium, Firefox and WebKit. (D-666 had it off in WebKit: a bundled embedder's machine never came up there with it. The cause was WebKit evaluating the channel service's Worker script a second time when the bundler's edge-go chunk imported it; the channel service now starts from `src/host/chan-service-entry.js`, which imports nothing, #86.) `GOWASM_ENGINES_OFF` in `src/gowasm/boot-setup.js` is the per-engine off switch (empty); `gowasm: { <engine>: true }` turns the twin on in an engine named there. What a consumer may pass to `bootWmd`: `gowasm: false` (off), `gowasm: { sources: [...] }`, `gowasm: { base: 'https://.../gowasm' }` (the override for an app that serves its own copy of the files `compile-<go release>.wasm`), `gowasm: { limits }`. An app with no Content-Security-Policy has nothing to do. An app with a policy that has `connect-src` adds one origin, `https://registry.npmjs.org` (the first source; jsDelivr and unpkg are only fallbacks, so they need not be listed), or names a source of its own that the policy allows with `gowasm: { sources: [...] }`. A source the policy blocks is left for the next one without a request, and when all are blocked the guest compiles and the `gowasm-off` event says what blocked each (the directive and the origin to add; in Playwright's WebKit the page gets no violation event from the twin's Worker, so the reason is the browser's own text with a hint naming `connect-src`); knowing that all three are blocked took 21 to 25 ms in Chromium and 22 to 28 ms in Firefox (counted once, under shared load). Test page words: `gowasm=1`, `gowasm=auto` (only a table the page states by `gowasmtools=<url>` or `<meta name="wmd-gowasm-table" content="<url>">`), `gowasmbase=<url>`. A checkpoint keeps the twin choice it was taken with (a checkpoint taken with the twin always restores: with `gowasm: false` the stub mounts stay, no twin Worker starts, every compile runs in the guest, one `gowasm-off` event, rule `checkpoint-twin`; one taken without it restores without it). Headers, limits, the cache, the checkpoint rule and the images that carry a listed compile: `docs/gowasm-twin.md`.
|
|
3026
3027
|
|
|
3027
3028
|
Off is off: with `gowasm: false` (or no twin source and no table) there is no twin file requested, no twin Worker started, no stub mount in the container (the guest's `/proc/mounts` has none), and no event. What the page does load is four small library modules that main's page does not, because the checkpoint rule needs the twin's spec text even when the twin is off: `src/gowasm/boot-setup.js`, `src/gowasm/setup.js`, `src/gowasm/pins-data.js` and `src/host/gowasm-guard.js`, 4 requests and 39,808 bytes uncompressed (counted once in Chromium against a copy of `origin/main`'s `web/`: 228 requests against 225, 65 distinct paths against 61; `web/test/x6/fix10-count.spec.js`). Nothing else differs in what the page asks for.
|
package/RELEASE.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wmd-web",
|
|
3
3
|
"version": "0.5.1",
|
|
4
|
-
"commit": "
|
|
4
|
+
"commit": "c35d2418a684f2b2d6bb865549f151ba6c570150",
|
|
5
5
|
"previous": null,
|
|
6
6
|
"decisions": [
|
|
7
7
|
"D-388",
|
|
@@ -156,7 +156,7 @@
|
|
|
156
156
|
}
|
|
157
157
|
},
|
|
158
158
|
"files": {
|
|
159
|
-
"README.md": "
|
|
159
|
+
"README.md": "6ac8c77da8d0352ed0c9d7390f9ea648d46f5ab64b03fe26658165e0e3ec5a7b",
|
|
160
160
|
"edge-site/own/HASHES.txt": "4d83edcb41399bb89eb7b1f89115886d739adac887bdde59a8d33e3a4602683a",
|
|
161
161
|
"edge-site/own/NOTICES.txt": "8ceca5406ee5833737bd5fa4a41d434bf5e4d26eff6da1e42c693176ee113101",
|
|
162
162
|
"edge-site/own/acorn/LICENSE": "76a876cf886ff9be2a8b5e2e86514fed06223c8c9f0c1e9ee9606e93841e00b7",
|
|
@@ -177,10 +177,10 @@
|
|
|
177
177
|
"guest/arm64/features": "02693b8b6c099e10fdb7a092394102ee92971ce1e39d0d6e5327ff8be1d0ee74",
|
|
178
178
|
"guest/arm64/initramfs.cpio.gz": "1cac59f3a8bcf52a2b6b2d5769bf94dc237ec16c8b54df50686b4612bbe7bfef",
|
|
179
179
|
"guest/arm64/vm.wasm": "7f94f411f4041834981deedb5b8bb7f8961a0cbb8fa896e15ce5ee99a94a2853",
|
|
180
|
-
"package.json": "
|
|
180
|
+
"package.json": "6de9aa9fabdb395651d39997c17e094f01a574f54a36f0af31bd3ffaae53cda1",
|
|
181
181
|
"src/base.js": "982f8e46dbb727ec542a494ebdb884ccd19a31ff4e091425b2d1fc01b0d4754a",
|
|
182
182
|
"src/blob.js": "bb2a2f0d87ce236280a7be2f246c926010dfe07f649c27da5e70d8eb5eaf7061",
|
|
183
|
-
"src/boot.js": "
|
|
183
|
+
"src/boot.js": "c84e0abb6c0f626395d8cc0d4ccbca70f50bccecce267e6e993cceda4ff08892",
|
|
184
184
|
"src/build/builder.js": "c7794ec15b183213228776c8f4fb0950dec7e621f948358da7de8f90ef4f70ec",
|
|
185
185
|
"src/build/context.js": "d38097c61dbdadc4d41290c010425a4422f499aba473fa2b83f2a5c41e543571",
|
|
186
186
|
"src/build/dockerfile.js": "5957fe3d4ac8ff8b312f980ee04bd1d98ad4373a61f9a33e02f1ff1108b6ea53",
|
|
@@ -190,7 +190,7 @@
|
|
|
190
190
|
"src/build/pin.js": "8c67f017ae3ec560d2638fdfc0bd91ddd758150af16c188bbe3bf2cb4d7e28b2",
|
|
191
191
|
"src/build/tar.js": "25cf477488d9a60da9015be9ca5830bad3ad24428da1546f0621411cb7f44949",
|
|
192
192
|
"src/calib-worker.js": "3d610591a1b3b58f59c3a2ab457f43c90727d95973cd43055b3b73b76180611d",
|
|
193
|
-
"src/edge/auto.js": "
|
|
193
|
+
"src/edge/auto.js": "6539a666d6858927777a32536acde696f1b4c09d1dfaedb3f74d8abeebf67684",
|
|
194
194
|
"src/edge/base.js": "9493218ccc47f5e4c9c64959313b19119effc8f4d973bc805462acdd3b29b53a",
|
|
195
195
|
"src/edge/bridge.js": "3fa5acb959c760d7665fc0acd45625e55c9043628bd656f8cc8250ae8988f5f9",
|
|
196
196
|
"src/edge/codes.js": "1bb32c060d4a960a2e3b384d9ff8583329861de6e2b515b0d901b503f8b8a4a7",
|
|
@@ -233,6 +233,7 @@
|
|
|
233
233
|
"src/edge/page.js": "0e08df63e1534dead4fa9ac891928daf6ad96878ff88e8baa17dbc60307c70c6",
|
|
234
234
|
"src/edge/pins.js": "06e62a8298b95f7e7afb9acbbaad82d37202d9ac946ba498bb4db1d016ebfb0d",
|
|
235
235
|
"src/edge/plan.js": "dffc6b94e9b22293f6b31cc4b44ad5b5330a969d8c015a1e5e1d745484482e88",
|
|
236
|
+
"src/edge/python-look.js": "2dbbf1f5954de8a730244a2d8b7b86efd4138063df0f2abe9f4151aa2315a922",
|
|
236
237
|
"src/edge/python-module.js": "e6e608b5b03783c4ad14aae4ec10a989118ee1120f8fde8cbebca23d2fc98254",
|
|
237
238
|
"src/edge/python-pins.js": "50e66db4df50553301acb66d8dcf48d5f8c54d384a1ac0af290bb43dc0231acf",
|
|
238
239
|
"src/edge/python-plan.js": "1da9bf454fc1625b557f290d3b659db34ef2fedc07c7d2f99bc5028a4037dff6",
|
|
@@ -254,7 +255,7 @@
|
|
|
254
255
|
"src/edge/sems.js": "f5bd680e67b7ec3eeb16b2f7ac9207b16491001400b435ff5ee3a34f050d8ceb",
|
|
255
256
|
"src/edge/service-host.js": "f77664be9e3a0cc1cc9b283c5aeda7d94c7a9d61b8cecda5b90822295d315df6",
|
|
256
257
|
"src/edge/service-port.js": "6daff74e083d8d6e4d3ce950004bafb8632e78c9fbf626197a2c18453ac96eeb",
|
|
257
|
-
"src/edge/setup.js": "
|
|
258
|
+
"src/edge/setup.js": "a868fb062f7ed18f77a517c1b7c6521231d26c29e8e289f83d38415250cc05cf",
|
|
258
259
|
"src/edge/shim.js": "25efa4dddd3bbdd4a2967d99116e10c011a41aa0a4bdd7ce670fbf6d01735a76",
|
|
259
260
|
"src/edge/site.js": "ff63be7c751678b773fd03e79e551e6fe6e85caa0444b6413b7bb940b8316979",
|
|
260
261
|
"src/edge/spawn-guard.js": "666cc6cca0628f3c07093f08da277a1d6291eebb91c19abebf0d422f6197e401",
|
|
@@ -272,7 +273,7 @@
|
|
|
272
273
|
"src/fs/seed.js": "1cd2765e5d28e961bc4e81b41898f768a63e24feaf44e0aa42bd23e5cb910a74",
|
|
273
274
|
"src/fs/svc-snapshot.js": "eae82a6e136f9430680197c617601028da35cbe8786df39d6cab28280a2f9a7c",
|
|
274
275
|
"src/fs/upper-pack.js": "737a7e2bb5aac0ff774645db5789d699adfff263ca6f979e6687a9183a47f9dc",
|
|
275
|
-
"src/gowasm/boot-setup.js": "
|
|
276
|
+
"src/gowasm/boot-setup.js": "f0e265e93ed04f24310e693a45faeace9a1cb979ded7c746a2b797b3317c9bf5",
|
|
276
277
|
"src/gowasm/fetch-twin.mjs": "de7c5f29c069dc3b009964b8b96084d567ef15d641238b1122a0d7f2c473f799",
|
|
277
278
|
"src/gowasm/make-pins-module.mjs": "d13db3b38fdfe37e4db66f3b7d0433df15d590260433b295e2654af12feacd75",
|
|
278
279
|
"src/gowasm/pins-data.js": "71fc2e21e2363de883823bccea5bb9ca3c46077e6fab56a04cfa511739563e19",
|
|
@@ -284,7 +285,8 @@
|
|
|
284
285
|
"src/host/base-file.js": "edb47c1eeb6b1cec627fa5894512185336b15d3f5db96a7151a8a57b34b4a2e8",
|
|
285
286
|
"src/host/base-io.js": "cdd049875dce9f1417f28b27efa2c6f494cbe2a49851249150d0c1ec871a8b59",
|
|
286
287
|
"src/host/boot-events.js": "a6567c889fa1e95ad7e917107a2593f03d14cc921827616368b3417de96faad2",
|
|
287
|
-
"src/host/chan-service.js": "
|
|
288
|
+
"src/host/chan-service-entry.js": "18f602f9ad72323e930157cb0820568f3ef83ce49b9672443791b01551f0ffd3",
|
|
289
|
+
"src/host/chan-service.js": "71523df6b371e64fbf9c214e3c50f350b6444ac8f27e19e1230dd96043317504",
|
|
288
290
|
"src/host/chan-services.js": "e7f52931b6ef76a8b97b793d0a1d86fb35d20dbca3dd333d18cc4ded0806c9f7",
|
|
289
291
|
"src/host/chan.js": "bb9e76890b0efeee7cfbd8481b9fb4620b3b184459d96d62ff68ddcdc8a46f83",
|
|
290
292
|
"src/host/ckpt-file.js": "da7938fa640a062e77bdfb59caad5b3b1fcbf6150e3220de3be23f253f4c4497",
|
|
@@ -343,7 +345,8 @@
|
|
|
343
345
|
"src/registry/pull.js": "24f2e01a76c9f7f27896af69b989f8c97f0ca31712b3e8110aaa5b5e3148b04b",
|
|
344
346
|
"src/registry/ref.js": "24038e0fbcb6ac143cb8e8f7b9fac4dd0803d0891961786dc88dba01a4402e7b",
|
|
345
347
|
"src/registry/wasi-mem.js": "8a8474a090a778db9eabfc2610f8c57f7f66b684ba7b7f8994aabd3ecb07a65a",
|
|
346
|
-
"src/worker.js": "c654be359e741d5b1fde1be05f8909968d4e00d1fca61be169e60ea691daa662"
|
|
348
|
+
"src/worker.js": "c654be359e741d5b1fde1be05f8909968d4e00d1fca61be169e60ea691daa662",
|
|
349
|
+
"src/workers.json": "2dd90729f76d5867a3a2974cdc958b610340383fc81a7a4d651272ba15c7e7dc"
|
|
347
350
|
},
|
|
348
351
|
"builder": {
|
|
349
352
|
"arm64": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threadedstack/wmd-web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.48",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://github.com/threadedstack/wmd-releases",
|
|
6
6
|
"repository": {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"description": "Browser host for wmd's guest vm.wasm (Web Workers + shared memory + WASI preview1)",
|
|
11
11
|
"wmd": {
|
|
12
|
-
"tag": "v0.1.
|
|
13
|
-
"commit": "
|
|
12
|
+
"tag": "v0.1.48",
|
|
13
|
+
"commit": "c35d2418a684f2b2d6bb865549f151ba6c570150",
|
|
14
14
|
"web": "0.5.1"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
package/src/boot.js
CHANGED
|
@@ -98,6 +98,24 @@ export async function edgeSetup(o = {}) {
|
|
|
98
98
|
return edgeSetupIn(pinned ? { ...o, pinned } : o, edgePlanCounts)
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
const pythonLooks = new WeakMap() // the look at a service's layers, once per service object (a restore's text choice asks again)
|
|
102
|
+
/** X25: {path, version, ms} of the image's python found in the 9P service's layers (src/edge/python-look.js), kept per service; never throws (a layer that cannot be read: no python). */
|
|
103
|
+
async function pythonLook(A, svc, env, e = {}) {
|
|
104
|
+
if (!svc.layers || !svc.layers.length) return null
|
|
105
|
+
let p = pythonLooks.get(svc)
|
|
106
|
+
if (!p) {
|
|
107
|
+
p = import('./edge/python-look.js')
|
|
108
|
+
.then(m => m.lookForPython(svc.layers, env, { at: svc.at ?? 'rootfs', ...(e.fetchLayer ? { fetchFn: e.fetchLayer } : {}) }))
|
|
109
|
+
.catch(() => ({ path: '', version: '', ms: 0 }))
|
|
110
|
+
pythonLooks.set(svc, p)
|
|
111
|
+
}
|
|
112
|
+
return p
|
|
113
|
+
}
|
|
114
|
+
const nodeMajorOf = env => {
|
|
115
|
+
const v = ((env || []).find(x => String(x).startsWith('NODE_VERSION=')) || '').slice(13)
|
|
116
|
+
return /^v?\d+/.test(v) ? v : ''
|
|
117
|
+
}
|
|
118
|
+
|
|
101
119
|
/**
|
|
102
120
|
* X5 option A: the whole setup of node in the frame for a container, from the options bootWmd got. Only `edge: { base }` (or `edge: {}`) asks for it;
|
|
103
121
|
* `edge: false`, no `edge`, and the page bridge a page made itself (edgeSetup().bootOption(), it has onMessage) come back as they are. It reads the 9P
|
|
@@ -128,9 +146,14 @@ export async function edgeAuto(o, counts = edgePlanCounts) {
|
|
|
128
146
|
} catch {
|
|
129
147
|
return off('bundle/config/config.json is not JSON')
|
|
130
148
|
}
|
|
131
|
-
//
|
|
149
|
+
// X25: the image's python, found in the service's layers (gone at once with `python: false` and for an image whose layers are not given)
|
|
150
|
+
const imagePython = e.python === false ? null : await pythonLook(A, svc, facts.env, e)
|
|
151
|
+
if (imagePython && typeof e.onLog === 'function') try { e.onLog(0, { type: 'python-look', ms: imagePython.ms, path: imagePython.path, version: imagePython.version }) } catch {} // the look's cost, for the page's own log
|
|
152
|
+
// a container that cannot use node in the frame loads no more of the edge code than the plan (the reason is counted); one that has a python the plan
|
|
153
|
+
// could take goes on without node (python only, src/edge/setup.js)
|
|
132
154
|
const pre = A.preplan(facts, { rt: e.rt, win: e.win })
|
|
133
|
-
|
|
155
|
+
const py = imagePython?.path ? A.pythonPlanFor(facts, imagePython, e, e.win) : { use: false }
|
|
156
|
+
if (!pre.use && !py.use) return off(imagePython?.path && !nodeMajorOf(facts.env) ? py.reason : pre.reason)
|
|
134
157
|
const setup = await edgeSetup({
|
|
135
158
|
...e,
|
|
136
159
|
edge: true,
|
|
@@ -141,9 +164,11 @@ export async function edgeAuto(o, counts = edgePlanCounts) {
|
|
|
141
164
|
p9port: svc.port,
|
|
142
165
|
root: svc.at ?? 'rootfs',
|
|
143
166
|
settings: { hostname: facts.hostname, ...(facts.cpus ? { cpus: facts.cpus } : {}), ...(e.settings || {}) },
|
|
167
|
+
...(imagePython?.path ? { imagePython } : {}),
|
|
144
168
|
})
|
|
145
169
|
if (!setup.use) return { o: { ...o, edge: undefined }, setup }
|
|
146
|
-
|
|
170
|
+
if (imagePython) setup.pythonLook = imagePython
|
|
171
|
+
const files = A.addEdgeMounts(svc.files, setup.edgeNode, undefined, setup.edgeTools || [])
|
|
147
172
|
const services = o.channels.services.map(s => (s === svc ? { ...s, files } : s))
|
|
148
173
|
return { o: { ...o, channels: { ...o.channels, services }, edge: setup.bootOption() }, setup }
|
|
149
174
|
}
|
|
@@ -156,7 +181,7 @@ const ABLE_WIN = { SharedArrayBuffer: function SharedArrayBuffer() {}, crossOrig
|
|
|
156
181
|
* (edge: false, no pins, no sources and a browser that cannot included): only the tools decide the text, as X6's twin does. null: no 9P service with a
|
|
157
182
|
* spec, a spec that is not JSON, or an image without node (a checkpoint of such a container cannot have had node in the frame).
|
|
158
183
|
*/
|
|
159
|
-
async function edgeTextOptions(plain) {
|
|
184
|
+
export async function edgeTextOptions(plain) {
|
|
160
185
|
const A = await import('./edge/auto.js')
|
|
161
186
|
const svc = A.findService(plain)
|
|
162
187
|
if (!svc) return null
|
|
@@ -164,8 +189,11 @@ async function edgeTextOptions(plain) {
|
|
|
164
189
|
const e = plain.edge && typeof plain.edge === 'object' ? plain.edge : {}
|
|
165
190
|
const facts = A.containerFacts(svc.files, plain.args || [])
|
|
166
191
|
const pre = A.preplan(facts, { rt: e.rt, win: ABLE_WIN })
|
|
167
|
-
|
|
168
|
-
const
|
|
192
|
+
// python's mounts by the same rule (the switch `python: false` is this boot's choice, not the text's): the checkpoint's key does not depend on it
|
|
193
|
+
const look = await pythonLook(A, svc, facts.env, e)
|
|
194
|
+
const py = look?.path ? A.pythonPlanFor(facts, look, { ...e, python: undefined }, ABLE_WIN) : { use: false }
|
|
195
|
+
if (!pre.use && !py.use) return null
|
|
196
|
+
const files = A.addEdgeMounts(svc.files, pre.use ? pre.node : undefined, undefined, py.use ? A.pythonSpecTools(py.python) : [])
|
|
169
197
|
if (files === svc.files) return null // the spec already holds the mounts (the page made them itself): nothing to choose
|
|
170
198
|
return { ...plain, channels: { ...plain.channels, services: plain.channels.services.map(x => (x === svc ? { ...x, files } : x)) } }
|
|
171
199
|
} catch {
|
|
@@ -1480,7 +1508,7 @@ async function bootMachine(o) {
|
|
|
1480
1508
|
throw err // (no Worker exists yet)
|
|
1481
1509
|
}
|
|
1482
1510
|
const lockName = `wmd-chan-${Math.random().toString(36).slice(2)}-${Date.now()}`
|
|
1483
|
-
chanSvc = new Worker(new URL('./host/chan-service.js', import.meta.url), { type: 'module', name: 'wmd-chan' })
|
|
1511
|
+
chanSvc = new Worker(new URL('./host/chan-service-entry.js', import.meta.url), { type: 'module', name: 'wmd-chan' })
|
|
1484
1512
|
workerState('chan-service', 'chan-service', 'starting')
|
|
1485
1513
|
chanSvc.onmessage = e => {
|
|
1486
1514
|
const m = e.data
|
package/src/edge/auto.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// X5 option A item 3: what bootWmd reads from a container's files to set up node in the frame by itself (src/boot.js edgeAuto), and the one thing it
|
|
2
2
|
// changes there: the three mounts of the image's node (src/host/ctl.js edgeSpecMounts). Plain functions, no browser.
|
|
3
|
-
import { EDGE_CONTAINER_DIR, NODE_PATHS, edgeSpecMounts, planEdge } from './plan.js'
|
|
3
|
+
import { EDGE_CONTAINER_DIR, NODE_PATHS, edgeSpecMounts, planEdge, planPython, pythonSpecTools } from './plan.js'
|
|
4
|
+
import { addEdgeToolMounts } from '../host/ctl.js'
|
|
4
5
|
|
|
5
6
|
export const BUNDLE_CONFIG = 'bundle/config/config.json'
|
|
6
7
|
export const BUNDLE_IMAGE = 'bundle/config/imageconfig.json'
|
|
@@ -50,19 +51,23 @@ export function containerFacts(files, args = []) {
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
/**
|
|
53
|
-
* The files with the edge mounts of the image's node
|
|
54
|
-
*
|
|
54
|
+
* The files with the edge mounts of the image's node (`node`, a path or none) and the stubs over its tools (`tools`, plan.js pythonSpecTools) added to the
|
|
55
|
+
* spec, once: a spec that already has them (containerBundle's `edgeNode` and `edge.tools`, or an earlier call) comes back unchanged. Node's mounts go where
|
|
56
|
+
* containerBundle puts them (before the /etc files), the tools' where addEdgeToolMounts puts them. A new files object; the caller's is not changed.
|
|
55
57
|
*/
|
|
56
|
-
export function addEdgeMounts(files, node, rootfsPath = '/run/wmd9p/rootfs') {
|
|
58
|
+
export function addEdgeMounts(files, node, rootfsPath = '/run/wmd9p/rootfs', tools = []) {
|
|
57
59
|
const text = textOf(files[BUNDLE_CONFIG])
|
|
58
60
|
const spec = JSON.parse(text)
|
|
59
61
|
const have = new Set((spec.mounts || []).map(m => m.destination))
|
|
60
62
|
const root = spec.root?.path || rootfsPath
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
let mounts = [...(spec.mounts || [])]
|
|
64
|
+
const add = node ? edgeSpecMounts(node, root).filter(m => !have.has(m.destination)) : []
|
|
65
|
+
if (add.length) {
|
|
66
|
+
const at = mounts.findIndex(m => String(m.destination).startsWith('/etc/'))
|
|
67
|
+
mounts.splice(at < 0 ? mounts.length : at, 0, ...add)
|
|
68
|
+
}
|
|
69
|
+
if (tools.length) mounts = addEdgeToolMounts(mounts, tools)
|
|
70
|
+
if (mounts.length === (spec.mounts || []).length) return files
|
|
66
71
|
const out = JSON.stringify({ ...spec, mounts }, null, 2) + '\n'
|
|
67
72
|
return { ...files, [BUNDLE_CONFIG]: sameForm(files[BUNDLE_CONFIG], out) }
|
|
68
73
|
}
|
|
@@ -75,3 +80,15 @@ export const browserOk = (g = globalThis) => typeof g.SharedArrayBuffer === 'fun
|
|
|
75
80
|
/** planEdge for the facts of a container (see containerFacts). -> {use, node?, reason?} */
|
|
76
81
|
export const preplan = (facts, { rt, win = globalThis } = {}) =>
|
|
77
82
|
planEdge({ enabled: true, env: facts.env, user: facts.user, readonlyRoot: facts.readonlyRoot, hasTmpfs: facts.hasTmpfs, hasJspi: browserOk(win), rt, nodePath: NODE_PATHS[0] })
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The plan for the image's python from what edgeAuto knows (the same planPython setup.js asks), for the spec text: -> {use, python?, version?, reason?}.
|
|
86
|
+
* `e` is the edge option's object (python, memoryMB, swapMB, ramMiB, rt).
|
|
87
|
+
*/
|
|
88
|
+
export const pythonPlanFor = (facts, imagePython, e = {}, win = globalThis) =>
|
|
89
|
+
planPython({
|
|
90
|
+
enabled: true, env: facts.env, user: facts.user, readonlyRoot: facts.readonlyRoot, hasTmpfs: facts.hasTmpfs, hasJspi: browserOk(win), rt: e.rt,
|
|
91
|
+
python: e.python, imagePython, memoryMB: e.memoryMB || 0, swapMB: e.swapMB || 0, ramMiB: e.ramMiB || 0,
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
export { pythonSpecTools }
|
package/src/edge/pins.gen.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// The files of node in the sandboxed frame: the path under a source (the option edge: { sources } of bootWmd), the role the frame gives the file, its
|
|
3
3
|
// sha256 and its size. The page accepts a file only when it has exactly this sha256 and size. The notice files travel with the rest.
|
|
4
4
|
// EDGE_PACKAGE is the package that holds these files, for the {name} {version} {file} of a registry source's url (null: none named).
|
|
5
|
-
export const EDGE_PACKAGE = { name: '@threadedstack/wmd-node', version: '0.1.
|
|
5
|
+
export const EDGE_PACKAGE = { name: '@threadedstack/wmd-node', version: '0.1.48' }
|
|
6
6
|
export const EDGE_PINS = [
|
|
7
7
|
{ path: 'wmd_browser_bg.wasm', role: 'wasm', sha256: '1e3db7f2c5f4be0ee44e5f2c0205cf8ca11f906d9addd5512915fad4821661c2', size: 6334959 },
|
|
8
8
|
{ path: 'wmd_browser.js', role: 'glue', sha256: 'b389b072096881ba39b22cd705d3a230af02acc5409c61fb4f997d1081c4df6f', size: 75647 },
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// X25: the image's python, found in the layers of the container's 9P service (the files bootWmd's service serves), for the setup of python in the frame.
|
|
2
|
+
// It opens the layers read-only as the 9P service does and asks src/edge/python-plan.js; the cost is measured (`ms`). Layers are urls (fetched; the browser's
|
|
3
|
+
// cache serves the boot's own fetch of the same urls) or bytes. No layer, or none with a python: {path: ''}.
|
|
4
|
+
import { Overlay } from '../fs/overlay.js'
|
|
5
|
+
import { Pack, bytesSource } from '../fs/pack.js'
|
|
6
|
+
import { findPython, imagePythonVersion } from './python-plan.js'
|
|
7
|
+
|
|
8
|
+
/** {path, version, ms} of the image's python, or {path: '', ms}: `layers` are urls or bytes, top first, `at` where the service puts the root. */
|
|
9
|
+
export async function lookForPython(layers, env, { at = 'rootfs', fetchFn = globalThis.fetch?.bind(globalThis) } = {}) {
|
|
10
|
+
const t0 = performance.now()
|
|
11
|
+
const ms = () => Math.round(performance.now() - t0)
|
|
12
|
+
if (!layers || !layers.length) return { path: '', version: '', ms: ms() }
|
|
13
|
+
const packs = await Promise.all(
|
|
14
|
+
layers.map(async (l, i) => {
|
|
15
|
+
const bytes = typeof l === 'string' ? new Uint8Array(await (await fetchFn(l)).arrayBuffer()) : l instanceof ArrayBuffer ? new Uint8Array(l) : l
|
|
16
|
+
return new Pack(bytesSource(bytes), `layer ${i}`)
|
|
17
|
+
}),
|
|
18
|
+
)
|
|
19
|
+
const fs = new Overlay({ layers: packs, at })
|
|
20
|
+
const root = fs.resolve(at)
|
|
21
|
+
const path = findPython(fs, root)
|
|
22
|
+
return { path, version: path ? imagePythonVersion(env, fs, root, path) : '', ms: ms() }
|
|
23
|
+
}
|
package/src/edge/setup.js
CHANGED
|
@@ -143,7 +143,10 @@ export function edgeSetupIn(o, counts) {
|
|
|
143
143
|
if (r.error) return r
|
|
144
144
|
const files = copyAll(r.files)
|
|
145
145
|
// python's module goes with them once it is in (a start that needs it waits for the gate below; a failed gate leaves python in the guest)
|
|
146
|
-
|
|
146
|
+
// python only (no node planned): the frame is made for python alone, so it waits for the module (the gate ends in a result or an error, bounded by its progress rule)
|
|
147
|
+
// instead of going without it; with node planned, the frame does not wait (node's start must not pay for python)
|
|
148
|
+
if (pyGate && !nodePlan.use && pyGate.state() !== 'ready') pyGate.begin()
|
|
149
|
+
if (pyGate && (pyGate.state() === 'ready' || !nodePlan.use)) {
|
|
147
150
|
const pr = await pyGate.join()
|
|
148
151
|
if (!pr.error) Object.assign(files, copyAll(pr.files))
|
|
149
152
|
}
|
package/src/gowasm/boot-setup.js
CHANGED
|
@@ -28,10 +28,11 @@ import { GOWASM_SOURCES_DEFAULT, planOf } from './setup.js'
|
|
|
28
28
|
export { GOWASM_SOURCES_DEFAULT }
|
|
29
29
|
const CONFIG = 'bundle/config/config.json'
|
|
30
30
|
/**
|
|
31
|
-
* The engines the twin is off in by default
|
|
32
|
-
*
|
|
31
|
+
* The engines the twin is off in by default: none. D-666 turned it off in WebKit (an embedder's machine, wmr's, never came up there with it); the cause
|
|
32
|
+
* was the channel service evaluated twice in a bundled page (threadedstack/wmd#86, src/host/chan-service-entry.js), not the twin. An engine named here
|
|
33
|
+
* gets the twin off by default ({engine: reason}); `gowasm: { <engine>: true }` turns it on there.
|
|
33
34
|
*/
|
|
34
|
-
export const GOWASM_ENGINES_OFF = {
|
|
35
|
+
export const GOWASM_ENGINES_OFF = {}
|
|
35
36
|
// the spec text does not depend on the sources, so a boot that does not use the twin still makes the text a checkpoint with the twin would hold
|
|
36
37
|
const TEXT_ONLY = [{ kind: 'file', base: 'https://twin.invalid/' }]
|
|
37
38
|
const textOf = raw => {
|
|
@@ -56,7 +57,8 @@ export async function twinForBoot(o) {
|
|
|
56
57
|
const services = o && o.channels && Array.isArray(o.channels.services) ? o.channels.services : []
|
|
57
58
|
const mine = services.map((s, i) => [s, i]).filter(([s]) => s && (s.kind === '9p' || s.kind === 1) && s.files && typeof s.files === 'object' && !s.gowasm && s.files[CONFIG] !== undefined)
|
|
58
59
|
if (!mine.length) return res(o)
|
|
59
|
-
const
|
|
60
|
+
const engine = engineOf(globalThis.navigator?.userAgent || '')
|
|
61
|
+
const engineWhy = opt === false || given[engine] === true ? '' : GOWASM_ENGINES_OFF[engine] || ''
|
|
60
62
|
const consumerOff = opt === false || !sources || !!engineWhy
|
|
61
63
|
const plan = planOf({ sources: consumerOff ? TEXT_ONLY : sources, pins: given.pins, packages: given.packages, limits: given.limits || {} })
|
|
62
64
|
const consumerWhy = opt === false ? 'gowasm: false' : engineWhy || 'no source'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// The channel service Worker's entry (threadedstack/wmd#86, X6WK). It imports nothing statically: it keeps the messages that come first,
|
|
2
|
+
// loads chan-service.js with a dynamic import and hands them to it in order. WebKit evaluates a module Worker's entry script a second time
|
|
3
|
+
// when a chunk the Worker imports dynamically imports that entry again, and a bundler (Vite, Rolldown) puts the code chan-service.js shares
|
|
4
|
+
// with edge-go.js, edge-host.js, service-port.js, fs-route.js and service-host.js in the entry chunk. The second instance installed its own
|
|
5
|
+
// onmessage, without the machine, and took every later message of the page: an embedder's machine never ran in WebKit with the Go twin on.
|
|
6
|
+
// A chunk that imports nothing gets no shared code, so those chunks import chan-service.js's chunk, which every browser evaluates once.
|
|
7
|
+
const early = []
|
|
8
|
+
self.onmessage = e => early.push(e)
|
|
9
|
+
import('./chan-service.js').then(
|
|
10
|
+
() => {
|
|
11
|
+
// chan-service.js installed its handler on load; the messages that came first go to it now, before any later one (a later message is a
|
|
12
|
+
// task of its own, after this one)
|
|
13
|
+
for (const e of early.splice(0)) self.onmessage?.(e)
|
|
14
|
+
},
|
|
15
|
+
err => {
|
|
16
|
+
// the module could not be loaded: an error event on the page's Worker object (boot.js marks the channel service failed)
|
|
17
|
+
setTimeout(() => {
|
|
18
|
+
throw err
|
|
19
|
+
})
|
|
20
|
+
},
|
|
21
|
+
)
|
package/src/host/chan-service.js
CHANGED
|
@@ -76,7 +76,7 @@ let goPort = null // ... and its port to the twin Worker
|
|
|
76
76
|
|
|
77
77
|
const nowMs = () => performance.now()
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
const onMessage = e => {
|
|
80
80
|
const m = e.data
|
|
81
81
|
try {
|
|
82
82
|
switch (m.t) {
|
|
@@ -204,6 +204,15 @@ self.onmessage = e => {
|
|
|
204
204
|
fail(err)
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
|
+
// X6WK (#86): one channel service per Worker. WebKit evaluates a module Worker's entry script again when a chunk it imports dynamically imports
|
|
208
|
+
// it (a bundler's shared-code chunk); a second evaluation of this module installs no handler, so the instance that gets `init` gets every
|
|
209
|
+
// message after it. The Worker starts from chan-service-entry.js, which makes that second evaluation unlikely; this is the defence for a page
|
|
210
|
+
// that starts chan-service.js itself.
|
|
211
|
+
const ONE = Symbol.for('wmd.chan-service.instance')
|
|
212
|
+
if (!self[ONE]) {
|
|
213
|
+
self[ONE] = true
|
|
214
|
+
self.onmessage = onMessage
|
|
215
|
+
}
|
|
207
216
|
|
|
208
217
|
/** Control events for the page (data bytes transferred). */
|
|
209
218
|
function postCtl() {
|
package/src/workers.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[
|
|
2
|
+
"src/calib-worker.js",
|
|
3
|
+
"src/host/base-io.js",
|
|
4
|
+
"src/host/chan-service-entry.js",
|
|
5
|
+
"src/host/ckpt-io.js",
|
|
6
|
+
"src/host/disk-worker.js",
|
|
7
|
+
"src/host/gowasm-worker.js",
|
|
8
|
+
"src/host/jit-hub.js",
|
|
9
|
+
"src/net/net-worker.js",
|
|
10
|
+
"src/registry/pack-worker.js",
|
|
11
|
+
"src/worker.js"
|
|
12
|
+
]
|
package/wmdpack.wasm
CHANGED
|
Binary file
|