wasm-idle 0.7.2 → 1.0.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 (386) hide show
  1. package/README.md +760 -81
  2. package/dist/index.d.ts +4 -9
  3. package/dist/index.js +2 -4
  4. package/dist/playground/applicationAssets.d.ts +4 -0
  5. package/dist/playground/applicationAssets.js +277 -0
  6. package/dist/playground/assemblyscript.d.ts +41 -0
  7. package/dist/playground/assemblyscript.js +630 -0
  8. package/dist/playground/assetBridge.d.ts +18 -7
  9. package/dist/playground/assetBridge.js +824 -100
  10. package/dist/playground/assets.d.ts +813 -19
  11. package/dist/playground/assets.js +2096 -156
  12. package/dist/playground/awk.d.ts +5 -0
  13. package/dist/playground/awk.js +60 -0
  14. package/dist/playground/bash.d.ts +53 -0
  15. package/dist/playground/bash.js +1096 -0
  16. package/dist/playground/bashWorkerProtocol.d.ts +88 -0
  17. package/dist/playground/bashWorkerProtocol.js +135 -0
  18. package/dist/playground/bqn.d.ts +5 -0
  19. package/dist/playground/bqn.js +57 -0
  20. package/dist/playground/bqnPreflight.d.ts +26 -0
  21. package/dist/playground/bqnPreflight.js +399 -0
  22. package/dist/playground/c3.d.ts +15 -0
  23. package/dist/playground/c3.js +154 -0
  24. package/dist/playground/clang.d.ts +35 -19
  25. package/dist/playground/clang.js +241 -52
  26. package/dist/playground/clangAssetIntegrity.d.ts +32 -0
  27. package/dist/playground/clangAssetIntegrity.js +8 -0
  28. package/dist/playground/clojurescript.d.ts +5 -0
  29. package/dist/playground/clojurescript.js +59 -0
  30. package/dist/playground/clojurescriptPreflight.d.ts +26 -0
  31. package/dist/playground/clojurescriptPreflight.js +383 -0
  32. package/dist/playground/cobol.d.ts +46 -0
  33. package/dist/playground/cobol.js +703 -0
  34. package/dist/playground/d.d.ts +47 -0
  35. package/dist/playground/d.js +644 -0
  36. package/dist/playground/dOuterAssets.d.ts +16 -0
  37. package/dist/playground/dOuterAssets.js +163 -0
  38. package/dist/playground/dotnet.d.ts +99 -0
  39. package/dist/playground/dotnet.js +1131 -0
  40. package/dist/playground/duckdb.d.ts +36 -0
  41. package/dist/playground/duckdb.js +542 -0
  42. package/dist/playground/elixir.d.ts +18 -10
  43. package/dist/playground/elixir.js +630 -96
  44. package/dist/playground/elixirAssets.d.ts +6 -0
  45. package/dist/playground/elixirAssets.js +33 -0
  46. package/dist/playground/executionObservation.d.ts +22 -0
  47. package/dist/playground/executionObservation.js +65 -0
  48. package/dist/playground/forth.d.ts +5 -0
  49. package/dist/playground/forth.js +53 -0
  50. package/dist/playground/forthPreflight.d.ts +24 -0
  51. package/dist/playground/forthPreflight.js +198 -0
  52. package/dist/playground/fortran.d.ts +47 -0
  53. package/dist/playground/fortran.js +651 -0
  54. package/dist/playground/fortranAssets.d.ts +6 -0
  55. package/dist/playground/fortranAssets.js +27 -0
  56. package/dist/playground/gleam.d.ts +6 -0
  57. package/dist/playground/gleam.js +33 -0
  58. package/dist/playground/go.d.ts +17 -11
  59. package/dist/playground/go.js +376 -72
  60. package/dist/playground/goDebugInstrumentation.d.ts +1 -0
  61. package/dist/playground/goDebugInstrumentation.js +229 -0
  62. package/dist/playground/haskell.d.ts +44 -0
  63. package/dist/playground/haskell.js +678 -0
  64. package/dist/playground/haskellAssets.d.ts +24 -0
  65. package/dist/playground/haskellAssets.js +93 -0
  66. package/dist/playground/index.d.ts +1 -1
  67. package/dist/playground/index.js +360 -111
  68. package/dist/playground/j.d.ts +5 -0
  69. package/dist/playground/j.js +60 -0
  70. package/dist/playground/jPreflight.d.ts +26 -0
  71. package/dist/playground/jPreflight.js +372 -0
  72. package/dist/playground/janet.d.ts +5 -0
  73. package/dist/playground/janet.js +64 -0
  74. package/dist/playground/java.d.ts +24 -10
  75. package/dist/playground/java.js +706 -84
  76. package/dist/playground/javaSource.d.ts +5 -0
  77. package/dist/playground/javaSource.js +16 -0
  78. package/dist/playground/javaStdin.d.ts +1 -1
  79. package/dist/playground/javaStdin.js +13 -4
  80. package/dist/playground/julia.d.ts +5 -0
  81. package/dist/playground/julia.js +64 -0
  82. package/dist/playground/lfortran.d.ts +8 -0
  83. package/dist/playground/lfortran.js +30 -0
  84. package/dist/playground/lfortranAssets.d.ts +21 -0
  85. package/dist/playground/lfortranAssets.js +118 -0
  86. package/dist/playground/lisp.d.ts +45 -0
  87. package/dist/playground/lisp.js +640 -0
  88. package/dist/playground/lispAssets.d.ts +9 -0
  89. package/dist/playground/lispAssets.js +74 -0
  90. package/dist/playground/lldbManifest.d.ts +3 -0
  91. package/dist/playground/lldbManifest.js +155 -0
  92. package/dist/playground/lldbSession.d.ts +115 -0
  93. package/dist/playground/lldbSession.js +1347 -0
  94. package/dist/playground/loadingProgress.d.ts +16 -0
  95. package/dist/playground/loadingProgress.js +166 -0
  96. package/dist/playground/lua.d.ts +44 -0
  97. package/dist/playground/lua.js +630 -0
  98. package/dist/playground/nim.d.ts +5 -0
  99. package/dist/playground/nim.js +76 -0
  100. package/dist/playground/objectivec.d.ts +39 -0
  101. package/dist/playground/objectivec.js +288 -0
  102. package/dist/playground/ocaml.d.ts +28 -10
  103. package/dist/playground/ocaml.js +815 -253
  104. package/dist/playground/octave.d.ts +43 -0
  105. package/dist/playground/octave.js +783 -0
  106. package/dist/playground/options.d.ts +19 -40
  107. package/dist/playground/options.js +2 -1
  108. package/dist/playground/pascal.d.ts +5 -0
  109. package/dist/playground/pascal.js +60 -0
  110. package/dist/playground/perl.d.ts +5 -0
  111. package/dist/playground/perl.js +61 -0
  112. package/dist/playground/php.d.ts +44 -0
  113. package/dist/playground/php.js +665 -0
  114. package/dist/playground/prolog.d.ts +6 -0
  115. package/dist/playground/prolog.js +75 -0
  116. package/dist/playground/python.d.ts +20 -14
  117. package/dist/playground/python.js +445 -101
  118. package/dist/playground/pythonPackageLock.d.ts +6 -0
  119. package/dist/playground/pythonPackageLock.js +56 -0
  120. package/dist/playground/r.d.ts +44 -0
  121. package/dist/playground/r.js +637 -0
  122. package/dist/playground/ruby.d.ts +46 -0
  123. package/dist/playground/ruby.js +732 -0
  124. package/dist/playground/rubyAssets.d.ts +23 -0
  125. package/dist/playground/rubyAssets.js +68 -0
  126. package/dist/playground/rubyTestPreflight.d.ts +2 -0
  127. package/dist/playground/rubyTestPreflight.js +18 -0
  128. package/dist/playground/runtimeModule.d.ts +1 -0
  129. package/dist/playground/runtimeModule.js +5 -0
  130. package/dist/playground/rust.d.ts +44 -13
  131. package/dist/playground/rust.js +714 -76
  132. package/dist/playground/rustExecutableGraph.d.ts +85 -0
  133. package/dist/playground/rustExecutableGraph.js +946 -0
  134. package/dist/playground/rustWorkerLimits.d.ts +17 -0
  135. package/dist/playground/rustWorkerLimits.js +34 -0
  136. package/dist/playground/sandbox.d.ts +16 -10
  137. package/dist/playground/sharedBuffer.d.ts +6 -0
  138. package/dist/playground/sharedBuffer.js +12 -0
  139. package/dist/playground/sqlite.d.ts +38 -0
  140. package/dist/playground/sqlite.js +550 -0
  141. package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -0
  142. package/dist/playground/staticRuntimeModuleVersion.js +2 -0
  143. package/dist/playground/staticRuntimePreflight.d.ts +13 -0
  144. package/dist/playground/staticRuntimePreflight.js +231 -0
  145. package/dist/playground/staticRuntimePreflightExecute.d.ts +8 -0
  146. package/dist/playground/staticRuntimePreflightExecute.js +66 -0
  147. package/dist/playground/staticRuntimePreflightProtocol.d.ts +68 -0
  148. package/dist/playground/staticRuntimePreflightProtocol.js +339 -0
  149. package/dist/playground/staticStdinRing.d.ts +45 -0
  150. package/dist/playground/staticStdinRing.js +158 -0
  151. package/dist/playground/staticWorkerRuntime.d.ts +154 -0
  152. package/dist/playground/staticWorkerRuntime.js +1917 -0
  153. package/dist/playground/stdinBuffer.d.ts +9 -7
  154. package/dist/playground/stdinBuffer.js +9 -18
  155. package/dist/playground/swift.d.ts +5 -0
  156. package/dist/playground/swift.js +17 -0
  157. package/dist/playground/tcl.d.ts +5 -0
  158. package/dist/playground/tcl.js +62 -0
  159. package/dist/playground/teavmConfig.d.ts +1 -1
  160. package/dist/playground/teavmConfig.js +2 -2
  161. package/dist/playground/tinygo.d.ts +48 -18
  162. package/dist/playground/tinygo.js +1202 -329
  163. package/dist/playground/tinygoExecutableGraph.d.ts +44 -0
  164. package/dist/playground/tinygoExecutableGraph.js +449 -0
  165. package/dist/playground/typescript.d.ts +55 -0
  166. package/dist/playground/typescript.js +924 -0
  167. package/dist/playground/wasm.d.ts +43 -0
  168. package/dist/playground/wasm.js +608 -0
  169. package/dist/playground/wasmAwkVersion.d.ts +59 -0
  170. package/dist/playground/wasmAwkVersion.js +31 -0
  171. package/dist/playground/wasmBashVersion.d.ts +63 -0
  172. package/dist/playground/wasmBashVersion.js +36 -0
  173. package/dist/playground/wasmBqnVersion.d.ts +24 -0
  174. package/dist/playground/wasmBqnVersion.js +24 -0
  175. package/dist/playground/wasmC3Version.d.ts +20 -0
  176. package/dist/playground/wasmC3Version.js +21 -0
  177. package/dist/playground/wasmClojureScriptVersion.d.ts +21 -0
  178. package/dist/playground/wasmClojureScriptVersion.js +21 -0
  179. package/dist/playground/wasmDIntegrity.d.ts +15 -0
  180. package/dist/playground/wasmDIntegrity.js +15 -0
  181. package/dist/playground/wasmDVersion.d.ts +1 -0
  182. package/dist/playground/wasmDVersion.js +1 -0
  183. package/dist/playground/wasmDebugVersion.d.ts +6 -0
  184. package/dist/playground/wasmDebugVersion.js +6 -0
  185. package/dist/playground/wasmDotnetVersion.d.ts +1 -0
  186. package/dist/playground/wasmDotnetVersion.js +1 -0
  187. package/dist/playground/wasmElixirVersion.d.ts +21 -1
  188. package/dist/playground/wasmElixirVersion.js +21 -1
  189. package/dist/playground/wasmForthVersion.d.ts +18 -0
  190. package/dist/playground/wasmForthVersion.js +18 -0
  191. package/dist/playground/wasmFortranExecutionAssets.d.ts +15 -0
  192. package/dist/playground/wasmFortranExecutionAssets.js +15 -0
  193. package/dist/playground/wasmFortranVersion.d.ts +1 -0
  194. package/dist/playground/wasmFortranVersion.js +1 -0
  195. package/dist/playground/wasmGleamVersion.d.ts +5 -0
  196. package/dist/playground/wasmGleamVersion.js +5 -0
  197. package/dist/playground/wasmGoVersion.d.ts +1 -1
  198. package/dist/playground/wasmGoVersion.js +1 -1
  199. package/dist/playground/wasmHaskellVersion.d.ts +1 -0
  200. package/dist/playground/wasmHaskellVersion.js +1 -0
  201. package/dist/playground/wasmJVersion.d.ts +24 -0
  202. package/dist/playground/wasmJVersion.js +24 -0
  203. package/dist/playground/wasmJanetVersion.d.ts +53 -0
  204. package/dist/playground/wasmJanetVersion.js +30 -0
  205. package/dist/playground/wasmJuliaVersion.d.ts +71 -0
  206. package/dist/playground/wasmJuliaVersion.js +39 -0
  207. package/dist/playground/wasmLfortranVersion.d.ts +28 -0
  208. package/dist/playground/wasmLfortranVersion.js +29 -0
  209. package/dist/playground/wasmLispVersion.d.ts +1 -0
  210. package/dist/playground/wasmLispVersion.js +1 -0
  211. package/dist/playground/wasmLuaVersion.d.ts +1 -0
  212. package/dist/playground/wasmLuaVersion.js +1 -0
  213. package/dist/playground/wasmNimVersion.d.ts +125 -0
  214. package/dist/playground/wasmNimVersion.js +66 -0
  215. package/dist/playground/wasmObjectiveCVersion.d.ts +27 -0
  216. package/dist/playground/wasmObjectiveCVersion.js +27 -0
  217. package/dist/playground/wasmOcamlVersion.d.ts +12 -1
  218. package/dist/playground/wasmOcamlVersion.js +12 -1
  219. package/dist/playground/wasmOctaveVersion.d.ts +1 -0
  220. package/dist/playground/wasmOctaveVersion.js +1 -0
  221. package/dist/playground/wasmPascalVersion.d.ts +61 -0
  222. package/dist/playground/wasmPascalVersion.js +34 -0
  223. package/dist/playground/wasmPerlVersion.d.ts +71 -0
  224. package/dist/playground/wasmPerlVersion.js +39 -0
  225. package/dist/playground/wasmPrologVersion.d.ts +31 -0
  226. package/dist/playground/wasmPrologVersion.js +31 -0
  227. package/dist/playground/wasmRVersion.d.ts +1 -0
  228. package/dist/playground/wasmRVersion.js +1 -0
  229. package/dist/playground/wasmRustVersion.d.ts +1306 -1
  230. package/dist/playground/wasmRustVersion.js +1458 -1
  231. package/dist/playground/wasmSwiftVersion.d.ts +1 -0
  232. package/dist/playground/wasmSwiftVersion.js +1 -0
  233. package/dist/playground/wasmTclVersion.d.ts +85 -0
  234. package/dist/playground/wasmTclVersion.js +46 -0
  235. package/dist/playground/wasmTinyGoVersion.d.ts +98 -1
  236. package/dist/playground/wasmTinyGoVersion.js +107 -1
  237. package/dist/playground/wasmTypeScriptVersion.d.ts +5 -0
  238. package/dist/playground/wasmTypeScriptVersion.js +5 -0
  239. package/dist/playground/wasmWatVersion.d.ts +1 -0
  240. package/dist/playground/wasmWatVersion.js +1 -0
  241. package/dist/playground/wasmZigVersion.d.ts +13 -0
  242. package/dist/playground/wasmZigVersion.js +13 -0
  243. package/dist/playground/wat.d.ts +44 -0
  244. package/dist/playground/wat.js +622 -0
  245. package/dist/playground/worker/assemblyscript.js +339 -0
  246. package/dist/playground/worker/assets.d.ts +7 -0
  247. package/dist/playground/worker/assets.js +288 -39
  248. package/dist/playground/worker/bash.js +338 -0
  249. package/dist/playground/worker/bashNestedBootstrap.d.ts +6 -0
  250. package/dist/playground/worker/bashNestedBootstrap.js +59 -0
  251. package/dist/playground/worker/bashRuntime.d.ts +89 -0
  252. package/dist/playground/worker/bashRuntime.js +982 -0
  253. package/dist/playground/worker/clang.js +92 -13
  254. package/dist/playground/worker/cobol.js +107 -0
  255. package/dist/playground/worker/d.js +199 -0
  256. package/dist/playground/worker/dotnet.js +141 -0
  257. package/dist/playground/worker/duckdb.d.ts +1 -0
  258. package/dist/playground/worker/duckdb.js +136 -0
  259. package/dist/playground/worker/elixir.js +307 -41
  260. package/dist/playground/worker/fortran.d.ts +1 -0
  261. package/dist/playground/worker/fortran.js +295 -0
  262. package/dist/playground/worker/go.js +246 -40
  263. package/dist/playground/worker/haskell.d.ts +7 -0
  264. package/dist/playground/worker/haskell.js +465 -0
  265. package/dist/playground/worker/java.js +59 -20
  266. package/dist/playground/worker/lisp.d.ts +1 -0
  267. package/dist/playground/worker/lisp.js +195 -0
  268. package/dist/playground/worker/lua.d.ts +1 -0
  269. package/dist/playground/worker/lua.js +163 -0
  270. package/dist/playground/worker/objectivec.d.ts +1 -0
  271. package/dist/playground/worker/objectivec.js +10 -0
  272. package/dist/playground/worker/ocaml.js +206 -58
  273. package/dist/playground/worker/php.d.ts +1 -0
  274. package/dist/playground/worker/php.js +261 -0
  275. package/dist/playground/worker/python.js +201 -44
  276. package/dist/playground/worker/r.d.ts +1 -0
  277. package/dist/playground/worker/r.js +192 -0
  278. package/dist/playground/worker/ruby.d.ts +1 -0
  279. package/dist/playground/worker/ruby.js +248 -0
  280. package/dist/playground/worker/runtimeAssetFetch.d.ts +15 -0
  281. package/dist/playground/worker/runtimeAssetFetch.js +375 -0
  282. package/dist/playground/worker/rust.js +546 -20
  283. package/dist/playground/worker/sqlite.d.ts +1 -0
  284. package/dist/playground/worker/sqlite.js +112 -0
  285. package/dist/playground/worker/staticRuntimePreflight.d.ts +1 -0
  286. package/dist/playground/worker/staticRuntimePreflight.js +56 -0
  287. package/dist/playground/worker/tinygo.js +34 -9
  288. package/dist/playground/worker/typescript.d.ts +1 -0
  289. package/dist/playground/worker/typescript.js +251 -0
  290. package/dist/playground/worker/wasm.d.ts +1 -0
  291. package/dist/playground/worker/wasm.js +273 -0
  292. package/dist/playground/worker/wat.d.ts +1 -0
  293. package/dist/playground/worker/wat.js +188 -0
  294. package/dist/playground/worker/zig.d.ts +8 -0
  295. package/dist/playground/worker/zig.js +578 -0
  296. package/dist/playground/workerProgress.d.ts +15 -0
  297. package/dist/playground/workerProgress.js +72 -0
  298. package/dist/playground/workerSession.d.ts +28 -0
  299. package/dist/playground/workerSession.js +164 -0
  300. package/dist/playground/zig.d.ts +46 -0
  301. package/dist/playground/zig.js +690 -0
  302. package/dist/playground/zigAssets.d.ts +6 -0
  303. package/dist/playground/zigAssets.js +49 -0
  304. package/package.json +234 -105
  305. package/dist/clang/app.d.ts +0 -75
  306. package/dist/clang/app.js +0 -744
  307. package/dist/clang/apply.d.ts +0 -2
  308. package/dist/clang/apply.js +0 -11
  309. package/dist/clang/color.d.ts +0 -3
  310. package/dist/clang/color.js +0 -3
  311. package/dist/clang/encode.d.ts +0 -4
  312. package/dist/clang/encode.js +0 -20
  313. package/dist/clang/error.d.ts +0 -14
  314. package/dist/clang/error.js +0 -27
  315. package/dist/clang/gccCompat.d.ts +0 -15
  316. package/dist/clang/gccCompat.js +0 -767
  317. package/dist/clang/index.d.ts +0 -85
  318. package/dist/clang/index.js +0 -1077
  319. package/dist/clang/memory/index.d.ts +0 -4
  320. package/dist/clang/memory/index.js +0 -4
  321. package/dist/clang/memory/memFs.d.ts +0 -35
  322. package/dist/clang/memory/memFs.js +0 -132
  323. package/dist/clang/memory/memory.d.ts +0 -22
  324. package/dist/clang/memory/memory.js +0 -73
  325. package/dist/clang/memory/tar.d.ts +0 -2
  326. package/dist/clang/memory/tar.js +0 -59
  327. package/dist/clang/url.d.ts +0 -4
  328. package/dist/clang/url.js +0 -5
  329. package/dist/clang/wasm.d.ts +0 -4
  330. package/dist/clang/wasm.js +0 -50
  331. package/dist/clangd/config.d.ts +0 -18
  332. package/dist/clangd/config.js +0 -14
  333. package/dist/clangd/jsonStream.d.ts +0 -9
  334. package/dist/clangd/jsonStream.js +0 -48
  335. package/dist/clangd/session.d.ts +0 -18
  336. package/dist/clangd/session.js +0 -112
  337. package/dist/clangd/worker.js +0 -131
  338. package/dist/debug/controller.svelte.d.ts +0 -43
  339. package/dist/debug/controller.svelte.js +0 -268
  340. package/dist/debug/editor/index.d.ts +0 -2
  341. package/dist/debug/editor/index.js +0 -1
  342. package/dist/debug/editor/monaco.d.ts +0 -26
  343. package/dist/debug/editor/monaco.js +0 -128
  344. package/dist/debug/expression.d.ts +0 -26
  345. package/dist/debug/expression.js +0 -547
  346. package/dist/debug/index.d.ts +0 -8
  347. package/dist/debug/index.js +0 -5
  348. package/dist/debug/language/cpp.d.ts +0 -2
  349. package/dist/debug/language/cpp.js +0 -7
  350. package/dist/debug/language/index.d.ts +0 -3
  351. package/dist/debug/language/index.js +0 -2
  352. package/dist/debug/language/python.d.ts +0 -2
  353. package/dist/debug/language/python.js +0 -14
  354. package/dist/debug/language/types.d.ts +0 -6
  355. package/dist/debug/locals.d.ts +0 -2
  356. package/dist/debug/locals.js +0 -8
  357. package/dist/lsp/cpp/server.d.ts +0 -2
  358. package/dist/lsp/cpp/server.js +0 -68
  359. package/dist/lsp/index.d.ts +0 -5
  360. package/dist/lsp/index.js +0 -4
  361. package/dist/lsp/python/main.worker.js +0 -92
  362. package/dist/lsp/python/package/arcturus_python_lsp/__init__.py +0 -3
  363. package/dist/lsp/python/package/arcturus_python_lsp/server.py +0 -462
  364. package/dist/lsp/python/server.d.ts +0 -2
  365. package/dist/lsp/python/server.js +0 -54
  366. package/dist/lsp/registry.d.ts +0 -2
  367. package/dist/lsp/registry.js +0 -12
  368. package/dist/lsp/runtime.d.ts +0 -5
  369. package/dist/lsp/runtime.js +0 -31
  370. package/dist/lsp/types.d.ts +0 -17
  371. package/dist/terminal/Terminal.svelte +0 -422
  372. package/dist/terminal/Terminal.svelte.d.ts +0 -26
  373. package/dist/terminal/index.d.ts +0 -7
  374. package/dist/terminal/index.js +0 -5
  375. package/dist/terminal/plugin/index.d.ts +0 -9
  376. package/dist/terminal/plugin/index.js +0 -19
  377. package/dist/terminal/theme.d.ts +0 -49
  378. package/dist/terminal/theme.js +0 -49
  379. package/dist/terminal/types.d.ts +0 -18
  380. package/dist/utils/vscodeJsonrpcBrowser.d.ts +0 -5
  381. package/dist/utils/vscodeJsonrpcBrowser.js +0 -4
  382. /package/dist/{clangd/worker.d.ts → playground/worker/assemblyscript.d.ts} +0 -0
  383. /package/dist/{debug/language/types.js → playground/worker/bash.d.ts} +0 -0
  384. /package/dist/{lsp/python/main.worker.d.ts → playground/worker/cobol.d.ts} +0 -0
  385. /package/dist/{lsp/types.js → playground/worker/d.d.ts} +0 -0
  386. /package/dist/{terminal/types.js → playground/worker/dotnet.d.ts} +0 -0
@@ -1,34 +1,202 @@
1
1
  import { waitForBufferedStdin } from '../stdinBuffer';
2
+ import { isSharedBufferBackedView } from '../sharedBuffer';
3
+ import { snapshotRustNonDebugResourceLimits } from '../rustWorkerLimits';
4
+ import { WASM_RUST_EXECUTABLE_GRAPH_PROFILE, WASM_RUST_RUNTIME_PROFILE } from '../wasmRustVersion';
5
+ import { createRuntimeAssetDeliveryBudget } from '@wasm-idle/core';
6
+ const lowercaseSha256Pattern = /^[0-9a-f]{64}$/u;
7
+ const testOnlyCompilerModuleImporter = import.meta.env.MODE === 'test'
8
+ ? globalThis.__WASM_IDLE_TEST_ONLY_RUST_COMPILER_MODULE_IMPORTER__
9
+ : undefined;
10
+ const importRustCompilerModule = typeof testOnlyCompilerModuleImporter === 'function'
11
+ ? testOnlyCompilerModuleImporter
12
+ : (url) => import(/* @vite-ignore */ url);
2
13
  self.document = {
3
14
  querySelectorAll() {
4
15
  return [];
5
16
  }
6
17
  };
7
18
  let stdinBufferRust = null;
19
+ let debugBufferRust = null;
8
20
  let compilerUrl = '';
21
+ let debugModuleUrl = '';
9
22
  let runtimeBaseUrl = '';
23
+ let runtimeProfile = null;
24
+ let verifiedModuleUrls = null;
25
+ let executableGraphFingerprint = '';
10
26
  let loadedCompilerUrl = '';
27
+ let loadedExecutableGraphFingerprint = '';
28
+ let acceptedCompilerBootstrap = false;
29
+ let activeExecution = false;
11
30
  let compilerPromise = null;
12
31
  let compiledArtifact = null;
13
32
  let compiledCacheKey = '';
14
- async function loadCompiler(url) {
15
- if (!url) {
16
- throw new Error('Rust runtime is not configured. Set PUBLIC_WASM_RUST_COMPILER_URL or runtimeAssets.rust.compilerUrl.');
33
+ let compiledAssetDeliveryBudget = null;
34
+ let loadedDebugModuleUrl = '';
35
+ let debugInstrumenterPromise = null;
36
+ function compareCodeUnits(left, right) {
37
+ return left < right ? -1 : left > right ? 1 : 0;
38
+ }
39
+ function hasExactKeys(value, expected) {
40
+ return (JSON.stringify(Object.keys(value).sort(compareCodeUnits)) ===
41
+ JSON.stringify([...expected].sort(compareCodeUnits)));
42
+ }
43
+ function requireCanonicalBlobUrl(value, label) {
44
+ if (typeof value !== 'string')
45
+ throw new Error(`${label} must be a canonical Blob URL`);
46
+ let parsed;
47
+ try {
48
+ parsed = new URL(value);
17
49
  }
18
- if (loadedCompilerUrl === url && compilerPromise) {
19
- return await compilerPromise;
50
+ catch {
51
+ throw new Error(`${label} must be a canonical Blob URL`);
52
+ }
53
+ if (parsed.protocol !== 'blob:' ||
54
+ value.includes('?') ||
55
+ value.includes('#') ||
56
+ parsed.href !== value) {
57
+ throw new Error(`${label} must be a canonical Blob URL without a query or fragment`);
58
+ }
59
+ return value;
60
+ }
61
+ function snapshotRuntimeProfile(value) {
62
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
63
+ throw new Error('wasm-rust runtime profile must match the bundled receipt profile');
64
+ }
65
+ const profile = value;
66
+ if (!hasExactKeys(profile, [
67
+ 'manifestFingerprint',
68
+ 'manifestPath',
69
+ 'manifestReceipt',
70
+ 'moduleUrl',
71
+ 'profileId',
72
+ 'protocolVersion'
73
+ ]) ||
74
+ profile.profileId !== WASM_RUST_RUNTIME_PROFILE.profileId ||
75
+ profile.protocolVersion !== WASM_RUST_RUNTIME_PROFILE.protocolVersion ||
76
+ profile.manifestPath !== WASM_RUST_RUNTIME_PROFILE.manifestPath ||
77
+ profile.manifestFingerprint !== WASM_RUST_RUNTIME_PROFILE.manifestFingerprint ||
78
+ !profile.manifestReceipt ||
79
+ typeof profile.manifestReceipt !== 'object' ||
80
+ Array.isArray(profile.manifestReceipt)) {
81
+ throw new Error('wasm-rust runtime profile must match the bundled receipt profile');
82
+ }
83
+ const manifestReceipt = profile.manifestReceipt;
84
+ if (!hasExactKeys(manifestReceipt, ['bytes', 'sha256']) ||
85
+ manifestReceipt.bytes !== WASM_RUST_RUNTIME_PROFILE.manifestReceipt.bytes ||
86
+ manifestReceipt.sha256 !== WASM_RUST_RUNTIME_PROFILE.manifestReceipt.sha256) {
87
+ throw new Error('wasm-rust runtime profile receipt must match the bundled receipt profile');
20
88
  }
21
- loadedCompilerUrl = url;
89
+ if (typeof profile.moduleUrl !== 'string') {
90
+ throw new Error('wasm-rust runtime profile module URL is invalid');
91
+ }
92
+ let moduleUrl;
22
93
  try {
23
- runtimeBaseUrl = new URL('./runtime/', url).toString();
94
+ moduleUrl = new URL(profile.moduleUrl);
24
95
  }
25
96
  catch {
26
- runtimeBaseUrl = url;
97
+ throw new Error('wasm-rust runtime profile module URL is invalid');
98
+ }
99
+ const expectedQuery = `?v=${WASM_RUST_RUNTIME_PROFILE.manifestFingerprint}&rustManifestBytes=${WASM_RUST_RUNTIME_PROFILE.manifestReceipt.bytes}&rustManifestSha256=${WASM_RUST_RUNTIME_PROFILE.manifestReceipt.sha256}`;
100
+ if ((moduleUrl.protocol !== 'http:' && moduleUrl.protocol !== 'https:') ||
101
+ moduleUrl.username ||
102
+ moduleUrl.password ||
103
+ profile.moduleUrl.includes('#') ||
104
+ moduleUrl.href !== profile.moduleUrl ||
105
+ /%(?:2e|2f|5c)/iu.test(moduleUrl.pathname) ||
106
+ !moduleUrl.pathname.endsWith(`/${WASM_RUST_EXECUTABLE_GRAPH_PROFILE.entryPath}`) ||
107
+ moduleUrl.search !== expectedQuery) {
108
+ throw new Error('wasm-rust runtime profile module URL is invalid');
109
+ }
110
+ return Object.freeze({
111
+ profileId: WASM_RUST_RUNTIME_PROFILE.profileId,
112
+ protocolVersion: WASM_RUST_RUNTIME_PROFILE.protocolVersion,
113
+ manifestPath: WASM_RUST_RUNTIME_PROFILE.manifestPath,
114
+ manifestFingerprint: WASM_RUST_RUNTIME_PROFILE.manifestFingerprint,
115
+ manifestReceipt: Object.freeze({
116
+ bytes: WASM_RUST_RUNTIME_PROFILE.manifestReceipt.bytes,
117
+ sha256: WASM_RUST_RUNTIME_PROFILE.manifestReceipt.sha256
118
+ }),
119
+ moduleUrl: moduleUrl.href
120
+ });
121
+ }
122
+ function snapshotVerifiedModuleUrls(value, runtimeModuleUrl) {
123
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
124
+ throw new Error('wasm-rust verified module URL map is invalid');
125
+ }
126
+ const sourceModuleUrl = new URL(runtimeModuleUrl);
127
+ const sourceBaseUrl = new URL('./', sourceModuleUrl);
128
+ sourceBaseUrl.search = sourceModuleUrl.search;
129
+ const expectedNetworkUrls = Object.keys(WASM_RUST_EXECUTABLE_GRAPH_PROFILE.modules)
130
+ .sort(compareCodeUnits)
131
+ .map((modulePath) => {
132
+ const networkUrl = new URL(modulePath, sourceBaseUrl);
133
+ networkUrl.search = sourceModuleUrl.search;
134
+ return networkUrl.href;
135
+ })
136
+ .sort(compareCodeUnits);
137
+ const entries = Object.entries(value);
138
+ const actualNetworkUrls = entries.map(([networkUrl]) => networkUrl).sort(compareCodeUnits);
139
+ if (JSON.stringify(actualNetworkUrls) !== JSON.stringify(expectedNetworkUrls)) {
140
+ throw new Error('wasm-rust verified module URL map does not match the bundled graph');
141
+ }
142
+ const snapshot = {};
143
+ const blobUrls = new Set();
144
+ for (const [networkUrl, candidateBlobUrl] of entries) {
145
+ const blobUrl = requireCanonicalBlobUrl(candidateBlobUrl, 'wasm-rust verified module URL');
146
+ if (blobUrls.has(blobUrl)) {
147
+ throw new Error('wasm-rust verified module URLs must map one-to-one to Blob URLs');
148
+ }
149
+ blobUrls.add(blobUrl);
150
+ snapshot[networkUrl] = blobUrl;
151
+ }
152
+ return Object.freeze(snapshot);
153
+ }
154
+ function snapshotCompilerBootstrap(url, profileValue, moduleUrlsValue, graphFingerprint) {
155
+ const verifiedCompilerUrl = requireCanonicalBlobUrl(url, 'wasm-rust compiler URL');
156
+ if (graphFingerprint !== WASM_RUST_EXECUTABLE_GRAPH_PROFILE.fingerprint) {
157
+ throw new Error('wasm-rust executable graph fingerprint does not match the bundled receipt profile');
27
158
  }
159
+ const profile = snapshotRuntimeProfile(profileValue);
160
+ const moduleUrls = snapshotVerifiedModuleUrls(moduleUrlsValue, profile.moduleUrl);
161
+ if (moduleUrls[profile.moduleUrl] !== verifiedCompilerUrl) {
162
+ throw new Error('wasm-rust compiler URL must identify the bundled graph entry');
163
+ }
164
+ return Object.freeze({
165
+ compilerUrl: verifiedCompilerUrl,
166
+ profile,
167
+ moduleUrls,
168
+ graphFingerprint: WASM_RUST_EXECUTABLE_GRAPH_PROFILE.fingerprint
169
+ });
170
+ }
171
+ async function loadCompiler(url, profile = runtimeProfile, moduleUrls = verifiedModuleUrls, graphFingerprint = executableGraphFingerprint) {
172
+ if (!url) {
173
+ throw new Error('Rust runtime is not configured. Set PUBLIC_WASM_RUST_COMPILER_URL or runtimeAssets.rust.compilerUrl.');
174
+ }
175
+ const bootstrap = snapshotCompilerBootstrap(url, profile, moduleUrls, graphFingerprint);
176
+ if (loadedCompilerUrl === bootstrap.compilerUrl &&
177
+ loadedExecutableGraphFingerprint === bootstrap.graphFingerprint &&
178
+ compilerPromise) {
179
+ return await compilerPromise;
180
+ }
181
+ compilerUrl = bootstrap.compilerUrl;
182
+ runtimeProfile = bootstrap.profile;
183
+ verifiedModuleUrls = bootstrap.moduleUrls;
184
+ executableGraphFingerprint = bootstrap.graphFingerprint;
185
+ loadedCompilerUrl = bootstrap.compilerUrl;
186
+ loadedExecutableGraphFingerprint = bootstrap.graphFingerprint;
187
+ const runtimeModuleUrl = new URL(bootstrap.profile.moduleUrl);
188
+ const resolvedRuntimeBaseUrl = new URL('./runtime/', runtimeModuleUrl);
189
+ resolvedRuntimeBaseUrl.search = runtimeModuleUrl.search;
190
+ runtimeBaseUrl = resolvedRuntimeBaseUrl.toString();
28
191
  compiledArtifact = null;
29
192
  compiledCacheKey = '';
193
+ compiledAssetDeliveryBudget = null;
30
194
  compilerPromise = (async () => {
31
- const module = await import(/* @vite-ignore */ url);
195
+ const module = await importRustCompilerModule(bootstrap.compilerUrl);
196
+ if (typeof module.configureVerifiedRuntimeExecutableModuleUrls !== 'function') {
197
+ throw new Error('wasm-rust module must export configureVerifiedRuntimeExecutableModuleUrls');
198
+ }
199
+ module.configureVerifiedRuntimeExecutableModuleUrls(bootstrap.moduleUrls, bootstrap.graphFingerprint);
32
200
  const factory = typeof module.createRustCompiler === 'function'
33
201
  ? module.createRustCompiler
34
202
  : typeof module.default === 'function'
@@ -41,33 +209,286 @@ async function loadCompiler(url) {
41
209
  throw new Error('wasm-rust module must export executeBrowserRustArtifact');
42
210
  }
43
211
  return {
44
- compiler: await factory(),
212
+ compiler: await factory({
213
+ dependencies: { runtimeProfile: bootstrap.profile }
214
+ }),
45
215
  executeBrowserRustArtifact: module.executeBrowserRustArtifact
46
216
  };
47
217
  })();
48
218
  return await compilerPromise;
49
219
  }
220
+ async function loadDebugInstrumenter(url) {
221
+ if (!url) {
222
+ throw new Error('Rust debugging is not configured. Set runtimeAssets.rust.debugModuleUrl.');
223
+ }
224
+ if (loadedDebugModuleUrl === url && debugInstrumenterPromise) {
225
+ return await debugInstrumenterPromise;
226
+ }
227
+ loadedDebugModuleUrl = url;
228
+ debugInstrumenterPromise = (async () => {
229
+ const module = (await import(/* @vite-ignore */ url));
230
+ if (typeof module.RUST_DEBUG_MARKER !== 'string' ||
231
+ typeof module.instrumentRustDebugSource !== 'function') {
232
+ throw new Error('Rust debug instrumenter must export RUST_DEBUG_MARKER and instrumentRustDebugSource.');
233
+ }
234
+ return module;
235
+ })().catch((error) => {
236
+ if (loadedDebugModuleUrl === url) {
237
+ loadedDebugModuleUrl = '';
238
+ debugInstrumenterPromise = null;
239
+ }
240
+ throw error;
241
+ });
242
+ return await debugInstrumenterPromise;
243
+ }
244
+ function normalizedBreakpointSet(values) {
245
+ return new Set([...(Array.isArray(values) ? values : [])]
246
+ .map((value) => Number(value))
247
+ .filter((value) => Number.isInteger(value) && value > 0));
248
+ }
249
+ function refreshRustDebugBreakpoints(state, control) {
250
+ const version = Atomics.load(control, 2);
251
+ if (state.breakpointVersion === version)
252
+ return;
253
+ state.breakpointVersion = version;
254
+ const count = Math.max(0, Math.min(Atomics.load(control, 3), control.length - 4));
255
+ const next = new Set();
256
+ for (let index = 0; index < count; index += 1) {
257
+ const line = Atomics.load(control, 4 + index);
258
+ if (Number.isInteger(line) && line > 0)
259
+ next.add(line);
260
+ }
261
+ state.breakpoints = next;
262
+ }
263
+ function waitForRustDebugCommand(state, control, locationKey, line, depth) {
264
+ while (true) {
265
+ const command = Atomics.exchange(control, 1, 0);
266
+ if (!command) {
267
+ const sequence = Atomics.load(control, 0);
268
+ Atomics.wait(control, 0, sequence, 100);
269
+ continue;
270
+ }
271
+ state.resumeSkip = locationKey;
272
+ state.stepMode = null;
273
+ state.nextDepth = null;
274
+ state.nextLine = null;
275
+ state.stepOutDepth = null;
276
+ if (command === 2) {
277
+ state.stepMode = 'step';
278
+ }
279
+ else if (command === 3) {
280
+ state.stepMode = 'next';
281
+ state.nextDepth = depth;
282
+ state.nextLine = line;
283
+ }
284
+ else if (command === 4) {
285
+ state.stepMode = 'out';
286
+ state.stepOutDepth = Math.max(0, depth - 1);
287
+ }
288
+ return;
289
+ }
290
+ }
291
+ function createRustDebugHost(options) {
292
+ const state = {
293
+ breakpointVersion: Atomics.load(options.control, 2),
294
+ breakpoints: normalizedBreakpointSet(options.breakpoints),
295
+ pauseOnEntry: options.pauseOnEntry,
296
+ stepMode: null,
297
+ resumeSkip: null,
298
+ nextDepth: null,
299
+ nextLine: null,
300
+ stepOutDepth: null,
301
+ callStack: []
302
+ };
303
+ let stderrBuffer = '';
304
+ const markerPrefix = `${options.marker}:`;
305
+ const handleMarker = (line, functionName) => {
306
+ refreshRustDebugBreakpoints(state, options.control);
307
+ const normalizedFunctionName = functionName || 'main';
308
+ const currentFrame = state.callStack.at(-1);
309
+ if (!currentFrame) {
310
+ state.callStack.push({ functionName: normalizedFunctionName, line });
311
+ }
312
+ else if (currentFrame.functionName === normalizedFunctionName) {
313
+ currentFrame.line = line;
314
+ }
315
+ else {
316
+ let existingFrameIndex = -1;
317
+ for (let index = state.callStack.length - 2; index >= 0; index -= 1) {
318
+ if (state.callStack[index].functionName === normalizedFunctionName) {
319
+ existingFrameIndex = index;
320
+ break;
321
+ }
322
+ }
323
+ if (existingFrameIndex >= 0) {
324
+ state.callStack.length = existingFrameIndex + 1;
325
+ state.callStack[existingFrameIndex].line = line;
326
+ }
327
+ else {
328
+ state.callStack.push({ functionName: normalizedFunctionName, line });
329
+ }
330
+ }
331
+ const depth = state.callStack.length;
332
+ const skipKey = `${depth}:${normalizedFunctionName}:${line}`;
333
+ if (state.resumeSkip === skipKey)
334
+ return;
335
+ if (state.resumeSkip)
336
+ state.resumeSkip = null;
337
+ let reason = null;
338
+ if (state.pauseOnEntry) {
339
+ reason = 'entry';
340
+ }
341
+ else if (state.breakpoints.has(line)) {
342
+ reason = 'breakpoint';
343
+ }
344
+ else if (state.stepMode === 'step') {
345
+ reason = 'step';
346
+ }
347
+ else if (state.stepMode === 'next' &&
348
+ state.nextDepth !== null &&
349
+ depth <= state.nextDepth &&
350
+ (depth !== state.nextDepth || line !== state.nextLine)) {
351
+ reason = 'nextLine';
352
+ }
353
+ else if (state.stepMode === 'out' &&
354
+ state.stepOutDepth !== null &&
355
+ depth <= state.stepOutDepth) {
356
+ reason = 'stepOut';
357
+ }
358
+ if (!reason)
359
+ return;
360
+ state.pauseOnEntry = false;
361
+ state.stepMode = null;
362
+ state.nextDepth = null;
363
+ state.nextLine = null;
364
+ state.stepOutDepth = null;
365
+ const callStack = state.callStack.slice().reverse();
366
+ postMessage({
367
+ debugEvent: {
368
+ type: 'pause',
369
+ line,
370
+ reason,
371
+ locals: [],
372
+ callStack
373
+ }
374
+ });
375
+ waitForRustDebugCommand(state, options.control, skipKey, line, depth);
376
+ };
377
+ const consumeLine = (line, hasNewline) => {
378
+ if (line.startsWith(markerPrefix)) {
379
+ const payload = line.slice(markerPrefix.length);
380
+ const separator = payload.indexOf(':');
381
+ if (separator >= 0) {
382
+ handleMarker(Math.max(1, Number(payload.slice(0, separator) || 1)), payload.slice(separator + 1) || 'main');
383
+ }
384
+ return '';
385
+ }
386
+ return `${line}${hasNewline ? '\n' : ''}`;
387
+ };
388
+ return {
389
+ handleStderr(chunk) {
390
+ stderrBuffer += chunk;
391
+ const parts = stderrBuffer.split('\n');
392
+ stderrBuffer = parts.pop() || '';
393
+ return parts.map((line) => consumeLine(line, true)).join('');
394
+ },
395
+ flush() {
396
+ if (!stderrBuffer)
397
+ return '';
398
+ const chunk = consumeLine(stderrBuffer, false);
399
+ stderrBuffer = '';
400
+ return chunk;
401
+ }
402
+ };
403
+ }
50
404
  self.onmessage = async (event) => {
51
- const { load, compilerUrl: nextCompilerUrl, buffer, code, prepare, args = [], targetTriple = 'wasm32-wasip1', log } = event.data;
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
+ let ownsExecution = false;
52
407
  try {
53
408
  if (load) {
409
+ if (acceptedCompilerBootstrap) {
410
+ throw new Error('wasm-rust application worker accepts exactly one bootstrap');
411
+ }
412
+ acceptedCompilerBootstrap = true;
54
413
  compilerUrl = nextCompilerUrl;
414
+ debugModuleUrl = nextDebugModuleUrl;
415
+ runtimeProfile = nextRuntimeProfile || null;
416
+ verifiedModuleUrls = nextVerifiedModuleUrls || null;
417
+ executableGraphFingerprint = nextExecutableGraphFingerprint || '';
55
418
  if (log) {
56
419
  console.log(`[wasm-idle:rust-worker] load compilerUrl=${compilerUrl}`);
57
420
  }
58
- await loadCompiler(compilerUrl);
421
+ await loadCompiler(compilerUrl, runtimeProfile, verifiedModuleUrls, executableGraphFingerprint);
59
422
  postMessage({ load: true });
60
423
  return;
61
424
  }
425
+ if (!acceptedCompilerBootstrap) {
426
+ throw new Error('wasm-rust application worker must be bootstrapped before execution');
427
+ }
428
+ if (activeExecution) {
429
+ throw new Error('wasm-rust application worker already has an active execution');
430
+ }
431
+ activeExecution = true;
432
+ ownsExecution = true;
433
+ const debugMode = requestedDebugMode === undefined ? (debug ? 'trace' : 'none') : requestedDebugMode;
434
+ if (debugMode !== 'none' && debugMode !== 'trace' && debugMode !== 'lldb') {
435
+ throw new Error(`Unsupported Rust debug mode: ${String(debugMode)}`);
436
+ }
437
+ const nonDebugResourceLimits = debugMode === 'none' ? snapshotRustNonDebugResourceLimits(executionLimits) : undefined;
62
438
  stdinBufferRust = new Int32Array(buffer);
439
+ debugBufferRust = debugBuffer ? new Int32Array(debugBuffer) : null;
440
+ if (debugMode === 'trace' &&
441
+ (!debugBufferRust || !isSharedBufferBackedView(debugBufferRust))) {
442
+ postMessage({ error: 'Rust debugging requires SharedArrayBuffer.' });
443
+ return;
444
+ }
63
445
  const runtime = await loadCompiler(compilerUrl);
64
- const compileCacheKey = `${targetTriple}\n${code}`;
446
+ let debugInstrumenter = null;
447
+ if (debugMode === 'trace') {
448
+ postMessage({
449
+ progress: {
450
+ stage: 'load-debug-instrumenter',
451
+ percent: 1,
452
+ message: 'Loading Rust debugger'
453
+ }
454
+ });
455
+ debugInstrumenter = await loadDebugInstrumenter(debugModuleUrl);
456
+ postMessage({
457
+ progress: {
458
+ stage: 'load-debug-instrumenter',
459
+ percent: 3,
460
+ message: 'Rust debugger loaded'
461
+ }
462
+ });
463
+ }
464
+ const compileCode = debugInstrumenter
465
+ ? debugInstrumenter.instrumentRustDebugSource(code)
466
+ : code;
467
+ const compileCacheKey = [
468
+ executableGraphFingerprint,
469
+ debugMode,
470
+ targetTriple,
471
+ ...(nonDebugResourceLimits
472
+ ? [String(nonDebugResourceLimits.maxAssetDeliveryBytes)]
473
+ : []),
474
+ compileCode
475
+ ].join('\n');
65
476
  if (!compiledArtifact || compiledCacheKey !== compileCacheKey) {
477
+ const assetDeliveryBudget = nonDebugResourceLimits
478
+ ? createRuntimeAssetDeliveryBudget(nonDebugResourceLimits.maxAssetDeliveryBytes)
479
+ : undefined;
66
480
  if (log) {
67
- console.log(`[wasm-idle:rust-worker] compile start prepare=${String(prepare)} target=${targetTriple} bytes=${code.length}`);
481
+ console.log(`[wasm-idle:rust-worker] compile start prepare=${String(prepare)} target=${targetTriple} bytes=${compileCode.length}`);
68
482
  }
69
483
  const result = await runtime.compiler.compile({
70
- code,
484
+ code: compileCode,
485
+ debugMode,
486
+ ...(nonDebugResourceLimits
487
+ ? {
488
+ workerLimits: nonDebugResourceLimits.compilerLimits,
489
+ assetDeliveryBudget
490
+ }
491
+ : {}),
71
492
  edition: '2024',
72
493
  crateType: 'bin',
73
494
  targetTriple,
@@ -87,7 +508,9 @@ self.onmessage = async (event) => {
87
508
  postMessage({ output: result.stdout });
88
509
  if (!result.success) {
89
510
  throw new Error(result.stderr ||
90
- result.diagnostics?.map((diagnostic) => diagnostic.message).join('\n') ||
511
+ result.diagnostics
512
+ ?.map((diagnostic) => diagnostic.message)
513
+ .join('\n') ||
91
514
  'Rust compilation failed');
92
515
  }
93
516
  if (result.stderr)
@@ -97,6 +520,7 @@ self.onmessage = async (event) => {
97
520
  }
98
521
  compiledArtifact = result.artifact;
99
522
  compiledCacheKey = compileCacheKey;
523
+ compiledAssetDeliveryBudget = assetDeliveryBudget || null;
100
524
  if (log) {
101
525
  console.log(`[wasm-idle:rust-worker] cached artifact target=${compiledArtifact.targetTriple} format=${compiledArtifact.format}`);
102
526
  }
@@ -108,15 +532,99 @@ self.onmessage = async (event) => {
108
532
  postMessage({ results: true });
109
533
  return;
110
534
  }
535
+ if (debugMode === 'lldb') {
536
+ if (compiledArtifact.targetTriple !== 'wasm32-wasip1' ||
537
+ compiledArtifact.format !== 'core-wasm') {
538
+ throw new Error('wasm-rust LLDB artifact must be wasm32-wasip1 core-wasm');
539
+ }
540
+ const descriptor = compiledArtifact.debug;
541
+ if (!descriptor ||
542
+ typeof descriptor !== 'object' ||
543
+ descriptor.kind !== 'dwarf' ||
544
+ descriptor.sourceRoot !== '/workspace') {
545
+ throw new Error('wasm-rust did not return an LLDB DWARF descriptor');
546
+ }
547
+ if (typeof descriptor.moduleSha256 !== 'string' ||
548
+ !lowercaseSha256Pattern.test(descriptor.moduleSha256)) {
549
+ throw new Error('wasm-rust LLDB descriptor has an invalid module SHA-256');
550
+ }
551
+ if (!Array.isArray(descriptor.files) ||
552
+ descriptor.files.length !== 1 ||
553
+ !descriptor.files[0] ||
554
+ typeof descriptor.files[0] !== 'object' ||
555
+ descriptor.files[0].path !== '/workspace/main.rs') {
556
+ throw new Error('wasm-rust LLDB descriptor must contain exactly one /workspace/main.rs source');
557
+ }
558
+ const sourceDescriptor = descriptor.files[0];
559
+ if (typeof sourceDescriptor.contentSha256 !== 'string' ||
560
+ !lowercaseSha256Pattern.test(sourceDescriptor.contentSha256)) {
561
+ throw new Error('wasm-rust LLDB descriptor has an invalid /workspace/main.rs SHA-256');
562
+ }
563
+ const compiler = descriptor.compiler;
564
+ if (!compiler ||
565
+ typeof compiler !== 'object' ||
566
+ compiler.name !== 'rustc' ||
567
+ [
568
+ 'version',
569
+ 'revision',
570
+ 'llvmVersion',
571
+ 'llvmRevision',
572
+ 'runtimeVersion',
573
+ 'hostTriple'
574
+ ].some((field) => typeof compiler[field] !== 'string' || compiler[field].trim().length === 0)) {
575
+ throw new Error('wasm-rust LLDB descriptor requires complete rustc compiler provenance');
576
+ }
577
+ const artifactBytes = compiledArtifact.wasm instanceof Uint8Array
578
+ ? compiledArtifact.wasm
579
+ : new Uint8Array(compiledArtifact.wasm);
580
+ postMessage({
581
+ lldbArtifact: {
582
+ bytes: new Uint8Array(artifactBytes),
583
+ descriptor,
584
+ sources: [
585
+ {
586
+ path: '/workspace/main.rs',
587
+ content: code,
588
+ contentSha256: sourceDescriptor.contentSha256
589
+ }
590
+ ]
591
+ }
592
+ });
593
+ return;
594
+ }
595
+ postMessage({ runtimePhase: 'run' });
111
596
  if (log) {
112
597
  console.log(`[wasm-idle:rust-worker] runtime start target=${compiledArtifact.targetTriple} format=${compiledArtifact.format}`);
113
598
  }
599
+ const rustDebugHost = debugMode === 'trace' && debugBufferRust && debugInstrumenter
600
+ ? createRustDebugHost({
601
+ control: debugBufferRust,
602
+ breakpoints,
603
+ pauseOnEntry: !!pauseOnEntry,
604
+ marker: debugInstrumenter.RUST_DEBUG_MARKER
605
+ })
606
+ : null;
607
+ const hasInitialStdin = typeof stdin === 'string';
608
+ let initialStdin = hasInitialStdin ? stdin : null;
114
609
  const execution = await runtime.executeBrowserRustArtifact(compiledArtifact, runtimeBaseUrl, {
610
+ ...(debugMode === 'none' && compiledAssetDeliveryBudget
611
+ ? { assetDeliveryBudget: compiledAssetDeliveryBudget }
612
+ : {}),
115
613
  args,
116
614
  env: {
117
615
  USER: 'jungol'
118
616
  },
119
617
  stdin: () => {
618
+ if (hasInitialStdin) {
619
+ const chunk = initialStdin;
620
+ initialStdin = null;
621
+ if (log) {
622
+ console.log(chunk == null
623
+ ? '[wasm-idle:rust-stdin] fd_read(bytes=0, eof=true)'
624
+ : `[wasm-idle:rust-stdin] fd_fill(bytes=${new TextEncoder().encode(chunk).byteLength}, text=${JSON.stringify(chunk)})`);
625
+ }
626
+ return chunk;
627
+ }
120
628
  const chunk = waitForBufferedStdin(stdinBufferRust, () => postMessage({ buffer: true }));
121
629
  if (chunk == null) {
122
630
  if (log) {
@@ -135,11 +643,16 @@ self.onmessage = async (event) => {
135
643
  }
136
644
  },
137
645
  stderr: (output) => {
138
- if (output) {
139
- postMessage({ output });
140
- }
646
+ const visibleOutput = rustDebugHost
647
+ ? rustDebugHost.handleStderr(output)
648
+ : output;
649
+ if (visibleOutput)
650
+ postMessage({ output: visibleOutput });
141
651
  }
142
652
  });
653
+ const flushedDebugOutput = rustDebugHost?.flush();
654
+ if (flushedDebugOutput)
655
+ postMessage({ output: flushedDebugOutput });
143
656
  if (log) {
144
657
  console.log(`[wasm-idle:rust-worker] wasi run complete exitCode=${String(execution.exitCode)}`);
145
658
  }
@@ -154,6 +667,19 @@ self.onmessage = async (event) => {
154
667
  if (log) {
155
668
  console.error('[wasm-idle:rust-worker] failed', error);
156
669
  }
157
- postMessage({ error: error?.message || String(error) });
670
+ const errorMessage = String(error?.message || error);
671
+ const maxErrorBytes = Number.isSafeInteger(executionLimits?.maxOutputBytes) &&
672
+ executionLimits.maxOutputBytes > 0
673
+ ? executionLimits.maxOutputBytes
674
+ : 1024 * 1024;
675
+ postMessage({
676
+ error: new TextEncoder().encode(errorMessage).byteLength <= maxErrorBytes
677
+ ? errorMessage
678
+ : `Rust worker error exceeded ${maxErrorBytes} bytes`
679
+ });
680
+ }
681
+ finally {
682
+ if (ownsExecution)
683
+ activeExecution = false;
158
684
  }
159
685
  };
@@ -0,0 +1 @@
1
+ export {};