@gasm-compiler/cli 0.2.0 → 0.4.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 +1 -0
- package/dist/cli.js +55 -12
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -56,6 +56,7 @@ Compiles a WebAssembly binary or AssemblyScript source to WGSL.
|
|
|
56
56
|
| `--verbose` | Show detailed compilation steps |
|
|
57
57
|
| `--keep-wasm` | Keep intermediate `.wasm` file when compiling from AssemblyScript |
|
|
58
58
|
| `--optimize` | Apply optimization passes |
|
|
59
|
+
| `--minify` | Optimize and emit compact, single-line WGSL |
|
|
59
60
|
|
|
60
61
|
**Examples:**
|
|
61
62
|
|
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,27 +37,37 @@ 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,
|
|
42
45
|
keepWasm = false,
|
|
43
|
-
optimize
|
|
46
|
+
optimize,
|
|
47
|
+
minify = false,
|
|
44
48
|
denyF64Demotion = false,
|
|
45
49
|
allowI64Demotion = false,
|
|
46
50
|
warningsAsErrors = false,
|
|
47
51
|
sourceMapping
|
|
48
52
|
} = options;
|
|
49
53
|
try {
|
|
54
|
+
if (minify && optimize === false) {
|
|
55
|
+
throw new Error("--minify cannot be combined with --no-optimize");
|
|
56
|
+
}
|
|
50
57
|
if (requestedSpecVersion !== void 0 && requestedSpecVersion !== "0.1" && requestedSpecVersion !== "0.2") {
|
|
51
58
|
throw new Error(
|
|
52
59
|
`Unsupported spec version "${requestedSpecVersion}"; expected 0.1 or 0.2`
|
|
53
60
|
);
|
|
54
61
|
}
|
|
62
|
+
if (prepare !== void 0 && prepare !== "auto") {
|
|
63
|
+
throw new Error(`Unsupported prepare mode "${prepare}"; expected "auto"`);
|
|
64
|
+
}
|
|
65
|
+
if (prepare && strict) {
|
|
66
|
+
throw new Error("--prepare and --strict cannot be used together");
|
|
67
|
+
}
|
|
55
68
|
const specVersion = requestedSpecVersion ?? "0.2";
|
|
56
69
|
if (metadataFile && specVersion !== "0.2") {
|
|
57
|
-
throw new Error(
|
|
58
|
-
"--metadata requires --spec-version 0.2"
|
|
59
|
-
);
|
|
70
|
+
throw new Error("--metadata requires --spec-version 0.2");
|
|
60
71
|
}
|
|
61
72
|
if (verbose) console.log(`[1/4] Validating input file: ${inputFile}`);
|
|
62
73
|
const resolvedInput = resolve(inputFile);
|
|
@@ -141,14 +152,31 @@ ${errorMsg}`);
|
|
|
141
152
|
sourceMappingLevel = "normal";
|
|
142
153
|
}
|
|
143
154
|
}
|
|
144
|
-
|
|
145
|
-
optimize,
|
|
155
|
+
let compileOptions = {
|
|
156
|
+
optimize: minify ? true : optimize ?? false,
|
|
157
|
+
minify,
|
|
146
158
|
demotionPolicy,
|
|
147
159
|
warningsAsErrors,
|
|
148
160
|
sourceMapping: sourceMappingLevel,
|
|
149
161
|
specVersion
|
|
150
162
|
};
|
|
151
|
-
|
|
163
|
+
let compilationBytes = wasmBytes;
|
|
164
|
+
if (prepare === "auto" || strict) {
|
|
165
|
+
const prepared = prepareModule(wasmBytes, {
|
|
166
|
+
...compileOptions,
|
|
167
|
+
mode: strict ? "strict" : "integrator"
|
|
168
|
+
});
|
|
169
|
+
for (const advisory of prepared.advisories) {
|
|
170
|
+
console.error(`advisory: ${advisory.message}`);
|
|
171
|
+
}
|
|
172
|
+
if (prepared.errors.length > 0) {
|
|
173
|
+
const first = prepared.errors[0];
|
|
174
|
+
throw new Error(`${first.code}: ${first.message}`);
|
|
175
|
+
}
|
|
176
|
+
compilationBytes = prepared.wasmBytes;
|
|
177
|
+
compileOptions = prepared.compileOptions;
|
|
178
|
+
}
|
|
179
|
+
const result = metadataFile ? compileToArtifact(compilationBytes, compileOptions) : compileWithDiagnostics(compilationBytes, compileOptions);
|
|
152
180
|
printDiagnostics(result.diagnostics, verbose);
|
|
153
181
|
if (!result.ok) {
|
|
154
182
|
const first = result.diagnostics.errors[0];
|
|
@@ -164,7 +192,9 @@ ${errorMsg}`);
|
|
|
164
192
|
const schema = validateGasmMetadataSchema(result.metadata);
|
|
165
193
|
if (!schema.valid) {
|
|
166
194
|
throw new Error(
|
|
167
|
-
`Generated metadata failed schema validation: ${schema.errors.join(
|
|
195
|
+
`Generated metadata failed schema validation: ${schema.errors.join(
|
|
196
|
+
", "
|
|
197
|
+
)}`
|
|
168
198
|
);
|
|
169
199
|
}
|
|
170
200
|
const resolvedMetadata = resolve(metadataFile);
|
|
@@ -182,7 +212,7 @@ ${errorMsg}`);
|
|
|
182
212
|
}
|
|
183
213
|
if (watOutputFile) {
|
|
184
214
|
if (verbose) console.log("[4a/4] Generating WAT disassembly...");
|
|
185
|
-
const parseResult = parseWasmModule(
|
|
215
|
+
const parseResult = parseWasmModule(compilationBytes);
|
|
186
216
|
if (!isParseError(parseResult)) {
|
|
187
217
|
const watCode = disassembleToWAT(parseResult);
|
|
188
218
|
const resolvedWatOutput = resolve(watOutputFile);
|
|
@@ -255,12 +285,13 @@ async function getAssemblyScriptPath() {
|
|
|
255
285
|
}
|
|
256
286
|
|
|
257
287
|
// src/cli.ts
|
|
258
|
-
var VERSION = "0.
|
|
288
|
+
var VERSION = "0.4.0";
|
|
259
289
|
async function main() {
|
|
260
290
|
const args = parseArgs(Deno.args, {
|
|
261
291
|
string: [
|
|
262
292
|
"output",
|
|
263
293
|
"metadata",
|
|
294
|
+
"prepare",
|
|
264
295
|
"spec-version",
|
|
265
296
|
"wat-output",
|
|
266
297
|
"source-mapping"
|
|
@@ -271,6 +302,9 @@ async function main() {
|
|
|
271
302
|
"verbose",
|
|
272
303
|
"keep-wasm",
|
|
273
304
|
"optimize",
|
|
305
|
+
"no-optimize",
|
|
306
|
+
"minify",
|
|
307
|
+
"strict",
|
|
274
308
|
"deny-f64-demotion",
|
|
275
309
|
"allow-i64-demotion",
|
|
276
310
|
"warnings-as-errors"
|
|
@@ -278,7 +312,7 @@ async function main() {
|
|
|
278
312
|
default: {
|
|
279
313
|
verbose: false,
|
|
280
314
|
"keep-wasm": false,
|
|
281
|
-
|
|
315
|
+
minify: false
|
|
282
316
|
}
|
|
283
317
|
});
|
|
284
318
|
if (args.version) {
|
|
@@ -303,11 +337,14 @@ async function main() {
|
|
|
303
337
|
const options = {
|
|
304
338
|
output: args.output,
|
|
305
339
|
metadata: args.metadata,
|
|
340
|
+
prepare: args.prepare,
|
|
341
|
+
strict: args.strict,
|
|
306
342
|
specVersion: args["spec-version"],
|
|
307
343
|
watOutput: args["wat-output"],
|
|
308
344
|
verbose: args.verbose,
|
|
309
345
|
keepWasm: args["keep-wasm"],
|
|
310
|
-
optimize: args.optimize,
|
|
346
|
+
optimize: Deno.args.includes("--optimize") ? true : Deno.args.includes("--no-optimize") ? false : void 0,
|
|
347
|
+
minify: args.minify,
|
|
311
348
|
denyF64Demotion: args["deny-f64-demotion"],
|
|
312
349
|
allowI64Demotion: args["allow-i64-demotion"],
|
|
313
350
|
warningsAsErrors: args["warnings-as-errors"],
|
|
@@ -347,11 +384,14 @@ COMMANDS:
|
|
|
347
384
|
OPTIONS:
|
|
348
385
|
--output <file> Write WGSL output to file (default: stdout)
|
|
349
386
|
--metadata <file> Write validated Gasm v0.2 metadata sidecar JSON
|
|
387
|
+
--prepare auto Infer and inject extensions for transient builds
|
|
388
|
+
--strict Analyze without modifying the input Wasm
|
|
350
389
|
--spec-version <version> Compile as Gasm 0.1 or 0.2 (default: 0.2)
|
|
351
390
|
--wat-output <file> Also write WAT (WebAssembly Text) disassembly to file
|
|
352
391
|
--verbose Show detailed compilation steps
|
|
353
392
|
--keep-wasm Keep intermediate WASM files
|
|
354
393
|
--optimize Apply optimization passes
|
|
394
|
+
--minify Emit compact, single-line WGSL (enables optimization)
|
|
355
395
|
--deny-f64-demotion Fail if f64 would be demoted to f32
|
|
356
396
|
--allow-i64-demotion Allow lossy i64\u2192i32 demotion (mod 2^32)
|
|
357
397
|
--warnings-as-errors Treat compiler warnings as errors
|
|
@@ -372,6 +412,9 @@ EXAMPLES:
|
|
|
372
412
|
# Compile with optimization
|
|
373
413
|
deno run --allow-all src/cli.ts compile input.wasm --optimize --output output.wgsl
|
|
374
414
|
|
|
415
|
+
# Compile minified WGSL
|
|
416
|
+
deno run --allow-all src/cli.ts compile input.wasm --minify --output output.wgsl
|
|
417
|
+
|
|
375
418
|
DOCUMENTATION:
|
|
376
419
|
https://github.com/MartinEricsson/gasm-compiler
|
|
377
420
|
`);
|
package/package.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasm-compiler/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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.
|
|
36
|
+
"@gasm-compiler/core": "0.7.0"
|
|
39
37
|
},
|
|
40
38
|
"devDependencies": {
|
|
41
39
|
"assemblyscript": "v0.28.9",
|