wasm-idle 1.1.0 → 1.2.0

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 (197) hide show
  1. package/README.md +267 -112
  2. package/dist/container/bash-profile.d.ts +80 -0
  3. package/dist/container/bash-profile.js +328 -0
  4. package/dist/container/binding.d.ts +39 -0
  5. package/dist/container/binding.js +331 -0
  6. package/dist/container/clang-runtime.d.ts +42 -0
  7. package/dist/container/clang-runtime.js +561 -0
  8. package/dist/container/client.d.ts +14 -0
  9. package/dist/container/client.js +185 -0
  10. package/dist/container/explorer.d.ts +31 -0
  11. package/dist/container/explorer.js +112 -0
  12. package/dist/container/index.d.ts +11 -0
  13. package/dist/container/index.js +11 -0
  14. package/dist/container/owner-worker.d.ts +19 -0
  15. package/dist/container/owner-worker.js +464 -0
  16. package/dist/container/protocol.d.ts +84 -0
  17. package/dist/container/protocol.js +28 -0
  18. package/dist/container/runtime-adapter.d.ts +75 -0
  19. package/dist/container/runtime-adapter.js +537 -0
  20. package/dist/container/shell-control.d.ts +49 -0
  21. package/dist/container/shell-control.js +360 -0
  22. package/dist/container/workspace.d.ts +12 -0
  23. package/dist/container/workspace.js +29 -0
  24. package/dist/index.d.ts +1 -1
  25. package/dist/playground/assetBridge.js +111 -33
  26. package/dist/playground/assets.d.ts +10 -2
  27. package/dist/playground/c3.js +22 -0
  28. package/dist/playground/c3Memory.d.ts +19 -0
  29. package/dist/playground/c3Memory.js +117 -0
  30. package/dist/playground/cachedClang.js +143 -34
  31. package/dist/playground/clang.d.ts +5 -1
  32. package/dist/playground/clang.js +61 -5
  33. package/dist/playground/clangAssetIntegrity.js +6 -6
  34. package/dist/playground/clangWorkerProtocol.d.ts +12 -1
  35. package/dist/playground/cobol.d.ts +3 -0
  36. package/dist/playground/cobol.js +10 -1
  37. package/dist/playground/commonlispAssets.d.ts +2 -2
  38. package/dist/playground/compiledArtifactCache.d.ts +3 -1
  39. package/dist/playground/compiledArtifactCache.js +31 -5
  40. package/dist/playground/compiledLldb.d.ts +41 -0
  41. package/dist/playground/compiledLldb.js +167 -0
  42. package/dist/playground/d.d.ts +10 -2
  43. package/dist/playground/d.js +161 -14
  44. package/dist/playground/debugDeadline.d.ts +12 -0
  45. package/dist/playground/debugDeadline.js +34 -0
  46. package/dist/playground/debugMailbox.d.ts +12 -0
  47. package/dist/playground/debugMailbox.js +77 -0
  48. package/dist/playground/dotnet.js +6 -8
  49. package/dist/playground/fortran.d.ts +3 -0
  50. package/dist/playground/fortran.js +10 -1
  51. package/dist/playground/go.js +23 -7
  52. package/dist/playground/goDebugInstrumentation.js +207 -97
  53. package/dist/playground/java-debug-FMHDKUN6.js +124 -0
  54. package/dist/playground/java-debug-notices.txt +492 -0
  55. package/dist/playground/java.d.ts +17 -1
  56. package/dist/playground/java.js +162 -5
  57. package/dist/playground/javaDebug.d.ts +62 -0
  58. package/dist/playground/javaDebug.js +305 -0
  59. package/dist/playground/javaDebugBridge.d.ts +6 -0
  60. package/dist/playground/javaDebugBridge.js +250 -0
  61. package/dist/playground/javaDebugSource.d.ts +9 -0
  62. package/dist/playground/javaDebugSource.js +4 -0
  63. package/dist/playground/javaRuntimeErrors.d.ts +9 -0
  64. package/dist/playground/javaRuntimeErrors.js +93 -0
  65. package/dist/playground/lean4Assets.d.ts +1 -25
  66. package/dist/playground/lean4Assets.js +2 -123
  67. package/dist/playground/lfortran.js +10 -0
  68. package/dist/playground/lfortranAssets.d.ts +2 -2
  69. package/dist/playground/lldbSession.d.ts +23 -2
  70. package/dist/playground/lldbSession.js +278 -58
  71. package/dist/playground/lldbSourcePath.d.ts +2 -0
  72. package/dist/playground/lldbSourcePath.js +9 -0
  73. package/dist/playground/lua.d.ts +20 -1
  74. package/dist/playground/lua.js +190 -8
  75. package/dist/playground/luaDebug.d.ts +1 -0
  76. package/dist/playground/luaDebug.js +1 -0
  77. package/dist/playground/nim.d.ts +1 -0
  78. package/dist/playground/nim.js +30 -0
  79. package/dist/playground/objectivec.d.ts +10 -6
  80. package/dist/playground/objectivec.js +85 -10
  81. package/dist/playground/options.d.ts +12 -4
  82. package/dist/playground/python.d.ts +8 -1
  83. package/dist/playground/python.js +89 -6
  84. package/dist/playground/ruby.d.ts +10 -1
  85. package/dist/playground/ruby.js +66 -1
  86. package/dist/playground/rubyDebug.d.ts +21 -0
  87. package/dist/playground/rubyDebug.js +128 -0
  88. package/dist/playground/runtimeAssetCache.d.ts +1 -32
  89. package/dist/playground/runtimeAssetCache.js +1 -193
  90. package/dist/playground/runtimeSession.d.ts +2 -2
  91. package/dist/playground/runtimeSession.js +11 -11
  92. package/dist/playground/rust.d.ts +10 -0
  93. package/dist/playground/rust.js +230 -51
  94. package/dist/playground/sandbox.d.ts +8 -1
  95. package/dist/playground/staticStdinRing.d.ts +2 -1
  96. package/dist/playground/staticStdinRing.js +21 -10
  97. package/dist/playground/staticWorkerRuntime.d.ts +15 -1
  98. package/dist/playground/staticWorkerRuntime.js +127 -19
  99. package/dist/playground/stdinBuffer.d.ts +1 -1
  100. package/dist/playground/stdinBuffer.js +19 -2
  101. package/dist/playground/tinygo.d.ts +3 -0
  102. package/dist/playground/tinygo.js +88 -6
  103. package/dist/playground/typescript.js +8 -0
  104. package/dist/playground/v.d.ts +6 -2
  105. package/dist/playground/v.js +76 -13
  106. package/dist/playground/wasmAwkVersion.d.ts +13 -13
  107. package/dist/playground/wasmAwkVersion.js +4 -4
  108. package/dist/playground/wasmBqnVersion.d.ts +2 -2
  109. package/dist/playground/wasmBqnVersion.js +2 -2
  110. package/dist/playground/wasmC3Version.d.ts +2 -2
  111. package/dist/playground/wasmC3Version.js +2 -2
  112. package/dist/playground/wasmClojureScriptVersion.d.ts +2 -2
  113. package/dist/playground/wasmClojureScriptVersion.js +2 -2
  114. package/dist/playground/wasmCommonLispVersion.d.ts +2 -2
  115. package/dist/playground/wasmCommonLispVersion.js +2 -2
  116. package/dist/playground/wasmDIntegrity.d.ts +5 -5
  117. package/dist/playground/wasmDIntegrity.js +5 -5
  118. package/dist/playground/wasmDVersion.d.ts +16 -1
  119. package/dist/playground/wasmDVersion.js +16 -1
  120. package/dist/playground/wasmDebugVersion.d.ts +1 -1
  121. package/dist/playground/wasmDebugVersion.js +1 -1
  122. package/dist/playground/wasmForthVersion.d.ts +2 -2
  123. package/dist/playground/wasmForthVersion.js +2 -2
  124. package/dist/playground/wasmGleamVersion.d.ts +2 -2
  125. package/dist/playground/wasmGleamVersion.js +2 -2
  126. package/dist/playground/wasmGrainVersion.d.ts +2 -2
  127. package/dist/playground/wasmGrainVersion.js +2 -2
  128. package/dist/playground/wasmJVersion.d.ts +2 -2
  129. package/dist/playground/wasmJVersion.js +2 -2
  130. package/dist/playground/wasmJanetVersion.js +2 -2
  131. package/dist/playground/wasmJuliaVersion.js +2 -2
  132. package/dist/playground/wasmLean4Version.d.ts +1 -110
  133. package/dist/playground/wasmLean4Version.js +2 -111
  134. package/dist/playground/wasmLfortranVersion.d.ts +2 -2
  135. package/dist/playground/wasmLfortranVersion.js +2 -2
  136. package/dist/playground/wasmLuaVersion.d.ts +1 -1
  137. package/dist/playground/wasmLuaVersion.js +1 -1
  138. package/dist/playground/wasmNimVersion.d.ts +9 -9
  139. package/dist/playground/wasmNimVersion.js +6 -6
  140. package/dist/playground/wasmOcamlVersion.d.ts +2 -2
  141. package/dist/playground/wasmOcamlVersion.js +1 -1
  142. package/dist/playground/wasmPascalVersion.js +2 -2
  143. package/dist/playground/wasmPerlVersion.js +2 -2
  144. package/dist/playground/wasmPrologVersion.d.ts +2 -2
  145. package/dist/playground/wasmPrologVersion.js +2 -2
  146. package/dist/playground/wasmReScriptVersion.d.ts +2 -2
  147. package/dist/playground/wasmReScriptVersion.js +2 -2
  148. package/dist/playground/wasmRustVersion.d.ts +26 -38
  149. package/dist/playground/wasmRustVersion.js +25 -40
  150. package/dist/playground/wasmTclVersion.d.ts +4 -4
  151. package/dist/playground/wasmTclVersion.js +2 -2
  152. package/dist/playground/wasmTinyGoVersion.d.ts +14 -14
  153. package/dist/playground/wasmTinyGoVersion.js +14 -14
  154. package/dist/playground/wasmTypeScriptVersion.d.ts +5 -5
  155. package/dist/playground/wasmTypeScriptVersion.js +5 -5
  156. package/dist/playground/worker/cachedClangCompile.js +52 -4
  157. package/dist/playground/worker/cachedClangExecute.js +6 -5
  158. package/dist/playground/worker/clang.js +33 -11
  159. package/dist/playground/worker/cobol.js +3 -3
  160. package/dist/playground/worker/d.js +63 -7
  161. package/dist/playground/worker/fortran.js +3 -3
  162. package/dist/playground/worker/go.js +16 -5
  163. package/dist/playground/worker/haskell.js +10 -7
  164. package/dist/playground/worker/java.js +263 -45
  165. package/dist/playground/worker/javaDebugEvaluator.d.ts +16 -0
  166. package/dist/playground/worker/javaDebugEvaluator.js +44 -0
  167. package/dist/playground/worker/javaDebugRuntime.d.ts +24 -0
  168. package/dist/playground/worker/javaDebugRuntime.js +315 -0
  169. package/dist/playground/worker/javaOutput.d.ts +11 -0
  170. package/dist/playground/worker/javaOutput.js +54 -0
  171. package/dist/playground/worker/lua.js +15 -3
  172. package/dist/playground/worker/php.js +15 -9
  173. package/dist/playground/worker/python.js +102 -30
  174. package/dist/playground/worker/pythonExecution.js +17 -1
  175. package/dist/playground/worker/pythonWorkspaceFiles.d.ts +6 -0
  176. package/dist/playground/worker/pythonWorkspaceFiles.js +26 -0
  177. package/dist/playground/worker/pythonWorkspaceImports.d.ts +4 -0
  178. package/dist/playground/worker/pythonWorkspaceImports.js +129 -0
  179. package/dist/playground/worker/r.js +13 -6
  180. package/dist/playground/worker/ruby.js +13 -0
  181. package/dist/playground/worker/rubyDebugPreview.d.ts +2 -0
  182. package/dist/playground/worker/rubyDebugPreview.js +80 -0
  183. package/dist/playground/worker/rubyTracepoint.d.ts +16 -0
  184. package/dist/playground/worker/rubyTracepoint.js +162 -0
  185. package/dist/playground/worker/rust.js +38 -3
  186. package/dist/playground/worker/sqlite.js +4 -3
  187. package/dist/playground/worker/tinygo.js +11 -3
  188. package/dist/playground/worker/typescript.js +2 -3
  189. package/dist/playground/worker/v.js +32 -7
  190. package/dist/playground/worker/wat.js +2 -3
  191. package/dist/playground/worker/zig.js +20 -6
  192. package/dist/playground/workerSession.d.ts +1 -28
  193. package/dist/playground/workerSession.js +1 -164
  194. package/dist/playground/zig.js +4 -0
  195. package/package.json +66 -15
  196. package/dist/playground/worker/python.runtime.cases.d.ts +0 -1
  197. package/dist/playground/worker/python.runtime.cases.js +0 -374
@@ -4,7 +4,7 @@ import { RuntimeAssetCache } from './runtimeAssetCache';
4
4
  import { resolveDebugRuntimeUrls, resolveRuntimeAssetConfig } from './assets';
5
5
  import { LldbSandboxSession } from './lldbSession';
6
6
  import { normalizeDwarfWorkspacePath } from '@wasm-idle/llvm-core/clang';
7
- import { resolveExecutionLimits } from '@wasm-idle/core';
7
+ import { resolveExecutionLimits, normalizeDebugSourceBreakpoints, mergeDebugBreakpointLines, assertDebugBreakpointSupport } from '@wasm-idle/core';
8
8
  import { resolveSandboxExecutionArgs } from './options';
9
9
  import { bufferedSequence, flushBufferedEof, flushQueuedStdin, resetBufferedStdin, waitForBufferedSequenceChange } from './stdinBuffer';
10
10
  import { createWasmIdleSharedBuffer, requireSharedArrayBuffer } from './sharedBuffer';
@@ -47,6 +47,7 @@ class Clang {
47
47
  disposal;
48
48
  debugMode = 'none';
49
49
  lldbBreakpoints = new Map();
50
+ lldbBreakpointSpecifications = new Map();
50
51
  debugEvaluationQueue = Promise.resolve();
51
52
  // A helper worker builds the precompiled <bits/stdc++.h> so the warm worker stays free for
52
53
  // runs. The header is sent once to each warm worker, which keeps it for later compiles.
@@ -198,6 +199,9 @@ class Clang {
198
199
  if (this.disposed)
199
200
  return Promise.reject(new Error('Clang runtime has been disposed'));
200
201
  const debugMode = options.debugMode || (options.debug ? 'trace' : 'none');
202
+ if (debugMode !== 'none' && debugMode !== 'trace' && debugMode !== 'lldb') {
203
+ return Promise.reject(new Error(`${this.language} does not support ${debugMode} debugging.`));
204
+ }
201
205
  this.debugMode = debugMode;
202
206
  if (debugMode !== 'none')
203
207
  requireSharedArrayBuffer(`${this.language} debugging`);
@@ -213,14 +217,33 @@ class Clang {
213
217
  const { compileArgs, programArgs } = resolveSandboxExecutionArgs(this.language, args, options);
214
218
  const sourcePath = normalizeLldbSourcePath(options.debugPath || options.activePath, this.language === 'C' ? 'main.c' : 'main.cc');
215
219
  this.lldbBreakpoints.clear();
220
+ this.lldbBreakpointSpecifications.clear();
216
221
  if (debugMode === 'lldb') {
217
222
  for (const sourceBreakpoints of options.sourceBreakpoints || []) {
218
- this.setBreakpoints(sourceBreakpoints.lines, sourceBreakpoints.sourcePath);
223
+ if (sourceBreakpoints.breakpoints) {
224
+ const values = normalizeDebugSourceBreakpoints(sourceBreakpoints.breakpoints);
225
+ const path = normalizeLldbSourcePath(sourceBreakpoints.sourcePath, sourcePath.replace(/^\/workspace\//u, ''));
226
+ this.lldbBreakpointSpecifications.set(path, values);
227
+ this.lldbBreakpoints.set(path, values
228
+ .filter((value) => value.enabled !== false)
229
+ .map((value) => value.line));
230
+ }
231
+ else
232
+ this.setBreakpoints(sourceBreakpoints.lines, sourceBreakpoints.sourcePath);
219
233
  }
220
- this.setBreakpoints([...(options.breakpoints || [])], sourcePath);
234
+ if (!this.lldbBreakpointSpecifications.has(sourcePath))
235
+ this.setBreakpoints([...(options.breakpoints || [])], sourcePath);
221
236
  }
222
237
  else {
223
- this.setBreakpoints([...(options.breakpoints || [])], sourcePath);
238
+ for (const source of options.sourceBreakpoints || [])
239
+ if (source.breakpoints)
240
+ assertDebugBreakpointSupport(normalizeDebugSourceBreakpoints(source.breakpoints), {});
241
+ const source = options.sourceBreakpoints?.find((entry) => normalizeLldbSourcePath(entry.sourcePath, sourcePath.replace(/^\/workspace\//u, '')) === sourcePath);
242
+ this.setBreakpoints(source?.breakpoints
243
+ ? source.breakpoints
244
+ .filter((value) => value.enabled !== false)
245
+ .map((value) => value.line)
246
+ : [...(options.breakpoints || [])], sourcePath);
224
247
  }
225
248
  const interrupt = new Uint8Array(this.interruptBuffer), _uid = ++this.uid;
226
249
  const handler = (event) => {
@@ -256,9 +279,15 @@ class Clang {
256
279
  breakpoints: [...(options.breakpoints || [])],
257
280
  sourceBreakpoints: Array.from(this.lldbBreakpoints, ([sourcePath, lines]) => ({
258
281
  sourcePath,
259
- lines: [...lines]
282
+ lines: [...lines],
283
+ ...(this.lldbBreakpointSpecifications.has(sourcePath)
284
+ ? {
285
+ breakpoints: normalizeDebugSourceBreakpoints(this.lldbBreakpointSpecifications.get(sourcePath))
286
+ }
287
+ : {})
260
288
  })),
261
289
  pauseOnEntry: !!options.pauseOnEntry,
290
+ debugSteppingOptions: options.debugSteppingOptions,
262
291
  pauseAtMain: true,
263
292
  programArgs,
264
293
  stdin: options.stdin,
@@ -386,6 +415,8 @@ class Clang {
386
415
  return this.lldbSession.setBreakpoints(lines, resolvedSourcePath);
387
416
  }
388
417
  if (this.debugMode === 'lldb') {
418
+ if (this.lldbBreakpointSpecifications.has(resolvedSourcePath))
419
+ return this.setSourceBreakpoints(mergeDebugBreakpointLines(this.lldbBreakpointSpecifications.get(resolvedSourcePath), lines), resolvedSourcePath);
389
420
  this.lldbBreakpoints.set(resolvedSourcePath, [...lines]);
390
421
  return;
391
422
  }
@@ -399,6 +430,31 @@ class Clang {
399
430
  Atomics.store(control, 3, next.length);
400
431
  Atomics.add(control, 2, 1);
401
432
  }
433
+ async setSourceBreakpoints(breakpoints, sourcePath) {
434
+ const values = normalizeDebugSourceBreakpoints(breakpoints);
435
+ const path = normalizeLldbSourcePath(sourcePath, this.language === 'C' ? 'main.c' : 'main.cc');
436
+ if (this.lldbSession)
437
+ return this.lldbSession.setSourceBreakpoints(values, path);
438
+ if (this.debugMode === 'lldb') {
439
+ this.lldbBreakpointSpecifications.set(path, values);
440
+ this.lldbBreakpoints.set(path, values.filter((value) => value.enabled !== false).map((value) => value.line));
441
+ return;
442
+ }
443
+ assertDebugBreakpointSupport(values, {});
444
+ this.setBreakpoints(values.filter((value) => value.enabled !== false).map((value) => value.line), sourcePath);
445
+ }
446
+ async debugSetSteppingOptions(options) {
447
+ if (!this.lldbSession)
448
+ throw new Error('Stepping options require an LLDB session.');
449
+ await this.lldbSession.setSteppingOptions(options);
450
+ }
451
+ async debugEvaluateValue(expression, options) {
452
+ if (this.lldbSession)
453
+ return this.lldbSession.evaluateValue(expression, options);
454
+ if (options?.frameId !== undefined || options?.context === 'hover')
455
+ return { result: '?', variablesReference: 0 };
456
+ return { result: await this.debugEvaluate(expression), variablesReference: 0 };
457
+ }
402
458
  debugEvaluate(expression) {
403
459
  if (this.lldbSession)
404
460
  return this.lldbSession.evaluate(expression);
@@ -7,10 +7,10 @@ export const BUNDLED_CLANG_ASSET_INTEGRITY = Object.freeze({
7
7
  'runtime-manifest.v1.json': integrityEntry(967, '0b854bc6b41924420cfcc840509ecbe03af3c63ca3edd4940897917e32c8d8ad'),
8
8
  'libc-printscan-long-double.a.gz': integrityEntry(52_723, 'b3f11e17e40fb13371a97244fdde00d5bd951ad8e20dfdf88a069167d6be628b', 111_062, '33e04007d3547095068391b42189d1ac5398dd04e9da3118dfa644ffea7f4148'),
9
9
  'bin/memfs.wasm.gz': integrityEntry(16_111, 'a3e43451bc15ae69a7f113009e2ee82ab4db711625c1782cd45d0d3c4d38175a', 38_071, '5b741e03dd3502bcfd80e4e5055232b5d633604e1461752efed0189f93407dc3'),
10
- 'bin/clang.wasm.gz': integrityEntry(13_121_917, '8dc032057fbeb41e4a9986dfc54b2336c17532033dee172eb0095eba9c5fbe75', 35_658_969, 'd92ef06cdd3fea88acf384db15a6f2a344790c05bcba8e9f13f5b75b36ad4a99'),
11
- 'bin/lld.wasm.gz': integrityEntry(6_417_339, '495813efde8f354c38483749cdface7a7d9e23c8411da45a6f5f80030159eb11', 16_171_013, '34d39bc410c098e7e09933b61cc8e28699447af9a28abf4544d71b6e9cad1f9d'),
12
- 'bin/sysroot.tar.gz': integrityEntry(5_059_493, 'c0ef46e903492383a3c7069bfd4aed0e764e8df988f92bb81eb96bea50bf2c00', 19_312_640, 'e122f1acec0642d62d8976101c542aaa5346460df6eae5a3f8efb594ff32f5ae'),
13
- 'bin/c-sysroot.tar.gz': integrityEntry(1_216_797, 'fb3e1cdacac3eceddcfe2e57cbbf78e593ec2a298f01acb61c06e4b9d24fbbee', 3_736_064, '720c620e459025e918747768b9f5f1aef7b48c6df1b34c1a31fb2e5b1b7a213e'),
14
- 'bin/cpp-addon.tar.gz': integrityEntry(3_840_608, '47e9946c5aaeb3b35a1d42d6a80eae8987c596f4f858b207e492c00d8680af9e', 15_572_992, '7d61b724d377dc4e5670725055fb2884ebc8153d697e05093992004d5859310d'),
15
- 'language-sysroots.v1.json': integrityEntry(175_348, 'd69acbdb636009dc5b2243f13f1580264f64a34362f0af67c9cd661388b565d0')
10
+ 'bin/clang.wasm.gz': integrityEntry(13_124_999, 'cc7b6b229af392f439a1ca89dbb8d5e016792264a0a6ee59608ff24e269be982', 35_597_829, 'fe7c40c2369d4a1b91d87cd2a38b1a5be11cd7f381373b7888be0b5f209e2d5b'),
11
+ 'bin/lld.wasm.gz': integrityEntry(6_421_841, '798ce825f3e3cf9a695b6a049f157ba28d38731a3dc5e699ccdf23d69d3a5c20', 16_136_490, '77949fed32d5481979b8ebe6081009e3ec69c7219cb355e3f388a316746ea9b7'),
12
+ 'bin/sysroot.tar.gz': integrityEntry(6_780_412, '6188b500fa7af2dceadcbd6dcf2619b6935fa94c224c1c2078426666ebea1d50', 35_594_240, 'fb6d8a8786ec395009d44f62ff24a5bf09ff8672340b7dae9f48e28cf1569cba'),
13
+ 'bin/c-sysroot.tar.gz': integrityEntry(2_006_388, 'da7a29250b2fe2d928fa8818069ff67e1dcb26c529bbf01f40bbeb251535ecaa', 12_213_760, '517b32208f4e556b22eb5ac775411c39fb75239dfaf81f206e6052e168425b62'),
14
+ 'bin/cpp-addon.tar.gz': integrityEntry(4_776_509, '6e243c219561b1f5aad64db4a9ff8bbeb85a97b5e3b5df3ed71d8340d35a8cd7', 23_382_528, 'feaf2aa538623ec8c543ccb49e9a833d2a1aa6dee7a9ad502c277deba24ef642'),
15
+ 'language-sysroots.v1.json': integrityEntry(426_858, '08f6c2c87b4bebc9599193334e1d0ed322ebb38cbdd2bbb83d2b8c3a4cb61263')
16
16
  });
@@ -1,9 +1,11 @@
1
1
  import type { BrowserClangArtifact, BrowserClangCompileProgress, BrowserClangCompileRequest, BrowserClangPrecompiledHeader, BrowserClangWorkspaceFile } from '@wasm-idle/llvm-core/clang';
2
+ import type { CompilerDiagnostic } from '@wasm-idle/llvm-core/clang';
2
3
  import type { WorkerRuntimeAssetConfig } from './worker/assets';
3
4
  export type ClangCompileWorkerRequest = {
4
5
  request: Omit<BrowserClangCompileRequest, 'onProgress'>;
5
6
  runtimeBaseUrl: string;
6
7
  maxAssetBytes?: number;
8
+ maxOutputBytes?: number;
7
9
  languageSysroots?: boolean;
8
10
  log?: boolean;
9
11
  assets: WorkerRuntimeAssetConfig;
@@ -23,18 +25,27 @@ export type ClangCompileWorkerResponse = {
23
25
  artifact: BrowserClangArtifact;
24
26
  stdout: string;
25
27
  stderr: string;
28
+ diagnostics?: CompilerDiagnostic[];
26
29
  precompiledHeader?: 'building';
27
- } | {
30
+ } | ({
28
31
  type: 'error';
29
32
  error: string;
30
33
  stdout: string;
31
34
  stderr: string;
35
+ diagnostics?: CompilerDiagnostic[];
32
36
  precompiledHeader?: 'building';
37
+ } & ({
38
+ code?: undefined;
33
39
  } | {
40
+ code: 'output-limit';
41
+ limit: number;
42
+ actual: number;
43
+ })) | {
34
44
  type: 'precompiled-header';
35
45
  header?: BrowserClangPrecompiledHeader;
36
46
  };
37
47
  export type ClangExecuteWorkerRequest = {
48
+ maxWasmMemoryBytes?: number;
38
49
  artifact: BrowserClangArtifact;
39
50
  programArgs?: string[];
40
51
  env?: Record<string, string>;
@@ -1,4 +1,5 @@
1
1
  import { WorkerAssetBridge } from './assetBridge';
2
+ import type { RuntimeAssetCache } from './runtimeAssetCache';
2
3
  import { type PlaygroundRuntimeAssets } from './assets';
3
4
  import type { SandboxExecutionOptions } from './options';
4
5
  import type { Sandbox, SandboxProgress } from './sandbox';
@@ -18,10 +19,12 @@ declare class Cobol implements Sandbox {
18
19
  assetBridge: WorkerAssetBridge | null;
19
20
  activeCobolBaseUrl: string;
20
21
  private activeOperation;
22
+ private runtimeAssetCache?;
21
23
  private disposed;
22
24
  private disposePromise;
23
25
  private readonly disposeCancellation;
24
26
  private readonly workerSession;
27
+ setRuntimeAssetCache(cache: RuntimeAssetCache): void;
25
28
  private beginOperation;
26
29
  private isOperationActive;
27
30
  private releaseOperation;
@@ -26,6 +26,7 @@ class Cobol {
26
26
  assetBridge = null;
27
27
  activeCobolBaseUrl = '';
28
28
  activeOperation = null;
29
+ runtimeAssetCache;
29
30
  disposed = false;
30
31
  disposePromise = null;
31
32
  disposeCancellation = new CancelledError('COBOL sandbox disposed', {
@@ -53,6 +54,14 @@ class Cobol {
53
54
  this.pendingEof = false;
54
55
  }
55
56
  });
57
+ setRuntimeAssetCache(cache) {
58
+ if (this.runtimeAssetCache === cache)
59
+ return;
60
+ if (this.disposed || this.worker || this.activeOperation) {
61
+ throw new RuntimeConfigurationError('Cannot replace an active COBOL compiler cache');
62
+ }
63
+ this.runtimeAssetCache = cache;
64
+ }
56
65
  beginOperation(phase) {
57
66
  if (this.disposed) {
58
67
  throw new RuntimeConfigurationError('COBOL sandbox is disposed', {
@@ -303,7 +312,7 @@ class Cobol {
303
312
  }
304
313
  let assetBridge;
305
314
  try {
306
- assetBridge = new WorkerAssetBridge(worker, 'clang', clangAssets, progress, limits.maxAssetBytes);
315
+ assetBridge = new WorkerAssetBridge(worker, 'clang', clangAssets, progress, limits.maxAssetBytes, false, this.runtimeAssetCache);
307
316
  }
308
317
  catch (error) {
309
318
  try {
@@ -10,8 +10,8 @@ export declare function resolveCommonLispRuntimeAssetConfig(assets: string | Pla
10
10
  workerUrl: string;
11
11
  manifestFingerprint: "56f1eb7cf6470619cb3393e99d5c8ad1841a001ab758f388c006ca1d801ba071";
12
12
  workerReceipt: {
13
- readonly bytes: 11814;
14
- readonly sha256: "46b24c0fbde93dfaa71ddbce697d717c772ad8fd03f8486ad2102c41145606c6";
13
+ readonly bytes: 12104;
14
+ readonly sha256: "d179242c40cdce862ff45bb35f736eaf8e79b97bdc06754576406ad4de698b7d";
15
15
  };
16
16
  };
17
17
  export declare function preflightCommonLispRuntimeAssets(baseUrl: string, options: {
@@ -1,4 +1,5 @@
1
1
  import type { BrowserClangArtifact, BrowserClangCompileRequest } from '@wasm-idle/llvm-core/clang';
2
+ import type { CompilerDiagnostic } from '@wasm-idle/llvm-core/clang';
2
3
  /** Only immutable compiler output lives here, never a worker, instance, or filesystem. */
3
4
  export declare class CompiledArtifactCache {
4
5
  private entries;
@@ -9,7 +10,8 @@ export declare class CompiledArtifactCache {
9
10
  private maxBytes;
10
11
  constructor(maxEntries?: number, maxBytes?: number);
11
12
  get(key: string): BrowserClangArtifact | undefined;
12
- set(key: string, artifact: BrowserClangArtifact): void;
13
+ getDiagnostics(key: string): CompilerDiagnostic[];
14
+ set(key: string, artifact: BrowserClangArtifact, diagnostics?: CompilerDiagnostic[]): void;
13
15
  clear(): void;
14
16
  stats(): {
15
17
  hits: number;
@@ -1,3 +1,12 @@
1
+ function snapshotArtifact(artifact) {
2
+ const { bytes, wasm, ...metadata } = artifact;
3
+ return {
4
+ ...structuredClone(metadata),
5
+ // Compiled modules are immutable. Byte views must not retain an oversized backing buffer.
6
+ wasm,
7
+ bytes: ArrayBuffer.isView(bytes) ? Uint8Array.from(bytes) : bytes.slice(0)
8
+ };
9
+ }
1
10
  /** Only immutable compiler output lives here, never a worker, instance, or filesystem. */
2
11
  export class CompiledArtifactCache {
3
12
  entries = new Map();
@@ -7,6 +16,10 @@ export class CompiledArtifactCache {
7
16
  maxEntries;
8
17
  maxBytes;
9
18
  constructor(maxEntries = 8, maxBytes = 32 * 1024 * 1024) {
19
+ if (!Number.isSafeInteger(maxEntries) || maxEntries < 0)
20
+ throw new TypeError('Invalid compiled artifact cache maxEntries');
21
+ if (!Number.isSafeInteger(maxBytes) || maxBytes < 0)
22
+ throw new TypeError('Invalid compiled artifact cache maxBytes');
10
23
  this.maxEntries = maxEntries;
11
24
  this.maxBytes = maxBytes;
12
25
  }
@@ -19,17 +32,29 @@ export class CompiledArtifactCache {
19
32
  this.hits++;
20
33
  this.entries.delete(key);
21
34
  this.entries.set(key, entry);
22
- return entry.artifact;
35
+ return snapshotArtifact(entry.artifact);
36
+ }
37
+ getDiagnostics(key) {
38
+ return this.entries.get(key)?.diagnostics.map((diagnostic) => ({ ...diagnostic })) ?? [];
23
39
  }
24
- set(key, artifact) {
25
- const size = artifact.bytes.byteLength + key.length * 2;
40
+ set(key, artifact, diagnostics = []) {
41
+ // A zero budget disables retention without disabling compilation.
42
+ if (this.maxEntries === 0 || this.maxBytes === 0)
43
+ return;
44
+ const size = artifact.bytes.byteLength +
45
+ key.length * 2 +
46
+ (diagnostics.length ? JSON.stringify(diagnostics).length * 2 : 0);
26
47
  if (size > this.maxBytes)
27
48
  return;
28
49
  const old = this.entries.get(key);
29
50
  if (old)
30
51
  this.bytes -= old.size;
31
52
  this.entries.delete(key);
32
- this.entries.set(key, { artifact, size });
53
+ this.entries.set(key, {
54
+ artifact: snapshotArtifact(artifact),
55
+ diagnostics: diagnostics.map((diagnostic) => ({ ...diagnostic })),
56
+ size
57
+ });
33
58
  this.bytes += size;
34
59
  while (this.entries.size > this.maxEntries || this.bytes > this.maxBytes) {
35
60
  const oldest = this.entries.keys().next().value;
@@ -52,7 +77,7 @@ export class CompiledArtifactCache {
52
77
  }
53
78
  export function clangCompileKey(runtimeBaseUrl, maxAssetBytes, request, languageSysroots = false) {
54
79
  return JSON.stringify([
55
- 'wasm-idle/clang-cache-v2',
80
+ 'wasm-idle/clang-cache-v3',
56
81
  runtimeBaseUrl,
57
82
  maxAssetBytes,
58
83
  languageSysroots,
@@ -62,6 +87,7 @@ export function clangCompileKey(runtimeBaseUrl, maxAssetBytes, request, language
62
87
  request.compileArgs,
63
88
  request.cVersion,
64
89
  request.cppVersion,
90
+ request.maxWasmMemoryBytes,
65
91
  [...(request.workspaceFiles || [])].sort((a, b) => a.path.localeCompare(b.path))
66
92
  ]);
67
93
  }
@@ -0,0 +1,41 @@
1
+ import { type PlaygroundRuntimeAssets } from './assets';
2
+ import { LldbSandboxSession, type LldbArtifactPayload } from './lldbSession';
3
+ import type { DebugCommand, DebugDataBreakpoint, DebugDataBreakpointInfoArguments, DebugSessionEvent, SandboxExecutionOptions } from './options';
4
+ import { type DebugEvaluateOptions, type DebugSourceBreakpoint, type DebugSteppingOptions } from '@wasm-idle/core';
5
+ /** The common LLDB controls for compilers that hand a real DWARF module to WAMR. */
6
+ export declare class CompiledLldbSandbox {
7
+ output?: (data: string) => void;
8
+ ondebug?: (event: DebugSessionEvent) => void;
9
+ protected lldbSession?: LldbSandboxSession;
10
+ protected lldbPending: boolean;
11
+ protected lldbEntryFunction: string;
12
+ private lldbRuntime?;
13
+ private lldbSourcePath;
14
+ private readonly lldbBreakpoints;
15
+ private readonly lldbBreakpointSpecifications;
16
+ private lldbPersistentCache?;
17
+ protected configureLldb(runtimeAssets: string | PlaygroundRuntimeAssets, options: SandboxExecutionOptions): void;
18
+ protected prepareLldb(options: SandboxExecutionOptions, defaultPath: string): void;
19
+ protected lldbReloadAssets(): Pick<PlaygroundRuntimeAssets, 'debug' | 'persistentCache'>;
20
+ protected startLldb(artifact: LldbArtifactPayload, options: SandboxExecutionOptions, programArgs: string[], pendingInput: string[], pendingEof: boolean, onOutput?: (text: string) => void | undefined): Promise<true>;
21
+ protected stopLldb(): Promise<void> | undefined;
22
+ private sourcePath;
23
+ debugCommand(command: DebugCommand): Promise<void> | undefined;
24
+ debugPause(): Promise<void> | undefined;
25
+ setBreakpoints(lines: number[], sourcePath?: string): Promise<void> | undefined;
26
+ setSourceBreakpoints(breakpoints: DebugSourceBreakpoint[], sourcePath?: string): Promise<void>;
27
+ debugSetSteppingOptions(options: DebugSteppingOptions): Promise<void>;
28
+ debugEvaluateValue(expression: string, options?: DebugEvaluateOptions): Promise<import("@wasm-idle/core").DebugEvaluateResult>;
29
+ debugEvaluate(expression: string): Promise<string>;
30
+ debugVariables(reference: number, start?: number, count?: number): Promise<import("@wasm-idle/core").DebugVariable[]>;
31
+ debugScopes(frameId: number): Promise<import("@wasm-idle/core").DebugScope[]>;
32
+ debugFrameScopes(frameId: number): Promise<import("@wasm-idle/core").DebugScope[]>;
33
+ debugFrameName(frameId: number): Promise<string | null>;
34
+ debugReadMemory(reference: string, offset: number, count: number): Promise<import("@wasm-idle/core").DebugMemory | null>;
35
+ debugWriteMemory(reference: string, offset: number, data: Uint8Array, allowPartial?: boolean): Promise<{
36
+ offset?: number;
37
+ bytesWritten: number;
38
+ } | null>;
39
+ debugDataBreakpointInfo(arguments_: DebugDataBreakpointInfoArguments): Promise<import("@wasm-idle/core").DebugDataBreakpointInfo | null>;
40
+ debugSetDataBreakpoints(breakpoints: DebugDataBreakpoint[]): Promise<import("@wasm-idle/core").DebugResolvedDataBreakpoint[]>;
41
+ }
@@ -0,0 +1,167 @@
1
+ import { resolveDebugRuntimeUrls } from './assets';
2
+ import { LldbSandboxSession } from './lldbSession';
3
+ import { normalizeLldbWorkspacePath } from './lldbSourcePath';
4
+ import { mergeDebugBreakpointLines, normalizeDebugSourceBreakpoints } from '@wasm-idle/core';
5
+ /** The common LLDB controls for compilers that hand a real DWARF module to WAMR. */
6
+ export class CompiledLldbSandbox {
7
+ output;
8
+ ondebug;
9
+ lldbSession;
10
+ lldbPending = false;
11
+ lldbEntryFunction = 'main';
12
+ lldbRuntime;
13
+ lldbSourcePath = '/workspace/main';
14
+ lldbBreakpoints = new Map();
15
+ lldbBreakpointSpecifications = new Map();
16
+ lldbPersistentCache;
17
+ configureLldb(runtimeAssets, options) {
18
+ this.lldbRuntime = resolveDebugRuntimeUrls(runtimeAssets, typeof window !== 'undefined' ? window.location.href : '');
19
+ this.lldbPersistentCache =
20
+ options.persistentCache ??
21
+ (typeof runtimeAssets === 'object' ? runtimeAssets.persistentCache : undefined);
22
+ }
23
+ prepareLldb(options, defaultPath) {
24
+ this.lldbPending = true;
25
+ this.lldbSourcePath = this.sourcePath(options.debugPath || options.activePath || defaultPath);
26
+ this.lldbBreakpoints.clear();
27
+ this.lldbBreakpointSpecifications.clear();
28
+ for (const entry of options.sourceBreakpoints || []) {
29
+ const path = this.sourcePath(entry.sourcePath);
30
+ if (entry.breakpoints) {
31
+ const values = normalizeDebugSourceBreakpoints(entry.breakpoints);
32
+ this.lldbBreakpointSpecifications.set(path, values);
33
+ this.lldbBreakpoints.set(path, values.filter((value) => value.enabled !== false).map((value) => value.line));
34
+ }
35
+ else
36
+ this.lldbBreakpoints.set(path, [...entry.lines]);
37
+ }
38
+ if (!this.lldbBreakpoints.has(this.lldbSourcePath)) {
39
+ this.lldbBreakpoints.set(this.lldbSourcePath, [...(options.breakpoints || [])]);
40
+ }
41
+ }
42
+ lldbReloadAssets() {
43
+ return {
44
+ debug: this.lldbRuntime
45
+ ? {
46
+ baseUrl: this.lldbRuntime.baseUrl,
47
+ manifestUrl: this.lldbRuntime.manifestUrl,
48
+ manifestSha256: this.lldbRuntime.manifestReceipt?.sha256
49
+ }
50
+ : undefined,
51
+ persistentCache: this.lldbPersistentCache
52
+ };
53
+ }
54
+ startLldb(artifact, options, programArgs, pendingInput, pendingEof, onOutput = (text) => this.output?.(text)) {
55
+ if (!this.lldbRuntime)
56
+ throw new Error('LLDB runtime assets have not been configured.');
57
+ const session = new LldbSandboxSession({
58
+ manifestUrl: this.lldbRuntime.manifestUrl,
59
+ manifestReceipt: this.lldbRuntime.manifestReceipt,
60
+ runtimeBaseUrl: this.lldbRuntime.baseUrl,
61
+ persistentCache: options.persistentCache ?? this.lldbPersistentCache,
62
+ artifact,
63
+ sourcePath: this.lldbSourcePath,
64
+ breakpoints: [...(this.lldbBreakpoints.get(this.lldbSourcePath) || [])],
65
+ sourceBreakpoints: [...this.lldbBreakpoints].map(([sourcePath, lines]) => ({
66
+ sourcePath,
67
+ lines: [...lines],
68
+ ...(this.lldbBreakpointSpecifications.has(sourcePath)
69
+ ? {
70
+ breakpoints: normalizeDebugSourceBreakpoints(this.lldbBreakpointSpecifications.get(sourcePath))
71
+ }
72
+ : {})
73
+ })),
74
+ debugSteppingOptions: options.debugSteppingOptions,
75
+ pauseOnEntry: !!options.pauseOnEntry,
76
+ pauseAtMain: true,
77
+ entryFunctionName: this.lldbEntryFunction,
78
+ programArgs,
79
+ stdin: options.stdin,
80
+ onDebugEvent: (event) => this.ondebug?.(event),
81
+ onOutput
82
+ });
83
+ this.lldbSession = session;
84
+ for (const input of pendingInput.splice(0))
85
+ void session.write(input);
86
+ if (pendingEof)
87
+ void session.eof();
88
+ return session.start().finally(() => {
89
+ if (this.lldbSession === session) {
90
+ this.lldbSession = undefined;
91
+ this.lldbPending = false;
92
+ }
93
+ });
94
+ }
95
+ stopLldb() {
96
+ const session = this.lldbSession;
97
+ this.lldbSession = undefined;
98
+ this.lldbPending = false;
99
+ return session?.disconnect();
100
+ }
101
+ sourcePath(path) {
102
+ const normalized = normalizeLldbWorkspacePath(path);
103
+ if (!normalized)
104
+ throw new Error('LLDB requires a workspace source path.');
105
+ return `/workspace/${normalized}`;
106
+ }
107
+ debugCommand(command) {
108
+ return this.lldbSession?.debugCommand(command);
109
+ }
110
+ debugPause() {
111
+ return this.lldbSession?.pause();
112
+ }
113
+ setBreakpoints(lines, sourcePath) {
114
+ const path = sourcePath ? this.sourcePath(sourcePath) : this.lldbSourcePath;
115
+ if (this.lldbSession)
116
+ return this.lldbSession.setBreakpoints(lines, path);
117
+ if (this.lldbBreakpointSpecifications.has(path))
118
+ return this.setSourceBreakpoints(mergeDebugBreakpointLines(this.lldbBreakpointSpecifications.get(path), lines), path);
119
+ this.lldbBreakpoints.set(path, [...lines]);
120
+ }
121
+ async setSourceBreakpoints(breakpoints, sourcePath) {
122
+ const values = normalizeDebugSourceBreakpoints(breakpoints);
123
+ const path = sourcePath ? this.sourcePath(sourcePath) : this.lldbSourcePath;
124
+ if (this.lldbSession)
125
+ return this.lldbSession.setSourceBreakpoints(values, path);
126
+ this.lldbBreakpointSpecifications.set(path, values);
127
+ this.lldbBreakpoints.set(path, values.filter((value) => value.enabled !== false).map((value) => value.line));
128
+ }
129
+ async debugSetSteppingOptions(options) {
130
+ if (!this.lldbSession)
131
+ throw new Error('Stepping options require an LLDB session.');
132
+ await this.lldbSession.setSteppingOptions(options);
133
+ }
134
+ debugEvaluateValue(expression, options) {
135
+ return (this.lldbSession?.evaluateValue(expression, options) ??
136
+ Promise.reject(new Error('LLDB is not running.')));
137
+ }
138
+ debugEvaluate(expression) {
139
+ return (this.lldbSession?.evaluate(expression) ??
140
+ Promise.reject(new Error('LLDB is not running.')));
141
+ }
142
+ debugVariables(reference, start, count) {
143
+ return this.lldbSession?.variables(reference, start, count) ?? Promise.resolve([]);
144
+ }
145
+ debugScopes(frameId) {
146
+ return this.lldbSession?.scopes(frameId) ?? Promise.resolve([]);
147
+ }
148
+ debugFrameScopes(frameId) {
149
+ return this.lldbSession?.frameScopes(frameId) ?? Promise.resolve([]);
150
+ }
151
+ debugFrameName(frameId) {
152
+ return this.lldbSession?.formattedFrameName(frameId) ?? Promise.resolve(null);
153
+ }
154
+ debugReadMemory(reference, offset, count) {
155
+ return this.lldbSession?.readMemory(reference, offset, count) ?? Promise.resolve(null);
156
+ }
157
+ debugWriteMemory(reference, offset, data, allowPartial = false) {
158
+ return (this.lldbSession?.writeMemory(reference, offset, data, allowPartial) ??
159
+ Promise.resolve(null));
160
+ }
161
+ debugDataBreakpointInfo(arguments_) {
162
+ return this.lldbSession?.dataBreakpointInfo(arguments_) ?? Promise.resolve(null);
163
+ }
164
+ debugSetDataBreakpoints(breakpoints) {
165
+ return this.lldbSession?.setDataBreakpoints(breakpoints) ?? Promise.resolve([]);
166
+ }
167
+ }
@@ -1,7 +1,10 @@
1
1
  import { type PlaygroundRuntimeAssets, type ResolvedDRuntimeAssetConfig } from './assets';
2
+ import { CompiledLldbSandbox } from './compiledLldb';
3
+ import { RuntimeAssetCache } from '@wasm-idle/core';
2
4
  import { type CompilerDiagnostic, type SandboxExecutionOptions } from './options';
3
5
  import type { Sandbox, SandboxProgress } from './sandbox';
4
- declare class D implements Sandbox {
6
+ declare class D extends CompiledLldbSandbox implements Sandbox {
7
+ protected lldbEntryFunction: string;
5
8
  output: any;
6
9
  worker?: Worker;
7
10
  buffer: import("./sharedBuffer").WasmIdleSharedBuffer;
@@ -18,7 +21,10 @@ declare class D implements Sandbox {
18
21
  waitingForInput: boolean;
19
22
  pendingEof: boolean;
20
23
  private activeOperation;
24
+ private lldbAssets;
21
25
  private disposed;
26
+ private runtimeAssetCache;
27
+ private ownsRuntimeAssetCache;
22
28
  private disposePromise;
23
29
  private readonly disposeCancellation;
24
30
  private readonly workerSession;
@@ -37,8 +43,10 @@ declare class D implements Sandbox {
37
43
  write(input: string): void;
38
44
  eof(): void;
39
45
  private flushPendingInput;
40
- run(code: string, prepare: boolean, _log?: boolean, _prog?: SandboxProgress, args?: string[], options?: SandboxExecutionOptions): Promise<boolean | string>;
46
+ run(code: string, prepare: boolean, log?: boolean, progress?: SandboxProgress, args?: string[], options?: SandboxExecutionOptions): Promise<boolean | string>;
47
+ private runLoaded;
41
48
  private cancelOperation;
49
+ setRuntimeAssetCache(cache: RuntimeAssetCache): void;
42
50
  kill(): void;
43
51
  terminate(reason?: unknown): void;
44
52
  clear(): Promise<void>;