@gasm-compiler/core 0.4.0 → 0.6.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 CHANGED
@@ -15,7 +15,8 @@ Gasm v0.1 behavior remains available through an explicit compatibility option.
15
15
  npm install @gasm-compiler/core
16
16
  ```
17
17
 
18
- **Requirements:** TypeScript 5.0+ (peer dependency)
18
+ The compiler core is distributed as a Rust-generated WebAssembly artifact. No
19
+ TypeScript runtime dependency is required by consumers.
19
20
 
20
21
  ---
21
22
 
@@ -85,10 +86,12 @@ const schema = validateGasmMetadataSchema(result.metadata);
85
86
  if (!schema.valid) throw new Error(schema.errors.join(", "));
86
87
  ```
87
88
 
88
- Gasm v0.2 semantics are implemented only in `packages/core-rs` and distributed
89
- through its Wasm artifact. The TypeScript compiler implementation is retained
90
- at v0.1 for compatibility. Deno remains the runtime for the CLI and the live
91
- core/CLI test suites, including headless WebGPU execution.
89
+ All Gasm compiler semantics, including explicit v0.1 compatibility mode, are
90
+ implemented in `packages/core-rs` and distributed through its Wasm artifact.
91
+ The TypeScript package code is limited to host integration, artifact metadata,
92
+ source-map comments, preparation helpers, and execution APIs. Deno remains the
93
+ runtime for the CLI and the live core/CLI test suites, including headless
94
+ WebGPU execution.
92
95
 
93
96
  The CLI also defaults to v0.2:
94
97
 
@@ -100,6 +103,22 @@ gasm-compiler compile input.wasm \
100
103
 
101
104
  Use `--spec-version 0.1` when compiling archived v0.1 inputs.
102
105
 
106
+ #### Migrating from 0.5.x
107
+
108
+ - The Rust/Wasm compiler is now the only compiler backend. The
109
+ `GASM_CORE_BACKEND` environment variable no longer changes compilation.
110
+ - Browser backend selection APIs have been removed:
111
+ `setBrowserCompilerBackend()`, `getBrowserCompilerBackend()`, and
112
+ `BrowserCompilerBackend`.
113
+ - TypeScript/Rust comparison APIs and their result types have been removed:
114
+ `compileWithBackendComparison()`, `compileWithBackendComparisonAsync()`,
115
+ `BackendComparisonResult`, and `BackendMismatchDetails`.
116
+ - Remove backend-selection and comparison UI from integrator applications and
117
+ call `compile()`, `compileWithDiagnostics()`, or
118
+ `compileWithDiagnosticsAsync()` directly.
119
+ - Consumers no longer need to install TypeScript as a peer dependency of
120
+ `@gasm-compiler/core`.
121
+
103
122
  #### Migrating from 0.3.x
104
123
 
105
124
  - Compilation now defaults to strict Gasm v0.2 validation.
@@ -113,6 +132,44 @@ Required extensions are declared by the module's `gasm.extensions` custom
113
132
  section. The CLI does not inject extensions, so validation reflects the exact
114
133
  module that will be distributed.
115
134
 
135
+ ### Integrator Workflow
136
+
137
+ Playgrounds, compiler backends, and other embedders can prepare transient Wasm
138
+ without modifying their producer toolchain:
139
+
140
+ ```typescript
141
+ import {
142
+ compileWithRuntimeInfo,
143
+ prepareModule,
144
+ } from "@gasm-compiler/core/browser";
145
+
146
+ const prepared = prepareModule(wasmBytes, {
147
+ demotionPolicy: { f64: "allow", i64: "allow-lossy" },
148
+ });
149
+ if (prepared.errors.length > 0) {
150
+ throw new Error(prepared.errors[0].message);
151
+ }
152
+
153
+ const result = compileWithRuntimeInfo(prepared.wasmBytes, {
154
+ ...prepared.compileOptions,
155
+ mode: "strict",
156
+ });
157
+ if (!result.ok) throw new Error(result.diagnostics.errors[0].message);
158
+ ```
159
+
160
+ `prepareModule()` defaults to integrator mode. It infers required extensions,
161
+ merges a stable `gasm.extensions` section, and returns binding and mutable-global
162
+ initialization data. Modules with undeclared mutable defined globals use the
163
+ v0.1 private-global compatibility path to avoid shared-storage races.
164
+
165
+ Use `{ mode: "strict" }` to analyze a distribution artifact without changing
166
+ its bytes. Strict compilation through `compile()` and
167
+ `compileWithDiagnostics()` remains unchanged and never injects extensions.
168
+
169
+ `compileWithRuntimeInfo()` is also available from the main and browser entry
170
+ points. It combines preparation, compilation, binding metadata, dispatch
171
+ information, and mutable-global initialization into one result.
172
+
116
173
  ### Basic Compilation
117
174
 
118
175
  ```typescript
package/dist/browser.d.ts CHANGED
@@ -1,18 +1,8 @@
1
- import { a as CompileDiagnostics, D as DispatchInfo$1, C as CompileOptions } from './error_codes-Cdy_3FNo.js';
2
- export { b as CompileError, c as DEFAULT_SPEC_VERSION, j as ErrorCode, E as ErrorCodes, d as SPEC_VERSION_V01, e as SPEC_VERSION_V02, S as SpecVersion, f as isCompileError, h as isParseError, i as isV02Mode, g as parseWasmModule, r as resolveSpecVersion } from './error_codes-Cdy_3FNo.js';
1
+ import { C as CompileDiagnostics, G as GasmMetadata, a as GasmBinding, P as PreparedModule, b as CompileOptions, c as PrepareModuleOptions } from './error_codes-5zCZDwFZ.js';
2
+ export { d as CompileError, h as DEFAULT_SPEC_VERSION, e as DemotionPolicy, f as Diagnostic, g as DiagnosticRecovery, o as ErrorCode, E as ErrorCodes, u as GasmMetadataEntryPoint, M as MutableGlobalsInit, x as PrepareMode, j as SPEC_VERSION_V01, k as SPEC_VERSION_V02, S as SpecVersion, w as buildBindingTable, s as buildGasmMetadata, l as isCompileError, n as isParseError, i as isV02Mode, m as parseWasmModule, p as prepareModule, r as resolveSpecVersion, v as validateGasmMetadataSchema } from './error_codes-5zCZDwFZ.js';
3
3
  export { BrowserGPUExecutor } from './browser-executor.js';
4
4
  export { BufferData, ExecuteOptions, ExecutionError, ExecutorConfig, IGPUExecutor, OutputBufferSpec, isExecutionError } from './executor.js';
5
5
 
6
- type BrowserTsCompileWithDiagnosticsResult = {
7
- ok: true;
8
- wgsl: string;
9
- diagnostics: CompileDiagnostics;
10
- dispatchInfo: DispatchInfo$1;
11
- } | {
12
- ok: false;
13
- diagnostics: CompileDiagnostics;
14
- };
15
-
16
6
  interface InitRustCompilerOptions {
17
7
  wasmUrl?: string | URL;
18
8
  }
@@ -21,32 +11,6 @@ declare const initRustCompiler: typeof preloadCompiler;
21
11
  declare function isRustCompilerInitialized(): boolean;
22
12
  declare function waitForRustCompilerInit(): Promise<void>;
23
13
 
24
- /**
25
- * Shared helpers for comparing TypeScript and Rust/Wasm WGSL output.
26
- */
27
- interface WgslDiffOptions {
28
- /** Maximum diff hunk lines to include in formatted output. */
29
- maxLines?: number;
30
- /** Lines of context around each change hunk. */
31
- context?: number;
32
- }
33
- interface WgslComparisonSummary {
34
- equivalent: boolean;
35
- moduleEquivalent: boolean;
36
- functionEquivalent?: boolean;
37
- moduleDiff?: string;
38
- functionDiff?: string;
39
- typescriptSnippet?: string;
40
- rustSnippet?: string;
41
- }
42
- declare function normalizeWgslForComparison(wgsl: string): string;
43
- declare function exportWgslFunctionSnippet(wgsl: string, funcName: string): string | null;
44
- declare function summarizeWgslComparison(typescriptWgsl: string, rustWgsl: string, funcName?: string, options?: WgslDiffOptions): WgslComparisonSummary;
45
- declare function formatUnifiedDiff(leftLabel: string, rightLabel: string, left: string, right: string, options?: WgslDiffOptions): string;
46
-
47
- type BrowserCompilerBackend = "typescript" | "rust" | "compare";
48
- declare function setBrowserCompilerBackend(backend: BrowserCompilerBackend): void;
49
- declare function getBrowserCompilerBackend(): BrowserCompilerBackend;
50
14
  declare function disassembleToWAT(wasmBytes: Uint8Array): Promise<string>;
51
15
 
52
16
  interface DispatchInfo {
@@ -67,35 +31,33 @@ type CompileWithDiagnosticsResult = {
67
31
  ok: false;
68
32
  diagnostics: CompileDiagnostics;
69
33
  };
70
- interface BackendMismatchDetails {
71
- kind: "wgsl" | "ok_mismatch" | "rust_error" | "diagnostics";
72
- message: string;
73
- moduleDiff?: string;
74
- functionDiff?: string;
75
- typescriptWgsl?: string;
76
- rustWgsl?: string;
77
- }
78
- interface BackendComparisonResult {
79
- selectedBackend: "typescript";
80
- returned: CompileWithDiagnosticsResult;
81
- typescript: BrowserTsCompileWithDiagnosticsResult;
82
- rust: CompileWithDiagnosticsResult | {
83
- ok: false;
84
- error: string;
85
- };
86
- equivalent: boolean;
87
- mismatch?: BackendMismatchDetails;
88
- }
89
-
34
+ type CompileArtifactResult = {
35
+ ok: true;
36
+ wgsl: string;
37
+ metadata: GasmMetadata;
38
+ diagnostics: CompileDiagnostics;
39
+ dispatchInfo: DispatchInfo;
40
+ } | {
41
+ ok: false;
42
+ diagnostics: CompileDiagnostics;
43
+ };
44
+ type CompileWithRuntimeInfoResult = {
45
+ ok: true;
46
+ wgsl: string;
47
+ diagnostics: CompileDiagnostics;
48
+ dispatchInfo: DispatchInfo;
49
+ bindings: GasmBinding[];
50
+ metadata: GasmMetadata;
51
+ mutableGlobalsInit?: PreparedModule["mutableGlobalsInit"];
52
+ } | {
53
+ ok: false;
54
+ diagnostics: CompileDiagnostics;
55
+ };
90
56
  declare function compileWithDiagnostics(wasmBytes: Uint8Array, options?: CompileOptions): CompileWithDiagnosticsResult;
57
+ declare function compileToArtifact(wasmBytes: Uint8Array, options?: CompileOptions): CompileArtifactResult;
58
+ declare function compileWithRuntimeInfo(wasmBytes: Uint8Array, options?: PrepareModuleOptions): CompileWithRuntimeInfoResult;
91
59
  declare function compileWithDiagnosticsAsync(wasmBytes: Uint8Array, options?: CompileOptions, initOptions?: InitRustCompilerOptions): Promise<CompileWithDiagnosticsResult>;
92
- declare function compileWithBackendComparison(wasmBytes: Uint8Array, options?: CompileOptions, compareOptions?: {
93
- funcName?: string;
94
- }): BackendComparisonResult;
95
- declare function compileWithBackendComparisonAsync(wasmBytes: Uint8Array, options?: CompileOptions, compareOptions?: {
96
- funcName?: string;
97
- }, initOptions?: InitRustCompilerOptions): Promise<BackendComparisonResult>;
98
60
  declare function compile(wasmBytes: Uint8Array, options?: CompileOptions): string;
99
61
  declare function compileAsync(wasmBytes: Uint8Array, options?: CompileOptions, initOptions?: InitRustCompilerOptions): Promise<string>;
100
62
 
101
- export { type BackendComparisonResult, type BackendMismatchDetails, type BrowserCompilerBackend, CompileDiagnostics, CompileOptions, type CompileWithDiagnosticsResult, type DispatchInfo, type InitRustCompilerOptions, type WgslComparisonSummary, type WgslDiffOptions, compile, compileAsync, compileWithBackendComparison, compileWithBackendComparisonAsync, compileWithDiagnostics, compileWithDiagnosticsAsync, disassembleToWAT, exportWgslFunctionSnippet, formatUnifiedDiff, getBrowserCompilerBackend, initRustCompiler, isRustCompilerInitialized, normalizeWgslForComparison, preloadCompiler, setBrowserCompilerBackend, summarizeWgslComparison, waitForRustCompilerInit };
63
+ export { type CompileArtifactResult, CompileDiagnostics, CompileOptions, type CompileWithDiagnosticsResult, type CompileWithRuntimeInfoResult, type DispatchInfo, GasmBinding, GasmMetadata, type InitRustCompilerOptions, PrepareModuleOptions, PreparedModule, compile, compileAsync, compileToArtifact, compileWithDiagnostics, compileWithDiagnosticsAsync, compileWithRuntimeInfo, disassembleToWAT, initRustCompiler, isRustCompilerInitialized, preloadCompiler, waitForRustCompilerInit };