@threadedstack/wmd-web 0.1.54 → 0.1.55
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 +8 -0
- package/RELEASE.json +11 -10
- package/package.json +3 -3
- package/src/base.js +12 -1
- package/src/boot.js +18 -4
- package/src/build/builder.js +34 -18
- package/src/edge/pins.gen.js +1 -1
- package/src/host/base-cache.js +14 -2
- package/src/host/boot-events.js +11 -0
- package/src/host/ckpt-file.js +10 -0
- package/src/host/ckpt-io.js +11 -2
- package/src/host/ckpt.js +9 -0
- package/src/host/opfs-avail.js +19 -0
- package/wmdpack.wasm +0 -0
package/README.md
CHANGED
|
@@ -187,6 +187,9 @@ const r2 = await buildImage({ ...builderOptions, context, timeoutMs: 30 * 60_000
|
|
|
187
187
|
mid-build, the next build mounts the disk again and its steps come back `CACHED`. `close({keep: false})` deletes
|
|
188
188
|
the disk.
|
|
189
189
|
- **A second tab** that asks for a disk already open gets a temporary disk, deleted when it closes.
|
|
190
|
+
- **A private window** (or any page with no OPFS) gets no disk: BuildKit's storage is in the builder's memory, as
|
|
191
|
+
with `disk: false`, and nothing is kept after the builder closes. The builder says so in two events:
|
|
192
|
+
`{t: 'storage', use: 'disk', storage: 'memory', reason}` and `{t: 'disk', reason: 'memory', message}`.
|
|
190
193
|
- **Features:** `RUN --mount=type=cache` and `type=secret`, `# syntax=` frontends, build args and target stages,
|
|
191
194
|
`.dockerignore`, file capabilities (`setcap`), push to a registry (TLS, or plain http in `httpRegistries`), and
|
|
192
195
|
`tar: true` for a Docker tar that `docker load` takes. `--mount=type=ssh` and another platform are refused before
|
|
@@ -2967,6 +2970,11 @@ engines' memory64 limit), passes `WMD_RAM_FLAT=1` to vm.wasm and hands the memor
|
|
|
2967
2970
|
`why` is `checkpoint`, `flatRam`, `ramInMemory0` (the option named `true`), `default` (the option on by the
|
|
2968
2971
|
default), `allowLargeRam` or `ram` (the RAM size alone); `options` is the layout the options alone would have
|
|
2969
2972
|
chosen. The test page keeps the last one as `ck.layout`.
|
|
2973
|
+
- A base snapshot read with `openBase({cache: opfsBaseCache()})` in a page with no OPFS (a private window, an
|
|
2974
|
+
automated WebKit with an ephemeral data store) is read from the network into memory and no copy is kept
|
|
2975
|
+
(`opfsBaseCache().available()` says so); `info.storage` is `{storage: 'memory', reason}` and the boot sends
|
|
2976
|
+
`{ t: 'boot', stage: 'storage', use: 'base', storage: 'memory', reason }`. An explicit
|
|
2977
|
+
`vm.checkpoint({save: {store: opfsStore()}})` there still fails with `CheckpointError` code `'unavailable'`.
|
|
2970
2978
|
- The default. `RAM_IN_MEMORY0.default` in `src/boot.js` is the value of `ramInMemory0` when a caller leaves it out
|
|
2971
2979
|
(`undefined` or `null`); it is `true` since the flip. Named values: only exactly `true` is on, only exactly
|
|
2972
2980
|
`false` is off, anything else is off. With it on, a caller's own `allowLargeRam: true` (without naming the option)
|
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": "96fbade729d8acbea87c59bca766aad70a49ded8",
|
|
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": "93df5cc354b723760c7c3db18de3a69eb3f124fdb7d9a56ef017a758e5b734da",
|
|
160
160
|
"edge-site/own/HASHES.txt": "4d83edcb41399bb89eb7b1f89115886d739adac887bdde59a8d33e3a4602683a",
|
|
161
161
|
"edge-site/own/NOTICES.txt": "8ceca5406ee5833737bd5fa4a41d434bf5e4d26eff6da1e42c693176ee113101",
|
|
162
162
|
"edge-site/own/acorn/LICENSE": "76a876cf886ff9be2a8b5e2e86514fed06223c8c9f0c1e9ee9606e93841e00b7",
|
|
@@ -178,10 +178,10 @@
|
|
|
178
178
|
"guest/arm64/initramfs.cpio.gz": "ac7c0fc194b059579943c3d8ceaa0757c3e3e248231c2ad779260e97d5084cd3",
|
|
179
179
|
"guest/arm64/vm.wasm": "7d16efadd83097e9b9188410187fb929b4ee5afbcb22cd387deebf1206b52376",
|
|
180
180
|
"package.json": "6de9aa9fabdb395651d39997c17e094f01a574f54a36f0af31bd3ffaae53cda1",
|
|
181
|
-
"src/base.js": "
|
|
181
|
+
"src/base.js": "c79df2c3d4a6519fb9a6ef5cda39d66a5b9bc1a6dd009d21e7455e141943079f",
|
|
182
182
|
"src/blob.js": "bb2a2f0d87ce236280a7be2f246c926010dfe07f649c27da5e70d8eb5eaf7061",
|
|
183
|
-
"src/boot.js": "
|
|
184
|
-
"src/build/builder.js": "
|
|
183
|
+
"src/boot.js": "d6d45757bbae9949de7ce0dad18c5acd3c50c64bb30cb7b1c9c155a8231ab671",
|
|
184
|
+
"src/build/builder.js": "57a8436acc00147d031a42cccffe508f8deb3735b0ab4f9efcc2aa1cf7c6859c",
|
|
185
185
|
"src/build/context.js": "d38097c61dbdadc4d41290c010425a4422f499aba473fa2b83f2a5c41e543571",
|
|
186
186
|
"src/build/dockerfile.js": "5957fe3d4ac8ff8b312f980ee04bd1d98ad4373a61f9a33e02f1ff1108b6ea53",
|
|
187
187
|
"src/build/dockerignore.js": "8fc03d09da020f43ea483979b1183891b71d76f012379ab7813838ea0e53c546",
|
|
@@ -281,20 +281,20 @@
|
|
|
281
281
|
"src/gowasm/pins.json": "0f40d8553c19915b328263077097b0c353072ec84d2afd5cf388e92a2fde9cce",
|
|
282
282
|
"src/gowasm/setup.js": "4cda761d94ca28b28fc03cb846a98b6735a8e03dbbfe09ebbf4f64742f712038",
|
|
283
283
|
"src/gowasm/twin-fetch.js": "c5d53ccb6ee21c0ffc76d4c9f41f2dea1ceec45a3fe26d5b98cfbd4b9aecce70",
|
|
284
|
-
"src/host/base-cache.js": "
|
|
284
|
+
"src/host/base-cache.js": "83fd8f28779446eff5dff096856e868416117cd7330d1ce7a8a06c4a10b1a111",
|
|
285
285
|
"src/host/base-file.js": "edb47c1eeb6b1cec627fa5894512185336b15d3f5db96a7151a8a57b34b4a2e8",
|
|
286
286
|
"src/host/base-io.js": "cdd049875dce9f1417f28b27efa2c6f494cbe2a49851249150d0c1ec871a8b59",
|
|
287
|
-
"src/host/boot-events.js": "
|
|
287
|
+
"src/host/boot-events.js": "4af19b460a18b5c4e18c3a30d3cf1e843d4881b823a4f1b052a8cad4cea6cd2b",
|
|
288
288
|
"src/host/chan-service-entry.js": "18f602f9ad72323e930157cb0820568f3ef83ce49b9672443791b01551f0ffd3",
|
|
289
289
|
"src/host/chan-service.js": "d61afdcbe1a6929dd93a2f7e842c8b94c8d742db59359004d08ec3997b154288",
|
|
290
290
|
"src/host/chan-services.js": "e7f52931b6ef76a8b97b793d0a1d86fb35d20dbca3dd333d18cc4ded0806c9f7",
|
|
291
291
|
"src/host/chan.js": "bb9e76890b0efeee7cfbd8481b9fb4620b3b184459d96d62ff68ddcdc8a46f83",
|
|
292
292
|
"src/host/ckpt-chain.js": "c208a882da772acafe1373ea1d7e04723e26e870396d4202ef330d4eaf758596",
|
|
293
|
-
"src/host/ckpt-file.js": "
|
|
294
|
-
"src/host/ckpt-io.js": "
|
|
293
|
+
"src/host/ckpt-file.js": "709344bfadf7c8151d51f70787b9e9d4b074ed1f5f80af113f11215851b9c28a",
|
|
294
|
+
"src/host/ckpt-io.js": "92e437fb3b118c4269ecc4aafec6e17cf99936d3fc0c410e38f48b9146e791fb",
|
|
295
295
|
"src/host/ckpt-point.js": "e08441b52d65b18c91f7e14b6ab3ad347572a0ac96a6642cf8072b47dde404eb",
|
|
296
296
|
"src/host/ckpt-save.js": "7bb07f536005fb5e7d9db6a09169a5ce1e3865d337ab65ce798a111334c6aa07",
|
|
297
|
-
"src/host/ckpt.js": "
|
|
297
|
+
"src/host/ckpt.js": "371acb574e31e94201ae1ff32a7cfad85801ae3eae2896cde7d53a96430c502d",
|
|
298
298
|
"src/host/clock.js": "aba6af3a8b1a985ae340892222e4b482d33afe20f5c8b3a4c7403ce87d1e247c",
|
|
299
299
|
"src/host/csp-reason.js": "ecec797e31006896176ff4e2972f11e5d5df160fe0cd80071c39d7808ff922fc",
|
|
300
300
|
"src/host/ctl.js": "86066c8d3be8e6f6b05e831344cd72ebc446ced391fc8290e1c584940b8ab3e0",
|
|
@@ -317,6 +317,7 @@
|
|
|
317
317
|
"src/host/jit.js": "72ef7334506fde2b3724cee93b52a987fbd6d45473b8de93d914db8a80ae9e17",
|
|
318
318
|
"src/host/layout.js": "c878b8da956da3ebc2391cf802869f12b3d74c131ffbcb9879536617728beeac",
|
|
319
319
|
"src/host/monitor.js": "ae1741ba35668bcc6192642246494433b175668933921634c699af5a0a69acc0",
|
|
320
|
+
"src/host/opfs-avail.js": "a98945c0f1792f29bc0147de662173cc9275a43dbeb44ec575ecb8ee44d5f122",
|
|
320
321
|
"src/host/p9mount.js": "cd27abd769b19ed8b26050ddd8b6d61f81faa5a431924217dd0bf2593258d5b9",
|
|
321
322
|
"src/host/pinned-fetch.js": "873eb804604c150f6c8e488eb6c49fb8dc7a85108e80bf1a831904b9555726eb",
|
|
322
323
|
"src/host/ram-mem.js": "bf4036d5d12be1d5d2f5223e526b0b8e225bc702ae7e60a2a59fdfe9fbbb49e3",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threadedstack/wmd-web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.55",
|
|
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.55",
|
|
13
|
+
"commit": "96fbade729d8acbea87c59bca766aad70a49ded8",
|
|
14
14
|
"web": "0.5.1"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
package/src/base.js
CHANGED
|
@@ -48,7 +48,7 @@ export async function vmKeyOf(url, fetchFn = (...a) => fetch(...a)) {
|
|
|
48
48
|
*/
|
|
49
49
|
export function openBase({ manifestUrl, image, cache = null, query = '', log = () => {}, fetchFn = (...a) => fetch(...a), vmKey = null, pick = es => es.at(-1), stallMs = 20_000, maxMs = 600_000, gate = true } = {}) {
|
|
50
50
|
const ac = new AbortController()
|
|
51
|
-
const info = { source: null, manifestMs: null, cacheWrite: null, attempts: [], netBytes: 0, stalled: null }
|
|
51
|
+
const info = { source: null, manifestMs: null, cacheWrite: null, attempts: [], netBytes: 0, stalled: null, storage: null }
|
|
52
52
|
let resolveHeader
|
|
53
53
|
let rejectHeader
|
|
54
54
|
const header = new Promise((res, rej) => ((resolveHeader = res), (rejectHeader = rej)))
|
|
@@ -198,6 +198,17 @@ export function openBase({ manifestUrl, image, cache = null, query = '', log = (
|
|
|
198
198
|
}
|
|
199
199
|
},
|
|
200
200
|
}
|
|
201
|
+
// IOS-3: a cache that says this page has no storage for it (OPFS in a private window) is not used: the snapshot is
|
|
202
|
+
// read from the network into memory and no copy is kept; info.storage (and the boot's 'storage' event) says why
|
|
203
|
+
if (cache) {
|
|
204
|
+
const a = cache.available ? await cache.available().catch(e => ({ ok: false, reason: String(e && e.message) })) : { ok: true }
|
|
205
|
+
if (a.ok) info.storage = { storage: cache.kind || 'cache' }
|
|
206
|
+
else {
|
|
207
|
+
info.storage = { storage: 'memory', reason: a.reason }
|
|
208
|
+
log(`base snapshot: no ${cache.kind || ''} cache here, nothing is kept (${a.reason})`)
|
|
209
|
+
cache = null
|
|
210
|
+
}
|
|
211
|
+
}
|
|
201
212
|
// attempt 1: the cache (if it holds the file); attempt 2 (or 1): the network. A cached file that fails verification is deleted and the network is tried.
|
|
202
213
|
for (const source of cache ? ['opfs', 'network'] : ['network']) {
|
|
203
214
|
let stream = null
|
package/src/boot.js
CHANGED
|
@@ -37,13 +37,13 @@ import {
|
|
|
37
37
|
} from './host/layout.js'
|
|
38
38
|
import { gcNudgeEvery } from './host/gcnudge.js'
|
|
39
39
|
import { createRamMemory, haveMemory64 } from './host/ram-mem.js'
|
|
40
|
-
import { bootFileName, cachedFromTiming, createBootEvents, createWorkerList, readBody, timingCount, vcpusOf } from './host/boot-events.js'
|
|
40
|
+
import { baseStorageEvent, bootFileName, cachedFromTiming, createBootEvents, createWorkerList, readBody, timingCount, vcpusOf } from './host/boot-events.js'
|
|
41
41
|
import { createJitStore, readJitStats, tableMinOf } from './host/jit.js'
|
|
42
42
|
import { createJitCacheHost } from './host/jit-cache.js'
|
|
43
43
|
import { createPanicScanner, createThrottleMeter, createWatchdog, watchdogDefaultMs } from './host/monitor.js'
|
|
44
44
|
import { BOOT_RING, MOBILE_RING, createStdio, stdioReader, stdioText } from './host/stdio.js'
|
|
45
45
|
import {
|
|
46
|
-
CONSOLE_IN_LIMIT, chanCounters, chanView, consoleInputGate, createChanBlock, markGuestGone, markServiceDead, ringBell, ringRead,
|
|
46
|
+
CONSOLE_IN_LIMIT, KIND_OF, chanCounters, chanView, consoleInputGate, createChanBlock, markGuestGone, markServiceDead, ringBell, ringRead,
|
|
47
47
|
} from './host/chan.js'
|
|
48
48
|
import { ControlClient } from './host/ctl.js'
|
|
49
49
|
import { chooseTwin, eventsOf, putBackTwin, specKeysDiffering, twinForBoot } from './gowasm/boot-setup.js'
|
|
@@ -57,7 +57,7 @@ export { DiskError, deleteDisk, openDisk, sweepDisks } from './host/disk.js'
|
|
|
57
57
|
export { NetSwitch } from './net/switch.js'
|
|
58
58
|
export { ImageFiles, openImage, parseGroup, parsePasswd, resolveUser } from './image-files.js'
|
|
59
59
|
export { P9_CACHE_DEFAULT, P9_FEATURES_LIMIT_MS, P9_FEATURES_MAX_BYTES, P9_NAMES_DEFAULT, P9_NAMES_FEATURE, fetchGuestFeatures, p9CacheDefault, p9FeaturesLost, p9InitCmdline, p9MountOptions, p9RunRefusal, parseGuestFeatures, readGuestFeatures } from './host/p9mount.js'
|
|
60
|
-
import { bootGuestFeatures, p9DropNames, p9HandleFields } from './host/p9mount.js'
|
|
60
|
+
import { P9_MSIZE_DEFAULT, bootGuestFeatures, p9DropNames, p9HandleFields } from './host/p9mount.js'
|
|
61
61
|
export { loadImageTar } from './registry/load-tar.js'
|
|
62
62
|
|
|
63
63
|
/** X5: the decisions of edgeSetup below, counted: `on` (node in the frame) and `off` by reason (node in the guest). */
|
|
@@ -431,6 +431,18 @@ export function stdioRingDefault(nav = globalThis.navigator) {
|
|
|
431
431
|
return isMobileWebKit(nav) ? MOBILE_RING : BOOT_RING
|
|
432
432
|
}
|
|
433
433
|
|
|
434
|
+
/**
|
|
435
|
+
* IOS-3: the chan block's sizes when the caller names none. The block is one SharedArrayBuffer, which mobile WebKit counts
|
|
436
|
+
* whole the moment it is made (D-516). The console pipe (service -> page) is written only by a 'console' service: 8 MiB
|
|
437
|
+
* with one, 4 KiB without. Each ring (a direction of a slot): the caller's ringBytes, else 1 MiB, or in mobile WebKit
|
|
438
|
+
* P9_MSIZE_DEFAULT (256 KiB, one whole 9P message; a ring is a byte stream, a larger message waits for room).
|
|
439
|
+
* Plain alpine's block: 26.4 MB before, 5.4 MB on a phone, 18.0 MB elsewhere.
|
|
440
|
+
*/
|
|
441
|
+
export function chanBlockDefaults({ services = [], ringBytes, nav = globalThis.navigator } = {}) {
|
|
442
|
+
const hasConsole = services.some(s => s.kind === 'console' || s.kind === KIND_OF.console)
|
|
443
|
+
return { ringBytes: ringBytes ?? (isMobileWebKit(nav) ? P9_MSIZE_DEFAULT : 1 << 20), pipeBytes: hasConsole ? 1 << 23 : 4096 }
|
|
444
|
+
}
|
|
445
|
+
|
|
434
446
|
/**
|
|
435
447
|
* W34: the bytes of live JIT modules a WebKit page can hold, so that the machine's memory at its
|
|
436
448
|
* maximum + the page's own files + the engine's copies of the modules stay under 5.5 GiB (2.5 GiB
|
|
@@ -1268,6 +1280,8 @@ async function bootMachine(o) {
|
|
|
1268
1280
|
if (lazyIn) {
|
|
1269
1281
|
try {
|
|
1270
1282
|
const h = await raceAbort(lazyIn.header)
|
|
1283
|
+
const se = baseStorageEvent(lazyIn.info) // IOS-3: no OPFS here (a private window): the snapshot is in memory only
|
|
1284
|
+
if (se) be.now('storage', se)
|
|
1271
1285
|
checkVmKeyFits(h, vmKey)
|
|
1272
1286
|
checkArgvFits(h, argv) // IOS-2: another command line (a 1024 MiB base under a 256 MiB request) is refused before its body is read
|
|
1273
1287
|
settleLayout(chooseLayout(o.args, o, h)) // X24 default: the base snapshot's own layout
|
|
@@ -1622,7 +1636,7 @@ async function bootMachine(o) {
|
|
|
1622
1636
|
chanSab = createChanBlock({
|
|
1623
1637
|
ports: chanSvcs.map(s => ({ port: s.port, kind: s.kind })),
|
|
1624
1638
|
nslots: o.channels.nslots ?? 8,
|
|
1625
|
-
ringBytes: o.channels.ringBytes
|
|
1639
|
+
...chanBlockDefaults({ services: chanSvcs, ringBytes: o.channels.ringBytes }), // IOS-3: no console service: a 4 KiB pipe; mobile WebKit: 256 KiB rings
|
|
1626
1640
|
count9p: !!o.channels.count9p, // X16: 9P counts by type and layer class (chanStats().p9Count); off by default
|
|
1627
1641
|
})
|
|
1628
1642
|
memTook += absMs() - tc
|
package/src/build/builder.js
CHANGED
|
@@ -10,6 +10,7 @@ import { blobBytes } from '../blob.js'
|
|
|
10
10
|
import { bootWmd, isWebKit, memory0RamLimit, ramInMemory0On } from '../boot.js'
|
|
11
11
|
import { MAIN_PROC_ID, containerBundle, fillRunRequest } from '../host/ctl.js'
|
|
12
12
|
import { DiskError, deleteDisk, openDisk, sweepDisks } from '../host/disk.js'
|
|
13
|
+
import { opfsAvailable } from '../host/opfs-avail.js'
|
|
13
14
|
import { p9OptsOfVm } from '../host/p9mount.js'
|
|
14
15
|
import { loadImageTar } from '../registry/load-tar.js'
|
|
15
16
|
import { packContext, readTarFile } from './context.js'
|
|
@@ -490,6 +491,38 @@ fi
|
|
|
490
491
|
exec /usr/bin/buildkit-runc "$@"
|
|
491
492
|
`
|
|
492
493
|
|
|
494
|
+
/**
|
|
495
|
+
* The builder's disk: wmd-builder-<namespace>-<arch>, or a temporary one when another tab holds it; null for disk: false.
|
|
496
|
+
* IOS-3: a page with no OPFS (a private window) gets no disk either: BuildKit's storage is then in the builder's memory,
|
|
497
|
+
* and a 'storage' event ({storage: 'memory', reason}) and a 'disk' event say so.
|
|
498
|
+
* available, openDisk, sweepDisks: test hooks.
|
|
499
|
+
*/
|
|
500
|
+
export async function openBuilderDisk({ disk: d, archName, emit, available = opfsAvailable, openDisk: open = openDisk, sweepDisks: sweep = sweepDisks }) {
|
|
501
|
+
if (d === false) return null
|
|
502
|
+
const a = await available()
|
|
503
|
+
if (!a.ok) {
|
|
504
|
+
emit({ t: 'storage', use: 'disk', storage: 'memory', reason: a.reason })
|
|
505
|
+
emit({ t: 'disk', reason: 'memory', message: `no OPFS here (${a.reason}): BuildKit's storage is in the builder's memory, kept until it closes` })
|
|
506
|
+
return null
|
|
507
|
+
}
|
|
508
|
+
const mib = d.mib || 10240
|
|
509
|
+
const base = `wmd-builder-${d.namespace}-${archName}`
|
|
510
|
+
const swept = await sweep('wmd-builder-tmp-').catch(() => [])
|
|
511
|
+
if (swept.length) emit({ t: 'disk', reason: 'swept', names: swept })
|
|
512
|
+
let disk
|
|
513
|
+
try {
|
|
514
|
+
disk = await open({ name: base, mib, onEvent: emit })
|
|
515
|
+
} catch (e) {
|
|
516
|
+
if (!(e instanceof DiskError) || e.reason !== 'locked') throw e
|
|
517
|
+
const tmp = `wmd-builder-tmp-${crypto.randomUUID().slice(0, 8)}-${archName}`
|
|
518
|
+
emit({ t: 'disk', reason: 'locked', message: `${base} is open in another tab; this builder uses ${tmp}, deleted on close` })
|
|
519
|
+
disk = await open({ name: tmp, mib, onEvent: emit })
|
|
520
|
+
disk.temporary = true
|
|
521
|
+
}
|
|
522
|
+
emit({ t: 'disk', reason: disk.created ? 'new' : 'open', name: disk.name, mib: disk.mib, persisted: disk.persisted })
|
|
523
|
+
return disk
|
|
524
|
+
}
|
|
525
|
+
|
|
493
526
|
export async function createBuilder(o) {
|
|
494
527
|
const archName = o.arch || 'arm64'
|
|
495
528
|
const arch = ARCHES[archName]
|
|
@@ -512,24 +545,7 @@ export async function createBuilder(o) {
|
|
|
512
545
|
const image = await builderImage(o.image, { converter: o.converter, platform: arch.platform, archName, fetchFn, store: o.store })
|
|
513
546
|
const digest = o.image?.tar ? o.image.sha256 : await indexDigest(image.index)
|
|
514
547
|
|
|
515
|
-
|
|
516
|
-
let disk = null
|
|
517
|
-
if (o.disk !== false) {
|
|
518
|
-
const mib = o.disk.mib || 10240
|
|
519
|
-
const base = `wmd-builder-${o.disk.namespace}-${archName}`
|
|
520
|
-
const swept = await sweepDisks('wmd-builder-tmp-').catch(() => [])
|
|
521
|
-
if (swept.length) emit({ t: 'disk', reason: 'swept', names: swept })
|
|
522
|
-
try {
|
|
523
|
-
disk = await openDisk({ name: base, mib, onEvent: emit })
|
|
524
|
-
} catch (e) {
|
|
525
|
-
if (!(e instanceof DiskError) || e.reason !== 'locked') throw e
|
|
526
|
-
const tmp = `wmd-builder-tmp-${crypto.randomUUID().slice(0, 8)}-${archName}`
|
|
527
|
-
emit({ t: 'disk', reason: 'locked', message: `${base} is open in another tab; this builder uses ${tmp}, deleted on close` })
|
|
528
|
-
disk = await openDisk({ name: tmp, mib, onEvent: emit })
|
|
529
|
-
disk.temporary = true
|
|
530
|
-
}
|
|
531
|
-
emit({ t: 'disk', reason: disk.created ? 'new' : 'open', name: disk.name, mib: disk.mib, persisted: disk.persisted })
|
|
532
|
-
}
|
|
548
|
+
const disk = await openBuilderDisk({ disk: o.disk, archName, emit })
|
|
533
549
|
|
|
534
550
|
const env = [
|
|
535
551
|
...(image.index.config?.Env || ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin']),
|
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.55' }
|
|
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 },
|
package/src/host/base-cache.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// writer(name) -> {write(u8), commit(), abort()} the tee of a download: pieces in file order; write() applies backpressure
|
|
9
9
|
// A cache is an optimisation: every failure is the caller's to log and ignore (the snapshot is verified again on every read).
|
|
10
10
|
import { BASE_MAGIC } from './base-file.js'
|
|
11
|
+
import { opfsAvailable } from './opfs-avail.js'
|
|
11
12
|
|
|
12
13
|
const MAGIC = new TextEncoder().encode(BASE_MAGIC)
|
|
13
14
|
const FLUSH = 4 << 20
|
|
@@ -78,7 +79,13 @@ export function makeWriter({ put, commit, abort }) {
|
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
/**
|
|
83
|
+
* @param {{workerUrl?: URL|string, dirName?: string, getDirectory?: () => Promise<FileSystemDirectoryHandle>}} o
|
|
84
|
+
* getDirectory: a test hook (default navigator.storage.getDirectory)
|
|
85
|
+
*/
|
|
86
|
+
export function opfsBaseCache({ workerUrl, dirName = 'wmd-base', getDirectory } = {}) {
|
|
87
|
+
const gd = getDirectory || (() => navigator.storage.getDirectory())
|
|
88
|
+
let avail = null
|
|
82
89
|
let w = null
|
|
83
90
|
let next = 1
|
|
84
91
|
const pending = new Map()
|
|
@@ -106,9 +113,14 @@ export function opfsBaseCache({ workerUrl, dirName = 'wmd-base' } = {}) {
|
|
|
106
113
|
w.postMessage({ ...msg, id }, transfer)
|
|
107
114
|
})
|
|
108
115
|
}
|
|
109
|
-
const dir = async () => (await
|
|
116
|
+
const dir = async () => (await gd()).getDirectoryHandle(dirName, { create: true })
|
|
110
117
|
return {
|
|
111
118
|
kind: 'opfs',
|
|
119
|
+
/** IOS-3: {ok: true} | {ok: false, reason}: no OPFS here (a private window); openBase() then keeps no copy. Asked once. */
|
|
120
|
+
available() {
|
|
121
|
+
avail ||= opfsAvailable({ getDirectory: getDirectory || (globalThis.navigator?.storage?.getDirectory ? gd : null) })
|
|
122
|
+
return avail
|
|
123
|
+
},
|
|
112
124
|
async open(name) {
|
|
113
125
|
let file
|
|
114
126
|
try {
|
package/src/host/boot-events.js
CHANGED
|
@@ -207,3 +207,14 @@ export function createWorkerList(at) {
|
|
|
207
207
|
has: id => ws.has(id),
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* IOS-3: the boot event for a base snapshot cache this page could not use (OPFS in a private window): the snapshot was
|
|
213
|
+
* read into memory and no copy kept. null when the cache was used, or there was none.
|
|
214
|
+
* @param {{storage?: {storage: string, reason?: string} | null} | null} info openBase()'s info
|
|
215
|
+
*/
|
|
216
|
+
export function baseStorageEvent(info) {
|
|
217
|
+
const s = info?.storage
|
|
218
|
+
if (!s || s.storage !== 'memory') return null
|
|
219
|
+
return { t: 'boot', stage: 'storage', use: 'base', storage: 'memory', reason: s.reason }
|
|
220
|
+
}
|
package/src/host/ckpt-file.js
CHANGED
|
@@ -30,6 +30,16 @@ export class CheckpointError extends Error {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* IOS-3: navigator.storage.getDirectory() refused. WebKit's ephemeral data store (a private window; Playwright's default
|
|
35
|
+
* WebKit context) rejects it with "UnknownError ... (e.g. out of memory)" before any file is touched: say what it is.
|
|
36
|
+
* Other errors are returned as they are.
|
|
37
|
+
*/
|
|
38
|
+
export function opfsDirError(e) {
|
|
39
|
+
if (!e || !['UnknownError', 'SecurityError'].includes(e.name)) return e
|
|
40
|
+
return new CheckpointError('unavailable', `this page has no origin private file system here (navigator.storage.getDirectory: ${e.name}: ${e.message}). A private window, or an automated WebKit with an ephemeral data store, does this: use memoryStore() for checkpoints in memory, or a normal window`)
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
export async function sha256Hex(u8) {
|
|
34
44
|
const d = new Uint8Array(await crypto.subtle.digest('SHA-256', u8))
|
|
35
45
|
let s = ''
|
package/src/host/ckpt-io.js
CHANGED
|
@@ -13,18 +13,24 @@
|
|
|
13
13
|
// {id, op:'verify', name} -> {ok, header, ms} (every digest)
|
|
14
14
|
// {id, op:'list'} -> {ok, items:[{name, size, modified}]}
|
|
15
15
|
// {id, op:'delete', name} -> {ok}
|
|
16
|
+
// {id, op:'ready'} -> {ok} or {ok:false, code:'unavailable'} (no OPFS here: a private window)
|
|
16
17
|
// {id, op:'usage'} -> {ok, usage, quota}
|
|
17
18
|
// {id, op:'poke', name, at, xor} / {id, op:'cut', name, size} test hooks: damage a file
|
|
18
19
|
// out: {id, ok:false, code, error} on failure (code: CheckpointError.code, or 'io').
|
|
19
20
|
import { createSaver } from './ckpt-save.js'
|
|
20
|
-
import { CheckpointError, baseNames, fileOf, readHeader, readSection, saveVersioned, versionsOf, withNewest } from './ckpt-file.js'
|
|
21
|
+
import { CheckpointError, baseNames, fileOf, opfsDirError, readHeader, readSection, saveVersioned, versionsOf, withNewest } from './ckpt-file.js'
|
|
21
22
|
import { chainIntoFile, loadChain, saveDiff } from './ckpt-chain.js'
|
|
22
23
|
|
|
23
24
|
const DIR = 'wmd-ckpt'
|
|
24
25
|
const now = () => performance.now()
|
|
25
26
|
|
|
26
27
|
async function dir() {
|
|
27
|
-
|
|
28
|
+
let root
|
|
29
|
+
try {
|
|
30
|
+
root = await navigator.storage.getDirectory()
|
|
31
|
+
} catch (e) {
|
|
32
|
+
throw opfsDirError(e) // IOS-3: a private window's (ephemeral) store has none
|
|
33
|
+
}
|
|
28
34
|
return root.getDirectoryHandle(DIR, { create: true })
|
|
29
35
|
}
|
|
30
36
|
|
|
@@ -215,6 +221,9 @@ async function handle(m) {
|
|
|
215
221
|
} catch {}
|
|
216
222
|
return { writtenMB: Math.round(written / (1 << 20)), error: err && `${err} (at ${step})` }
|
|
217
223
|
}
|
|
224
|
+
case 'ready': // IOS-3: whether this page has an origin private file system here
|
|
225
|
+
await dir()
|
|
226
|
+
return {}
|
|
218
227
|
case 'usage': {
|
|
219
228
|
const e = await navigator.storage.estimate()
|
|
220
229
|
return { usage: e.usage, quota: e.quota }
|
package/src/host/ckpt.js
CHANGED
|
@@ -572,6 +572,15 @@ export function opfsStore({ workerUrl } = {}) {
|
|
|
572
572
|
async delete(name) {
|
|
573
573
|
await call({ op: 'delete', name })
|
|
574
574
|
},
|
|
575
|
+
/** IOS-3: resolves {ok: true} when this page has an origin private file system, else {ok: false, code, reason} (a private window has none) */
|
|
576
|
+
async available() {
|
|
577
|
+
try {
|
|
578
|
+
await call({ op: 'ready' })
|
|
579
|
+
return { ok: true }
|
|
580
|
+
} catch (e) {
|
|
581
|
+
return { ok: false, code: e.code || 'io', reason: e.message }
|
|
582
|
+
}
|
|
583
|
+
},
|
|
575
584
|
async usage() {
|
|
576
585
|
const r = await call({ op: 'usage' })
|
|
577
586
|
return { usage: r.usage, quota: r.quota }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// IOS-3: whether this page has an origin private file system. A private window, or an automated WebKit with an
|
|
2
|
+
// ephemeral data store, rejects navigator.storage.getDirectory() (UnknownError); where wmd itself picks OPFS (the base
|
|
3
|
+
// snapshot cache, the builder's disk) it then uses memory and says so in an event ({storage: 'memory', reason}).
|
|
4
|
+
|
|
5
|
+
const pageGetDirectory = () => (globalThis.navigator?.storage?.getDirectory ? () => globalThis.navigator.storage.getDirectory() : null)
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {{getDirectory?: (() => Promise<any>) | null}} o test hook: the getDirectory to try (null: there is none)
|
|
9
|
+
* @returns {Promise<{ok: true} | {ok: false, reason: string}>}
|
|
10
|
+
*/
|
|
11
|
+
export async function opfsAvailable({ getDirectory = pageGetDirectory() } = {}) {
|
|
12
|
+
if (typeof getDirectory !== 'function') return { ok: false, reason: 'navigator.storage.getDirectory is not in this browser' }
|
|
13
|
+
try {
|
|
14
|
+
await getDirectory()
|
|
15
|
+
return { ok: true }
|
|
16
|
+
} catch (e) {
|
|
17
|
+
return { ok: false, reason: `navigator.storage.getDirectory: ${e?.name || 'Error'}: ${e?.message || e}` }
|
|
18
|
+
}
|
|
19
|
+
}
|
package/wmdpack.wasm
CHANGED
|
Binary file
|