@skathi-native/cli 0.1.0-beta.3 → 0.1.0-beta.4
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/check/codes.ts +19 -0
- package/check/command.ts +5 -3
- package/check/index.ts +44 -1
- package/cli/aot-build.ts +10 -7
- package/cli/build-app.ts +37 -8
- package/cli/config.ts +2 -2
- package/cli/create.ts +2 -1
- package/cli/dev.ts +109 -19
- package/cli/effects.ts +162 -0
- package/cli/elf.ts +3 -2
- package/cli/help.ts +56 -147
- package/cli/host-fetch.ts +33 -10
- package/cli/host.ts +43 -33
- package/cli/sk.ts +437 -234
- package/cli/skpk.ts +2 -0
- package/cli/stamp.ts +2 -2
- package/cli/term.ts +169 -38
- package/cli/workload-cache.ts +258 -0
- package/effects/compile.ts +952 -0
- package/effects/redslangc.json +23 -0
- package/effects/redslangc.ts +220 -0
- package/effects/sk.slang +558 -0
- package/package.json +5 -2
- package/templates/minimal/src/App.vue +2 -2
- package/templates/showcase/shaders/sheen.slang +23 -0
- package/templates/showcase/src/pages/StylesPage.vue +9 -1
- package/templates/showcase/src/styles.css +2 -2
package/check/codes.ts
CHANGED
|
@@ -57,6 +57,25 @@ const CODES: CodeInfo[] = [
|
|
|
57
57
|
fix: "Fix the build error (sk build shows the same one), then run sk check again.",
|
|
58
58
|
fatal: true,
|
|
59
59
|
},
|
|
60
|
+
{
|
|
61
|
+
code: "SK0005",
|
|
62
|
+
severity: "error",
|
|
63
|
+
title: "an effect shader does not compile",
|
|
64
|
+
explanation:
|
|
65
|
+
"The app's shaders/*.slang are its own `--shading` effects, compiled into the app for every OS by sk build. One of them does not compile, or breaks a rule of the effect schema (an attribute, a parameter type, a name), so sk build refuses the app.",
|
|
66
|
+
example:
|
|
67
|
+
'[SkEffect("ripple")]\nstruct Ripple : IEffect\n{\n int rings; // parameters are float, float2, float3 or float4\n float4 shade(EffectInput input) { return float4(0, 0, 0, 0); }\n};',
|
|
68
|
+
fix: "Fix the shader at the reported line; the rules are in the comments of the `sk` prelude (`import sk;`).",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
code: "SK0006",
|
|
72
|
+
severity: "warning",
|
|
73
|
+
title: "the effect shaders could not be checked",
|
|
74
|
+
explanation:
|
|
75
|
+
"The app has shaders/*.slang, but the shader compiler (redslangc) could not be found or downloaded, so they were not compiled. sk build needs it too.",
|
|
76
|
+
example: "SK_HOST_OFFLINE=1 with no cached redslangc",
|
|
77
|
+
fix: "Allow the download once, or set SK_REDSLANGC to a redslangc binary.",
|
|
78
|
+
},
|
|
60
79
|
{
|
|
61
80
|
code: "SK1001",
|
|
62
81
|
severity: "error",
|
package/check/command.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { colorEnabled, colorFlag, paint, quietProgress, spinner, type Progress } from "../cli/term";
|
|
1
|
+
import { colorEnabled, colorFlag, interactive, paint, quietProgress, spinner, type Progress } from "../cli/term";
|
|
2
2
|
import { highlighter, type Highlight } from "./highlight";
|
|
3
3
|
import { exitCode, explain, formatPretty, listCodes, loadTypeScript, runCheck } from "./index";
|
|
4
4
|
|
|
@@ -25,7 +25,9 @@ export const defaultIo = (flags: Pick<CheckFlags, "color" | "no-color"> = {}): I
|
|
|
25
25
|
err: (text) => process.stderr.write(`${text}\n`),
|
|
26
26
|
color,
|
|
27
27
|
progress: () =>
|
|
28
|
-
|
|
28
|
+
interactive(process.stderr)
|
|
29
|
+
? spinner(process.stderr, colorEnabled(process.stderr, colorFlag(flags)))
|
|
30
|
+
: quietProgress,
|
|
29
31
|
};
|
|
30
32
|
};
|
|
31
33
|
|
|
@@ -73,7 +75,7 @@ export async function checkCommand(
|
|
|
73
75
|
}
|
|
74
76
|
return exitCode(report, flags["deny-warnings"] === true);
|
|
75
77
|
} catch (e) {
|
|
76
|
-
progress.
|
|
78
|
+
progress.fail();
|
|
77
79
|
fail(e instanceof Error ? e.message : String(e));
|
|
78
80
|
return 2;
|
|
79
81
|
}
|
package/check/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
-
import { join, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { loadAppConfig } from "../cli/config";
|
|
5
|
+
import { appShadersDir, compileAppEffects, EffectsError, hasAppEffects } from "../effects/compile";
|
|
6
|
+
import { resolveCompiler } from "../effects/redslangc";
|
|
5
7
|
import { quietProgress, type Progress } from "../cli/term";
|
|
6
8
|
import { Builtins } from "./builtins";
|
|
7
9
|
import { codeInfo, REGISTRY } from "./codes";
|
|
@@ -91,6 +93,7 @@ export async function runCheck(options: CheckOptions): Promise<CheckReport> {
|
|
|
91
93
|
const typescript = loadTypeScript(config.appRoot);
|
|
92
94
|
const base = { typescript, root: config.appRoot, entry: config.entry, toolVersion: options.toolVersion, progress };
|
|
93
95
|
if (findings.length) return analyze({ ...base, modules: [], findings });
|
|
96
|
+
findings.push(...(await effectFindings(config.appRoot, progress)));
|
|
94
97
|
|
|
95
98
|
progress.step("module graph");
|
|
96
99
|
let graph: ModuleGraph;
|
|
@@ -137,9 +140,49 @@ export async function runCheck(options: CheckOptions): Promise<CheckReport> {
|
|
|
137
140
|
declarations: graph.declarations,
|
|
138
141
|
allow: checkConfig.allow,
|
|
139
142
|
deps: options.deps ?? true,
|
|
143
|
+
findings,
|
|
140
144
|
});
|
|
141
145
|
}
|
|
142
146
|
|
|
147
|
+
/** The app's shaders/*.slang, compiled as sk build would: one SK0005 per error, at the author's line. */
|
|
148
|
+
export async function effectFindings(appRoot: string, progress: Progress = quietProgress): Promise<Finding[]> {
|
|
149
|
+
if (!hasAppEffects(appRoot)) return [];
|
|
150
|
+
const dir = appShadersDir(appRoot);
|
|
151
|
+
progress.step("effect shaders");
|
|
152
|
+
let compiler: string;
|
|
153
|
+
try {
|
|
154
|
+
compiler = (
|
|
155
|
+
await resolveCompiler({
|
|
156
|
+
log: (line) => progress.info(line),
|
|
157
|
+
onBytes: (done, total) => progress.bytes(done, total),
|
|
158
|
+
})
|
|
159
|
+
).path;
|
|
160
|
+
} catch (e) {
|
|
161
|
+
const message = `the effect shaders were not compiled: ${e instanceof Error ? e.message : String(e)}`;
|
|
162
|
+
return [{ code: "SK0006", message, file: dir, range: ZERO_RANGE, related: [] }];
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
await compileAppEffects(appRoot, compiler);
|
|
166
|
+
return [];
|
|
167
|
+
} catch (e) {
|
|
168
|
+
if (!(e instanceof EffectsError)) throw e;
|
|
169
|
+
return e.problems
|
|
170
|
+
.filter((p) => p.severity === "error")
|
|
171
|
+
.map((p): Finding => {
|
|
172
|
+
const own = isAbsolute(p.file);
|
|
173
|
+
const line = own ? Math.max(0, p.line - 1) : 0;
|
|
174
|
+
const character = own ? Math.max(0, p.column - 1) : 0;
|
|
175
|
+
return {
|
|
176
|
+
code: "SK0005",
|
|
177
|
+
message: own ? p.message : `${p.file}${p.line ? `:${p.line}` : ""}: ${p.message}`,
|
|
178
|
+
file: own ? p.file : dir,
|
|
179
|
+
range: { start: { line, character }, end: { line, character } },
|
|
180
|
+
related: [],
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
143
186
|
export function analyze(input: AnalyzeInput): CheckReport {
|
|
144
187
|
const { typescript } = input;
|
|
145
188
|
const progress = input.progress ?? quietProgress;
|
package/cli/aot-build.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { TRANSFORM } from "../aot/transform";
|
|
|
15
15
|
import { exitCode, formatPretty, runCheck, type CheckReport } from "../check/index";
|
|
16
16
|
import { ConfigError } from "./config";
|
|
17
17
|
import { CLI_VERSION, HostError, REPO_ROOT, type HostAot, type ResolvedHost } from "./host";
|
|
18
|
-
import { cachedAotCompiler, fetchAotCompiler } from "./host-fetch";
|
|
18
|
+
import { cachedAotCompiler, fetchAotCompiler, type OnBytes } from "./host-fetch";
|
|
19
19
|
import type { Platform } from "./platform";
|
|
20
20
|
import { KIND, NAMES, type SkpkInput } from "./skpk";
|
|
21
21
|
import type { Progress } from "./term";
|
|
@@ -55,13 +55,13 @@ export function hostAot(host: ResolvedHost): HostAot {
|
|
|
55
55
|
if (!host.info.features.includes("native-aot") || !aot) {
|
|
56
56
|
throw new HostError(
|
|
57
57
|
`${host.exe} cannot load native images (it was built without the native AOT loader) — ` +
|
|
58
|
-
`use a Skathi ${CLI_VERSION} release
|
|
58
|
+
`use a Skathi ${CLI_VERSION} release workload (sk workload install), or build one with the native-aot cargo feature`,
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
61
|
if (aot.transform !== TRANSFORM) {
|
|
62
62
|
throw new HostError(
|
|
63
63
|
`${host.exe} expects native images made with the ${aot.transform} transform and this sk makes ${TRANSFORM} — ` +
|
|
64
|
-
"use the sk that matches the
|
|
64
|
+
"use the sk that matches the workload",
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
return aot;
|
|
@@ -81,12 +81,13 @@ export async function resolveAotCompiler(
|
|
|
81
81
|
aot: HostAot,
|
|
82
82
|
named: string | undefined,
|
|
83
83
|
log: (line: string) => void,
|
|
84
|
+
onBytes?: OnBytes,
|
|
84
85
|
): Promise<CompilerChoice> {
|
|
85
86
|
const explicit = named ?? process.env.SK_AOT_COMPILER;
|
|
86
87
|
if (explicit) {
|
|
87
88
|
const info = await compilerInfo(explicit);
|
|
88
89
|
const mismatch = compilerMismatch(info, aot);
|
|
89
|
-
if (mismatch) throw new AotError(`${explicit} compiles for another
|
|
90
|
+
if (mismatch) throw new AotError(`${explicit} compiles for another workload: ${mismatch}`);
|
|
90
91
|
return { path: explicit, info, source: named ? "--aot-compiler" : "SK_AOT_COMPILER" };
|
|
91
92
|
}
|
|
92
93
|
const tried: string[] = [];
|
|
@@ -102,11 +103,11 @@ export async function resolveAotCompiler(
|
|
|
102
103
|
}
|
|
103
104
|
if (process.env.SK_HOST_OFFLINE === "1") {
|
|
104
105
|
throw new AotError(
|
|
105
|
-
`no sk-aot matches the
|
|
106
|
+
`no sk-aot matches the workload${tried.length ? `:\n ${tried.join("\n ")}` : ""}\n` +
|
|
106
107
|
"SK_HOST_OFFLINE=1 forbids downloading it; pass --aot-compiler <sk-aot.exe>",
|
|
107
108
|
);
|
|
108
109
|
}
|
|
109
|
-
const fetched = await fetchAotCompiler({ log });
|
|
110
|
+
const fetched = await fetchAotCompiler({ log, onBytes });
|
|
110
111
|
const mismatch = compilerMismatch(fetched.info, aot);
|
|
111
112
|
if (mismatch) throw new AotError(`the Skathi ${CLI_VERSION} release's sk-aot: ${mismatch}`);
|
|
112
113
|
return { path: fetched.path, info: await compilerInfo(fetched.path), source: "release" };
|
|
@@ -156,7 +157,9 @@ export async function buildNative(options: {
|
|
|
156
157
|
}): Promise<NativeBuild> {
|
|
157
158
|
const { progress, log, aot, work } = options;
|
|
158
159
|
progress.step("AOT toolchain");
|
|
159
|
-
const compiler = await resolveAotCompiler(aot, options.compilerPath, log)
|
|
160
|
+
const compiler = await resolveAotCompiler(aot, options.compilerPath, log, (done, total) =>
|
|
161
|
+
progress.bytes(done, total),
|
|
162
|
+
);
|
|
160
163
|
progress.detail(`sk-aot (${compiler.source})`);
|
|
161
164
|
progress.step("native image");
|
|
162
165
|
const native = await compileNative({
|
package/cli/build-app.ts
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
// macos-bundle.ts: the host is copied into `<exeName>.app`, the SKPK goes in Contents/Resources,
|
|
10
10
|
// and the bundle is signed (ad hoc unless an identity is given). On Linux the SKPK is appended to a
|
|
11
11
|
// copy of the host ELF (elf.ts). `PACKAGERS` holds the three. With `--aot` (Windows x64), aot-build.ts adds
|
|
12
|
-
// the app's native image to the SKPK.
|
|
12
|
+
// the app's native image to the SKPK. The app's shaders/*.slang go in as `sk/effects/*` (effects.ts), every
|
|
13
|
+
// renderer's target whatever the OS.
|
|
13
14
|
|
|
14
15
|
import { createHash } from "node:crypto";
|
|
15
16
|
import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
@@ -17,6 +18,7 @@ import { join, relative, resolve, sep } from "node:path";
|
|
|
17
18
|
import { aotCheck, aotPlatformProblem, buildNative, hostAot, type NativeBuild } from "./aot-build";
|
|
18
19
|
import { collectAssets, type AssetFile } from "./assets";
|
|
19
20
|
import { ConfigError, loadAppConfig, parseVariant, type AppConfig, type PackConfig, type Variant } from "./config";
|
|
21
|
+
import { buildAppEffects, type BuiltEffects } from "./effects";
|
|
20
22
|
import { stampElf, type ElfStampResult } from "./elf";
|
|
21
23
|
import { CLI_VERSION, PKG_DIR, type ResolvedHost } from "./host";
|
|
22
24
|
import { resolveOrFetchHost } from "./host-fetch";
|
|
@@ -60,6 +62,8 @@ export interface BuildOptions {
|
|
|
60
62
|
aot?: boolean | undefined;
|
|
61
63
|
/** The sk-aot to use instead of the checkout's or the release's. */
|
|
62
64
|
aotCompiler?: string | undefined;
|
|
65
|
+
/** The redslangc that compiles the app's effect shaders instead of the pinned release. */
|
|
66
|
+
shaderCompiler?: string | undefined;
|
|
63
67
|
/** Colors in a report that refuses the build. */
|
|
64
68
|
color?: boolean;
|
|
65
69
|
platform?: Platform | undefined;
|
|
@@ -119,6 +123,8 @@ export interface BuildResult {
|
|
|
119
123
|
payloadBytes: number;
|
|
120
124
|
packs: { name: string; path: string; bytes: number; assets: number }[];
|
|
121
125
|
aotInputs: string | null;
|
|
126
|
+
/** The app's own --shading effects, compiled into the payload. */
|
|
127
|
+
effects: { names: string[]; dir: string; compiler: string } | null;
|
|
122
128
|
native: {
|
|
123
129
|
manifest: string;
|
|
124
130
|
imageBytes: number;
|
|
@@ -344,9 +350,12 @@ const PACKAGERS: Record<Platform, (input: PackageInput) => Packaged> = {
|
|
|
344
350
|
export async function buildApp(options: BuildOptions): Promise<BuildResult> {
|
|
345
351
|
const progress = options.progress ?? (options.log ? lineProgress(options.log, false) : progressFor(process.stderr));
|
|
346
352
|
try {
|
|
347
|
-
|
|
348
|
-
} finally {
|
|
353
|
+
const result = await build(options, progress);
|
|
349
354
|
if (!options.progress) progress.end();
|
|
355
|
+
return result;
|
|
356
|
+
} catch (e) {
|
|
357
|
+
progress.fail();
|
|
358
|
+
throw e;
|
|
350
359
|
}
|
|
351
360
|
}
|
|
352
361
|
|
|
@@ -366,14 +375,16 @@ async function build(options: BuildOptions, progress: Progress): Promise<BuildRe
|
|
|
366
375
|
const problem = aotPlatformProblem(platform);
|
|
367
376
|
if (problem) throw new ConfigError(problem);
|
|
368
377
|
if (options.payloadOnly)
|
|
369
|
-
throw new ConfigError(
|
|
378
|
+
throw new ConfigError(
|
|
379
|
+
"--aot compiles against the workload it stamps, so it cannot be combined with --payload-only",
|
|
380
|
+
);
|
|
370
381
|
}
|
|
371
382
|
const outDir = resolve(options.out ?? join(config.appRoot, "dist", ...(options.mode ? [options.mode] : [])));
|
|
372
383
|
const work = join(outDir, ".sk");
|
|
373
384
|
mkdirSync(work, { recursive: true });
|
|
374
385
|
|
|
375
386
|
// The host first: a missing or mismatched host should fail before a bundle is spent on it.
|
|
376
|
-
if (!options.payloadOnly) progress.step("
|
|
387
|
+
if (!options.payloadOnly) progress.step("workload");
|
|
377
388
|
const host = options.payloadOnly
|
|
378
389
|
? null
|
|
379
390
|
: await resolveOrFetchHost({
|
|
@@ -382,6 +393,7 @@ async function build(options: BuildOptions, progress: Progress): Promise<BuildRe
|
|
|
382
393
|
allowMismatch: options.allowHostMismatch,
|
|
383
394
|
platform,
|
|
384
395
|
log,
|
|
396
|
+
onBytes: (done, total) => progress.bytes(done, total),
|
|
385
397
|
});
|
|
386
398
|
if (host) {
|
|
387
399
|
progress.detail(`${host.info.variant} · Skathi ${host.info.skathi} ${host.info.profile} · ${host.source}`);
|
|
@@ -389,6 +401,14 @@ async function build(options: BuildOptions, progress: Progress): Promise<BuildRe
|
|
|
389
401
|
}
|
|
390
402
|
const hostNative = aot && host ? hostAot(host) : null;
|
|
391
403
|
|
|
404
|
+
const effects: BuiltEffects | null = await buildAppEffects({
|
|
405
|
+
appRoot: config.appRoot,
|
|
406
|
+
out: join(work, "effects"),
|
|
407
|
+
compiler: options.shaderCompiler,
|
|
408
|
+
progress,
|
|
409
|
+
});
|
|
410
|
+
if (!effects) rmSync(join(work, "effects"), { recursive: true, force: true });
|
|
411
|
+
|
|
392
412
|
const jsOut = join(work, "app.prod.js");
|
|
393
413
|
const assetsJson = join(work, "assets.json");
|
|
394
414
|
// A stale list from an older build must not survive a builder that wrote none.
|
|
@@ -482,6 +502,7 @@ async function build(options: BuildOptions, progress: Progress): Promise<BuildRe
|
|
|
482
502
|
{ name: NAMES.WINDOW, kind: KIND.WINDOW, data: windowJson },
|
|
483
503
|
{ name: NAMES.SCRIPT, kind: KIND.SCRIPT, data: script },
|
|
484
504
|
...split.own.map((f) => ({ name: f.key, kind: KIND.ASSET, data: new Uint8Array(readFileSync(f.path)) })),
|
|
505
|
+
...(effects?.inputs ?? []),
|
|
485
506
|
];
|
|
486
507
|
const skpk = join(work, "app.skpk");
|
|
487
508
|
for (const p of packs) writeFileSync(join(work, p.file), p.blob);
|
|
@@ -535,6 +556,11 @@ async function build(options: BuildOptions, progress: Progress): Promise<BuildRe
|
|
|
535
556
|
assets: collected.files,
|
|
536
557
|
bundleBytes: script.length,
|
|
537
558
|
aotInputs: options.aotInputs ? join(work, "aot-inputs", "manifest.json") : null,
|
|
559
|
+
effects: effects && {
|
|
560
|
+
names: effects.effects.compiled.map((c) => c.effect.name),
|
|
561
|
+
dir: join(work, "effects"),
|
|
562
|
+
compiler: effects.compiler.path,
|
|
563
|
+
},
|
|
538
564
|
native: native && {
|
|
539
565
|
manifest: native.manifestPath,
|
|
540
566
|
imageBytes: native.imageBytes,
|
|
@@ -578,7 +604,7 @@ export function summary(r: BuildResult, color = false): string {
|
|
|
578
604
|
row("exe", p.cyan(r.exe)),
|
|
579
605
|
row(
|
|
580
606
|
"",
|
|
581
|
-
`${mib(s.bytes)}, ${r.variant}
|
|
607
|
+
`${mib(s.bytes)}, ${r.variant} workload, subsystem ${s.subsystem === 2 ? "GUI" : "console"}, ` +
|
|
582
608
|
`${s.iconCount ? `${s.iconCount} icon` : "no icon"}, ` +
|
|
583
609
|
bad(s.dataAligned, "data page-aligned", "data NOT aligned"),
|
|
584
610
|
),
|
|
@@ -590,7 +616,7 @@ export function summary(r: BuildResult, color = false): string {
|
|
|
590
616
|
row("exe", p.cyan(e.out)),
|
|
591
617
|
row(
|
|
592
618
|
"",
|
|
593
|
-
`${mib(e.bytes)}, ${r.variant}
|
|
619
|
+
`${mib(e.bytes)}, ${r.variant} workload (${e.machine}), payload appended at ${e.payloadOffset}, ` +
|
|
594
620
|
bad(e.dataAligned, "data page-aligned", "data NOT aligned"),
|
|
595
621
|
),
|
|
596
622
|
);
|
|
@@ -602,7 +628,7 @@ export function summary(r: BuildResult, color = false): string {
|
|
|
602
628
|
b.signed === "-" ? "signed ad hoc" : b.signed ? `signed as ${JSON.stringify(b.signed)}` : p.yellow("NOT signed");
|
|
603
629
|
lines.push(
|
|
604
630
|
row("app", p.cyan(b.app)),
|
|
605
|
-
row("", `${mib(b.bytes)}, ${r.variant}
|
|
631
|
+
row("", `${mib(b.bytes)}, ${r.variant} workload, ${b.bundleId}, ${icon}, ${signed}`),
|
|
606
632
|
);
|
|
607
633
|
if (b.signNote) lines.push(row("", p.dim(b.signNote)));
|
|
608
634
|
}
|
|
@@ -613,6 +639,9 @@ export function summary(r: BuildResult, color = false): string {
|
|
|
613
639
|
),
|
|
614
640
|
row("payload", `${kib(r.payloadBytes)} ${p.dim(r.skpk)}`),
|
|
615
641
|
);
|
|
642
|
+
if (r.effects) {
|
|
643
|
+
lines.push(row("effects", `${r.effects.names.join(", ")} ${p.dim("hlsl · wgsl · metal")}`));
|
|
644
|
+
}
|
|
616
645
|
if (r.native) {
|
|
617
646
|
lines.push(
|
|
618
647
|
row(
|
package/cli/config.ts
CHANGED
|
@@ -37,7 +37,7 @@ export const PARTS_NOT_SELECTABLE =
|
|
|
37
37
|
export function parseVariant(v: unknown, where: string): Variant {
|
|
38
38
|
const name = typeof v === "string" ? v.trim() : "";
|
|
39
39
|
if (VARIANTS.includes(name)) return name;
|
|
40
|
-
throw new ConfigError(`${where}: ${JSON.stringify(v)} is not a
|
|
40
|
+
throw new ConfigError(`${where}: ${JSON.stringify(v)} is not a workload variant — ${VARIANTS.join(" or ")}`);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export function cargoFeatureArgs(variant: Variant): string[] {
|
|
@@ -306,7 +306,7 @@ function readMacos(
|
|
|
306
306
|
const [wantMaj = 0, wantMinor = 0] = MACOS_MINIMUM.split(".").map(Number);
|
|
307
307
|
if (maj < wantMaj || (maj === wantMaj && minor < wantMinor)) {
|
|
308
308
|
warnings.push(
|
|
309
|
-
`sk.config.json "macos.minimumSystemVersion" ${min} is below ${MACOS_MINIMUM}, which the
|
|
309
|
+
`sk.config.json "macos.minimumSystemVersion" ${min} is below ${MACOS_MINIMUM}, which the workload is built for — ` +
|
|
310
310
|
"an older macOS will offer to open the app and then fail to load it",
|
|
311
311
|
);
|
|
312
312
|
}
|
package/cli/create.ts
CHANGED
|
@@ -179,6 +179,7 @@ export interface CreateFlags {
|
|
|
179
179
|
devtools?: boolean | undefined;
|
|
180
180
|
pm?: string | undefined;
|
|
181
181
|
yes?: boolean | undefined;
|
|
182
|
+
color?: boolean | undefined;
|
|
182
183
|
}
|
|
183
184
|
|
|
184
185
|
function parsePm(v: string): PackageManager {
|
|
@@ -277,7 +278,7 @@ export async function createCommand(target: string | undefined, flags: CreateFla
|
|
|
277
278
|
p.note(next, "Next");
|
|
278
279
|
p.outro(`${options.name ?? basename(resolve(dir))} is ready`);
|
|
279
280
|
} else {
|
|
280
|
-
const c = paint(colorEnabled(process.stdout));
|
|
281
|
+
const c = paint(colorEnabled(process.stdout, flags.color));
|
|
281
282
|
console.log(`${c.green("✓")} created ${c.cyan(resolve(dir))}\n ${c.dim("next:")} ${next.replace(/\n/g, " && ")}`);
|
|
282
283
|
}
|
|
283
284
|
return 0;
|
package/cli/dev.ts
CHANGED
|
@@ -3,23 +3,32 @@
|
|
|
3
3
|
//
|
|
4
4
|
// The dev host, first hit wins: `--exe` or SK_DEV_HOST; in a checkout, its debug sk-app (`cargo build
|
|
5
5
|
// -p sk-app`); the cached dev host of this version; a download of it from the release (host-fetch.ts).
|
|
6
|
+
//
|
|
7
|
+
// An app with shaders/*.slang has them compiled into <dist>/effects, which the host reads through
|
|
8
|
+
// SK_EFFECTS_DIR, and recompiled on every change. A good rebuild reaches the running app as a message
|
|
9
|
+
// beside the HMR changes.json and replaces its effects in place; a host that predates that (its
|
|
10
|
+
// --sk-host-info has no `devReload: ["effects"]`) is restarted. A failed rebuild prints the
|
|
11
|
+
// diagnostics and keeps the last good build running.
|
|
6
12
|
|
|
7
|
-
import { spawn } from "node:child_process";
|
|
13
|
+
import { spawn, type ChildProcess } from "node:child_process";
|
|
8
14
|
import { existsSync, mkdirSync } from "node:fs";
|
|
9
15
|
import { join } from "node:path";
|
|
16
|
+
import { compileAppEffects, EffectsError, formatProblems, hasAppEffects, writeEffectFiles } from "../effects/compile";
|
|
17
|
+
import { resolveCompiler } from "../effects/redslangc";
|
|
10
18
|
import { loadAppConfig } from "./config";
|
|
19
|
+
import { devEffectsWatch, type EffectsWatch } from "./effects";
|
|
11
20
|
import { cachedHost, checkHost, DEV_HOST, HostError, hostInfo, PKG_DIR, REPO_ROOT, CLI_VERSION } from "./host";
|
|
12
|
-
import { fetchHost } from "./host-fetch";
|
|
21
|
+
import { fetchHost, type OnBytes } from "./host-fetch";
|
|
13
22
|
import { currentPlatform, hostsFor, repoHostExe } from "./platform";
|
|
14
23
|
import { colorEnabled, paint, progressFor } from "./term";
|
|
15
24
|
|
|
16
25
|
export async function devHost(
|
|
17
|
-
options: { exe?: string | undefined; log?: (line: string) => void } = {},
|
|
26
|
+
options: { exe?: string | undefined; log?: (line: string) => void; onBytes?: OnBytes } = {},
|
|
18
27
|
): Promise<string> {
|
|
19
28
|
const log = options.log ?? console.log;
|
|
20
29
|
const named = options.exe ?? process.env.SK_DEV_HOST;
|
|
21
30
|
if (named) {
|
|
22
|
-
if (!existsSync(named)) throw new HostError(`no dev
|
|
31
|
+
if (!existsSync(named)) throw new HostError(`no dev workload at ${named}`);
|
|
23
32
|
return named;
|
|
24
33
|
}
|
|
25
34
|
if (REPO_ROOT) {
|
|
@@ -37,26 +46,70 @@ export async function devHost(
|
|
|
37
46
|
if (!usable()) {
|
|
38
47
|
if (process.env.SK_HOST_OFFLINE === "1") {
|
|
39
48
|
throw new HostError(
|
|
40
|
-
`no dev
|
|
41
|
-
"pass --exe <dev
|
|
49
|
+
`no dev workload: ${cached} is missing or unusable and SK_HOST_OFFLINE=1 forbids a download — ` +
|
|
50
|
+
"pass --exe <dev workload>" +
|
|
42
51
|
(REPO_ROOT
|
|
43
52
|
? `, or build one with \`${["cargo build -p sk-app", ...hostsFor(currentPlatform()).cargoTarget].join(" ")}\``
|
|
44
53
|
: ""),
|
|
45
54
|
);
|
|
46
55
|
}
|
|
47
|
-
await fetchHost({ variant: DEV_HOST, log });
|
|
56
|
+
await fetchHost({ variant: DEV_HOST, log, onBytes: options.onBytes });
|
|
48
57
|
}
|
|
49
58
|
return cached;
|
|
50
59
|
}
|
|
51
60
|
|
|
52
|
-
|
|
61
|
+
function reloadsEffects(exe: string): boolean {
|
|
62
|
+
try {
|
|
63
|
+
return hostInfo(exe).devReload?.includes("effects") ?? false;
|
|
64
|
+
} catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function dev(
|
|
70
|
+
target: string,
|
|
71
|
+
options: { exe?: string | undefined; shaderCompiler?: string | undefined; color?: boolean | undefined } = {},
|
|
72
|
+
): Promise<number> {
|
|
53
73
|
const config = loadAppConfig(target);
|
|
54
|
-
const c = paint(colorEnabled(process.stdout));
|
|
55
|
-
const progress = progressFor(process.stderr);
|
|
56
|
-
progress.step("dev
|
|
57
|
-
const exe = await devHost({
|
|
74
|
+
const c = paint(colorEnabled(process.stdout, options.color));
|
|
75
|
+
const progress = progressFor(process.stderr, colorEnabled(process.stderr, options.color));
|
|
76
|
+
progress.step("dev workload");
|
|
77
|
+
const exe = await devHost({
|
|
78
|
+
...options,
|
|
79
|
+
log: (line) => progress.detail(line),
|
|
80
|
+
onBytes: (done, total) => progress.bytes(done, total),
|
|
81
|
+
}).catch((e: unknown) => {
|
|
82
|
+
progress.fail();
|
|
83
|
+
throw e;
|
|
84
|
+
});
|
|
58
85
|
const dist = join(config.appRoot, "dist", ".sk-dev");
|
|
59
86
|
mkdirSync(dist, { recursive: true });
|
|
87
|
+
|
|
88
|
+
const effectsDir = join(dist, "effects");
|
|
89
|
+
const overridden = !!process.env.SK_EFFECTS_DIR;
|
|
90
|
+
let compiler: string | null = null;
|
|
91
|
+
if (hasAppEffects(config.appRoot) && !overridden) {
|
|
92
|
+
progress.step("effects");
|
|
93
|
+
try {
|
|
94
|
+
compiler = (
|
|
95
|
+
await resolveCompiler({
|
|
96
|
+
named: options.shaderCompiler,
|
|
97
|
+
log: (line) => progress.info(line),
|
|
98
|
+
onBytes: (done, total) => progress.bytes(done, total),
|
|
99
|
+
})
|
|
100
|
+
).path;
|
|
101
|
+
const effects = await compileAppEffects(config.appRoot, compiler);
|
|
102
|
+
writeEffectFiles(effectsDir, effects.files);
|
|
103
|
+
progress.detail(effects.compiled.map((e) => e.effect.name).join(", "));
|
|
104
|
+
} catch (e) {
|
|
105
|
+
progress.fail();
|
|
106
|
+
const text = e instanceof EffectsError ? formatProblems(e.problems) : e instanceof Error ? e.message : String(e);
|
|
107
|
+
console.error(`${c.red("effects")}: ${text}`);
|
|
108
|
+
if (existsSync(join(effectsDir, "effects.json"))) console.error(c.dim("the app starts with the last good build"));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
progress.end();
|
|
112
|
+
|
|
60
113
|
const watcher = spawn(process.execPath, [join(PKG_DIR, "build.ts"), config.entry, dist, "--watch"], {
|
|
61
114
|
cwd: PKG_DIR,
|
|
62
115
|
stdio: "inherit",
|
|
@@ -68,13 +121,42 @@ export async function dev(target: string, options: { exe?: string | undefined }
|
|
|
68
121
|
if (Date.now() > deadline) throw new Error("bun build.ts produced no manifest within 2 minutes");
|
|
69
122
|
await Bun.sleep(100);
|
|
70
123
|
}
|
|
71
|
-
console.log(`${c.green("▶")} ${c.bold(config.name)} ${c.dim(`dist ${dist},
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
124
|
+
console.log(`${c.green("▶")} ${c.bold(config.name)} ${c.dim(`dist ${dist}, workload ${exe}`)}`);
|
|
125
|
+
const start = (): ChildProcess =>
|
|
126
|
+
spawn(exe, [], {
|
|
127
|
+
stdio: "inherit",
|
|
128
|
+
// SK_OWNER_PID: the host dies with this process however it ends (crates/sk-app/src/owner.rs).
|
|
129
|
+
env: {
|
|
130
|
+
...process.env,
|
|
131
|
+
SK_DIST: dist,
|
|
132
|
+
SK_APP_ROOT: config.appRoot,
|
|
133
|
+
SK_OWNER_PID: String(process.pid),
|
|
134
|
+
...(!overridden && existsSync(join(effectsDir, "effects.json")) ? { SK_EFFECTS_DIR: effectsDir } : {}),
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
let host = start();
|
|
138
|
+
let restarting = false;
|
|
139
|
+
let effectsWatch: EffectsWatch | null = null;
|
|
140
|
+
if (compiler) {
|
|
141
|
+
effectsWatch = devEffectsWatch({
|
|
142
|
+
appRoot: config.appRoot,
|
|
143
|
+
dist,
|
|
144
|
+
out: effectsDir,
|
|
145
|
+
compiler,
|
|
146
|
+
inPlace: reloadsEffects(exe),
|
|
147
|
+
restart: () => {
|
|
148
|
+
restarting = true;
|
|
149
|
+
host.kill();
|
|
150
|
+
},
|
|
151
|
+
log: (line) => console.log(`${c.cyan("↻")} ${line}`),
|
|
152
|
+
onError: (text) => {
|
|
153
|
+
console.error(`${c.red("effects")}: ${text}`);
|
|
154
|
+
console.error(c.dim("the app keeps running the last good build"));
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
}
|
|
77
158
|
const stop = () => {
|
|
159
|
+
effectsWatch?.close();
|
|
78
160
|
try {
|
|
79
161
|
watcher.kill();
|
|
80
162
|
} catch {}
|
|
@@ -86,7 +168,15 @@ export async function dev(target: string, options: { exe?: string | undefined }
|
|
|
86
168
|
stop();
|
|
87
169
|
process.exit(130);
|
|
88
170
|
});
|
|
89
|
-
const code: number = await new Promise((done) =>
|
|
171
|
+
const code: number = await new Promise((done) => {
|
|
172
|
+
const exited = (status: number | null) => {
|
|
173
|
+
if (!restarting) return done(status ?? 0);
|
|
174
|
+
restarting = false;
|
|
175
|
+
host = start();
|
|
176
|
+
host.on("exit", exited);
|
|
177
|
+
};
|
|
178
|
+
host.on("exit", exited);
|
|
179
|
+
});
|
|
90
180
|
stop();
|
|
91
181
|
return code;
|
|
92
182
|
}
|