@wasm-oj/server 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -0
  3. package/THIRD_PARTY_NOTICES.md +302 -0
  4. package/crates/runtime-core/Cargo.lock +5099 -0
  5. package/crates/runtime-core/Cargo.toml +66 -0
  6. package/crates/runtime-core/README.md +47 -0
  7. package/crates/runtime-core/src/bin/wasm-oj-compiler.rs +418 -0
  8. package/crates/runtime-core/src/bin/wasm-oj-runner.rs +294 -0
  9. package/crates/runtime-core/src/capabilities.rs +118 -0
  10. package/crates/runtime-core/src/compiler.rs +658 -0
  11. package/crates/runtime-core/src/contract.rs +5 -0
  12. package/crates/runtime-core/src/deterministic.rs +1051 -0
  13. package/crates/runtime-core/src/error.rs +58 -0
  14. package/crates/runtime-core/src/filesystem.rs +547 -0
  15. package/crates/runtime-core/src/filesystem_quota.rs +167 -0
  16. package/crates/runtime-core/src/go_compiler_session.rs +297 -0
  17. package/crates/runtime-core/src/interactive.rs +1019 -0
  18. package/crates/runtime-core/src/judge_package.rs +1539 -0
  19. package/crates/runtime-core/src/lib.rs +98 -0
  20. package/crates/runtime-core/src/memory.rs +84 -0
  21. package/crates/runtime-core/src/meter.rs +549 -0
  22. package/crates/runtime-core/src/module_imports.rs +149 -0
  23. package/crates/runtime-core/src/module_policy.rs +714 -0
  24. package/crates/runtime-core/src/output.rs +204 -0
  25. package/crates/runtime-core/src/run/mod.rs +208 -0
  26. package/crates/runtime-core/src/run/native.rs +260 -0
  27. package/crates/runtime-core/src/run/web.rs +229 -0
  28. package/crates/runtime-core/src/run/web_runtime.rs +109 -0
  29. package/crates/runtime-core/src/types.rs +268 -0
  30. package/crates/runtime-core/src/web.rs +83 -0
  31. package/dist/chunks/go-toolchain-Dbt-lp2L.js +426 -0
  32. package/dist/chunks/java-toolchain-DajoRCHu.js +44 -0
  33. package/dist/chunks/python-toolchain-Dx834o2A.js +4 -0
  34. package/dist/chunks/rust-toolchain-CJ3sMxPE.js +252 -0
  35. package/dist/chunks/toolchains-C6KuA1yM.js +224 -0
  36. package/dist/go-stage.mjs +193 -0
  37. package/dist/index.d.ts +221 -0
  38. package/dist/index.js +4393 -0
  39. package/dist/java-stage.mjs +111 -0
  40. package/dist/python-stage.mjs +90 -0
  41. package/dist/rustc-stage.mjs +301 -0
  42. package/dist/server-build-stage.mjs +2564 -0
  43. package/dist/server-runner-stage.mjs +155 -0
  44. package/licenses/fflate-MIT.txt +21 -0
  45. package/licenses/runtime-core-dependencies.html +6253 -0
  46. package/licenses/runtime-core-dependencies.json +3041 -0
  47. package/licenses/wasmer-sdk-MIT.txt +21 -0
  48. package/licenses/wasmer-sdk-dependencies.html +6901 -0
  49. package/licenses/wasmer-sdk-dependencies.json +3013 -0
  50. package/package.json +70 -0
  51. package/rust-toolchain.toml +5 -0
  52. package/testdata/wojjdg02-v2-text.hex +1 -0
  53. package/vendor/shared-buffer/Cargo.toml +22 -0
  54. package/vendor/shared-buffer/LICENSE_APACHE.md +176 -0
  55. package/vendor/shared-buffer/LICENSE_MIT.md +25 -0
  56. package/vendor/shared-buffer/README.md +34 -0
  57. package/vendor/shared-buffer/src/lib.rs +58 -0
  58. package/vendor/shared-buffer/src/mmap.rs +250 -0
  59. package/vendor/shared-buffer/src/owned.rs +389 -0
  60. package/vendor/virtual-fs/Cargo.toml +181 -0
  61. package/vendor/virtual-fs/LICENSE +25 -0
  62. package/vendor/virtual-fs/src/arc_box_file.rs +142 -0
  63. package/vendor/virtual-fs/src/arc_file.rs +182 -0
  64. package/vendor/virtual-fs/src/arc_fs.rs +68 -0
  65. package/vendor/virtual-fs/src/buffer_file.rs +103 -0
  66. package/vendor/virtual-fs/src/builder.rs +232 -0
  67. package/vendor/virtual-fs/src/combine_file.rs +101 -0
  68. package/vendor/virtual-fs/src/cow_file.rs +345 -0
  69. package/vendor/virtual-fs/src/dual_write_file.rs +113 -0
  70. package/vendor/virtual-fs/src/empty_fs.rs +81 -0
  71. package/vendor/virtual-fs/src/filesystems.rs +108 -0
  72. package/vendor/virtual-fs/src/host_fs.rs +1390 -0
  73. package/vendor/virtual-fs/src/lib.rs +782 -0
  74. package/vendor/virtual-fs/src/limiter.rs +252 -0
  75. package/vendor/virtual-fs/src/mem_fs/file.rs +1799 -0
  76. package/vendor/virtual-fs/src/mem_fs/file_opener.rs +941 -0
  77. package/vendor/virtual-fs/src/mem_fs/filesystem.rs +2134 -0
  78. package/vendor/virtual-fs/src/mem_fs/mod.rs +245 -0
  79. package/vendor/virtual-fs/src/mem_fs/offloaded_file.rs +474 -0
  80. package/vendor/virtual-fs/src/mem_fs/stdio.rs +318 -0
  81. package/vendor/virtual-fs/src/mount_fs.rs +2225 -0
  82. package/vendor/virtual-fs/src/null_file.rs +87 -0
  83. package/vendor/virtual-fs/src/ops.rs +364 -0
  84. package/vendor/virtual-fs/src/overlay_fs.rs +2216 -0
  85. package/vendor/virtual-fs/src/passthru_fs.rs +119 -0
  86. package/vendor/virtual-fs/src/pipe.rs +603 -0
  87. package/vendor/virtual-fs/src/random_file.rs +88 -0
  88. package/vendor/virtual-fs/src/special_file.rs +108 -0
  89. package/vendor/virtual-fs/src/static_file.rs +133 -0
  90. package/vendor/virtual-fs/src/static_fs.rs +460 -0
  91. package/vendor/virtual-fs/src/tmp_fs.rs +95 -0
  92. package/vendor/virtual-fs/src/trace_fs.rs +258 -0
  93. package/vendor/virtual-fs/src/webc_volume_fs.rs +829 -0
  94. package/vendor/virtual-fs/src/zero_file.rs +90 -0
@@ -0,0 +1,221 @@
1
+ import { Compiler, Runner, RuntimeDriverRegistry, TrustedJudgeProgram, ArtifactStore, JudgeEngineOptions, Engine } from '@wasm-oj/core';
2
+ import { ServerToolchainSource, Project, BuildResult, WorkerProgress, BuildArtifact, RunConfig, RunResult, InteractiveRunConfig, InteractiveRunResult } from '@wasm-oj/contracts';
3
+ export { ServerToolchainSource } from '@wasm-oj/contracts';
4
+
5
+ interface VerifiedServerDistributionEvidence {
6
+ readonly compilerExecutable: string;
7
+ readonly compilerSha256: string;
8
+ readonly runtimeExecutable: string;
9
+ readonly runnerSha256: string;
10
+ readonly toolchains: readonly ServerToolchainSource[];
11
+ /** Descriptor asset path to the digest verified by immutable-container startup. */
12
+ readonly toolchainAssets: Readonly<Record<string, string>>;
13
+ readonly toolchainRootSha256: string;
14
+ }
15
+ interface VerifiedServerDistribution {
16
+ readonly compilerExecutable: string;
17
+ readonly runtimeExecutable: string;
18
+ readonly toolchainAssetFiles: Readonly<Record<string, string>>;
19
+ readonly toolchainRootSha256: string;
20
+ }
21
+ /** @internal Create a process-local capability from already verified container inventory. */
22
+ declare function createVerifiedServerDistribution(evidence: VerifiedServerDistributionEvidence): VerifiedServerDistribution;
23
+
24
+ interface ServerCompilerOptions {
25
+ /** Native `wasm-oj-compiler` executable built from `crates/runtime-core`. */
26
+ compilerExecutable: string;
27
+ /** Explicit package-owned toolchain sources. */
28
+ toolchains: readonly ServerToolchainSource[];
29
+ /** @internal Verified immutable-container capability. */
30
+ verifiedDistribution?: VerifiedServerDistribution;
31
+ /** @internal Inherited only by the private isolated build stage. */
32
+ verifiedToolchain?: boolean;
33
+ }
34
+ declare const IN_PROCESS_STAGE: unique symbol;
35
+ interface ServerCompilerStageOptions extends ServerCompilerOptions {
36
+ /** @internal Canonical stage root inherited from the package entry process. */
37
+ stageDirectory: string;
38
+ }
39
+ /**
40
+ * Node/server compiler host using the exact language drivers and Wasmer
41
+ * packages used by the browser Worker.
42
+ */
43
+ declare class ServerCompiler implements Compiler {
44
+ private readonly progressListeners;
45
+ private readonly compilerExecutable;
46
+ private readonly toolchains;
47
+ private initialization;
48
+ private generation;
49
+ private disposed;
50
+ private readonly inProcess;
51
+ private readonly verifiedToolchain;
52
+ private readonly stageDirectory;
53
+ private readonly activeChildren;
54
+ private activeOperation;
55
+ constructor(options: ServerCompilerOptions);
56
+ /** @internal */
57
+ constructor(options: ServerCompilerStageOptions, stage: typeof IN_PROCESS_STAGE);
58
+ cacheIdentity(project: Project): string;
59
+ ready(): Promise<void>;
60
+ build(project: Project, cacheKey: string): Promise<BuildResult>;
61
+ onProgress(listener: (progress: WorkerProgress) => void): () => void;
62
+ clearToolchainCache(): Promise<void>;
63
+ cancel(): void;
64
+ restart(): void;
65
+ dispose(): void;
66
+ private initialize;
67
+ private buildIsolated;
68
+ private compileRust;
69
+ private compilePython;
70
+ private compileGo;
71
+ private compileJava;
72
+ private runCompilerStage;
73
+ private loadToolchainAsset;
74
+ private loadToolchainFile;
75
+ private verifyToolchainAsset;
76
+ private beginOperation;
77
+ private endOperation;
78
+ private assertCurrent;
79
+ private isCurrent;
80
+ private terminateChildren;
81
+ private assertActive;
82
+ }
83
+
84
+ interface ServerRunnerOptions {
85
+ /** Native `wasm-oj-runner` executable built from `crates/runtime-core`. */
86
+ runtimeExecutable: string;
87
+ /** Explicit package-owned toolchain sources. */
88
+ toolchains: readonly ServerToolchainSource[];
89
+ /** Writable directory for deterministic runtime filesystem archives. */
90
+ cacheDirectory: string;
91
+ /** Optional runtime-driver registry, used by calibration and embedders. */
92
+ runtimeDrivers?: RuntimeDriverRegistry;
93
+ /** Calibrated profiles for downstream languages using the built-in runtime drivers. */
94
+ additionalCostBaselines?: Readonly<Record<string, number>>;
95
+ /** @internal Verified immutable-container capability. */
96
+ verifiedDistribution?: VerifiedServerDistribution;
97
+ }
98
+ declare class ServerRunner implements Runner {
99
+ private readonly runtimeExecutable;
100
+ private readonly toolchains;
101
+ private readonly cacheDirectory;
102
+ private readonly verifiedToolchain;
103
+ private readonly stageDirectory;
104
+ private resolvedCacheDirectory;
105
+ private readonly runtimeDrivers;
106
+ private readonly packageCommands;
107
+ private readonly packageFileSystems;
108
+ private readonly progressListeners;
109
+ private readonly streamListeners;
110
+ private initialization;
111
+ private readonly activeNativeRuns;
112
+ private readonly activePreparationStages;
113
+ private readonly inFlightRuns;
114
+ private activeOperation;
115
+ private cacheClearActive;
116
+ private generation;
117
+ private disposed;
118
+ constructor(options: ServerRunnerOptions);
119
+ ready(): Promise<void>;
120
+ run(artifact: BuildArtifact, config: RunConfig): Promise<RunResult>;
121
+ runTrusted(program: TrustedJudgeProgram, config: RunConfig): Promise<RunResult>;
122
+ interact(contestantArtifact: BuildArtifact, interactorArtifact: BuildArtifact, config: InteractiveRunConfig): Promise<InteractiveRunResult>;
123
+ interactTrusted(contestantArtifact: BuildArtifact, interactorProgram: TrustedJudgeProgram, config: InteractiveRunConfig): Promise<InteractiveRunResult>;
124
+ onProgress(listener: (progress: WorkerProgress) => void): () => void;
125
+ onStream(listener: (stream: "stdout" | "stderr", chunk: string) => void): () => void;
126
+ clearRuntimeCache(): Promise<void>;
127
+ cancel(): void;
128
+ cancelAndWait(): Promise<void>;
129
+ restart(): void;
130
+ dispose(): void;
131
+ private initialize;
132
+ private runtimeCacheDirectory;
133
+ private resolver;
134
+ private prepareWithDeadline;
135
+ private prepareInteractiveWithDeadline;
136
+ private prepareTrustedWithDeadline;
137
+ private loadQuickJsForOperation;
138
+ private loadQuickJs;
139
+ private packageCommand;
140
+ private assertPinnedPackageCommand;
141
+ private loadCompressedToolchainAsset;
142
+ private verifyDigest;
143
+ private packageFileSystem;
144
+ private loadOrExportPackageFileSystem;
145
+ private runPackageStage;
146
+ private readRuntimeCacheArchive;
147
+ private removeInvalidRuntimeCacheArchive;
148
+ private persistVerifiedRuntimeCacheArchive;
149
+ private reportRuntimeCacheIssue;
150
+ private runNativeCore;
151
+ private runNativeInteractive;
152
+ private progress;
153
+ private stream;
154
+ private assertCurrent;
155
+ private abortPreparationStages;
156
+ private terminateActiveNativeRuns;
157
+ private assertActive;
158
+ private assertArtifactToolchain;
159
+ }
160
+
161
+ interface DependencyCache {
162
+ load(integritySha256: string): Promise<Uint8Array | undefined>;
163
+ save(integritySha256: string, payload: Uint8Array): Promise<void>;
164
+ delete(integritySha256: string): Promise<void>;
165
+ clear(): Promise<void>;
166
+ }
167
+
168
+ /** Atomic server-side content-addressed dependency cache. */
169
+ declare class FileSystemDependencyCache implements DependencyCache {
170
+ private readonly directory;
171
+ private initialized;
172
+ constructor(directory: string);
173
+ load(integritySha256: string): Promise<Uint8Array | undefined>;
174
+ save(integritySha256: string, payload: Uint8Array): Promise<void>;
175
+ delete(integritySha256: string): Promise<void>;
176
+ clear(): Promise<void>;
177
+ private ready;
178
+ private pathFor;
179
+ }
180
+
181
+ /** Atomic, content-addressed artifact storage for the Node/server host. */
182
+ declare class FileSystemArtifactStore implements ArtifactStore {
183
+ private readonly directory;
184
+ private initialized;
185
+ constructor(directory: string);
186
+ load(cacheKey: string): Promise<BuildArtifact | undefined>;
187
+ save(artifact: BuildArtifact): Promise<void>;
188
+ delete(cacheKey: string): Promise<void>;
189
+ clear(): Promise<void>;
190
+ private ready;
191
+ private pathFor;
192
+ }
193
+
194
+ interface ServerEngineOptions {
195
+ /** Directory containing provisioned `wasm-oj-compiler` and `wasm-oj-runner` binaries. */
196
+ runtimeDirectory: string;
197
+ /** Explicit package-owned toolchain sources. No toolchain is installed implicitly. */
198
+ toolchains: readonly ServerToolchainSource[];
199
+ /** Writable WASM-OJ cache root. Defaults to `<cwd>/.wasm-oj`. */
200
+ cacheDirectory?: string;
201
+ /** Set false to disable the server artifact cache. */
202
+ artifactCache?: boolean;
203
+ runtimeDrivers?: RuntimeDriverRegistry;
204
+ additionalCostBaselines?: Readonly<Record<string, number>>;
205
+ judge?: JudgeEngineOptions;
206
+ /** @internal Process-local capability emitted by container identity verification. */
207
+ verifiedDistribution?: VerifiedServerDistribution;
208
+ }
209
+ interface ResolvedServerPaths {
210
+ compilerExecutable: string;
211
+ runtimeExecutable: string;
212
+ toolchains: readonly ServerToolchainSource[];
213
+ cacheDirectory: string;
214
+ }
215
+ /** Resolve an explicitly provisioned WASM-OJ distribution without performing I/O. */
216
+ declare function resolveServerPaths(options: ServerEngineOptions): ResolvedServerPaths;
217
+ /** Verify the explicit local distribution and construct one ready server engine. */
218
+ declare function createServerEngine(options: ServerEngineOptions): Promise<Engine>;
219
+
220
+ export { FileSystemArtifactStore, FileSystemDependencyCache, ServerCompiler, ServerRunner, createServerEngine, createVerifiedServerDistribution, resolveServerPaths };
221
+ export type { ResolvedServerPaths, ServerCompilerOptions, ServerEngineOptions, ServerRunnerOptions, VerifiedServerDistribution, VerifiedServerDistributionEvidence };