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.
- package/README.md +760 -81
- package/dist/index.d.ts +4 -9
- package/dist/index.js +2 -4
- package/dist/playground/applicationAssets.d.ts +4 -0
- package/dist/playground/applicationAssets.js +277 -0
- package/dist/playground/assemblyscript.d.ts +41 -0
- package/dist/playground/assemblyscript.js +630 -0
- package/dist/playground/assetBridge.d.ts +18 -7
- package/dist/playground/assetBridge.js +824 -100
- package/dist/playground/assets.d.ts +813 -19
- package/dist/playground/assets.js +2096 -156
- package/dist/playground/awk.d.ts +5 -0
- package/dist/playground/awk.js +60 -0
- package/dist/playground/bash.d.ts +53 -0
- package/dist/playground/bash.js +1096 -0
- package/dist/playground/bashWorkerProtocol.d.ts +88 -0
- package/dist/playground/bashWorkerProtocol.js +135 -0
- package/dist/playground/bqn.d.ts +5 -0
- package/dist/playground/bqn.js +57 -0
- package/dist/playground/bqnPreflight.d.ts +26 -0
- package/dist/playground/bqnPreflight.js +399 -0
- package/dist/playground/c3.d.ts +15 -0
- package/dist/playground/c3.js +154 -0
- package/dist/playground/clang.d.ts +35 -19
- package/dist/playground/clang.js +241 -52
- package/dist/playground/clangAssetIntegrity.d.ts +32 -0
- package/dist/playground/clangAssetIntegrity.js +8 -0
- package/dist/playground/clojurescript.d.ts +5 -0
- package/dist/playground/clojurescript.js +59 -0
- package/dist/playground/clojurescriptPreflight.d.ts +26 -0
- package/dist/playground/clojurescriptPreflight.js +383 -0
- package/dist/playground/cobol.d.ts +46 -0
- package/dist/playground/cobol.js +703 -0
- package/dist/playground/d.d.ts +47 -0
- package/dist/playground/d.js +644 -0
- package/dist/playground/dOuterAssets.d.ts +16 -0
- package/dist/playground/dOuterAssets.js +163 -0
- package/dist/playground/dotnet.d.ts +99 -0
- package/dist/playground/dotnet.js +1131 -0
- package/dist/playground/duckdb.d.ts +36 -0
- package/dist/playground/duckdb.js +542 -0
- package/dist/playground/elixir.d.ts +18 -10
- package/dist/playground/elixir.js +630 -96
- package/dist/playground/elixirAssets.d.ts +6 -0
- package/dist/playground/elixirAssets.js +33 -0
- package/dist/playground/executionObservation.d.ts +22 -0
- package/dist/playground/executionObservation.js +65 -0
- package/dist/playground/forth.d.ts +5 -0
- package/dist/playground/forth.js +53 -0
- package/dist/playground/forthPreflight.d.ts +24 -0
- package/dist/playground/forthPreflight.js +198 -0
- package/dist/playground/fortran.d.ts +47 -0
- package/dist/playground/fortran.js +651 -0
- package/dist/playground/fortranAssets.d.ts +6 -0
- package/dist/playground/fortranAssets.js +27 -0
- package/dist/playground/gleam.d.ts +6 -0
- package/dist/playground/gleam.js +33 -0
- package/dist/playground/go.d.ts +17 -11
- package/dist/playground/go.js +376 -72
- package/dist/playground/goDebugInstrumentation.d.ts +1 -0
- package/dist/playground/goDebugInstrumentation.js +229 -0
- package/dist/playground/haskell.d.ts +44 -0
- package/dist/playground/haskell.js +678 -0
- package/dist/playground/haskellAssets.d.ts +24 -0
- package/dist/playground/haskellAssets.js +93 -0
- package/dist/playground/index.d.ts +1 -1
- package/dist/playground/index.js +360 -111
- package/dist/playground/j.d.ts +5 -0
- package/dist/playground/j.js +60 -0
- package/dist/playground/jPreflight.d.ts +26 -0
- package/dist/playground/jPreflight.js +372 -0
- package/dist/playground/janet.d.ts +5 -0
- package/dist/playground/janet.js +64 -0
- package/dist/playground/java.d.ts +24 -10
- package/dist/playground/java.js +706 -84
- package/dist/playground/javaSource.d.ts +5 -0
- package/dist/playground/javaSource.js +16 -0
- package/dist/playground/javaStdin.d.ts +1 -1
- package/dist/playground/javaStdin.js +13 -4
- package/dist/playground/julia.d.ts +5 -0
- package/dist/playground/julia.js +64 -0
- package/dist/playground/lfortran.d.ts +8 -0
- package/dist/playground/lfortran.js +30 -0
- package/dist/playground/lfortranAssets.d.ts +21 -0
- package/dist/playground/lfortranAssets.js +118 -0
- package/dist/playground/lisp.d.ts +45 -0
- package/dist/playground/lisp.js +640 -0
- package/dist/playground/lispAssets.d.ts +9 -0
- package/dist/playground/lispAssets.js +74 -0
- package/dist/playground/lldbManifest.d.ts +3 -0
- package/dist/playground/lldbManifest.js +155 -0
- package/dist/playground/lldbSession.d.ts +115 -0
- package/dist/playground/lldbSession.js +1347 -0
- package/dist/playground/loadingProgress.d.ts +16 -0
- package/dist/playground/loadingProgress.js +166 -0
- package/dist/playground/lua.d.ts +44 -0
- package/dist/playground/lua.js +630 -0
- package/dist/playground/nim.d.ts +5 -0
- package/dist/playground/nim.js +76 -0
- package/dist/playground/objectivec.d.ts +39 -0
- package/dist/playground/objectivec.js +288 -0
- package/dist/playground/ocaml.d.ts +28 -10
- package/dist/playground/ocaml.js +815 -253
- package/dist/playground/octave.d.ts +43 -0
- package/dist/playground/octave.js +783 -0
- package/dist/playground/options.d.ts +19 -40
- package/dist/playground/options.js +2 -1
- package/dist/playground/pascal.d.ts +5 -0
- package/dist/playground/pascal.js +60 -0
- package/dist/playground/perl.d.ts +5 -0
- package/dist/playground/perl.js +61 -0
- package/dist/playground/php.d.ts +44 -0
- package/dist/playground/php.js +665 -0
- package/dist/playground/prolog.d.ts +6 -0
- package/dist/playground/prolog.js +75 -0
- package/dist/playground/python.d.ts +20 -14
- package/dist/playground/python.js +445 -101
- package/dist/playground/pythonPackageLock.d.ts +6 -0
- package/dist/playground/pythonPackageLock.js +56 -0
- package/dist/playground/r.d.ts +44 -0
- package/dist/playground/r.js +637 -0
- package/dist/playground/ruby.d.ts +46 -0
- package/dist/playground/ruby.js +732 -0
- package/dist/playground/rubyAssets.d.ts +23 -0
- package/dist/playground/rubyAssets.js +68 -0
- package/dist/playground/rubyTestPreflight.d.ts +2 -0
- package/dist/playground/rubyTestPreflight.js +18 -0
- package/dist/playground/runtimeModule.d.ts +1 -0
- package/dist/playground/runtimeModule.js +5 -0
- package/dist/playground/rust.d.ts +44 -13
- package/dist/playground/rust.js +714 -76
- package/dist/playground/rustExecutableGraph.d.ts +85 -0
- package/dist/playground/rustExecutableGraph.js +946 -0
- package/dist/playground/rustWorkerLimits.d.ts +17 -0
- package/dist/playground/rustWorkerLimits.js +34 -0
- package/dist/playground/sandbox.d.ts +16 -10
- package/dist/playground/sharedBuffer.d.ts +6 -0
- package/dist/playground/sharedBuffer.js +12 -0
- package/dist/playground/sqlite.d.ts +38 -0
- package/dist/playground/sqlite.js +550 -0
- package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -0
- package/dist/playground/staticRuntimeModuleVersion.js +2 -0
- package/dist/playground/staticRuntimePreflight.d.ts +13 -0
- package/dist/playground/staticRuntimePreflight.js +231 -0
- package/dist/playground/staticRuntimePreflightExecute.d.ts +8 -0
- package/dist/playground/staticRuntimePreflightExecute.js +66 -0
- package/dist/playground/staticRuntimePreflightProtocol.d.ts +68 -0
- package/dist/playground/staticRuntimePreflightProtocol.js +339 -0
- package/dist/playground/staticStdinRing.d.ts +45 -0
- package/dist/playground/staticStdinRing.js +158 -0
- package/dist/playground/staticWorkerRuntime.d.ts +154 -0
- package/dist/playground/staticWorkerRuntime.js +1917 -0
- package/dist/playground/stdinBuffer.d.ts +9 -7
- package/dist/playground/stdinBuffer.js +9 -18
- package/dist/playground/swift.d.ts +5 -0
- package/dist/playground/swift.js +17 -0
- package/dist/playground/tcl.d.ts +5 -0
- package/dist/playground/tcl.js +62 -0
- package/dist/playground/teavmConfig.d.ts +1 -1
- package/dist/playground/teavmConfig.js +2 -2
- package/dist/playground/tinygo.d.ts +48 -18
- package/dist/playground/tinygo.js +1202 -329
- package/dist/playground/tinygoExecutableGraph.d.ts +44 -0
- package/dist/playground/tinygoExecutableGraph.js +449 -0
- package/dist/playground/typescript.d.ts +55 -0
- package/dist/playground/typescript.js +924 -0
- package/dist/playground/wasm.d.ts +43 -0
- package/dist/playground/wasm.js +608 -0
- package/dist/playground/wasmAwkVersion.d.ts +59 -0
- package/dist/playground/wasmAwkVersion.js +31 -0
- package/dist/playground/wasmBashVersion.d.ts +63 -0
- package/dist/playground/wasmBashVersion.js +36 -0
- package/dist/playground/wasmBqnVersion.d.ts +24 -0
- package/dist/playground/wasmBqnVersion.js +24 -0
- package/dist/playground/wasmC3Version.d.ts +20 -0
- package/dist/playground/wasmC3Version.js +21 -0
- package/dist/playground/wasmClojureScriptVersion.d.ts +21 -0
- package/dist/playground/wasmClojureScriptVersion.js +21 -0
- package/dist/playground/wasmDIntegrity.d.ts +15 -0
- package/dist/playground/wasmDIntegrity.js +15 -0
- package/dist/playground/wasmDVersion.d.ts +1 -0
- package/dist/playground/wasmDVersion.js +1 -0
- package/dist/playground/wasmDebugVersion.d.ts +6 -0
- package/dist/playground/wasmDebugVersion.js +6 -0
- package/dist/playground/wasmDotnetVersion.d.ts +1 -0
- package/dist/playground/wasmDotnetVersion.js +1 -0
- package/dist/playground/wasmElixirVersion.d.ts +21 -1
- package/dist/playground/wasmElixirVersion.js +21 -1
- package/dist/playground/wasmForthVersion.d.ts +18 -0
- package/dist/playground/wasmForthVersion.js +18 -0
- package/dist/playground/wasmFortranExecutionAssets.d.ts +15 -0
- package/dist/playground/wasmFortranExecutionAssets.js +15 -0
- package/dist/playground/wasmFortranVersion.d.ts +1 -0
- package/dist/playground/wasmFortranVersion.js +1 -0
- package/dist/playground/wasmGleamVersion.d.ts +5 -0
- package/dist/playground/wasmGleamVersion.js +5 -0
- package/dist/playground/wasmGoVersion.d.ts +1 -1
- package/dist/playground/wasmGoVersion.js +1 -1
- package/dist/playground/wasmHaskellVersion.d.ts +1 -0
- package/dist/playground/wasmHaskellVersion.js +1 -0
- package/dist/playground/wasmJVersion.d.ts +24 -0
- package/dist/playground/wasmJVersion.js +24 -0
- package/dist/playground/wasmJanetVersion.d.ts +53 -0
- package/dist/playground/wasmJanetVersion.js +30 -0
- package/dist/playground/wasmJuliaVersion.d.ts +71 -0
- package/dist/playground/wasmJuliaVersion.js +39 -0
- package/dist/playground/wasmLfortranVersion.d.ts +28 -0
- package/dist/playground/wasmLfortranVersion.js +29 -0
- package/dist/playground/wasmLispVersion.d.ts +1 -0
- package/dist/playground/wasmLispVersion.js +1 -0
- package/dist/playground/wasmLuaVersion.d.ts +1 -0
- package/dist/playground/wasmLuaVersion.js +1 -0
- package/dist/playground/wasmNimVersion.d.ts +125 -0
- package/dist/playground/wasmNimVersion.js +66 -0
- package/dist/playground/wasmObjectiveCVersion.d.ts +27 -0
- package/dist/playground/wasmObjectiveCVersion.js +27 -0
- package/dist/playground/wasmOcamlVersion.d.ts +12 -1
- package/dist/playground/wasmOcamlVersion.js +12 -1
- package/dist/playground/wasmOctaveVersion.d.ts +1 -0
- package/dist/playground/wasmOctaveVersion.js +1 -0
- package/dist/playground/wasmPascalVersion.d.ts +61 -0
- package/dist/playground/wasmPascalVersion.js +34 -0
- package/dist/playground/wasmPerlVersion.d.ts +71 -0
- package/dist/playground/wasmPerlVersion.js +39 -0
- package/dist/playground/wasmPrologVersion.d.ts +31 -0
- package/dist/playground/wasmPrologVersion.js +31 -0
- package/dist/playground/wasmRVersion.d.ts +1 -0
- package/dist/playground/wasmRVersion.js +1 -0
- package/dist/playground/wasmRustVersion.d.ts +1306 -1
- package/dist/playground/wasmRustVersion.js +1458 -1
- package/dist/playground/wasmSwiftVersion.d.ts +1 -0
- package/dist/playground/wasmSwiftVersion.js +1 -0
- package/dist/playground/wasmTclVersion.d.ts +85 -0
- package/dist/playground/wasmTclVersion.js +46 -0
- package/dist/playground/wasmTinyGoVersion.d.ts +98 -1
- package/dist/playground/wasmTinyGoVersion.js +107 -1
- package/dist/playground/wasmTypeScriptVersion.d.ts +5 -0
- package/dist/playground/wasmTypeScriptVersion.js +5 -0
- package/dist/playground/wasmWatVersion.d.ts +1 -0
- package/dist/playground/wasmWatVersion.js +1 -0
- package/dist/playground/wasmZigVersion.d.ts +13 -0
- package/dist/playground/wasmZigVersion.js +13 -0
- package/dist/playground/wat.d.ts +44 -0
- package/dist/playground/wat.js +622 -0
- package/dist/playground/worker/assemblyscript.js +339 -0
- package/dist/playground/worker/assets.d.ts +7 -0
- package/dist/playground/worker/assets.js +288 -39
- package/dist/playground/worker/bash.js +338 -0
- package/dist/playground/worker/bashNestedBootstrap.d.ts +6 -0
- package/dist/playground/worker/bashNestedBootstrap.js +59 -0
- package/dist/playground/worker/bashRuntime.d.ts +89 -0
- package/dist/playground/worker/bashRuntime.js +982 -0
- package/dist/playground/worker/clang.js +92 -13
- package/dist/playground/worker/cobol.js +107 -0
- package/dist/playground/worker/d.js +199 -0
- package/dist/playground/worker/dotnet.js +141 -0
- package/dist/playground/worker/duckdb.d.ts +1 -0
- package/dist/playground/worker/duckdb.js +136 -0
- package/dist/playground/worker/elixir.js +307 -41
- package/dist/playground/worker/fortran.d.ts +1 -0
- package/dist/playground/worker/fortran.js +295 -0
- package/dist/playground/worker/go.js +246 -40
- package/dist/playground/worker/haskell.d.ts +7 -0
- package/dist/playground/worker/haskell.js +465 -0
- package/dist/playground/worker/java.js +59 -20
- package/dist/playground/worker/lisp.d.ts +1 -0
- package/dist/playground/worker/lisp.js +195 -0
- package/dist/playground/worker/lua.d.ts +1 -0
- package/dist/playground/worker/lua.js +163 -0
- package/dist/playground/worker/objectivec.d.ts +1 -0
- package/dist/playground/worker/objectivec.js +10 -0
- package/dist/playground/worker/ocaml.js +206 -58
- package/dist/playground/worker/php.d.ts +1 -0
- package/dist/playground/worker/php.js +261 -0
- package/dist/playground/worker/python.js +201 -44
- package/dist/playground/worker/r.d.ts +1 -0
- package/dist/playground/worker/r.js +192 -0
- package/dist/playground/worker/ruby.d.ts +1 -0
- package/dist/playground/worker/ruby.js +248 -0
- package/dist/playground/worker/runtimeAssetFetch.d.ts +15 -0
- package/dist/playground/worker/runtimeAssetFetch.js +375 -0
- package/dist/playground/worker/rust.js +546 -20
- package/dist/playground/worker/sqlite.d.ts +1 -0
- package/dist/playground/worker/sqlite.js +112 -0
- package/dist/playground/worker/staticRuntimePreflight.d.ts +1 -0
- package/dist/playground/worker/staticRuntimePreflight.js +56 -0
- package/dist/playground/worker/tinygo.js +34 -9
- package/dist/playground/worker/typescript.d.ts +1 -0
- package/dist/playground/worker/typescript.js +251 -0
- package/dist/playground/worker/wasm.d.ts +1 -0
- package/dist/playground/worker/wasm.js +273 -0
- package/dist/playground/worker/wat.d.ts +1 -0
- package/dist/playground/worker/wat.js +188 -0
- package/dist/playground/worker/zig.d.ts +8 -0
- package/dist/playground/worker/zig.js +578 -0
- package/dist/playground/workerProgress.d.ts +15 -0
- package/dist/playground/workerProgress.js +72 -0
- package/dist/playground/workerSession.d.ts +28 -0
- package/dist/playground/workerSession.js +164 -0
- package/dist/playground/zig.d.ts +46 -0
- package/dist/playground/zig.js +690 -0
- package/dist/playground/zigAssets.d.ts +6 -0
- package/dist/playground/zigAssets.js +49 -0
- package/package.json +234 -105
- package/dist/clang/app.d.ts +0 -75
- package/dist/clang/app.js +0 -744
- package/dist/clang/apply.d.ts +0 -2
- package/dist/clang/apply.js +0 -11
- package/dist/clang/color.d.ts +0 -3
- package/dist/clang/color.js +0 -3
- package/dist/clang/encode.d.ts +0 -4
- package/dist/clang/encode.js +0 -20
- package/dist/clang/error.d.ts +0 -14
- package/dist/clang/error.js +0 -27
- package/dist/clang/gccCompat.d.ts +0 -15
- package/dist/clang/gccCompat.js +0 -767
- package/dist/clang/index.d.ts +0 -85
- package/dist/clang/index.js +0 -1077
- package/dist/clang/memory/index.d.ts +0 -4
- package/dist/clang/memory/index.js +0 -4
- package/dist/clang/memory/memFs.d.ts +0 -35
- package/dist/clang/memory/memFs.js +0 -132
- package/dist/clang/memory/memory.d.ts +0 -22
- package/dist/clang/memory/memory.js +0 -73
- package/dist/clang/memory/tar.d.ts +0 -2
- package/dist/clang/memory/tar.js +0 -59
- package/dist/clang/url.d.ts +0 -4
- package/dist/clang/url.js +0 -5
- package/dist/clang/wasm.d.ts +0 -4
- package/dist/clang/wasm.js +0 -50
- package/dist/clangd/config.d.ts +0 -18
- package/dist/clangd/config.js +0 -14
- package/dist/clangd/jsonStream.d.ts +0 -9
- package/dist/clangd/jsonStream.js +0 -48
- package/dist/clangd/session.d.ts +0 -18
- package/dist/clangd/session.js +0 -112
- package/dist/clangd/worker.js +0 -131
- package/dist/debug/controller.svelte.d.ts +0 -43
- package/dist/debug/controller.svelte.js +0 -268
- package/dist/debug/editor/index.d.ts +0 -2
- package/dist/debug/editor/index.js +0 -1
- package/dist/debug/editor/monaco.d.ts +0 -26
- package/dist/debug/editor/monaco.js +0 -128
- package/dist/debug/expression.d.ts +0 -26
- package/dist/debug/expression.js +0 -547
- package/dist/debug/index.d.ts +0 -8
- package/dist/debug/index.js +0 -5
- package/dist/debug/language/cpp.d.ts +0 -2
- package/dist/debug/language/cpp.js +0 -7
- package/dist/debug/language/index.d.ts +0 -3
- package/dist/debug/language/index.js +0 -2
- package/dist/debug/language/python.d.ts +0 -2
- package/dist/debug/language/python.js +0 -14
- package/dist/debug/language/types.d.ts +0 -6
- package/dist/debug/locals.d.ts +0 -2
- package/dist/debug/locals.js +0 -8
- package/dist/lsp/cpp/server.d.ts +0 -2
- package/dist/lsp/cpp/server.js +0 -68
- package/dist/lsp/index.d.ts +0 -5
- package/dist/lsp/index.js +0 -4
- package/dist/lsp/python/main.worker.js +0 -92
- package/dist/lsp/python/package/arcturus_python_lsp/__init__.py +0 -3
- package/dist/lsp/python/package/arcturus_python_lsp/server.py +0 -462
- package/dist/lsp/python/server.d.ts +0 -2
- package/dist/lsp/python/server.js +0 -54
- package/dist/lsp/registry.d.ts +0 -2
- package/dist/lsp/registry.js +0 -12
- package/dist/lsp/runtime.d.ts +0 -5
- package/dist/lsp/runtime.js +0 -31
- package/dist/lsp/types.d.ts +0 -17
- package/dist/terminal/Terminal.svelte +0 -422
- package/dist/terminal/Terminal.svelte.d.ts +0 -26
- package/dist/terminal/index.d.ts +0 -7
- package/dist/terminal/index.js +0 -5
- package/dist/terminal/plugin/index.d.ts +0 -9
- package/dist/terminal/plugin/index.js +0 -19
- package/dist/terminal/theme.d.ts +0 -49
- package/dist/terminal/theme.js +0 -49
- package/dist/terminal/types.d.ts +0 -18
- package/dist/utils/vscodeJsonrpcBrowser.d.ts +0 -5
- package/dist/utils/vscodeJsonrpcBrowser.js +0 -4
- /package/dist/{clangd/worker.d.ts → playground/worker/assemblyscript.d.ts} +0 -0
- /package/dist/{debug/language/types.js → playground/worker/bash.d.ts} +0 -0
- /package/dist/{lsp/python/main.worker.d.ts → playground/worker/cobol.d.ts} +0 -0
- /package/dist/{lsp/types.js → playground/worker/d.d.ts} +0 -0
- /package/dist/{terminal/types.js → playground/worker/dotnet.d.ts} +0 -0
package/dist/playground/rust.js
CHANGED
|
@@ -1,81 +1,334 @@
|
|
|
1
|
-
import { resolveRustCompilerUrl } from './assets';
|
|
1
|
+
import { resolveDebugRuntimeUrls, resolveRustCompilerUrl, resolveRustDebugModuleUrl } from './assets';
|
|
2
|
+
import { LldbSandboxSession } from './lldbSession';
|
|
2
3
|
import { resolveSandboxExecutionArgs } from './options';
|
|
3
4
|
import { flushBufferedEof, flushQueuedStdin, resetBufferedStdin } from './stdinBuffer';
|
|
5
|
+
import { createWasmIdleSharedBuffer, requireSharedArrayBuffer } from './sharedBuffer';
|
|
6
|
+
import { loadVerifiedRustExecutableGraph } from './rustExecutableGraph';
|
|
7
|
+
import { resolveRustNonDebugResourceLimits } from './rustWorkerLimits';
|
|
8
|
+
import { WASM_RUST_EXECUTABLE_GRAPH_PROFILE, WASM_RUST_RUNTIME_PROFILE } from './wasmRustVersion';
|
|
9
|
+
import { WorkerSession } from './workerSession';
|
|
10
|
+
import { reportWorkerInputReady, reportWorkerProgress } from './workerProgress';
|
|
11
|
+
import { resolveExecutionLimits, TimeoutError } from '@wasm-idle/core';
|
|
12
|
+
const debugBreakpointBufferInts = 1028;
|
|
13
|
+
const rustLldbSourcePath = '/workspace/main.rs';
|
|
14
|
+
const outputEncoder = new TextEncoder();
|
|
15
|
+
function normalizeRustLldbSourcePath(sourcePath) {
|
|
16
|
+
let normalized = (sourcePath || 'main.rs').trim().replaceAll('\\', '/');
|
|
17
|
+
if (normalized === '/workspace') {
|
|
18
|
+
normalized = '';
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
normalized = normalized.replace(/^\/workspace\//u, '');
|
|
22
|
+
}
|
|
23
|
+
normalized = normalized.replace(/^\/+/u, '');
|
|
24
|
+
const segments = [];
|
|
25
|
+
for (const segment of normalized.split('/')) {
|
|
26
|
+
if (!segment || segment === '.')
|
|
27
|
+
continue;
|
|
28
|
+
if (segment === '..') {
|
|
29
|
+
segments.pop();
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
segments.push(segment);
|
|
33
|
+
}
|
|
34
|
+
return `/workspace/${segments.join('/') || 'main.rs'}`;
|
|
35
|
+
}
|
|
36
|
+
function normalizeRustBreakpointLines(lines) {
|
|
37
|
+
return [...new Set(lines.filter((line) => Number.isInteger(line) && line > 0))].sort((left, right) => left - right);
|
|
38
|
+
}
|
|
4
39
|
class Rust {
|
|
5
40
|
output = null;
|
|
41
|
+
ondebug;
|
|
6
42
|
worker = null;
|
|
7
|
-
buffer =
|
|
43
|
+
buffer = createWasmIdleSharedBuffer(1024);
|
|
44
|
+
debugBuffer = createWasmIdleSharedBuffer(Int32Array.BYTES_PER_ELEMENT * debugBreakpointBufferInts);
|
|
8
45
|
pendingInput = [];
|
|
9
46
|
begin = 0;
|
|
10
47
|
elapse = 0;
|
|
11
48
|
uid = 0;
|
|
12
49
|
exit = true;
|
|
13
50
|
compilerUrl = '';
|
|
51
|
+
debugModuleUrl = '';
|
|
14
52
|
assetPath = '';
|
|
15
|
-
|
|
53
|
+
debugRuntimeBaseUrl = '';
|
|
54
|
+
debugManifestUrl = '';
|
|
55
|
+
debugManifestReceipt;
|
|
56
|
+
executableGraphFingerprint = '';
|
|
16
57
|
oncompilerdiagnostic;
|
|
17
58
|
waitingForInput = false;
|
|
18
59
|
pendingEof = false;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
60
|
+
workerSession = new WorkerSession({
|
|
61
|
+
label: 'Rust',
|
|
62
|
+
onDispose: (worker) => {
|
|
63
|
+
this.disposeWorkerExecutableGraph(worker);
|
|
64
|
+
if (this.worker === worker)
|
|
65
|
+
delete this.worker;
|
|
66
|
+
this.exit = true;
|
|
22
67
|
this.waitingForInput = false;
|
|
23
68
|
this.pendingEof = false;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
69
|
+
this.ondebug?.({ type: 'stop' });
|
|
70
|
+
void this.lldbSession?.disconnect();
|
|
71
|
+
this.lldbSession = undefined;
|
|
72
|
+
this.lldbEditorSourcePath = rustLldbSourcePath;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
workerExecutableGraphs = new WeakMap();
|
|
76
|
+
loadGeneration = 0;
|
|
77
|
+
loadController = null;
|
|
78
|
+
pendingLoadWorker = null;
|
|
79
|
+
pendingLoadGraph = null;
|
|
80
|
+
pendingLoadReject = null;
|
|
81
|
+
runActive = false;
|
|
82
|
+
lldbSession;
|
|
83
|
+
debugMode = 'none';
|
|
84
|
+
activeDebugPhaseTimeout;
|
|
85
|
+
lldbBreakpoints = new Map();
|
|
86
|
+
lldbEditorSourcePath = rustLldbSourcePath;
|
|
87
|
+
disposeWorkerExecutableGraph(worker) {
|
|
88
|
+
const executableGraph = this.workerExecutableGraphs.get(worker);
|
|
89
|
+
this.workerExecutableGraphs.delete(worker);
|
|
90
|
+
executableGraph?.dispose();
|
|
91
|
+
}
|
|
92
|
+
load(runtimeAssets = '', _code = '', _log = true, _args = [], _options = {}, progress) {
|
|
93
|
+
this.loadGeneration += 1;
|
|
94
|
+
const generation = this.loadGeneration;
|
|
95
|
+
this.loadController?.abort(new Error('Rust runtime load superseded'));
|
|
96
|
+
this.loadController = new AbortController();
|
|
97
|
+
this.pendingLoadReject?.('Rust runtime load superseded');
|
|
98
|
+
this.pendingLoadReject = null;
|
|
99
|
+
if (this.pendingLoadWorker) {
|
|
100
|
+
try {
|
|
101
|
+
this.pendingLoadWorker.terminate();
|
|
34
102
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.assetPath = nextAssetPath;
|
|
38
|
-
if (needsWorkerReset && this.worker) {
|
|
39
|
-
this.worker.terminate();
|
|
40
|
-
delete this.worker;
|
|
103
|
+
catch {
|
|
104
|
+
// A superseded candidate worker may already be stopped.
|
|
41
105
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
106
|
+
this.pendingLoadWorker = null;
|
|
107
|
+
}
|
|
108
|
+
this.pendingLoadGraph?.dispose();
|
|
109
|
+
this.pendingLoadGraph = null;
|
|
110
|
+
const controller = this.loadController;
|
|
111
|
+
const forwardAbort = () => controller.abort(_options.signal?.reason ?? new Error('Rust runtime load aborted'));
|
|
112
|
+
if (_options.signal?.aborted) {
|
|
113
|
+
forwardAbort();
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
_options.signal?.addEventListener('abort', forwardAbort, { once: true });
|
|
117
|
+
}
|
|
118
|
+
return (async () => {
|
|
119
|
+
let nextExecutableGraph = null;
|
|
120
|
+
let candidateWorker = null;
|
|
121
|
+
let candidateLoadReject = null;
|
|
122
|
+
let clearCandidateWait = () => { };
|
|
123
|
+
try {
|
|
124
|
+
const currentUrl = typeof window !== 'undefined' ? window.location.href : '';
|
|
125
|
+
const nextCompilerUrl = resolveRustCompilerUrl(runtimeAssets, currentUrl);
|
|
126
|
+
const nextDebugModuleUrl = resolveRustDebugModuleUrl(runtimeAssets, currentUrl);
|
|
127
|
+
const debugRuntime = resolveDebugRuntimeUrls(runtimeAssets, currentUrl);
|
|
128
|
+
const nextDebugRuntimeBaseUrl = debugRuntime.baseUrl;
|
|
129
|
+
const nextDebugManifestUrl = debugRuntime.manifestUrl;
|
|
130
|
+
const nextDebugManifestReceipt = debugRuntime.manifestReceipt;
|
|
131
|
+
const nextAssetPath = typeof runtimeAssets === 'string'
|
|
132
|
+
? runtimeAssets
|
|
133
|
+
: runtimeAssets?.rootUrl ||
|
|
134
|
+
(typeof window !== 'undefined'
|
|
135
|
+
? window.location.pathname.replace(/\/$/, '')
|
|
136
|
+
: '');
|
|
137
|
+
if (!nextCompilerUrl) {
|
|
138
|
+
throw new Error('Rust runtime is not configured. Set PUBLIC_WASM_RUST_COMPILER_URL or runtimeAssets.rust.compilerUrl.');
|
|
139
|
+
}
|
|
140
|
+
const configuredGraphFingerprint = typeof runtimeAssets === 'string'
|
|
141
|
+
? undefined
|
|
142
|
+
: runtimeAssets.rust?.executableGraphFingerprint;
|
|
143
|
+
if (configuredGraphFingerprint !== undefined &&
|
|
144
|
+
configuredGraphFingerprint !== WASM_RUST_EXECUTABLE_GRAPH_PROFILE.fingerprint) {
|
|
145
|
+
throw new Error('Rust executable graph fingerprint does not match the bundled receipt profile');
|
|
146
|
+
}
|
|
147
|
+
const configuredRuntimeProfile = typeof runtimeAssets === 'string' ? undefined : runtimeAssets.rust;
|
|
148
|
+
if (configuredRuntimeProfile &&
|
|
149
|
+
((configuredRuntimeProfile.profileId !== undefined &&
|
|
150
|
+
configuredRuntimeProfile.profileId !==
|
|
151
|
+
WASM_RUST_RUNTIME_PROFILE.profileId) ||
|
|
152
|
+
(configuredRuntimeProfile.protocolVersion !== undefined &&
|
|
153
|
+
configuredRuntimeProfile.protocolVersion !==
|
|
154
|
+
WASM_RUST_RUNTIME_PROFILE.protocolVersion) ||
|
|
155
|
+
(configuredRuntimeProfile.manifestPath !== undefined &&
|
|
156
|
+
configuredRuntimeProfile.manifestPath !==
|
|
157
|
+
WASM_RUST_RUNTIME_PROFILE.manifestPath) ||
|
|
158
|
+
(configuredRuntimeProfile.manifestFingerprint !== undefined &&
|
|
159
|
+
configuredRuntimeProfile.manifestFingerprint !==
|
|
160
|
+
WASM_RUST_RUNTIME_PROFILE.manifestFingerprint) ||
|
|
161
|
+
(configuredRuntimeProfile.manifestReceipt !== undefined &&
|
|
162
|
+
(configuredRuntimeProfile.manifestReceipt.bytes !==
|
|
163
|
+
WASM_RUST_RUNTIME_PROFILE.manifestReceipt.bytes ||
|
|
164
|
+
configuredRuntimeProfile.manifestReceipt.sha256 !==
|
|
165
|
+
WASM_RUST_RUNTIME_PROFILE.manifestReceipt.sha256)))) {
|
|
166
|
+
throw new Error('Rust runtime profile does not match the bundled receipt profile');
|
|
167
|
+
}
|
|
168
|
+
if (controller.signal.aborted) {
|
|
169
|
+
throw controller.signal.reason ?? new Error('Rust runtime load aborted');
|
|
170
|
+
}
|
|
171
|
+
const needsWorkerReset = !this.worker ||
|
|
172
|
+
this.compilerUrl !== nextCompilerUrl ||
|
|
173
|
+
this.debugModuleUrl !== nextDebugModuleUrl ||
|
|
174
|
+
this.assetPath !== nextAssetPath ||
|
|
175
|
+
this.executableGraphFingerprint !==
|
|
176
|
+
WASM_RUST_EXECUTABLE_GRAPH_PROFILE.fingerprint;
|
|
177
|
+
if (!needsWorkerReset) {
|
|
178
|
+
this.debugRuntimeBaseUrl = nextDebugRuntimeBaseUrl;
|
|
179
|
+
this.debugManifestUrl = nextDebugManifestUrl;
|
|
180
|
+
this.debugManifestReceipt = nextDebugManifestReceipt;
|
|
181
|
+
progress?.set?.(1);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
nextExecutableGraph = await loadVerifiedRustExecutableGraph({
|
|
185
|
+
moduleUrl: nextCompilerUrl,
|
|
186
|
+
currentUrl,
|
|
187
|
+
profile: WASM_RUST_EXECUTABLE_GRAPH_PROFILE,
|
|
188
|
+
runtimeProfile: WASM_RUST_RUNTIME_PROFILE,
|
|
189
|
+
signal: controller.signal,
|
|
190
|
+
...(_options.limits?.maxAssetBytes !== undefined
|
|
191
|
+
? { maxAssetBytes: _options.limits.maxAssetBytes }
|
|
192
|
+
: {}),
|
|
193
|
+
...(_options.limits?.assetTimeoutMs !== undefined
|
|
194
|
+
? { assetTimeoutMs: _options.limits.assetTimeoutMs }
|
|
195
|
+
: {})
|
|
196
|
+
});
|
|
197
|
+
if (generation !== this.loadGeneration ||
|
|
198
|
+
controller.signal.aborted ||
|
|
199
|
+
this.loadController !== controller) {
|
|
200
|
+
throw controller.signal.reason ?? new Error('Rust runtime load superseded');
|
|
201
|
+
}
|
|
202
|
+
this.pendingLoadGraph = nextExecutableGraph;
|
|
203
|
+
const WorkerConstructor = (await import('./worker/rust?worker'))
|
|
204
|
+
.default;
|
|
205
|
+
if (generation !== this.loadGeneration ||
|
|
206
|
+
controller.signal.aborted ||
|
|
207
|
+
this.loadController !== controller) {
|
|
208
|
+
throw controller.signal.reason ?? new Error('Rust runtime load superseded');
|
|
209
|
+
}
|
|
210
|
+
candidateWorker = new WorkerConstructor();
|
|
211
|
+
this.pendingLoadWorker = candidateWorker;
|
|
212
|
+
await new Promise((resolveCandidate, rejectCandidate) => {
|
|
213
|
+
const startupTimeoutMs = _options.limits?.startupTimeoutMs ?? 60_000;
|
|
214
|
+
if (!Number.isSafeInteger(startupTimeoutMs) || startupTimeoutMs <= 0) {
|
|
215
|
+
rejectCandidate(new Error('Rust worker startup timeout must be a positive integer'));
|
|
216
|
+
return;
|
|
57
217
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
218
|
+
let settled = false;
|
|
219
|
+
const settle = (action) => {
|
|
220
|
+
if (settled)
|
|
221
|
+
return;
|
|
222
|
+
settled = true;
|
|
223
|
+
clearCandidateWait();
|
|
224
|
+
action();
|
|
225
|
+
};
|
|
226
|
+
const rejectForAbort = () => settle(() => rejectCandidate(controller.signal.reason ?? new Error('Rust runtime load aborted')));
|
|
227
|
+
const timeout = setTimeout(() => settle(() => rejectCandidate(new Error(`Rust worker startup timed out after ${startupTimeoutMs} ms`))), startupTimeoutMs);
|
|
228
|
+
clearCandidateWait = () => {
|
|
229
|
+
clearTimeout(timeout);
|
|
230
|
+
controller.signal.removeEventListener('abort', rejectForAbort);
|
|
231
|
+
};
|
|
232
|
+
controller.signal.addEventListener('abort', rejectForAbort, { once: true });
|
|
233
|
+
if (controller.signal.aborted) {
|
|
234
|
+
rejectForAbort();
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
candidateLoadReject = rejectCandidate;
|
|
238
|
+
this.pendingLoadReject = rejectCandidate;
|
|
239
|
+
candidateWorker.onmessage = (event) => {
|
|
240
|
+
if (event.data?.load) {
|
|
241
|
+
settle(resolveCandidate);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (event.data?.error)
|
|
245
|
+
settle(() => rejectCandidate(event.data.error));
|
|
246
|
+
};
|
|
247
|
+
candidateWorker.onerror = (event) => {
|
|
248
|
+
const location = event.filename && event.lineno
|
|
249
|
+
? ` (${event.filename}:${event.lineno}:${event.colno})`
|
|
250
|
+
: '';
|
|
251
|
+
settle(() => rejectCandidate(`Rust worker script error: ${event.message || 'unknown error'}${location}`));
|
|
252
|
+
};
|
|
253
|
+
candidateWorker.onmessageerror = () => {
|
|
254
|
+
settle(() => rejectCandidate('Rust worker message deserialization failed'));
|
|
255
|
+
};
|
|
256
|
+
candidateWorker.postMessage({
|
|
257
|
+
load: true,
|
|
258
|
+
compilerUrl: nextExecutableGraph.entryUrl,
|
|
259
|
+
debugModuleUrl: nextDebugModuleUrl,
|
|
260
|
+
path: nextAssetPath,
|
|
261
|
+
runtimeProfile: nextExecutableGraph.runtimeProfile,
|
|
262
|
+
verifiedModuleUrls: nextExecutableGraph.networkModuleUrls,
|
|
263
|
+
executableGraphFingerprint: WASM_RUST_EXECUTABLE_GRAPH_PROFILE.fingerprint
|
|
264
|
+
});
|
|
65
265
|
});
|
|
66
|
-
|
|
67
|
-
|
|
266
|
+
if (this.pendingLoadReject === candidateLoadReject)
|
|
267
|
+
this.pendingLoadReject = null;
|
|
268
|
+
if (generation !== this.loadGeneration ||
|
|
269
|
+
controller.signal.aborted ||
|
|
270
|
+
this.loadController !== controller) {
|
|
271
|
+
throw controller.signal.reason ?? new Error('Rust runtime load superseded');
|
|
272
|
+
}
|
|
273
|
+
this.pendingInput = [];
|
|
274
|
+
this.waitingForInput = false;
|
|
275
|
+
this.pendingEof = false;
|
|
276
|
+
this.compilerUrl = nextCompilerUrl;
|
|
277
|
+
this.debugModuleUrl = nextDebugModuleUrl;
|
|
278
|
+
this.assetPath = nextAssetPath;
|
|
279
|
+
this.debugRuntimeBaseUrl = nextDebugRuntimeBaseUrl;
|
|
280
|
+
this.debugManifestUrl = nextDebugManifestUrl;
|
|
281
|
+
this.debugManifestReceipt = nextDebugManifestReceipt;
|
|
282
|
+
this.executableGraphFingerprint = WASM_RUST_EXECUTABLE_GRAPH_PROFILE.fingerprint;
|
|
283
|
+
if (this.worker && this.worker !== candidateWorker) {
|
|
284
|
+
this.workerSession.terminate('Rust runtime worker replaced');
|
|
285
|
+
}
|
|
286
|
+
this.worker = candidateWorker;
|
|
287
|
+
this.workerExecutableGraphs.set(candidateWorker, nextExecutableGraph);
|
|
288
|
+
nextExecutableGraph = null;
|
|
289
|
+
this.pendingLoadGraph = null;
|
|
290
|
+
this.pendingLoadWorker = null;
|
|
291
|
+
this.workerSession.attach(candidateWorker);
|
|
292
|
+
candidateWorker = null;
|
|
68
293
|
progress?.set?.(1);
|
|
69
|
-
resolve();
|
|
70
294
|
}
|
|
71
|
-
|
|
295
|
+
finally {
|
|
296
|
+
clearCandidateWait();
|
|
297
|
+
if (this.pendingLoadReject === candidateLoadReject)
|
|
298
|
+
this.pendingLoadReject = null;
|
|
299
|
+
if (candidateWorker) {
|
|
300
|
+
try {
|
|
301
|
+
candidateWorker.terminate();
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
// Candidate cleanup must not replace the load result.
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (this.pendingLoadWorker === candidateWorker)
|
|
308
|
+
this.pendingLoadWorker = null;
|
|
309
|
+
nextExecutableGraph?.dispose();
|
|
310
|
+
if (this.pendingLoadGraph === nextExecutableGraph)
|
|
311
|
+
this.pendingLoadGraph = null;
|
|
312
|
+
if (this.loadController === controller)
|
|
313
|
+
this.loadController = null;
|
|
314
|
+
_options.signal?.removeEventListener('abort', forwardAbort);
|
|
315
|
+
}
|
|
316
|
+
})();
|
|
72
317
|
}
|
|
73
318
|
write(input) {
|
|
319
|
+
if (this.lldbSession) {
|
|
320
|
+
void this.lldbSession.write(input);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
74
323
|
this.pendingInput.push(input);
|
|
75
324
|
this.pendingEof = false;
|
|
76
325
|
this.flushPendingInput();
|
|
77
326
|
}
|
|
78
327
|
eof() {
|
|
328
|
+
if (this.lldbSession) {
|
|
329
|
+
void this.lldbSession.eof();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
79
332
|
this.pendingEof = true;
|
|
80
333
|
this.flushPendingInput();
|
|
81
334
|
}
|
|
@@ -93,72 +346,456 @@ class Rust {
|
|
|
93
346
|
}
|
|
94
347
|
}
|
|
95
348
|
run(code, prepare, _log = true, _prog, args = [], options = {}) {
|
|
96
|
-
|
|
349
|
+
const debugMode = options.debugMode || (options.debug ? 'trace' : 'none');
|
|
350
|
+
this.debugMode = debugMode;
|
|
351
|
+
if (debugMode !== 'none')
|
|
352
|
+
requireSharedArrayBuffer('Rust debugging');
|
|
97
353
|
return new Promise((resolve, reject) => {
|
|
98
354
|
if (!this.worker)
|
|
99
355
|
return reject('Worker not loaded');
|
|
356
|
+
if (this.runActive)
|
|
357
|
+
return reject('Rust runtime already has an active run');
|
|
358
|
+
if (options.signal?.aborted) {
|
|
359
|
+
return reject(options.signal.reason ?? new Error('Rust runtime run aborted'));
|
|
360
|
+
}
|
|
361
|
+
let limits;
|
|
362
|
+
let nonDebugResourceLimits;
|
|
363
|
+
try {
|
|
364
|
+
limits = resolveExecutionLimits(options.limits);
|
|
365
|
+
nonDebugResourceLimits =
|
|
366
|
+
debugMode === 'none' ? resolveRustNonDebugResourceLimits(limits) : undefined;
|
|
367
|
+
}
|
|
368
|
+
catch (error) {
|
|
369
|
+
return reject(error);
|
|
370
|
+
}
|
|
371
|
+
this.runActive = true;
|
|
372
|
+
this.exit = false;
|
|
373
|
+
let settled = false;
|
|
374
|
+
let phaseTimeout;
|
|
375
|
+
let phaseTimeoutState;
|
|
376
|
+
let outputBytes = 0;
|
|
377
|
+
let diagnosticCount = 0;
|
|
378
|
+
const clearScheduledPhaseTimeout = () => {
|
|
379
|
+
if (phaseTimeout !== undefined)
|
|
380
|
+
clearTimeout(phaseTimeout);
|
|
381
|
+
phaseTimeout = undefined;
|
|
382
|
+
};
|
|
383
|
+
const clearPhaseTimeout = () => {
|
|
384
|
+
clearScheduledPhaseTimeout();
|
|
385
|
+
phaseTimeoutState = undefined;
|
|
386
|
+
};
|
|
387
|
+
const armPhaseTimeout = () => {
|
|
388
|
+
const state = phaseTimeoutState;
|
|
389
|
+
if (!state || state.paused || settled)
|
|
390
|
+
return;
|
|
391
|
+
clearScheduledPhaseTimeout();
|
|
392
|
+
state.startedAt = Date.now();
|
|
393
|
+
phaseTimeout = setTimeout(() => {
|
|
394
|
+
if (phaseTimeoutState !== state || state.paused || settled)
|
|
395
|
+
return;
|
|
396
|
+
phaseTimeout = undefined;
|
|
397
|
+
state.remainingMs = 0;
|
|
398
|
+
const timeoutError = new TimeoutError(`Rust ${state.phase} timed out after ${state.timeoutMs} ms`, {
|
|
399
|
+
phase: state.phase === 'compile' ? 'compile' : 'execute',
|
|
400
|
+
runtimeId: 'RUST',
|
|
401
|
+
timeoutMs: state.timeoutMs
|
|
402
|
+
});
|
|
403
|
+
const lldbSession = this.lldbSession;
|
|
404
|
+
if (!lldbSession) {
|
|
405
|
+
this.workerSession.terminate(timeoutError);
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (!this.workerSession.complete(operation))
|
|
409
|
+
return;
|
|
410
|
+
let disconnecting;
|
|
411
|
+
try {
|
|
412
|
+
disconnecting = Promise.resolve(lldbSession.disconnect());
|
|
413
|
+
}
|
|
414
|
+
catch {
|
|
415
|
+
disconnecting = Promise.resolve();
|
|
416
|
+
}
|
|
417
|
+
void disconnecting
|
|
418
|
+
.catch(() => undefined)
|
|
419
|
+
.then(() => {
|
|
420
|
+
if (this.lldbSession === lldbSession)
|
|
421
|
+
this.lldbSession = undefined;
|
|
422
|
+
this.lldbEditorSourcePath = rustLldbSourcePath;
|
|
423
|
+
this.exit = true;
|
|
424
|
+
this.waitingForInput = false;
|
|
425
|
+
this.pendingEof = false;
|
|
426
|
+
finishReject(timeoutError);
|
|
427
|
+
});
|
|
428
|
+
}, state.remainingMs);
|
|
429
|
+
};
|
|
430
|
+
const debugPhaseTimeout = {
|
|
431
|
+
pause: () => {
|
|
432
|
+
const state = phaseTimeoutState;
|
|
433
|
+
if (!state || state.paused || settled)
|
|
434
|
+
return;
|
|
435
|
+
state.remainingMs = Math.max(0, state.remainingMs - Math.max(0, Date.now() - state.startedAt));
|
|
436
|
+
state.paused = true;
|
|
437
|
+
clearScheduledPhaseTimeout();
|
|
438
|
+
},
|
|
439
|
+
resume: () => {
|
|
440
|
+
const state = phaseTimeoutState;
|
|
441
|
+
if (!state || !state.paused || settled)
|
|
442
|
+
return;
|
|
443
|
+
state.paused = false;
|
|
444
|
+
armPhaseTimeout();
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
if (debugMode !== 'none')
|
|
448
|
+
this.activeDebugPhaseTimeout = debugPhaseTimeout;
|
|
449
|
+
const finishResolve = (result) => {
|
|
450
|
+
if (settled)
|
|
451
|
+
return;
|
|
452
|
+
settled = true;
|
|
453
|
+
this.runActive = false;
|
|
454
|
+
clearPhaseTimeout();
|
|
455
|
+
if (this.activeDebugPhaseTimeout === debugPhaseTimeout) {
|
|
456
|
+
this.activeDebugPhaseTimeout = undefined;
|
|
457
|
+
}
|
|
458
|
+
options.signal?.removeEventListener('abort', abortRun);
|
|
459
|
+
resolve(result);
|
|
460
|
+
};
|
|
461
|
+
const finishReject = (reason) => {
|
|
462
|
+
if (settled)
|
|
463
|
+
return;
|
|
464
|
+
settled = true;
|
|
465
|
+
this.runActive = false;
|
|
466
|
+
clearPhaseTimeout();
|
|
467
|
+
if (this.activeDebugPhaseTimeout === debugPhaseTimeout) {
|
|
468
|
+
this.activeDebugPhaseTimeout = undefined;
|
|
469
|
+
}
|
|
470
|
+
options.signal?.removeEventListener('abort', abortRun);
|
|
471
|
+
reject(reason);
|
|
472
|
+
};
|
|
473
|
+
const abortRun = () => {
|
|
474
|
+
try {
|
|
475
|
+
const disconnecting = this.lldbSession?.disconnect();
|
|
476
|
+
if (disconnecting)
|
|
477
|
+
void Promise.resolve(disconnecting).catch(() => { });
|
|
478
|
+
}
|
|
479
|
+
catch {
|
|
480
|
+
// Worker termination below still settles the run if LLDB teardown throws.
|
|
481
|
+
}
|
|
482
|
+
this.workerSession.terminate(options.signal?.reason ?? new Error('Rust runtime run aborted'));
|
|
483
|
+
};
|
|
484
|
+
const startPhaseTimeout = (phase, timeoutMs) => {
|
|
485
|
+
const paused = phaseTimeoutState?.paused === true;
|
|
486
|
+
clearScheduledPhaseTimeout();
|
|
487
|
+
phaseTimeoutState = {
|
|
488
|
+
phase,
|
|
489
|
+
timeoutMs,
|
|
490
|
+
remainingMs: timeoutMs,
|
|
491
|
+
startedAt: Date.now(),
|
|
492
|
+
paused
|
|
493
|
+
};
|
|
494
|
+
armPhaseTimeout();
|
|
495
|
+
};
|
|
496
|
+
const forwardDebugEvent = (event) => {
|
|
497
|
+
if (event.type === 'pause')
|
|
498
|
+
debugPhaseTimeout.pause();
|
|
499
|
+
else if (event.type === 'resume')
|
|
500
|
+
debugPhaseTimeout.resume();
|
|
501
|
+
this.ondebug?.(event);
|
|
502
|
+
};
|
|
100
503
|
const { programArgs } = resolveSandboxExecutionArgs('RUST', args, options);
|
|
101
504
|
const targetTriple = options.rustTargetTriple || 'wasm32-wasip1';
|
|
102
505
|
const _uid = ++this.uid;
|
|
103
|
-
this.
|
|
506
|
+
const operation = this.workerSession.beginRun(this.worker, finishReject);
|
|
507
|
+
startPhaseTimeout('compile', limits.compileTimeoutMs);
|
|
508
|
+
options.signal?.addEventListener('abort', abortRun, { once: true });
|
|
509
|
+
if (options.signal?.aborted) {
|
|
510
|
+
abortRun();
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
const editorSourcePath = normalizeRustLldbSourcePath(options.debugPath || options.activePath);
|
|
514
|
+
this.lldbEditorSourcePath = editorSourcePath;
|
|
515
|
+
this.lldbBreakpoints.clear();
|
|
516
|
+
let lldbBreakpointLines = [];
|
|
517
|
+
if (debugMode === 'lldb') {
|
|
518
|
+
const requestedLines = [...(options.breakpoints || [])];
|
|
519
|
+
for (const sourceBreakpoints of options.sourceBreakpoints || []) {
|
|
520
|
+
if (normalizeRustLldbSourcePath(sourceBreakpoints.sourcePath) ===
|
|
521
|
+
editorSourcePath) {
|
|
522
|
+
requestedLines.push(...sourceBreakpoints.lines);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
lldbBreakpointLines = normalizeRustBreakpointLines(requestedLines);
|
|
526
|
+
this.lldbBreakpoints.set(rustLldbSourcePath, lldbBreakpointLines);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
this.setBreakpoints([...(options.breakpoints || [])], editorSourcePath);
|
|
530
|
+
}
|
|
104
531
|
const handler = (event) => {
|
|
105
532
|
if (!this.worker)
|
|
106
|
-
return
|
|
533
|
+
return finishReject('Worker not loaded');
|
|
107
534
|
if (_uid !== this.uid)
|
|
108
535
|
return (this.worker.onmessage = null);
|
|
109
|
-
const { output, results, error, buffer, diagnostic, progress } = event.data;
|
|
536
|
+
const { output, results, error, buffer, diagnostic, progress, runtimePhase, debugEvent, lldbArtifact } = event.data;
|
|
537
|
+
if (runtimePhase === 'run') {
|
|
538
|
+
startPhaseTimeout('run', limits.runTimeoutMs);
|
|
539
|
+
}
|
|
110
540
|
if (buffer) {
|
|
541
|
+
if (!prepare) {
|
|
542
|
+
reportWorkerInputReady(_prog, 'Rust program is waiting for input');
|
|
543
|
+
}
|
|
111
544
|
this.waitingForInput = true;
|
|
112
545
|
this.flushPendingInput();
|
|
113
546
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
547
|
+
reportWorkerProgress(_prog, progress);
|
|
548
|
+
if (output) {
|
|
549
|
+
outputBytes += outputEncoder.encode(String(output)).byteLength;
|
|
550
|
+
if (outputBytes > limits.maxOutputBytes) {
|
|
551
|
+
this.workerSession.terminate(new Error(`Rust output exceeded ${limits.maxOutputBytes} bytes`));
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
118
554
|
this.output(output);
|
|
119
|
-
|
|
555
|
+
}
|
|
556
|
+
if (diagnostic) {
|
|
557
|
+
diagnosticCount += 1;
|
|
558
|
+
if (diagnosticCount > limits.maxDiagnostics) {
|
|
559
|
+
this.workerSession.terminate(new Error(`Rust diagnostics exceeded ${limits.maxDiagnostics} entries`));
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
120
562
|
this.oncompilerdiagnostic?.(diagnostic);
|
|
563
|
+
}
|
|
564
|
+
if (debugEvent)
|
|
565
|
+
forwardDebugEvent(debugEvent);
|
|
566
|
+
if (lldbArtifact) {
|
|
567
|
+
startPhaseTimeout('run', limits.runTimeoutMs);
|
|
568
|
+
const compilerWorker = this.worker;
|
|
569
|
+
const lldbSession = new LldbSandboxSession({
|
|
570
|
+
manifestUrl: this.debugManifestUrl,
|
|
571
|
+
manifestReceipt: this.debugManifestReceipt,
|
|
572
|
+
runtimeBaseUrl: this.debugRuntimeBaseUrl,
|
|
573
|
+
artifact: lldbArtifact,
|
|
574
|
+
sourcePath: rustLldbSourcePath,
|
|
575
|
+
breakpoints: lldbBreakpointLines,
|
|
576
|
+
sourceBreakpoints: Array.from(this.lldbBreakpoints, ([sourcePath, lines]) => ({
|
|
577
|
+
sourcePath,
|
|
578
|
+
lines: [...lines]
|
|
579
|
+
})),
|
|
580
|
+
pauseOnEntry: !!options.pauseOnEntry,
|
|
581
|
+
programArgs,
|
|
582
|
+
stdin: options.stdin,
|
|
583
|
+
onDebugEvent: (debugEvent) => {
|
|
584
|
+
if (editorSourcePath !== rustLldbSourcePath &&
|
|
585
|
+
debugEvent.type === 'breakpoints' &&
|
|
586
|
+
debugEvent.sourcePath === rustLldbSourcePath) {
|
|
587
|
+
forwardDebugEvent({
|
|
588
|
+
...debugEvent,
|
|
589
|
+
sourcePath: editorSourcePath
|
|
590
|
+
});
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
if (editorSourcePath !== rustLldbSourcePath &&
|
|
594
|
+
debugEvent.type === 'pause') {
|
|
595
|
+
forwardDebugEvent({
|
|
596
|
+
...debugEvent,
|
|
597
|
+
sourcePath: debugEvent.sourcePath === rustLldbSourcePath
|
|
598
|
+
? editorSourcePath
|
|
599
|
+
: debugEvent.sourcePath,
|
|
600
|
+
callStack: debugEvent.callStack.map((frame) => frame.sourcePath === rustLldbSourcePath
|
|
601
|
+
? { ...frame, sourcePath: editorSourcePath }
|
|
602
|
+
: frame)
|
|
603
|
+
});
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
forwardDebugEvent(debugEvent);
|
|
607
|
+
},
|
|
608
|
+
onOutput: (debugOutput) => this.output(debugOutput)
|
|
609
|
+
});
|
|
610
|
+
this.lldbSession = lldbSession;
|
|
611
|
+
for (const input of this.pendingInput.splice(0))
|
|
612
|
+
void lldbSession.write(input);
|
|
613
|
+
if (this.pendingEof) {
|
|
614
|
+
this.pendingEof = false;
|
|
615
|
+
void lldbSession.eof();
|
|
616
|
+
}
|
|
617
|
+
if (compilerWorker && this.workerSession.release(compilerWorker)) {
|
|
618
|
+
this.disposeWorkerExecutableGraph(compilerWorker);
|
|
619
|
+
if (this.worker === compilerWorker)
|
|
620
|
+
delete this.worker;
|
|
621
|
+
}
|
|
622
|
+
void lldbSession.start().then((result) => {
|
|
623
|
+
if (this.lldbSession === lldbSession)
|
|
624
|
+
this.lldbSession = undefined;
|
|
625
|
+
this.lldbEditorSourcePath = rustLldbSourcePath;
|
|
626
|
+
this.elapse = Date.now() - this.begin;
|
|
627
|
+
this.exit = true;
|
|
628
|
+
if (!this.workerSession.complete(operation))
|
|
629
|
+
return;
|
|
630
|
+
finishResolve(result);
|
|
631
|
+
}, (sessionError) => {
|
|
632
|
+
if (this.lldbSession === lldbSession)
|
|
633
|
+
this.lldbSession = undefined;
|
|
634
|
+
this.lldbEditorSourcePath = rustLldbSourcePath;
|
|
635
|
+
this.elapse = Date.now() - this.begin;
|
|
636
|
+
this.exit = true;
|
|
637
|
+
if (!this.workerSession.complete(operation))
|
|
638
|
+
return;
|
|
639
|
+
finishReject(sessionError);
|
|
640
|
+
});
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
121
643
|
if (results) {
|
|
122
644
|
this.elapse = Date.now() - this.begin;
|
|
123
645
|
this.exit = true;
|
|
124
646
|
this.waitingForInput = false;
|
|
125
647
|
this.pendingEof = false;
|
|
126
|
-
this.
|
|
127
|
-
|
|
648
|
+
if (!this.workerSession.complete(operation))
|
|
649
|
+
return;
|
|
650
|
+
this.ondebug?.({ type: 'stop' });
|
|
651
|
+
finishResolve(results);
|
|
128
652
|
}
|
|
129
653
|
if (error) {
|
|
654
|
+
const errorText = String(error);
|
|
655
|
+
outputBytes += outputEncoder.encode(errorText).byteLength;
|
|
656
|
+
if (outputBytes > limits.maxOutputBytes) {
|
|
657
|
+
this.workerSession.terminate(new Error(`Rust output exceeded ${limits.maxOutputBytes} bytes`));
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
130
660
|
this.elapse = Date.now() - this.begin;
|
|
131
661
|
this.exit = true;
|
|
132
662
|
this.waitingForInput = false;
|
|
133
663
|
this.pendingEof = false;
|
|
134
|
-
this.
|
|
135
|
-
|
|
664
|
+
if (!this.workerSession.complete(operation))
|
|
665
|
+
return;
|
|
666
|
+
this.ondebug?.({ type: 'stop' });
|
|
667
|
+
finishReject(errorText);
|
|
136
668
|
}
|
|
137
669
|
};
|
|
138
670
|
this.worker.onmessage = handler;
|
|
139
671
|
this.begin = Date.now();
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
672
|
+
try {
|
|
673
|
+
this.worker.postMessage({
|
|
674
|
+
code,
|
|
675
|
+
prepare,
|
|
676
|
+
buffer: this.buffer,
|
|
677
|
+
debugBuffer: this.debugBuffer,
|
|
678
|
+
stdin: options.stdin,
|
|
679
|
+
args: programArgs,
|
|
680
|
+
targetTriple,
|
|
681
|
+
log: _log,
|
|
682
|
+
debugMode,
|
|
683
|
+
debug: debugMode === 'trace',
|
|
684
|
+
breakpoints: [...(options.breakpoints || [])],
|
|
685
|
+
pauseOnEntry: !!options.pauseOnEntry,
|
|
686
|
+
limits: {
|
|
687
|
+
maxOutputBytes: limits.maxOutputBytes,
|
|
688
|
+
maxDiagnostics: limits.maxDiagnostics,
|
|
689
|
+
...(nonDebugResourceLimits
|
|
690
|
+
? {
|
|
691
|
+
maxAssetBytes: limits.maxAssetBytes,
|
|
692
|
+
maxWorkers: nonDebugResourceLimits.maxWorkers,
|
|
693
|
+
maxThreads: nonDebugResourceLimits.maxThreads
|
|
694
|
+
}
|
|
695
|
+
: {})
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
catch (error) {
|
|
700
|
+
this.workerSession.terminate(error);
|
|
701
|
+
}
|
|
148
702
|
});
|
|
149
703
|
}
|
|
704
|
+
debugCommand(command) {
|
|
705
|
+
if (this.lldbSession)
|
|
706
|
+
return this.lldbSession.debugCommand(command);
|
|
707
|
+
const control = new Int32Array(this.debugBuffer);
|
|
708
|
+
Atomics.store(control, 1, command === 'stepInto' ? 2 : command === 'nextLine' ? 3 : command === 'stepOut' ? 4 : 1);
|
|
709
|
+
Atomics.add(control, 0, 1);
|
|
710
|
+
Atomics.notify(control, 0);
|
|
711
|
+
this.activeDebugPhaseTimeout?.resume();
|
|
712
|
+
this.ondebug?.({ type: 'resume', command });
|
|
713
|
+
}
|
|
714
|
+
debugPause() {
|
|
715
|
+
return this.lldbSession?.pause();
|
|
716
|
+
}
|
|
717
|
+
setBreakpoints(lines, sourcePath) {
|
|
718
|
+
const resolvedSourcePath = normalizeRustLldbSourcePath(sourcePath || this.lldbEditorSourcePath);
|
|
719
|
+
if (this.lldbSession) {
|
|
720
|
+
if (resolvedSourcePath !== this.lldbEditorSourcePath)
|
|
721
|
+
return;
|
|
722
|
+
return this.lldbSession.setBreakpoints(normalizeRustBreakpointLines(lines), rustLldbSourcePath);
|
|
723
|
+
}
|
|
724
|
+
if (this.debugMode === 'lldb') {
|
|
725
|
+
if (resolvedSourcePath !== this.lldbEditorSourcePath)
|
|
726
|
+
return;
|
|
727
|
+
this.lldbBreakpoints.set(rustLldbSourcePath, normalizeRustBreakpointLines(lines));
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
const control = new Int32Array(this.debugBuffer);
|
|
731
|
+
const next = normalizeRustBreakpointLines(lines).slice(0, Math.max(0, control.length - 4));
|
|
732
|
+
for (let index = 4; index < control.length; index += 1) {
|
|
733
|
+
Atomics.store(control, index, next[index - 4] || 0);
|
|
734
|
+
}
|
|
735
|
+
Atomics.store(control, 3, next.length);
|
|
736
|
+
Atomics.add(control, 2, 1);
|
|
737
|
+
}
|
|
738
|
+
debugEvaluate(expression) {
|
|
739
|
+
return this.lldbSession?.evaluate(expression) ?? Promise.resolve('?');
|
|
740
|
+
}
|
|
741
|
+
debugVariables(variablesReference, start, count) {
|
|
742
|
+
return this.lldbSession?.variables(variablesReference, start, count) ?? Promise.resolve([]);
|
|
743
|
+
}
|
|
744
|
+
debugScopes(frameId) {
|
|
745
|
+
return this.lldbSession?.scopes(frameId) ?? Promise.resolve([]);
|
|
746
|
+
}
|
|
747
|
+
debugFrameScopes(frameId) {
|
|
748
|
+
return this.lldbSession?.frameScopes(frameId) ?? Promise.resolve([]);
|
|
749
|
+
}
|
|
750
|
+
debugFrameName(frameId) {
|
|
751
|
+
return this.lldbSession?.formattedFrameName(frameId) ?? Promise.resolve(null);
|
|
752
|
+
}
|
|
753
|
+
debugReadMemory(memoryReference, offset, count) {
|
|
754
|
+
return (this.lldbSession?.readMemory(memoryReference, offset, count) ?? Promise.resolve(null));
|
|
755
|
+
}
|
|
756
|
+
debugWriteMemory(memoryReference, offset, data, allowPartial = false) {
|
|
757
|
+
return (this.lldbSession?.writeMemory(memoryReference, offset, data, allowPartial) ??
|
|
758
|
+
Promise.resolve(null));
|
|
759
|
+
}
|
|
760
|
+
debugDataBreakpointInfo(arguments_) {
|
|
761
|
+
return this.lldbSession?.dataBreakpointInfo(arguments_) ?? Promise.resolve(null);
|
|
762
|
+
}
|
|
763
|
+
debugSetDataBreakpoints(breakpoints) {
|
|
764
|
+
return this.lldbSession?.setDataBreakpoints(breakpoints) ?? Promise.resolve([]);
|
|
765
|
+
}
|
|
150
766
|
kill() {
|
|
151
|
-
this.terminate();
|
|
767
|
+
return this.terminate();
|
|
152
768
|
}
|
|
153
|
-
terminate() {
|
|
154
|
-
this.
|
|
155
|
-
this.
|
|
769
|
+
async terminate() {
|
|
770
|
+
this.loadGeneration += 1;
|
|
771
|
+
this.loadController?.abort(new Error('Rust runtime terminated'));
|
|
772
|
+
this.loadController = null;
|
|
773
|
+
this.pendingLoadReject?.('Process terminated');
|
|
774
|
+
this.pendingLoadReject = null;
|
|
775
|
+
if (this.pendingLoadWorker) {
|
|
776
|
+
try {
|
|
777
|
+
this.pendingLoadWorker.terminate();
|
|
778
|
+
}
|
|
779
|
+
catch {
|
|
780
|
+
// A candidate worker may already be stopped.
|
|
781
|
+
}
|
|
782
|
+
this.pendingLoadWorker = null;
|
|
783
|
+
}
|
|
784
|
+
this.pendingLoadGraph?.dispose();
|
|
785
|
+
this.pendingLoadGraph = null;
|
|
786
|
+
const lldbSession = this.lldbSession;
|
|
787
|
+
this.lldbSession = undefined;
|
|
788
|
+
this.lldbEditorSourcePath = rustLldbSourcePath;
|
|
789
|
+
const disconnecting = lldbSession?.disconnect();
|
|
156
790
|
this.waitingForInput = false;
|
|
157
791
|
this.pendingEof = false;
|
|
158
792
|
this.uid += 1;
|
|
159
|
-
this.
|
|
160
|
-
|
|
793
|
+
const control = new Int32Array(this.debugBuffer);
|
|
794
|
+
Atomics.add(control, 0, 1);
|
|
795
|
+
Atomics.notify(control, 0);
|
|
796
|
+
this.workerSession.terminate();
|
|
161
797
|
this.exit = true;
|
|
798
|
+
await disconnecting;
|
|
162
799
|
}
|
|
163
800
|
async clear() {
|
|
164
801
|
this.pendingInput = [];
|
|
@@ -167,8 +804,9 @@ class Rust {
|
|
|
167
804
|
if (this.worker)
|
|
168
805
|
this.worker.onmessage = null;
|
|
169
806
|
resetBufferedStdin(this.buffer);
|
|
807
|
+
new Int32Array(this.debugBuffer).fill(0);
|
|
170
808
|
if (!this.exit) {
|
|
171
|
-
this.terminate();
|
|
809
|
+
await this.terminate();
|
|
172
810
|
}
|
|
173
811
|
}
|
|
174
812
|
}
|