wasm-idle 1.0.5 → 1.0.7

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.
Files changed (112) hide show
  1. package/README.md +52 -5
  2. package/dist/index.d.ts +4 -1
  3. package/dist/index.js +2 -0
  4. package/dist/playground/assetBridge.d.ts +11 -2
  5. package/dist/playground/assetBridge.js +190 -46
  6. package/dist/playground/assets.d.ts +9 -1
  7. package/dist/playground/assets.js +29 -5
  8. package/dist/playground/awk.js +1 -0
  9. package/dist/playground/bash.d.ts +1 -0
  10. package/dist/playground/bash.js +7 -1
  11. package/dist/playground/bqn.js +1 -0
  12. package/dist/playground/bqnPreflight.d.ts +2 -1
  13. package/dist/playground/bqnPreflight.js +1 -0
  14. package/dist/playground/c3.js +1 -0
  15. package/dist/playground/cachedClang.d.ts +10 -0
  16. package/dist/playground/cachedClang.js +330 -0
  17. package/dist/playground/clang.d.ts +8 -0
  18. package/dist/playground/clang.js +47 -8
  19. package/dist/playground/clangWorkerProtocol.d.ts +57 -0
  20. package/dist/playground/clangWorkerProtocol.js +11 -0
  21. package/dist/playground/clojurescript.js +1 -0
  22. package/dist/playground/clojurescriptPreflight.d.ts +2 -1
  23. package/dist/playground/clojurescriptPreflight.js +1 -0
  24. package/dist/playground/compiledArtifactCache.d.ts +21 -0
  25. package/dist/playground/compiledArtifactCache.js +67 -0
  26. package/dist/playground/elixir.js +4 -1
  27. package/dist/playground/forth.js +1 -0
  28. package/dist/playground/forthPreflight.d.ts +2 -1
  29. package/dist/playground/forthPreflight.js +1 -0
  30. package/dist/playground/fortran.js +7 -1
  31. package/dist/playground/haskell.js +4 -1
  32. package/dist/playground/haskellAssets.d.ts +2 -1
  33. package/dist/playground/haskellAssets.js +8 -8
  34. package/dist/playground/index.d.ts +1 -1
  35. package/dist/playground/index.js +2 -2
  36. package/dist/playground/j.js +1 -0
  37. package/dist/playground/jPreflight.d.ts +2 -1
  38. package/dist/playground/jPreflight.js +1 -0
  39. package/dist/playground/janet.js +1 -0
  40. package/dist/playground/java.js +20 -8
  41. package/dist/playground/julia.js +1 -0
  42. package/dist/playground/lfortranAssets.d.ts +2 -1
  43. package/dist/playground/lfortranAssets.js +1 -0
  44. package/dist/playground/lisp.js +4 -1
  45. package/dist/playground/lispAssets.d.ts +2 -1
  46. package/dist/playground/lispAssets.js +10 -0
  47. package/dist/playground/lldbManifest.d.ts +2 -2
  48. package/dist/playground/lldbManifest.js +17 -3
  49. package/dist/playground/lldbSession.d.ts +1 -0
  50. package/dist/playground/lldbSession.js +2 -1
  51. package/dist/playground/nim.js +1 -0
  52. package/dist/playground/ocaml.d.ts +1 -0
  53. package/dist/playground/ocaml.js +12 -1
  54. package/dist/playground/options.d.ts +2 -0
  55. package/dist/playground/pascal.js +1 -0
  56. package/dist/playground/perl.js +1 -0
  57. package/dist/playground/prolog.js +1 -0
  58. package/dist/playground/python.d.ts +7 -0
  59. package/dist/playground/python.js +41 -8
  60. package/dist/playground/runtimeAssetCache.d.ts +26 -0
  61. package/dist/playground/runtimeAssetCache.js +84 -0
  62. package/dist/playground/runtimeSession.d.ts +21 -0
  63. package/dist/playground/runtimeSession.js +119 -0
  64. package/dist/playground/rust.d.ts +1 -0
  65. package/dist/playground/rust.js +11 -1
  66. package/dist/playground/rustExecutableGraph.d.ts +1 -0
  67. package/dist/playground/rustExecutableGraph.js +1 -0
  68. package/dist/playground/staticRuntimePreflight.d.ts +2 -1
  69. package/dist/playground/staticRuntimePreflight.js +4 -2
  70. package/dist/playground/staticRuntimePreflightExecute.js +1 -0
  71. package/dist/playground/staticRuntimePreflightProtocol.d.ts +2 -1
  72. package/dist/playground/staticWorkerRuntime.d.ts +3 -1
  73. package/dist/playground/staticWorkerRuntime.js +44 -3
  74. package/dist/playground/tcl.js +1 -0
  75. package/dist/playground/tinygo.d.ts +2 -0
  76. package/dist/playground/tinygo.js +57 -3
  77. package/dist/playground/tinygoExecutableGraph.d.ts +4 -1
  78. package/dist/playground/tinygoExecutableGraph.js +59 -7
  79. package/dist/playground/typescript.js +4 -1
  80. package/dist/playground/wasmGoVersion.d.ts +1 -1
  81. package/dist/playground/wasmGoVersion.js +1 -1
  82. package/dist/playground/wasmOcamlVersion.d.ts +2 -2
  83. package/dist/playground/wasmOcamlVersion.js +1 -1
  84. package/dist/playground/wasmRustVersion.d.ts +90 -24
  85. package/dist/playground/wasmRustVersion.js +98 -23
  86. package/dist/playground/wasmTinyGoVersion.d.ts +40 -29
  87. package/dist/playground/wasmTinyGoVersion.js +43 -31
  88. package/dist/playground/worker/assets.d.ts +3 -0
  89. package/dist/playground/worker/assets.js +41 -0
  90. package/dist/playground/worker/cachedClangCompile.d.ts +1 -0
  91. package/dist/playground/worker/cachedClangCompile.js +85 -0
  92. package/dist/playground/worker/cachedClangExecute.d.ts +1 -0
  93. package/dist/playground/worker/cachedClangExecute.js +67 -0
  94. package/dist/playground/worker/clang.js +2 -8
  95. package/dist/playground/worker/clangStreaming.d.ts +1 -1
  96. package/dist/playground/worker/clangStreaming.js +20 -2
  97. package/dist/playground/worker/elixir.js +10 -8
  98. package/dist/playground/worker/fortran.js +4 -7
  99. package/dist/playground/worker/haskell.js +2 -0
  100. package/dist/playground/worker/lisp.js +2 -0
  101. package/dist/playground/worker/ocaml.js +13 -1
  102. package/dist/playground/worker/python.js +3 -2
  103. package/dist/playground/worker/runtimeAssetFetch.d.ts +11 -1
  104. package/dist/playground/worker/runtimeAssetFetch.js +64 -1
  105. package/dist/playground/worker/runtimeModule.d.ts +8 -0
  106. package/dist/playground/worker/runtimeModule.js +49 -0
  107. package/dist/playground/worker/rust.js +9 -2
  108. package/dist/playground/worker/staticRuntimePreflight.js +2 -0
  109. package/dist/playground/worker/typescript.js +4 -1
  110. package/dist/playground/worker/zig.js +7 -4
  111. package/dist/playground/zig.js +4 -1
  112. package/package.json +10 -7
@@ -2,7 +2,7 @@ import { waitForBufferedStdin } from '../stdinBuffer';
2
2
  import { isSharedBufferBackedView } from '../sharedBuffer';
3
3
  import { snapshotRustNonDebugResourceLimits } from '../rustWorkerLimits';
4
4
  import { WASM_RUST_EXECUTABLE_GRAPH_PROFILE, WASM_RUST_RUNTIME_PROFILE } from '../wasmRustVersion';
5
- import { createRuntimeAssetDeliveryBudget } from '@wasm-idle/core';
5
+ import { createRuntimeAssetDeliveryBudget, createRuntimeAssetCacheBackend, resolveRuntimeAssetCacheOptions } from '@wasm-idle/core';
6
6
  const lowercaseSha256Pattern = /^[0-9a-f]{64}$/u;
7
7
  const testOnlyCompilerModuleImporter = import.meta.env.MODE === 'test'
8
8
  ? globalThis.__WASM_IDLE_TEST_ONLY_RUST_COMPILER_MODULE_IMPORTER__
@@ -27,6 +27,7 @@ let loadedCompilerUrl = '';
27
27
  let loadedExecutableGraphFingerprint = '';
28
28
  let acceptedCompilerBootstrap = false;
29
29
  let activeExecution = false;
30
+ let persistentCacheBaseline;
30
31
  let compilerPromise = null;
31
32
  let compiledArtifact = null;
32
33
  let compiledCacheKey = '';
@@ -402,7 +403,7 @@ function createRustDebugHost(options) {
402
403
  };
403
404
  }
404
405
  self.onmessage = async (event) => {
405
- const { load, compilerUrl: nextCompilerUrl, runtimeProfile: nextRuntimeProfile, verifiedModuleUrls: nextVerifiedModuleUrls, executableGraphFingerprint: nextExecutableGraphFingerprint, debugModuleUrl: nextDebugModuleUrl, buffer, debugBuffer, code, prepare, args = [], stdin, targetTriple = 'wasm32-wasip1', log, debug = false, debugMode: requestedDebugMode, breakpoints = [], pauseOnEntry = false, limits: executionLimits } = event.data;
406
+ const { load, persistentCache, compilerUrl: nextCompilerUrl, runtimeProfile: nextRuntimeProfile, verifiedModuleUrls: nextVerifiedModuleUrls, executableGraphFingerprint: nextExecutableGraphFingerprint, debugModuleUrl: nextDebugModuleUrl, buffer, debugBuffer, code, prepare, args = [], stdin, targetTriple = 'wasm32-wasip1', log, debug = false, debugMode: requestedDebugMode, breakpoints = [], pauseOnEntry = false, limits: executionLimits } = event.data;
406
407
  let ownsExecution = false;
407
408
  try {
408
409
  if (load) {
@@ -410,6 +411,7 @@ self.onmessage = async (event) => {
410
411
  throw new Error('wasm-rust application worker accepts exactly one bootstrap');
411
412
  }
412
413
  acceptedCompilerBootstrap = true;
414
+ persistentCacheBaseline = resolveRuntimeAssetCacheOptions(persistentCache);
413
415
  compilerUrl = nextCompilerUrl;
414
416
  debugModuleUrl = nextDebugModuleUrl;
415
417
  runtimeProfile = nextRuntimeProfile || null;
@@ -430,6 +432,10 @@ self.onmessage = async (event) => {
430
432
  }
431
433
  activeExecution = true;
432
434
  ownsExecution = true;
435
+ const executionCache = resolveRuntimeAssetCacheOptions(persistentCacheBaseline, persistentCache);
436
+ const assetCache = executionCache.enabled
437
+ ? createRuntimeAssetCacheBackend(executionCache)
438
+ : undefined;
433
439
  const debugMode = requestedDebugMode === undefined ? (debug ? 'trace' : 'none') : requestedDebugMode;
434
440
  if (debugMode !== 'none' && debugMode !== 'trace' && debugMode !== 'lldb') {
435
441
  throw new Error(`Unsupported Rust debug mode: ${String(debugMode)}`);
@@ -481,6 +487,7 @@ self.onmessage = async (event) => {
481
487
  console.log(`[wasm-idle:rust-worker] compile start prepare=${String(prepare)} target=${targetTriple} bytes=${compileCode.length}`);
482
488
  }
483
489
  const result = await runtime.compiler.compile({
490
+ ...(assetCache ? { assetCache } : {}),
484
491
  code: compileCode,
485
492
  debugMode,
486
493
  ...(nonDebugResourceLimits
@@ -1,3 +1,4 @@
1
+ import { configureRuntimeAssetCache } from '@wasm-idle/core';
1
2
  import { executeStaticRuntimePreflight } from '../staticRuntimePreflightExecute';
2
3
  import { STATIC_RUNTIME_PREFLIGHT_PROTOCOL_VERSION, collectStaticRuntimePreflightTransferables, serializeStaticRuntimePreflightError } from '../staticRuntimePreflightProtocol';
3
4
  const workerSelf = globalThis;
@@ -29,6 +30,7 @@ workerSelf.onmessage = async (event) => {
29
30
  return;
30
31
  handled = true;
31
32
  try {
33
+ configureRuntimeAssetCache(request.persistentCache ?? false);
32
34
  const payload = await executeStaticRuntimePreflight(request, (progress) => {
33
35
  workerSelf.postMessage({
34
36
  protocolVersion: STATIC_RUNTIME_PREFLIGHT_PROTOCOL_VERSION,
@@ -1,6 +1,6 @@
1
1
  import { waitForBufferedStdin } from '../stdinBuffer';
2
2
  import { fetchRuntimeAssetBytes } from './runtimeAssetFetch';
3
- import { verifyRuntimeAssetIntegrity } from '@wasm-idle/core';
3
+ import { configureRuntimeAssetCache, verifyRuntimeAssetIntegrity } from '@wasm-idle/core';
4
4
  let stdinBufferTypeScript = null;
5
5
  let moduleUrl = '';
6
6
  let moduleReceipt = null;
@@ -69,6 +69,8 @@ async function loadRuntime(urlValue, receiptValue, maxAssetBytesValue) {
69
69
  const bytes = await fetchRuntimeAssetBytes({
70
70
  url,
71
71
  label: 'TypeScript runtime module',
72
+ expected: receipt,
73
+ integrityContext: { runtimeId: 'TYPESCRIPT' },
72
74
  maxAssetBytes: receipt.bytes
73
75
  });
74
76
  await verifyRuntimeAssetIntegrity({
@@ -133,6 +135,7 @@ self.onmessage = async (event) => {
133
135
  const { load, moduleUrl: nextModuleUrl, moduleReceipt: nextModuleReceipt, maxAssetBytes: nextMaxAssetBytes, buffer, code, prepare, args = [], stdin, language = 'typescript', activePath = language === 'typescript' ? 'main.ts' : 'main.js', workspaceFiles = [], log } = event.data;
134
136
  try {
135
137
  if (load) {
138
+ configureRuntimeAssetCache(event.data.persistentCache ?? {});
136
139
  const configuredModuleUrl = requireModuleUrl(nextModuleUrl);
137
140
  const configuredModuleReceipt = snapshotModuleReceipt(nextModuleReceipt);
138
141
  const configuredMaxAssetBytes = requireMaxAssetBytes(nextMaxAssetBytes);
@@ -1,6 +1,6 @@
1
1
  import { ConsoleStdout, Directory, Fd, File, OpenFile, PreopenDirectory, WASI, wasi } from '@bjorn3/browser_wasi_shim';
2
2
  import { decompressGzip, untar } from '@wasm-idle/llvm-core';
3
- import { verifyRuntimeAssetIntegrity } from '@wasm-idle/core';
3
+ import { configureRuntimeAssetCache, verifyRuntimeAssetIntegrity } from '@wasm-idle/core';
4
4
  import { waitForBufferedStdin } from '../stdinBuffer';
5
5
  import { snapshotZigExecutionAssetReceipts } from '../zigAssets';
6
6
  import { fetchRuntimeAssetBytes, resolveRuntimeAssetUrl } from './runtimeAssetFetch';
@@ -138,10 +138,12 @@ function buildWorkspaceRoot(code, activePath, workspaceFiles) {
138
138
  addFileToDirectory(root, entryPath, encoder.encode(code));
139
139
  return { root, entryPath };
140
140
  }
141
- async function fetchBytes(url, asset, maxAssetBytes, progressStart, progressEnd) {
141
+ async function fetchBytes(url, asset, maxAssetBytes, progressStart, progressEnd, expected) {
142
142
  const data = await fetchRuntimeAssetBytes({
143
143
  url,
144
144
  label: asset,
145
+ expected,
146
+ integrityContext: { asset, runtimeId: 'ZIG' },
145
147
  maxAssetBytes,
146
148
  onProgress: ({ loaded, total }) => {
147
149
  if (total && total > 0) {
@@ -398,8 +400,8 @@ async function loadAssets(nextCompilerUrl, nextStdlibUrl, nextIntegrity, maxAsse
398
400
  const pending = (async () => {
399
401
  postProgress(5);
400
402
  const [compilerBytes, stdlibBytes] = await Promise.all([
401
- fetchBytes(nextCompilerUrl, 'zig_small.wasm', receipts['zig_small.wasm'].bytes, 5, 45),
402
- fetchBytes(nextStdlibUrl, 'std.tar.gz', Math.max(receipts['std.tar.gz'].bytes, receipts['std.tar.gz'].uncompressedBytes || 0), 45, 70)
403
+ fetchBytes(nextCompilerUrl, 'zig_small.wasm', receipts['zig_small.wasm'].bytes, 5, 45, receipts['zig_small.wasm']),
404
+ fetchBytes(nextStdlibUrl, 'std.tar.gz', Math.max(receipts['std.tar.gz'].bytes, receipts['std.tar.gz'].uncompressedBytes || 0), 45, 70, receipts['std.tar.gz'])
403
405
  ]);
404
406
  await verifyRuntimeAssetIntegrity({
405
407
  asset: 'zig_small.wasm',
@@ -526,6 +528,7 @@ self.onmessage = async (event) => {
526
528
  const { load, compilerUrl: nextCompilerUrl, stdlibUrl: nextStdlibUrl, integrity: nextIntegrity, maxAssetBytes: nextMaxAssetBytes, buffer, code, prepare, args = [], compileArgs = [], stdin, activePath = 'main.zig', workspaceFiles = [], targetTriple = 'wasm64-wasi', log } = event.data;
527
529
  try {
528
530
  if (load) {
531
+ configureRuntimeAssetCache(event.data.persistentCache ?? {});
529
532
  if (log) {
530
533
  console.log(`[wasm-idle:zig-worker] load compilerUrl=${nextCompilerUrl} stdlibUrl=${nextStdlibUrl}`);
531
534
  }
@@ -2,7 +2,7 @@ import { resolveSandboxExecutionArgs } from './options';
2
2
  import { resolveZigCompilerUrl, resolveZigStdlibUrl } from './assets';
3
3
  import { snapshotZigExecutionAssetReceipts } from './zigAssets';
4
4
  import { WASM_ZIG_ASSET_RECEIPTS } from './wasmZigVersion';
5
- import { BusyError, CancelledError, DEFAULT_WORKSPACE_LIMITS, DiagnosticLimitError, OutputLimitError, RuntimeConfigurationError, TimeoutError, resolveExecutionLimits, validateExecutionWorkspace } from '@wasm-idle/core';
5
+ import { BusyError, CancelledError, DEFAULT_WORKSPACE_LIMITS, DiagnosticLimitError, OutputLimitError, RuntimeConfigurationError, TimeoutError, resolveExecutionLimits, resolveRuntimeAssetCacheOptions, validateExecutionWorkspace } from '@wasm-idle/core';
6
6
  import { flushBufferedEof, flushQueuedStdin, resetBufferedStdin } from './stdinBuffer';
7
7
  import { createWasmIdleSharedBuffer } from './sharedBuffer';
8
8
  import { WorkerSession } from './workerSession';
@@ -370,6 +370,9 @@ class Zig {
370
370
  worker.onmessage = handler;
371
371
  worker.postMessage({
372
372
  load: true,
373
+ persistentCache: resolveRuntimeAssetCacheOptions(typeof runtimeAssets === 'object'
374
+ ? runtimeAssets?.persistentCache
375
+ : undefined, options.persistentCache),
373
376
  compilerUrl: nextCompilerUrl,
374
377
  stdlibUrl: nextStdlibUrl,
375
378
  integrity: nextIntegrity,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wasm-idle",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "A simple web app to run code in the browser",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -61,15 +61,15 @@
61
61
  "vitest": "^4.1.4",
62
62
  "waforth": "0.20.1",
63
63
  "webr": "0.6.0",
64
- "@wasm-idle/debug": "1.0.5",
65
- "@wasm-idle/lsp": "1.0.5",
66
- "@wasm-idle/terminal": "1.0.5"
64
+ "@wasm-idle/debug": "1.0.7",
65
+ "@wasm-idle/terminal": "1.0.7",
66
+ "@wasm-idle/lsp": "1.0.7"
67
67
  },
68
68
  "dependencies": {
69
69
  "@bjorn3/browser_wasi_shim": "^0.4.2",
70
70
  "fflate": "0.8.3",
71
- "@wasm-idle/core": "1.0.5",
72
- "@wasm-idle/llvm-core": "1.0.5"
71
+ "@wasm-idle/core": "1.0.7",
72
+ "@wasm-idle/llvm-core": "1.0.7"
73
73
  },
74
74
  "files": [
75
75
  "dist",
@@ -190,8 +190,11 @@
190
190
  "sync:webr": "node scripts/sync-runtime.mjs webr",
191
191
  "compress:static-runtimes": "node scripts/compress-static-runtime-assets.mjs static",
192
192
  "compress:build-runtimes": "node scripts/compress-static-runtime-assets.mjs build",
193
+ "compact:build-runtimes": "node scripts/compact-runtime-aliases.mjs build",
193
194
  "layer:static-runtimes": "node scripts/build-layered-runtime-assets.mjs static",
194
195
  "asset:sizes": "node scripts/static-asset-sizes.mjs report",
196
+ "assets:lock": "node scripts/generate-runtime-asset-lock.mjs",
197
+ "check:assets-lock": "node scripts/generate-runtime-asset-lock.mjs --check",
195
198
  "check:asset-sizes": "node scripts/static-asset-sizes.mjs check",
196
199
  "build:page-runtimes": "node scripts/prepare-page-runtimes.mjs",
197
200
  "verify:wasm-typescript-freshness": "pnpm --dir runtimes/wasm-typescript build && node scripts/sync-wasm-typescript.mjs --verify",
@@ -201,7 +204,7 @@
201
204
  "support:matrix": "node scripts/support-matrix.mjs write",
202
205
  "check:support-matrix": "node scripts/support-matrix.mjs check",
203
206
  "sync:page-runtimes": "pnpm run sync:pyodide && pnpm run sync:webr && pnpm run sync:wasm-of-js-of-ocaml && pnpm run sync:wasm-typescript && pnpm run sync:wasm-octave && pnpm run sync:wasm-prolog && pnpm run sync:wasm-gleam && pnpm run sync:wasm-perl && pnpm run sync:wasm-tcl && pnpm run sync:wasm-awk && pnpm run sync:wasm-pascal && pnpm run sync:wasm-forth && pnpm run sync:wasm-j && pnpm run sync:wasm-bqn && pnpm run sync:wasm-janet && pnpm run sync:wasm-julia && pnpm run sync:wasm-nim && pnpm run sync:wasm-ruby && pnpm run sync:wasm-bash && pnpm run sync:wasm-clojurescript",
204
- "page:build": "pnpm run verify:page-c3 && pnpm run verify:page-lfortran && pnpm run prepare:test-assets -- clang && pnpm run build:page-runtimes && pnpm run sync:page-runtimes && pnpm run build:static-runtime-modules && pnpm run prepare:wasm-debug-release && pnpm run layer:static-runtimes && pnpm run compress:static-runtimes && pnpm run build && pnpm run compress:build-runtimes && pnpm run verify:page-c3 build && pnpm run verify:page-lfortran build",
207
+ "page:build": "pnpm run verify:page-c3 && pnpm run verify:page-lfortran && pnpm run prepare:test-assets -- clang && pnpm run build:page-runtimes && pnpm run sync:page-runtimes && pnpm run build:static-runtime-modules && pnpm run prepare:wasm-debug-release && pnpm run layer:static-runtimes && pnpm run compress:static-runtimes && pnpm run assets:lock && pnpm run check:assets-lock && pnpm run build && pnpm run compress:build-runtimes && pnpm run verify:page-c3 build && pnpm run verify:page-lfortran build",
205
208
  "package:root": "svelte-kit sync && node scripts/clean-package-output.mjs && svelte-package --tsconfig ./tsconfig.package.json && publint",
206
209
  "package": "pnpm run build:publish-deps && pnpm run package:root",
207
210
  "verify:package": "node scripts/verify-package.mjs",