@gasm-compiler/cli 0.2.0 → 0.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.
Files changed (2) hide show
  1. package/dist/cli.js +37 -4
  2. package/package.json +2 -4
package/dist/cli.js CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  disassembleToWAT,
15
15
  isParseError,
16
16
  parseWasmModule,
17
+ prepareModule,
17
18
  validateGasmMetadataSchema
18
19
  } from "@gasm-compiler/core";
19
20
  function printDiagnostics(diagnostics, verbose) {
@@ -36,6 +37,8 @@ async function compileAssemblyScriptToWGSL(inputFile, options = {}) {
36
37
  const {
37
38
  output: outputFile,
38
39
  metadata: metadataFile,
40
+ prepare,
41
+ strict = false,
39
42
  specVersion: requestedSpecVersion,
40
43
  watOutput: watOutputFile,
41
44
  verbose = false,
@@ -52,6 +55,14 @@ async function compileAssemblyScriptToWGSL(inputFile, options = {}) {
52
55
  `Unsupported spec version "${requestedSpecVersion}"; expected 0.1 or 0.2`
53
56
  );
54
57
  }
58
+ if (prepare !== void 0 && prepare !== "auto") {
59
+ throw new Error(
60
+ `Unsupported prepare mode "${prepare}"; expected "auto"`
61
+ );
62
+ }
63
+ if (prepare && strict) {
64
+ throw new Error("--prepare and --strict cannot be used together");
65
+ }
55
66
  const specVersion = requestedSpecVersion ?? "0.2";
56
67
  if (metadataFile && specVersion !== "0.2") {
57
68
  throw new Error(
@@ -141,14 +152,30 @@ ${errorMsg}`);
141
152
  sourceMappingLevel = "normal";
142
153
  }
143
154
  }
144
- const compileOptions = {
155
+ let compileOptions = {
145
156
  optimize,
146
157
  demotionPolicy,
147
158
  warningsAsErrors,
148
159
  sourceMapping: sourceMappingLevel,
149
160
  specVersion
150
161
  };
151
- const result = metadataFile ? compileToArtifact(wasmBytes, compileOptions) : compileWithDiagnostics(wasmBytes, compileOptions);
162
+ let compilationBytes = wasmBytes;
163
+ if (prepare === "auto" || strict) {
164
+ const prepared = prepareModule(wasmBytes, {
165
+ ...compileOptions,
166
+ mode: strict ? "strict" : "integrator"
167
+ });
168
+ for (const advisory of prepared.advisories) {
169
+ console.error(`advisory: ${advisory.message}`);
170
+ }
171
+ if (prepared.errors.length > 0) {
172
+ const first = prepared.errors[0];
173
+ throw new Error(`${first.code}: ${first.message}`);
174
+ }
175
+ compilationBytes = prepared.wasmBytes;
176
+ compileOptions = prepared.compileOptions;
177
+ }
178
+ const result = metadataFile ? compileToArtifact(compilationBytes, compileOptions) : compileWithDiagnostics(compilationBytes, compileOptions);
152
179
  printDiagnostics(result.diagnostics, verbose);
153
180
  if (!result.ok) {
154
181
  const first = result.diagnostics.errors[0];
@@ -182,7 +209,7 @@ ${errorMsg}`);
182
209
  }
183
210
  if (watOutputFile) {
184
211
  if (verbose) console.log("[4a/4] Generating WAT disassembly...");
185
- const parseResult = parseWasmModule(wasmBytes);
212
+ const parseResult = parseWasmModule(compilationBytes);
186
213
  if (!isParseError(parseResult)) {
187
214
  const watCode = disassembleToWAT(parseResult);
188
215
  const resolvedWatOutput = resolve(watOutputFile);
@@ -255,12 +282,13 @@ async function getAssemblyScriptPath() {
255
282
  }
256
283
 
257
284
  // src/cli.ts
258
- var VERSION = "0.2.0";
285
+ var VERSION = "0.3.0";
259
286
  async function main() {
260
287
  const args = parseArgs(Deno.args, {
261
288
  string: [
262
289
  "output",
263
290
  "metadata",
291
+ "prepare",
264
292
  "spec-version",
265
293
  "wat-output",
266
294
  "source-mapping"
@@ -271,6 +299,7 @@ async function main() {
271
299
  "verbose",
272
300
  "keep-wasm",
273
301
  "optimize",
302
+ "strict",
274
303
  "deny-f64-demotion",
275
304
  "allow-i64-demotion",
276
305
  "warnings-as-errors"
@@ -303,6 +332,8 @@ async function main() {
303
332
  const options = {
304
333
  output: args.output,
305
334
  metadata: args.metadata,
335
+ prepare: args.prepare,
336
+ strict: args.strict,
306
337
  specVersion: args["spec-version"],
307
338
  watOutput: args["wat-output"],
308
339
  verbose: args.verbose,
@@ -347,6 +378,8 @@ COMMANDS:
347
378
  OPTIONS:
348
379
  --output <file> Write WGSL output to file (default: stdout)
349
380
  --metadata <file> Write validated Gasm v0.2 metadata sidecar JSON
381
+ --prepare auto Infer and inject extensions for transient builds
382
+ --strict Analyze without modifying the input Wasm
350
383
  --spec-version <version> Compile as Gasm 0.1 or 0.2 (default: 0.2)
351
384
  --wat-output <file> Also write WAT (WebAssembly Text) disassembly to file
352
385
  --verbose Show detailed compilation steps
package/package.json CHANGED
@@ -1,16 +1,14 @@
1
1
  {
2
2
  "name": "@gasm-compiler/cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "CLI for compiling WebAssembly/AssemblyScript to WGSL using Gasm Compiler",
5
5
  "type": "module",
6
6
  "main": "./dist/cli.js",
7
- "types": "./dist/cli.d.ts",
8
7
  "bin": {
9
8
  "gasm-compiler": "./dist/cli.js"
10
9
  },
11
10
  "exports": {
12
11
  ".": {
13
- "types": "./dist/cli.d.ts",
14
12
  "import": "./dist/cli.js",
15
13
  "default": "./dist/cli.js"
16
14
  }
@@ -35,7 +33,7 @@
35
33
  "cli"
36
34
  ],
37
35
  "dependencies": {
38
- "@gasm-compiler/core": "0.4.0"
36
+ "@gasm-compiler/core": "0.5.0"
39
37
  },
40
38
  "devDependencies": {
41
39
  "assemblyscript": "v0.28.9",