wasm-idle 1.1.2 → 1.3.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 +211 -91
- package/dist/container/bash-profile.d.ts +80 -0
- package/dist/container/bash-profile.js +328 -0
- package/dist/{playground/container → container}/binding.d.ts +21 -8
- package/dist/{playground/container → container}/binding.js +109 -25
- package/dist/{playground/container → container}/clang-runtime.d.ts +11 -7
- package/dist/container/clang-runtime.js +561 -0
- package/dist/container/client.d.ts +14 -0
- package/dist/{playground/container → container}/client.js +2 -6
- package/dist/{playground/container → container}/explorer.d.ts +1 -1
- package/dist/container/index.d.ts +11 -0
- package/dist/container/index.js +11 -0
- package/dist/container/owner-worker.d.ts +19 -0
- package/dist/container/owner-worker.js +464 -0
- package/dist/{playground/container → container}/protocol.d.ts +12 -1
- package/dist/{playground/container → container}/runtime-adapter.d.ts +13 -11
- package/dist/{playground/container → container}/runtime-adapter.js +104 -41
- package/dist/{playground/container → container}/shell-control.d.ts +2 -2
- package/dist/{playground/container → container}/shell-control.js +93 -36
- package/dist/{playground/container → container}/workspace.d.ts +5 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/playground/assetBridge.js +5 -2
- package/dist/playground/assets.d.ts +8 -0
- package/dist/playground/clang.d.ts +5 -1
- package/dist/playground/clang.js +61 -5
- package/dist/playground/compiledLldb.d.ts +41 -0
- package/dist/playground/compiledLldb.js +167 -0
- package/dist/playground/d.d.ts +4 -1
- package/dist/playground/d.js +78 -9
- package/dist/playground/debugDeadline.d.ts +12 -0
- package/dist/playground/debugDeadline.js +34 -0
- package/dist/playground/debugMailbox.d.ts +12 -0
- package/dist/playground/debugMailbox.js +77 -0
- package/dist/playground/go.js +9 -4
- package/dist/playground/goDebugInstrumentation.js +24 -44
- package/dist/playground/java-debug-HUZVAK4F.js +124 -0
- package/dist/playground/java-debug-notices.txt +492 -0
- package/dist/playground/java.d.ts +17 -1
- package/dist/playground/java.js +159 -3
- package/dist/playground/javaDebug.d.ts +62 -0
- package/dist/playground/javaDebug.js +305 -0
- package/dist/playground/javaDebugBridge.d.ts +6 -0
- package/dist/playground/javaDebugBridge.js +250 -0
- package/dist/playground/javaDebugSource.d.ts +9 -0
- package/dist/playground/javaDebugSource.js +4 -0
- package/dist/playground/javaRuntimeErrors.js +34 -1
- package/dist/playground/lean4Assets.d.ts +1 -25
- package/dist/playground/lean4Assets.js +2 -123
- package/dist/playground/lfortranAssets.d.ts +2 -2
- package/dist/playground/lldbSession.d.ts +24 -2
- package/dist/playground/lldbSession.js +322 -59
- package/dist/playground/lldbSourcePath.d.ts +2 -0
- package/dist/playground/lldbSourcePath.js +9 -0
- package/dist/playground/lua.d.ts +20 -1
- package/dist/playground/lua.js +190 -8
- package/dist/playground/luaDebug.d.ts +1 -0
- package/dist/playground/luaDebug.js +1 -0
- package/dist/playground/nim.d.ts +1 -0
- package/dist/playground/nim.js +8 -0
- package/dist/playground/objectivec.d.ts +7 -6
- package/dist/playground/objectivec.js +75 -9
- package/dist/playground/options.d.ts +10 -4
- package/dist/playground/python.d.ts +11 -1
- package/dist/playground/python.js +203 -8
- package/dist/playground/pythonCompileOptions.d.ts +49 -0
- package/dist/playground/pythonCompileOptions.js +40 -0
- package/dist/playground/ruby.d.ts +10 -1
- package/dist/playground/ruby.js +66 -1
- package/dist/playground/rubyDebug.d.ts +21 -0
- package/dist/playground/rubyDebug.js +128 -0
- package/dist/playground/rust.d.ts +5 -1
- package/dist/playground/rust.js +128 -46
- package/dist/playground/sandbox.d.ts +8 -1
- package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -1
- package/dist/playground/staticRuntimeModuleVersion.js +1 -1
- package/dist/playground/staticWorkerRuntime.js +8 -2
- package/dist/playground/stdinBuffer.d.ts +1 -1
- package/dist/playground/stdinBuffer.js +19 -2
- package/dist/playground/tinygo.js +7 -0
- package/dist/playground/typescript.js +8 -0
- package/dist/playground/v.d.ts +3 -2
- package/dist/playground/v.js +66 -12
- package/dist/playground/wasmC3Version.d.ts +2 -2
- package/dist/playground/wasmC3Version.js +2 -2
- package/dist/playground/wasmDebugVersion.d.ts +1 -1
- package/dist/playground/wasmDebugVersion.js +1 -1
- package/dist/playground/wasmLean4Version.d.ts +1 -110
- package/dist/playground/wasmLean4Version.js +2 -111
- package/dist/playground/wasmLfortranVersion.d.ts +2 -2
- package/dist/playground/wasmLfortranVersion.js +2 -2
- package/dist/playground/wasmLuaVersion.d.ts +1 -1
- package/dist/playground/wasmLuaVersion.js +1 -1
- package/dist/playground/wasmPrologVersion.d.ts +17 -17
- package/dist/playground/wasmPrologVersion.js +16 -16
- package/dist/playground/wasmRustVersion.d.ts +26 -38
- package/dist/playground/wasmRustVersion.js +25 -40
- package/dist/playground/wasmTypeScriptVersion.d.ts +3 -3
- package/dist/playground/wasmTypeScriptVersion.js +3 -3
- package/dist/playground/worker/clang.js +1 -1
- package/dist/playground/worker/cobol.js +1 -1
- package/dist/playground/worker/d.js +51 -2
- package/dist/playground/worker/fortran.js +1 -1
- package/dist/playground/worker/java.js +188 -35
- package/dist/playground/worker/javaDebugEvaluator.d.ts +16 -0
- package/dist/playground/worker/javaDebugEvaluator.js +44 -0
- package/dist/playground/worker/javaDebugRuntime.d.ts +24 -0
- package/dist/playground/worker/javaDebugRuntime.js +315 -0
- package/dist/playground/worker/javaOutput.d.ts +11 -0
- package/dist/playground/worker/javaOutput.js +54 -0
- package/dist/playground/worker/lua.js +13 -0
- package/dist/playground/worker/python.js +81 -23
- package/dist/playground/worker/pythonCompile.d.ts +4 -0
- package/dist/playground/worker/pythonCompile.js +122 -0
- package/dist/playground/worker/ruby.js +13 -0
- package/dist/playground/worker/rubyDebugPreview.d.ts +2 -0
- package/dist/playground/worker/rubyDebugPreview.js +80 -0
- package/dist/playground/worker/rubyTracepoint.d.ts +16 -0
- package/dist/playground/worker/rubyTracepoint.js +162 -0
- package/dist/playground/worker/rust.js +4 -1
- package/dist/playground/worker/v.js +30 -5
- package/dist/playground/zig.js +4 -0
- package/dist/pythonCompiler.d.ts +8 -0
- package/dist/pythonCompiler.js +52 -0
- package/package.json +76 -28
- package/dist/playground/container/ContainerExplorer.svelte +0 -307
- package/dist/playground/container/ContainerExplorer.svelte.d.ts +0 -14
- package/dist/playground/container/clang-runtime.js +0 -343
- package/dist/playground/container/client.d.ts +0 -15
- package/dist/playground/container/owner.worker.d.ts +0 -1
- package/dist/playground/container/owner.worker.js +0 -390
- package/dist/playground/container/release.d.ts +0 -31
- package/dist/playground/container/release.js +0 -612
- /package/dist/{playground/container → container}/explorer.js +0 -0
- /package/dist/{playground/container → container}/protocol.js +0 -0
- /package/dist/{playground/container → container}/workspace.js +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type Container, type ContainerOptions, type SnapshotEntry, type HostCommandInvocation, type HostCommandRecord, type HostCommandRoute } from '@wasm-idle/container';
|
|
2
|
+
import { type WasixAssetReference, type WasixSdk, type WasixShellOptions, type WasixShellSession, type WasixWorkerGroup } from '@wasm-idle/container/adapters/wasix';
|
|
3
|
+
export declare const BASH_BIN = "/usr/local/bin";
|
|
4
|
+
export declare const BASH_SYSROOT = "/usr/share/wasm-sysroot";
|
|
5
|
+
export declare const C_SYSROOT = "/usr/share/wasm-sysroot-c";
|
|
6
|
+
/** Expose the verified legacy sysroot through the canonical driver's automatic search paths. */
|
|
7
|
+
export declare function withCanonicalWasiPaths(entries: readonly Omit<SnapshotEntry, 'inode'>[]): readonly Omit<SnapshotEntry, "inode">[];
|
|
8
|
+
/** Pinned assets and worker URLs selected by trusted application code. */
|
|
9
|
+
export interface BashProfileConfiguration {
|
|
10
|
+
manifest: string;
|
|
11
|
+
manifestSha256: string;
|
|
12
|
+
assetURLs: readonly string[];
|
|
13
|
+
sdkUrl: string;
|
|
14
|
+
sdkWorkerUrl: string;
|
|
15
|
+
liveWorkerUrl: string;
|
|
16
|
+
clangWorkerUrl: string;
|
|
17
|
+
sdkAsset?: WasixAssetReference;
|
|
18
|
+
shellAsset?: WasixAssetReference;
|
|
19
|
+
bashWasmSha256: string;
|
|
20
|
+
memory: WasixShellOptions['memory'];
|
|
21
|
+
clangSha256: string;
|
|
22
|
+
linkerSha256: string;
|
|
23
|
+
cacheNamespace: string;
|
|
24
|
+
commandTimeoutMs?: number;
|
|
25
|
+
maxWorkers?: number;
|
|
26
|
+
clangFilesystem?: string;
|
|
27
|
+
/** Requires a matching host Worker with module reuse services. */
|
|
28
|
+
clangModuleServices?: boolean;
|
|
29
|
+
sysrootProfile?: 'full' | 'c-base-v1';
|
|
30
|
+
sysrootLayers?: {
|
|
31
|
+
schemaVersion: 1;
|
|
32
|
+
basePackage: 'llvm-sysroot-c';
|
|
33
|
+
cxxPackage: 'llvm-sysroot-cxx';
|
|
34
|
+
full: {
|
|
35
|
+
sha256: string;
|
|
36
|
+
bytes: number;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface BashProfileOptions {
|
|
41
|
+
config: BashProfileConfiguration;
|
|
42
|
+
sdk: WasixSdk;
|
|
43
|
+
/** The injecting host retains the lifetime of this persistence workspace. */
|
|
44
|
+
workspace?: ContainerOptions['workspace'];
|
|
45
|
+
fetch?: typeof globalThis.fetch;
|
|
46
|
+
onRecord?: (record: HostCommandRecord) => void;
|
|
47
|
+
onInvocation?: (invocation: HostCommandInvocation) => void;
|
|
48
|
+
adapters?: ContainerOptions['adapters'];
|
|
49
|
+
commands?: ContainerOptions['commands'];
|
|
50
|
+
workerGroup?: WasixWorkerGroup;
|
|
51
|
+
/** Registered BusyBox commands chosen by the application's pinned distribution. */
|
|
52
|
+
shellCommands?: readonly string[];
|
|
53
|
+
shellRoutes?: Readonly<Record<string, HostCommandRoute>>;
|
|
54
|
+
}
|
|
55
|
+
/** Compose verified USTAR layers without changing retained header or file bytes. */
|
|
56
|
+
export declare function composeSysrootLayers(base: Uint8Array, cxx: Uint8Array): Uint8Array<ArrayBuffer>;
|
|
57
|
+
/** A shared Bash/Clang owner. Importing this module does not load any runtime assets. */
|
|
58
|
+
export declare function createBashProfile({ config, sdk, workspace, fetch: fetcher, onRecord, onInvocation, adapters, commands, workerGroup, shellCommands, shellRoutes }: BashProfileOptions): Promise<Readonly<{
|
|
59
|
+
container: Container;
|
|
60
|
+
manager: import("@wasm-idle/container").ContainerPackageManager;
|
|
61
|
+
shellAssets: import("@wasm-idle/container").VerifiedAssetLoader;
|
|
62
|
+
workers: WasixWorkerGroup;
|
|
63
|
+
cache: Readonly<{
|
|
64
|
+
enabled: true;
|
|
65
|
+
namespace: string;
|
|
66
|
+
version: string;
|
|
67
|
+
storageReserveBytes: 0;
|
|
68
|
+
}>;
|
|
69
|
+
clangFilesystem: "snapshot" | "live";
|
|
70
|
+
sysrootProfile: "full" | "c-base-v1";
|
|
71
|
+
inspectSysroot: (profile?: string) => {
|
|
72
|
+
sha256: string;
|
|
73
|
+
entries: number;
|
|
74
|
+
files: number;
|
|
75
|
+
} | null;
|
|
76
|
+
prepareCommand: (invocation: HostCommandInvocation, signal: AbortSignal) => Promise<void>;
|
|
77
|
+
prepareClang(profile: "c" | "full", signal: AbortSignal): Promise<string[]>;
|
|
78
|
+
startShell(options?: Pick<WasixShellOptions, "mounts" | "args" | "cwd" | "env">, signal?: AbortSignal): Promise<WasixShellSession>;
|
|
79
|
+
dispose(): Promise<void>;
|
|
80
|
+
}>>;
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { createContainer, createContainerPackageManager, createVerifiedAssetLoader, validateDistribution, extractTarPackage } from '@wasm-idle/container';
|
|
2
|
+
import { createClangAdapter } from '@wasm-idle/container/adapters/clang';
|
|
3
|
+
import { createLiveClangAdapter } from '@wasm-idle/container/adapters/clang-live';
|
|
4
|
+
import { createLiveWasiAdapter } from '@wasm-idle/container/adapters/wasi-live';
|
|
5
|
+
import { clangSimdDriverArgs, installClangSimdHeaders } from '@wasm-idle/llvm-core/core/clang-simd';
|
|
6
|
+
import { createWasixShellSession, installWasixWorkerGroup } from '@wasm-idle/container/adapters/wasix';
|
|
7
|
+
export const BASH_BIN = '/usr/local/bin';
|
|
8
|
+
export const BASH_SYSROOT = '/usr/share/wasm-sysroot';
|
|
9
|
+
export const C_SYSROOT = '/usr/share/wasm-sysroot-c';
|
|
10
|
+
const TOOLCHAIN = '/opt/toolchains/llvm';
|
|
11
|
+
/** Expose the verified legacy sysroot through the canonical driver's automatic search paths. */
|
|
12
|
+
export function withCanonicalWasiPaths(entries) {
|
|
13
|
+
const additions = [];
|
|
14
|
+
for (const parent of ['include', 'lib']) {
|
|
15
|
+
if (entries.some((entry) => entry.path === `${parent}/wasm32-wasi` && entry.type === 'directory') &&
|
|
16
|
+
!entries.some((entry) => entry.path === `${parent}/wasm32-wasip1`))
|
|
17
|
+
additions.push({
|
|
18
|
+
path: `${parent}/wasm32-wasip1`,
|
|
19
|
+
type: 'symlink',
|
|
20
|
+
mode: 0o777,
|
|
21
|
+
target: 'wasm32-wasi'
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const directory = 'lib/clang/22/lib/wasm32-unknown-wasip1';
|
|
25
|
+
const path = `${directory}/libclang_rt.builtins.a`;
|
|
26
|
+
if (!entries.some((entry) => entry.path === path) &&
|
|
27
|
+
entries.some((entry) => entry.path === 'lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a' &&
|
|
28
|
+
entry.type === 'file')) {
|
|
29
|
+
if (!entries.some((entry) => entry.path === directory))
|
|
30
|
+
additions.push({ path: directory, type: 'directory', mode: 0o755 });
|
|
31
|
+
additions.push({
|
|
32
|
+
path,
|
|
33
|
+
type: 'symlink',
|
|
34
|
+
mode: 0o777,
|
|
35
|
+
target: '../wasi/libclang_rt.builtins-wasm32.a'
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return additions.length ? [...entries, ...additions] : entries;
|
|
39
|
+
}
|
|
40
|
+
const digest = async (bytes) => Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256', Uint8Array.from(bytes))), (value) => value.toString(16).padStart(2, '0')).join('');
|
|
41
|
+
/** Compose verified USTAR layers without changing retained header or file bytes. */
|
|
42
|
+
export function composeSysrootLayers(base, cxx) {
|
|
43
|
+
for (const layer of [base, cxx]) {
|
|
44
|
+
if (!(layer instanceof Uint8Array) ||
|
|
45
|
+
layer.length < 1024 ||
|
|
46
|
+
layer.length % 512 ||
|
|
47
|
+
layer.subarray(-1024).some((byte) => byte !== 0))
|
|
48
|
+
throw new Error('Invalid sysroot layer terminator');
|
|
49
|
+
}
|
|
50
|
+
const length = base.length + cxx.length - 1024;
|
|
51
|
+
if (length > 128 * 1024 * 1024)
|
|
52
|
+
throw new Error('Composed sysroot exceeds its archive budget');
|
|
53
|
+
const archive = new Uint8Array(length);
|
|
54
|
+
archive.set(base.subarray(0, -1024));
|
|
55
|
+
archive.set(cxx.subarray(0, -1024), base.length - 1024);
|
|
56
|
+
return archive;
|
|
57
|
+
}
|
|
58
|
+
/** A shared Bash/Clang owner. Importing this module does not load any runtime assets. */
|
|
59
|
+
export async function createBashProfile({ config, sdk, workspace, fetch: fetcher, onRecord, onInvocation, adapters = [], commands = {}, workerGroup, shellCommands = [], shellRoutes = {} }) {
|
|
60
|
+
const filesystem = config.clangFilesystem === undefined ? 'snapshot' : config.clangFilesystem;
|
|
61
|
+
if (filesystem !== 'snapshot' && filesystem !== 'live')
|
|
62
|
+
throw new TypeError('clangFilesystem must be snapshot or live');
|
|
63
|
+
const adapterId = filesystem === 'live' ? 'llvm-clang-tool-host-live-v1' : 'llvm-clang-tool-host-v1';
|
|
64
|
+
const layers = config.sysrootLayers;
|
|
65
|
+
if ((config.sysrootProfile !== undefined &&
|
|
66
|
+
!['full', 'c-base-v1'].includes(config.sysrootProfile)) ||
|
|
67
|
+
Boolean(layers) !== (config.sysrootProfile === 'c-base-v1'))
|
|
68
|
+
throw new Error('Explicit C base profile and pinned layers must be configured together');
|
|
69
|
+
if (layers &&
|
|
70
|
+
(layers.schemaVersion !== 1 ||
|
|
71
|
+
layers.basePackage !== 'llvm-sysroot-c' ||
|
|
72
|
+
layers.cxxPackage !== 'llvm-sysroot-cxx' ||
|
|
73
|
+
!/^[a-f0-9]{64}$/.test(layers.full?.sha256) ||
|
|
74
|
+
!Number.isSafeInteger(layers.full?.bytes) ||
|
|
75
|
+
layers.full.bytes < 1024 ||
|
|
76
|
+
layers.full.bytes > 128 * 1024 * 1024))
|
|
77
|
+
throw new Error('Invalid pinned sysroot layer configuration');
|
|
78
|
+
const distribution = await validateDistribution({
|
|
79
|
+
bytes: new TextEncoder().encode(config.manifest),
|
|
80
|
+
expectedSha256: config.manifestSha256,
|
|
81
|
+
adapterIds: ['wasi-preview1-live', adapterId],
|
|
82
|
+
allowedAssetURLs: config.assetURLs
|
|
83
|
+
});
|
|
84
|
+
const cache = Object.freeze({
|
|
85
|
+
enabled: true,
|
|
86
|
+
namespace: config.cacheNamespace,
|
|
87
|
+
version: config.manifestSha256,
|
|
88
|
+
storageReserveBytes: 0
|
|
89
|
+
});
|
|
90
|
+
const assetOptions = {
|
|
91
|
+
distribution,
|
|
92
|
+
fetch: fetcher,
|
|
93
|
+
persistentCache: cache,
|
|
94
|
+
maxCachedBytes: 192 * 1024 * 1024
|
|
95
|
+
};
|
|
96
|
+
const manager = createContainerPackageManager({
|
|
97
|
+
...assetOptions,
|
|
98
|
+
capabilities: ['wasi-preview1', 'llvm-tool-host-exec-v1']
|
|
99
|
+
});
|
|
100
|
+
const shellAssets = createVerifiedAssetLoader({
|
|
101
|
+
...assetOptions,
|
|
102
|
+
maxCachedBytes: 64 * 1024 * 1024
|
|
103
|
+
});
|
|
104
|
+
let workers;
|
|
105
|
+
let container;
|
|
106
|
+
let compiler;
|
|
107
|
+
try {
|
|
108
|
+
workers = workerGroup ?? installWasixWorkerGroup({ maxWorkers: config.maxWorkers ?? 32 });
|
|
109
|
+
compiler = (filesystem === 'live' ? createLiveClangAdapter : createClangAdapter)({
|
|
110
|
+
clangSha256: config.clangSha256,
|
|
111
|
+
linkerSha256: config.linkerSha256,
|
|
112
|
+
linkerPath: `${TOOLCHAIN}/bin/wasm-ld`,
|
|
113
|
+
compilerPaths: [`${TOOLCHAIN}/bin/llvm`],
|
|
114
|
+
...(filesystem === 'live'
|
|
115
|
+
? { moduleServices: config.clangModuleServices === true }
|
|
116
|
+
: {}),
|
|
117
|
+
executableOutputProfile: 'wasi-preview1-process',
|
|
118
|
+
workerFactory: () => new Worker(config.clangWorkerUrl, { type: 'module' })
|
|
119
|
+
});
|
|
120
|
+
container = createContainer({
|
|
121
|
+
workspace,
|
|
122
|
+
packages: manager,
|
|
123
|
+
commands,
|
|
124
|
+
maxBytes: workspace?.fs.maxBytes ?? 256 * 1024 * 1024,
|
|
125
|
+
adapters: [
|
|
126
|
+
...adapters,
|
|
127
|
+
createLiveWasiAdapter({
|
|
128
|
+
maxBlockedIoMs: 120000,
|
|
129
|
+
workerFactory: () => new Worker(config.liveWorkerUrl, { type: 'module' })
|
|
130
|
+
}),
|
|
131
|
+
compiler
|
|
132
|
+
],
|
|
133
|
+
artifactAdapter: 'wasi-preview1-live',
|
|
134
|
+
maxMemoryBytes: 2 ** 32,
|
|
135
|
+
maxProcesses: 8
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
compiler?.clearModuleCache?.();
|
|
140
|
+
await workers?.dispose();
|
|
141
|
+
await manager.dispose();
|
|
142
|
+
await shellAssets.dispose();
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
const routes = {
|
|
146
|
+
...Object.fromEntries(shellCommands.map((name) => [`${BASH_BIN}/${name}`, { command: name }])),
|
|
147
|
+
[`${BASH_BIN}/clang`]: {
|
|
148
|
+
command: 'clang',
|
|
149
|
+
// Prepared release manifests may predate the current SIMD defaults.
|
|
150
|
+
args: clangSimdDriverArgs(BASH_SYSROOT),
|
|
151
|
+
stdio: filesystem === 'live' ? 'delegated' : 'forwarded'
|
|
152
|
+
},
|
|
153
|
+
[`${BASH_BIN}/wasm-run`]: { command: 'wasm-run' },
|
|
154
|
+
...shellRoutes
|
|
155
|
+
};
|
|
156
|
+
const sysroots = new Map();
|
|
157
|
+
let session;
|
|
158
|
+
let starting;
|
|
159
|
+
let disposal;
|
|
160
|
+
const stop = new AbortController();
|
|
161
|
+
const prepareSysroot = async (requestedProfile, signal) => {
|
|
162
|
+
if (requestedProfile !== 'c' && requestedProfile !== 'full')
|
|
163
|
+
throw new Error('Unknown Clang sysroot profile');
|
|
164
|
+
const profile = !layers || requestedProfile === 'full' || sysroots.has('full') ? 'full' : 'c';
|
|
165
|
+
const root = profile === 'c' ? C_SYSROOT : BASH_SYSROOT;
|
|
166
|
+
const args = [
|
|
167
|
+
...(profile === 'c'
|
|
168
|
+
? [`--sysroot=${C_SYSROOT}`, `-resource-dir=${C_SYSROOT}/lib/clang/22`]
|
|
169
|
+
: []),
|
|
170
|
+
...clangSimdDriverArgs(root)
|
|
171
|
+
];
|
|
172
|
+
if (sysroots.has(profile))
|
|
173
|
+
return args;
|
|
174
|
+
// Each consumer owns its signal; the verified asset loader shares only fetches.
|
|
175
|
+
const prepared = await manager.prepare('llvm', { signal });
|
|
176
|
+
let archive;
|
|
177
|
+
if (layers) {
|
|
178
|
+
const base = await manager.prepare(layers.basePackage, { signal });
|
|
179
|
+
archive = base.packages
|
|
180
|
+
.find((pkg) => pkg.id === layers.basePackage)
|
|
181
|
+
?.files.find((file) => file.path === 'sysroot.tar')?.bytes;
|
|
182
|
+
if (!archive)
|
|
183
|
+
throw new Error('Pinned LLVM profile has no base sysroot archive');
|
|
184
|
+
if (profile === 'full') {
|
|
185
|
+
const cxx = await manager.prepare(layers.cxxPackage, { signal });
|
|
186
|
+
const delta = cxx.packages
|
|
187
|
+
.find((pkg) => pkg.id === layers.cxxPackage)
|
|
188
|
+
?.files.find((file) => file.path === 'sysroot.tar')?.bytes;
|
|
189
|
+
if (!delta)
|
|
190
|
+
throw new Error('Pinned LLVM profile has no C++ sysroot archive');
|
|
191
|
+
archive = composeSysrootLayers(archive, delta);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else
|
|
195
|
+
archive = prepared.packages
|
|
196
|
+
.find((pkg) => pkg.id === 'llvm')
|
|
197
|
+
?.files.find((file) => file.path === 'sysroot.tar')?.bytes;
|
|
198
|
+
if (!archive)
|
|
199
|
+
throw new Error('Pinned LLVM profile has no sysroot archive');
|
|
200
|
+
const sha256 = await digest(archive);
|
|
201
|
+
signal.throwIfAborted();
|
|
202
|
+
if (layers &&
|
|
203
|
+
profile === 'full' &&
|
|
204
|
+
(archive.length !== layers.full.bytes || sha256 !== layers.full.sha256))
|
|
205
|
+
throw new Error('Composed sysroot does not match its pinned identity');
|
|
206
|
+
const entries = extractTarPackage(archive);
|
|
207
|
+
const metadata = {
|
|
208
|
+
sha256,
|
|
209
|
+
entries: entries.length,
|
|
210
|
+
files: entries.filter((file) => file.type === 'file').length
|
|
211
|
+
};
|
|
212
|
+
signal.throwIfAborted();
|
|
213
|
+
if (!sysroots.has(profile)) {
|
|
214
|
+
// The archive identity describes upstream bytes. Add the trusted application's
|
|
215
|
+
// SIMD headers only after verification, leaving its Clang resource headers intact.
|
|
216
|
+
const mounted = new Map(entries.map((entry) => [entry.path, entry]));
|
|
217
|
+
installClangSimdHeaders({
|
|
218
|
+
mkdirTree(path) {
|
|
219
|
+
let parent = '';
|
|
220
|
+
for (const part of path.slice(1).split('/')) {
|
|
221
|
+
parent = parent ? `${parent}/${part}` : part;
|
|
222
|
+
const existing = mounted.get(parent);
|
|
223
|
+
if (existing && existing.type !== 'directory')
|
|
224
|
+
throw new Error('SIMD header directory conflicts with the pinned sysroot');
|
|
225
|
+
if (!existing)
|
|
226
|
+
mounted.set(parent, { path: parent, type: 'directory', mode: 0o555 });
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
writeFile(path, data) {
|
|
230
|
+
const relative = path.slice(1);
|
|
231
|
+
if (mounted.has(relative))
|
|
232
|
+
throw new Error('SIMD header conflicts with the pinned sysroot');
|
|
233
|
+
mounted.set(relative, { path: relative, type: 'file', mode: 0o444, data });
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
container.fs.mountReadonly(root, withCanonicalWasiPaths([...mounted.values()]));
|
|
237
|
+
sysroots.set(profile, metadata);
|
|
238
|
+
}
|
|
239
|
+
return args;
|
|
240
|
+
};
|
|
241
|
+
const prepareCommand = async (invocation, signal) => {
|
|
242
|
+
onInvocation?.(invocation);
|
|
243
|
+
if (invocation.path === `${BASH_BIN}/clang`)
|
|
244
|
+
await prepareSysroot('full', signal);
|
|
245
|
+
};
|
|
246
|
+
return Object.freeze({
|
|
247
|
+
container,
|
|
248
|
+
manager,
|
|
249
|
+
shellAssets,
|
|
250
|
+
workers,
|
|
251
|
+
cache,
|
|
252
|
+
clangFilesystem: filesystem,
|
|
253
|
+
sysrootProfile: layers ? 'c-base-v1' : 'full',
|
|
254
|
+
inspectSysroot: (profile = 'full') => sysroots.get(profile) ?? null,
|
|
255
|
+
prepareCommand,
|
|
256
|
+
prepareClang(profile, signal) {
|
|
257
|
+
onInvocation?.({
|
|
258
|
+
path: `${BASH_BIN}/clang`,
|
|
259
|
+
argv: ['clang'],
|
|
260
|
+
env: [],
|
|
261
|
+
cwd: '/workspace',
|
|
262
|
+
stdin: null,
|
|
263
|
+
stdout: null,
|
|
264
|
+
stderr: null
|
|
265
|
+
});
|
|
266
|
+
return prepareSysroot(profile, signal);
|
|
267
|
+
},
|
|
268
|
+
startShell(options = {}, signal) {
|
|
269
|
+
if (starting || stop.signal.aborted)
|
|
270
|
+
return Promise.reject(new Error('The dedicated Bash owner has already started or retired'));
|
|
271
|
+
starting = createWasixShellSession({
|
|
272
|
+
container,
|
|
273
|
+
sdk,
|
|
274
|
+
workers,
|
|
275
|
+
assets: shellAssets,
|
|
276
|
+
sdkAsset: config.sdkAsset ?? { packageId: 'shell', assetId: 'sdk' },
|
|
277
|
+
shellAsset: config.shellAsset ?? { packageId: 'shell', assetId: 'bash' },
|
|
278
|
+
shellWasmSha256: config.bashWasmSha256,
|
|
279
|
+
sdkUrl: config.sdkUrl,
|
|
280
|
+
workerUrl: config.sdkWorkerUrl,
|
|
281
|
+
memory: config.memory,
|
|
282
|
+
routes,
|
|
283
|
+
mounts: options.mounts,
|
|
284
|
+
moduleDirectories: ['/workspace'],
|
|
285
|
+
timeoutMs: config.commandTimeoutMs,
|
|
286
|
+
args: options.args ?? ['--noprofile', '--norc'],
|
|
287
|
+
cwd: options.cwd ?? '/workspace',
|
|
288
|
+
env: {
|
|
289
|
+
PATH: `${BASH_BIN}:/usr/bin:/bin`,
|
|
290
|
+
HOME: '/workspace',
|
|
291
|
+
LANG: 'C',
|
|
292
|
+
...options.env
|
|
293
|
+
},
|
|
294
|
+
signal: signal ? AbortSignal.any([signal, stop.signal]) : stop.signal,
|
|
295
|
+
prepareCommand,
|
|
296
|
+
onRecord
|
|
297
|
+
}).then((value) => {
|
|
298
|
+
session = value;
|
|
299
|
+
return value;
|
|
300
|
+
});
|
|
301
|
+
return starting;
|
|
302
|
+
},
|
|
303
|
+
dispose() {
|
|
304
|
+
return (disposal ??= (async () => {
|
|
305
|
+
stop.abort();
|
|
306
|
+
const errors = [];
|
|
307
|
+
for (const cleanup of [
|
|
308
|
+
() => workers.dispose(),
|
|
309
|
+
() => session?.dispose(),
|
|
310
|
+
() => container.dispose(),
|
|
311
|
+
() => compiler?.clearModuleCache?.(),
|
|
312
|
+
() => manager.dispose(),
|
|
313
|
+
() => shellAssets.dispose()
|
|
314
|
+
]) {
|
|
315
|
+
try {
|
|
316
|
+
await cleanup();
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
errors.push(error);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
await starting?.catch(() => { });
|
|
323
|
+
if (errors.length)
|
|
324
|
+
throw new AggregateError(errors, 'Bash profile cleanup failed');
|
|
325
|
+
})());
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}
|
|
@@ -1,19 +1,33 @@
|
|
|
1
|
-
import type { PlaygroundBinding, SandboxRuntimeAssets } from '../sandbox';
|
|
2
|
-
import type { TerminalShellBinding } from '@wasm-idle/terminal';
|
|
1
|
+
import type { PlaygroundBinding, SandboxRuntimeAssets } from '../playground/sandbox.js';
|
|
3
2
|
import type { WorkspaceFile as ContainerWorkspaceFile } from '@wasm-idle/core';
|
|
4
|
-
import { type ContainerWorkerClient } from './client';
|
|
5
|
-
import type { ContainerWorkerEvent, ContainerWorkspaceEntry } from './protocol';
|
|
6
|
-
type
|
|
3
|
+
import { type ContainerWorkerClient, type ContainerOwnerWorker } from './client.js';
|
|
4
|
+
import type { ContainerWorkerEvent, ContainerWorkspaceEntry } from './protocol.js';
|
|
5
|
+
export type ContainerPlaygroundBindingOptions = {
|
|
7
6
|
applicationRootURL: string;
|
|
8
7
|
workspaceId: string;
|
|
9
8
|
getLanguage?: () => string;
|
|
9
|
+
/** The app bundles this worker entry; no worker is created until first use. */
|
|
10
|
+
workerFactory?: () => ContainerOwnerWorker;
|
|
10
11
|
/** Deterministic transport contract tests only. */
|
|
11
12
|
clientFactory?: () => ContainerWorkerClient;
|
|
12
13
|
};
|
|
14
|
+
/** Structurally compatible with terminal UIs without depending on their components. */
|
|
15
|
+
export interface ContainerShellBinding {
|
|
16
|
+
connect(onOutput: (text: string) => void, onError?: (error: unknown) => void): Promise<void>;
|
|
17
|
+
write(text: string): Promise<void>;
|
|
18
|
+
eof(): Promise<void>;
|
|
19
|
+
interrupt(): Promise<void>;
|
|
20
|
+
dispose(): Promise<void>;
|
|
21
|
+
}
|
|
13
22
|
export interface ContainerPlaygroundBinding extends PlaygroundBinding {
|
|
14
|
-
readonly shell:
|
|
23
|
+
readonly shell: ContainerShellBinding;
|
|
24
|
+
dispose(): Promise<void>;
|
|
15
25
|
inspect(): Promise<unknown>;
|
|
16
26
|
setShellDirectory(language: string): Promise<void>;
|
|
27
|
+
/** Claim the shared display at Bash's real primary prompt without consuming its input. */
|
|
28
|
+
beginTerminalExecution(): Promise<void>;
|
|
29
|
+
/** Redraw the actual Bash prompt after the Terminal has written its execution footer. */
|
|
30
|
+
endTerminalExecution(): Promise<void>;
|
|
17
31
|
syncWorkspace(language: string, files: readonly ContainerWorkspaceFile[]): Promise<void>;
|
|
18
32
|
readWorkspace(language: string): Promise<ContainerWorkspaceFile[]>;
|
|
19
33
|
listWorkspaceFiles(): Promise<ContainerWorkspaceEntry[]>;
|
|
@@ -22,5 +36,4 @@ export interface ContainerPlaygroundBinding extends PlaygroundBinding {
|
|
|
22
36
|
onWorkspaceChange(listener: (event: ContainerWorkerEvent) => void): () => void;
|
|
23
37
|
}
|
|
24
38
|
/** Existing Terminal/Debug controls use this facade; every execution belongs to the owner Container. */
|
|
25
|
-
export declare function createContainerPlaygroundBinding(runtimeAssets: SandboxRuntimeAssets, options:
|
|
26
|
-
export {};
|
|
39
|
+
export declare function createContainerPlaygroundBinding(runtimeAssets: SandboxRuntimeAssets, options: ContainerPlaygroundBindingOptions): ContainerPlaygroundBinding;
|