@skathi-native/cli 0.1.0-beta.3 → 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.
- package/aot-inputs.ts +21 -2
- package/build.ts +241 -60
- package/check/bundle.ts +265 -0
- package/check/codes.ts +19 -0
- package/check/command.ts +5 -3
- package/check/graph.ts +3 -1
- package/check/index.ts +54 -2
- package/check/program.ts +26 -6
- package/cli/aot-build.ts +10 -7
- package/cli/build-app.ts +37 -8
- package/cli/config.ts +2 -2
- package/cli/create.ts +31 -8
- 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/devtools/commands.ts +25 -0
- package/effects/compile.ts +1081 -0
- package/effects/redslangc.json +23 -0
- package/effects/redslangc.ts +220 -0
- package/effects/sk.slang +882 -0
- package/package.json +10 -4
- package/prod.ts +40 -7
- package/svelte.ts +76 -0
- package/templates/icon.png +0 -0
- package/templates/minimal/src/App.vue +2 -2
- package/templates/showcase/assets/textures/golden.png +0 -0
- package/templates/showcase/assets/textures/hammered.png +0 -0
- package/templates/showcase/assets/textures/noir.png +0 -0
- package/templates/showcase/assets/textures/reeded.png +0 -0
- package/templates/showcase/assets/textures/teal-orange.png +0 -0
- package/templates/showcase/shaders/dissolve.slang +40 -0
- package/templates/showcase/shaders/fireflies.slang +58 -0
- package/templates/showcase/shaders/glass.slang +31 -0
- package/templates/showcase/shaders/grade.slang +34 -0
- package/templates/showcase/shaders/halftone.slang +42 -0
- package/templates/showcase/shaders/lens.slang +51 -0
- package/templates/showcase/shaders/nebula.slang +57 -0
- package/templates/showcase/shaders/orbit.slang +52 -0
- package/templates/showcase/shaders/pond.slang +76 -0
- package/templates/showcase/shaders/ripples.slang +71 -0
- package/templates/showcase/shaders/shatter.slang +116 -0
- package/templates/showcase/shaders/sheen.slang +23 -0
- package/templates/showcase/shaders/snow.slang +57 -0
- package/templates/showcase/shaders/spotlight.slang +52 -0
- package/templates/showcase/src/App.vue +11 -16
- package/templates/showcase/src/components/FullWindow.vue +77 -0
- package/templates/showcase/src/components/Page.vue +2 -0
- package/templates/showcase/src/fullwindow.ts +36 -0
- package/templates/showcase/src/icons.ts +2 -0
- package/templates/showcase/src/pages/GraphicsPage.vue +122 -0
- package/templates/showcase/src/pages/MotionPage.vue +71 -1
- package/templates/showcase/src/pages/ShadersPage.vue +443 -0
- package/templates/showcase/src/pages/StylesPage.vue +9 -1
- package/templates/showcase/src/router.ts +32 -1
- package/templates/showcase/src/styles.css +2 -2
- package/templates/svelte/.vscode/settings.json +3 -0
- package/templates/svelte/assets/hello.txt +1 -0
- package/templates/svelte/src/App.svelte +142 -0
- package/templates/svelte/src/main.ts +4 -0
- package/vitecompat.ts +2 -0
package/cli/help.ts
CHANGED
|
@@ -1,159 +1,68 @@
|
|
|
1
|
-
|
|
1
|
+
// `sk --help` and `sk <command> --help`, laid out from the commander declarations in sk.ts: usage,
|
|
2
|
+
// what the command does, its subcommands, and its options under their group headings.
|
|
3
|
+
|
|
4
|
+
import type { Argument, CommandUnknownOpts, Help } from "@commander-js/extra-typings";
|
|
2
5
|
import { paint, type Paint } from "./term";
|
|
3
6
|
|
|
4
|
-
type Row = [string, string];
|
|
5
|
-
type Section = { title: string; rows: Row[] };
|
|
7
|
+
export type Row = [string, string];
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
["publish [app]", "Release build to ship"],
|
|
12
|
-
["run [app]", "Build, then start the app"],
|
|
13
|
-
["check [app]", "What breaks under AOT, and how well the code is typed"],
|
|
14
|
-
["explain <code>", "What a check code means and how to fix it"],
|
|
15
|
-
["host <command>", "Manage the prebuilt engine hosts"],
|
|
16
|
-
];
|
|
9
|
+
export function table(p: Paint, rows: Row[]): string[] {
|
|
10
|
+
const width = Math.max(...rows.map(([term]) => term.length));
|
|
11
|
+
return rows.map(([term, text]) => ` ${p.cyan(term.padEnd(width))} ${text}`);
|
|
12
|
+
}
|
|
17
13
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
title: "Options",
|
|
21
|
-
rows: [
|
|
22
|
-
["--platform <os>", "windows, macos or linux (default: this OS)"],
|
|
23
|
-
["--out <dir>", "Output directory (default: <app>/dist/debug or dist/release)"],
|
|
24
|
-
["--define K=V", "A Vite-style define; repeatable"],
|
|
25
|
-
["--config <path>", "An sk.config.json outside the app"],
|
|
26
|
-
["--sign <identity>", "macOS: codesign identity (- for ad hoc)"],
|
|
27
|
-
["--no-sign", "macOS: leave the bundle unsigned"],
|
|
28
|
-
["--console", "Windows: keep the console window"],
|
|
29
|
-
["--aot", "Windows x64: compile the app to a native image (--no-aot: don't)"],
|
|
30
|
-
["--json", "Print the result as JSON"],
|
|
31
|
-
],
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
title: "Advanced",
|
|
35
|
-
rows: [
|
|
36
|
-
["--host <exe>", "Stamp this host instead of the cached one"],
|
|
37
|
-
["--payload-only", "Write dist/.sk/app.skpk and stop"],
|
|
38
|
-
["--aot-inputs", "Keep the typed sources for a later AOT compile"],
|
|
39
|
-
["--aot-compiler <exe>", "Compile native images with this sk-aot.exe (or SK_AOT_COMPILER)"],
|
|
40
|
-
],
|
|
41
|
-
},
|
|
42
|
-
];
|
|
14
|
+
export const section = (p: Paint, title: string, rows: Row[]): string[] =>
|
|
15
|
+
rows.length ? ["", p.bold(title), ...table(p, rows)] : [];
|
|
43
16
|
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
about: "Start a new app. In a terminal it asks for whatever the options leave open.",
|
|
48
|
-
sections: [
|
|
49
|
-
{
|
|
50
|
-
title: "Options",
|
|
51
|
-
rows: [
|
|
52
|
-
["--name <name>", "The app's name (default: the directory's)"],
|
|
53
|
-
["--template <name>", "showcase (every feature) or minimal"],
|
|
54
|
-
["--os <list>", "What to package for: windows, macos, linux"],
|
|
55
|
-
["--devtools", "Keep devtools (F12) in published builds"],
|
|
56
|
-
["--pm <name>", "bun, npm, pnpm or yarn"],
|
|
57
|
-
["-y, --yes", "Ask nothing, take the defaults"],
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
},
|
|
62
|
-
dev: {
|
|
63
|
-
usage: "sk dev [app] [options]",
|
|
64
|
-
about: "Run the app with hot reload: edits to .vue, .ts and .css apply without a restart.",
|
|
65
|
-
sections: [{ title: "Options", rows: [["--exe <host>", "Run this dev host instead of the cached one"]] }],
|
|
66
|
-
},
|
|
67
|
-
build: {
|
|
68
|
-
usage: "sk build [app] [options]",
|
|
69
|
-
about: "A debug build in <app>/dist/debug: devtools (F12) on, the bundle not minified.",
|
|
70
|
-
sections: BUILD,
|
|
71
|
-
},
|
|
72
|
-
publish: {
|
|
73
|
-
usage: "sk publish [app] [options]",
|
|
74
|
-
about:
|
|
75
|
-
'The release build in <app>/dist/release: minified, devtools only with "publishDevtools": true in sk.config.json.',
|
|
76
|
-
sections: BUILD,
|
|
77
|
-
},
|
|
78
|
-
run: {
|
|
79
|
-
usage: "sk run [app] [options] [-- app args]",
|
|
80
|
-
about: "sk build, then start the app with its output in this terminal.",
|
|
81
|
-
sections: BUILD,
|
|
82
|
-
},
|
|
83
|
-
check: {
|
|
84
|
-
usage: "sk check [app] [options]",
|
|
85
|
-
about: "What in the bundle, app code and node_modules, breaks or slows down under AOT, and how well it is typed.",
|
|
86
|
-
sections: [
|
|
87
|
-
{
|
|
88
|
-
title: "Options",
|
|
89
|
-
rows: [
|
|
90
|
-
["--format json", "One JSON report on stdout (schema skathi.check)"],
|
|
91
|
-
["--deny-warnings", "Fail on warnings too"],
|
|
92
|
-
["--no-deps", "Only the app's own code"],
|
|
93
|
-
["--config <path>", "An sk.config.json outside the app"],
|
|
94
|
-
],
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
title: "Exit codes",
|
|
98
|
-
rows: [
|
|
99
|
-
["0", "Clean"],
|
|
100
|
-
["1", "Errors (or warnings with --deny-warnings)"],
|
|
101
|
-
["2", "Bad usage or config, or the check failed"],
|
|
102
|
-
],
|
|
103
|
-
},
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
explain: {
|
|
107
|
-
usage: "sk explain <code> | --list",
|
|
108
|
-
about: "What a check code means, an example, and how to fix it.",
|
|
109
|
-
sections: [{ title: "Options", rows: [["--list", "Every code"]] }],
|
|
110
|
-
},
|
|
111
|
-
host: {
|
|
112
|
-
usage: "sk host <command>",
|
|
113
|
-
about: "The engine host is the prebuilt executable an app is packed into. sk build fetches it on demand.",
|
|
114
|
-
sections: [
|
|
115
|
-
{
|
|
116
|
-
title: "Commands",
|
|
117
|
-
rows: [
|
|
118
|
-
["fetch", "Download this version's hosts into the local cache"],
|
|
119
|
-
["path", "Which host sk build would use"],
|
|
120
|
-
["info [exe]", "What a host says about itself"],
|
|
121
|
-
["add <exe>", "Verify a host and add it to the cache"],
|
|
122
|
-
["build", "In a Skathi checkout: build the hosts with cargo"],
|
|
123
|
-
],
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
},
|
|
17
|
+
const argTerm = (a: Argument) => {
|
|
18
|
+
const name = `${a.name()}${a.variadic ? "..." : ""}`;
|
|
19
|
+
return a.required ? `<${name}>` : `[${name}]`;
|
|
127
20
|
};
|
|
128
21
|
|
|
129
|
-
function
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
function sections(p: Paint, list: Section[]): string[] {
|
|
135
|
-
return list.flatMap((s) => ["", p.bold(s.title), ...rows(p, s.rows)]);
|
|
22
|
+
function path(cmd: CommandUnknownOpts): string {
|
|
23
|
+
const names: string[] = [];
|
|
24
|
+
for (let c: CommandUnknownOpts | null = cmd; c; c = c.parent) names.unshift(c.name());
|
|
25
|
+
return names.join(" ");
|
|
136
26
|
}
|
|
137
27
|
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
export function topHelp(color: boolean): string {
|
|
141
|
-
const p = paint(color);
|
|
142
|
-
return [
|
|
143
|
-
head(p),
|
|
144
|
-
"",
|
|
145
|
-
`${p.bold("Usage")} sk <command> [app] [options]`,
|
|
146
|
-
"",
|
|
147
|
-
p.bold("Commands"),
|
|
148
|
-
...rows(p, COMMANDS),
|
|
149
|
-
"",
|
|
150
|
-
p.dim("Run sk <command> --help for its options. [app] is a directory (default: .)."),
|
|
151
|
-
].join("\n");
|
|
152
|
-
}
|
|
28
|
+
const visible = (helper: Help, cmd: CommandUnknownOpts) =>
|
|
29
|
+
helper.visibleCommands(cmd).filter((c) => c.name() !== "help");
|
|
153
30
|
|
|
154
|
-
export function
|
|
155
|
-
const help = HELP[command];
|
|
156
|
-
if (!help) return null;
|
|
31
|
+
export function helpFormat(color: boolean): Partial<Help> {
|
|
157
32
|
const p = paint(color);
|
|
158
|
-
return
|
|
33
|
+
return {
|
|
34
|
+
formatHelp(cmd, helper) {
|
|
35
|
+
const commands = visible(helper, cmd);
|
|
36
|
+
const options = helper.visibleOptions(cmd);
|
|
37
|
+
const usage = [
|
|
38
|
+
path(cmd),
|
|
39
|
+
...cmd.registeredArguments.map(argTerm),
|
|
40
|
+
...(commands.length ? ["<command>"] : []),
|
|
41
|
+
...(options.length ? ["[options]"] : []),
|
|
42
|
+
].join(" ");
|
|
43
|
+
const lines: string[] = [];
|
|
44
|
+
if (!cmd.parent) lines.push(`${p.bold(cmd.name())} ${p.dim(cmd.version() ?? "")} ${cmd.description()}`, "");
|
|
45
|
+
lines.push(`${p.bold("Usage")} ${usage}`);
|
|
46
|
+
if (cmd.parent && cmd.description()) lines.push("", cmd.description());
|
|
47
|
+
lines.push(
|
|
48
|
+
...section(
|
|
49
|
+
p,
|
|
50
|
+
"Commands",
|
|
51
|
+
commands.map((c) => [
|
|
52
|
+
[c.name(), ...c.registeredArguments.map(argTerm), ...(visible(helper, c).length ? ["<command>"] : [])].join(
|
|
53
|
+
" ",
|
|
54
|
+
),
|
|
55
|
+
c.summary() || c.description(),
|
|
56
|
+
]),
|
|
57
|
+
),
|
|
58
|
+
);
|
|
59
|
+
const groups = new Map<string, Row[]>();
|
|
60
|
+
for (const o of options) {
|
|
61
|
+
const title = (o.helpGroupHeading ?? "Options").replace(/:$/, "");
|
|
62
|
+
groups.set(title, [...(groups.get(title) ?? []), [o.flags, o.description]]);
|
|
63
|
+
}
|
|
64
|
+
for (const [title, rows] of groups) lines.push(...section(p, title, rows));
|
|
65
|
+
return `${lines.join("\n")}\n`;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
159
68
|
}
|
package/cli/host-fetch.ts
CHANGED
|
@@ -77,6 +77,7 @@ export interface FetchOptions {
|
|
|
77
77
|
platform?: Platform;
|
|
78
78
|
arch?: string;
|
|
79
79
|
log?: (line: string) => void;
|
|
80
|
+
onBytes?: OnBytes | undefined;
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
function source() {
|
|
@@ -88,10 +89,31 @@ function source() {
|
|
|
88
89
|
return { repo, api, headers };
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
export type OnBytes = (done: number, total: number) => void;
|
|
93
|
+
|
|
94
|
+
async function download(
|
|
95
|
+
asset: ReleaseAsset,
|
|
96
|
+
headers: Record<string, string>,
|
|
97
|
+
onBytes?: OnBytes,
|
|
98
|
+
): Promise<Uint8Array<ArrayBuffer>> {
|
|
92
99
|
const res = await fetch(asset.url, { headers: { ...headers, Accept: "application/octet-stream" } });
|
|
93
100
|
if (!res.ok) throw new HostError(`downloading ${asset.name}: HTTP ${res.status}`);
|
|
94
|
-
return new Uint8Array(await res.arrayBuffer());
|
|
101
|
+
if (!onBytes || !res.body) return new Uint8Array(await res.arrayBuffer());
|
|
102
|
+
const total = Number(res.headers.get("content-length")) || asset.size;
|
|
103
|
+
const chunks: Uint8Array[] = [];
|
|
104
|
+
let done = 0;
|
|
105
|
+
for await (const chunk of res.body) {
|
|
106
|
+
chunks.push(chunk);
|
|
107
|
+
done += chunk.length;
|
|
108
|
+
onBytes(done, total);
|
|
109
|
+
}
|
|
110
|
+
const bytes = new Uint8Array(done);
|
|
111
|
+
let at = 0;
|
|
112
|
+
for (const chunk of chunks) {
|
|
113
|
+
bytes.set(chunk, at);
|
|
114
|
+
at += chunk.length;
|
|
115
|
+
}
|
|
116
|
+
return bytes;
|
|
95
117
|
}
|
|
96
118
|
|
|
97
119
|
interface Release {
|
|
@@ -132,11 +154,12 @@ async function cacheAsset(
|
|
|
132
154
|
digest: string,
|
|
133
155
|
dest: string,
|
|
134
156
|
log: (line: string) => void,
|
|
157
|
+
onBytes?: OnBytes,
|
|
135
158
|
): Promise<void> {
|
|
136
159
|
const asset = release.asset(name);
|
|
137
160
|
if (!asset) throw new HostError(`release ${release.tag} lists ${name} in ${MANIFEST_NAME} but does not carry it`);
|
|
138
161
|
log(`downloading ${name} (${(asset.size / 1048576).toFixed(1)} MB) from github.com/${release.repo} ${release.tag}`);
|
|
139
|
-
const bytes = Bun.gunzipSync(await download(asset, release.headers));
|
|
162
|
+
const bytes = Bun.gunzipSync(await download(asset, release.headers, onBytes));
|
|
140
163
|
if (bytes.length !== size || sha256(bytes) !== digest) {
|
|
141
164
|
throw new HostError(`${name} does not match the sha256 in ${MANIFEST_NAME}; nothing was cached`);
|
|
142
165
|
}
|
|
@@ -148,7 +171,7 @@ async function cacheAsset(
|
|
|
148
171
|
renameSync(tmp, dest);
|
|
149
172
|
}
|
|
150
173
|
|
|
151
|
-
/** Downloads the
|
|
174
|
+
/** Downloads the workload for `variant` from the release of `version` into the local cache, checked against `hosts.json`. */
|
|
152
175
|
export async function fetchHost(options: FetchOptions): Promise<{ path: string; info: HostInfo }> {
|
|
153
176
|
const version = options.version ?? CLI_VERSION;
|
|
154
177
|
const platform = options.platform ?? currentPlatform();
|
|
@@ -163,14 +186,14 @@ export async function fetchHost(options: FetchOptions): Promise<{ path: string;
|
|
|
163
186
|
.map((h) => h.variant)
|
|
164
187
|
.join(", ");
|
|
165
188
|
throw new HostError(
|
|
166
|
-
`release ${tag} has no ${options.variant}
|
|
167
|
-
(offered ? ` (it has: ${offered}); other variants are built from a checkout with sk
|
|
189
|
+
`release ${tag} has no ${options.variant} workload for ${platform}-${arch}` +
|
|
190
|
+
(offered ? ` (it has: ${offered}); other variants are built from a checkout with sk workload build` : ""),
|
|
168
191
|
);
|
|
169
192
|
}
|
|
170
193
|
const dest = cachedHost(version, options.variant, platform);
|
|
171
|
-
await cacheAsset(release, entry.file, entry.size, entry.sha256, dest, log);
|
|
194
|
+
await cacheAsset(release, entry.file, entry.size, entry.sha256, dest, log, options.onBytes);
|
|
172
195
|
writeFileSync(join(dirname(dest), "host.json"), JSON.stringify(entry.info, null, 2) + "\n");
|
|
173
|
-
log(`cached ${options.variant}
|
|
196
|
+
log(`cached ${options.variant} workload ${version} → ${dest}`);
|
|
174
197
|
return { path: dest, info: entry.info };
|
|
175
198
|
}
|
|
176
199
|
|
|
@@ -190,7 +213,7 @@ export async function fetchAotCompiler(
|
|
|
190
213
|
const entry = release.manifest.aot?.find((c) => c.platform === platform && c.arch === arch);
|
|
191
214
|
if (!entry) throw new HostError(`release ${release.tag} has no sk-aot for ${platform}-${arch}`);
|
|
192
215
|
const dest = cachedAotCompiler(version, platform);
|
|
193
|
-
await cacheAsset(release, entry.file, entry.size, entry.sha256, dest, log);
|
|
216
|
+
await cacheAsset(release, entry.file, entry.size, entry.sha256, dest, log, options.onBytes);
|
|
194
217
|
writeFileSync(join(dirname(dest), "compiler.json"), JSON.stringify(entry.info, null, 2) + "\n");
|
|
195
218
|
log(`cached sk-aot ${version} → ${dest}`);
|
|
196
219
|
return { path: dest, info: entry.info };
|
|
@@ -208,7 +231,7 @@ export async function resolveOrFetchHost(options: ResolveOptions): Promise<Resol
|
|
|
208
231
|
const cross = (options.platform ?? currentPlatform()) !== currentPlatform();
|
|
209
232
|
if (!(e instanceof HostError) || named || cross || process.env.SK_HOST_OFFLINE === "1") throw e;
|
|
210
233
|
try {
|
|
211
|
-
await fetchHost({ variant: options.variant, ...(options.log && { log: options.log }) });
|
|
234
|
+
await fetchHost({ variant: options.variant, onBytes: options.onBytes, ...(options.log && { log: options.log }) });
|
|
212
235
|
} catch (f) {
|
|
213
236
|
throw new HostError(`${e.message}\n(downloading it failed too: ${(f as Error).message})`);
|
|
214
237
|
}
|
package/cli/host.ts
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
// --features prod` (the whole engine, no app), built once per Skathi version and variant: `standard`, or
|
|
3
3
|
// `no-devtools` with the devtools compiled out.
|
|
4
4
|
//
|
|
5
|
-
// Resolution, first hit wins: 1. `--
|
|
5
|
+
// Resolution, first hit wins: 1. `--workload <exe>` or `SK_HOST`; 2. in-repo
|
|
6
6
|
// target/x86_64-pc-windows-msvc/release/sk-app.exe, when that is a prod host of this variant and
|
|
7
|
-
// version; 3. the local cache (`sk
|
|
7
|
+
// version; 3. the local cache (`sk workload add <exe>`, `sk workload build`, or a download from this
|
|
8
8
|
// version's GitHub release: host-fetch.ts); 4. an error naming them. Paths per OS are in platform.ts.
|
|
9
9
|
//
|
|
10
|
-
// A host for another OS cannot be run to ask what it is: only `--
|
|
10
|
+
// A host for another OS cannot be run to ask what it is: only `--workload` / `SK_HOST` names one, its
|
|
11
11
|
// format is sniffed, and what it is comes from a `host.json` beside it or is taken on trust, with a warning.
|
|
12
12
|
//
|
|
13
13
|
// A host and a bundle must come from the same Skathi version (the bundle carries the JS half of
|
|
14
14
|
// the `__sk_*` protocol): the CLI refuses a host whose `--sk-host-info` disagrees
|
|
15
|
-
// (`--allow-
|
|
15
|
+
// (`--allow-workload-mismatch` is for maintainers).
|
|
16
16
|
|
|
17
17
|
import { spawnSync } from "node:child_process";
|
|
18
18
|
import {
|
|
@@ -57,6 +57,8 @@ export interface HostInfo {
|
|
|
57
57
|
jscPin: string;
|
|
58
58
|
payloadFormat: number;
|
|
59
59
|
profile: string;
|
|
60
|
+
/** What a dev host reloads in place from `sk dev` besides JS modules; absent on older hosts. */
|
|
61
|
+
devReload?: string[];
|
|
60
62
|
/** A host built with the native AOT loader: what an app image must be compiled against. */
|
|
61
63
|
aot?: HostAot | null;
|
|
62
64
|
}
|
|
@@ -69,7 +71,7 @@ export interface HostAot extends CompilerInfo {
|
|
|
69
71
|
export interface ResolvedHost {
|
|
70
72
|
exe: string;
|
|
71
73
|
info: HostInfo;
|
|
72
|
-
source: "--
|
|
74
|
+
source: "--workload" | "SK_HOST" | "repo" | "cache";
|
|
73
75
|
unverified?: string;
|
|
74
76
|
}
|
|
75
77
|
|
|
@@ -91,12 +93,12 @@ function formatProblem(exe: string, platform: Platform): string | null {
|
|
|
91
93
|
if (platform === "windows") return null;
|
|
92
94
|
if (platform === "linux") {
|
|
93
95
|
const machine = elfMachineOf(exe);
|
|
94
|
-
if (!machine) return `${exe} is not an ELF executable — a Linux build needs a Linux sk-app`;
|
|
96
|
+
if (!machine) return `${exe} is not an ELF executable — a Linux build needs a Linux workload (sk-app)`;
|
|
95
97
|
if (machine !== "x86_64" && machine !== "aarch64") return `${exe} is an ELF for ${machine}, not x86_64 or aarch64`;
|
|
96
98
|
return null;
|
|
97
99
|
}
|
|
98
100
|
const archs = machOArchs(exe);
|
|
99
|
-
if (!archs) return `${exe} is not a Mach-O executable — a macOS bundle needs a macOS sk-app`;
|
|
101
|
+
if (!archs) return `${exe} is not a Mach-O executable — a macOS bundle needs a macOS workload (sk-app)`;
|
|
100
102
|
if (!archs.some((a) => a === "arm64" || a === "x86_64"))
|
|
101
103
|
return `${exe} is a Mach-O for ${archs.join(", ")}, not arm64 or x86_64`;
|
|
102
104
|
return null;
|
|
@@ -114,7 +116,10 @@ export function crossHostInfo(
|
|
|
114
116
|
try {
|
|
115
117
|
const info = JSON.parse(readFileSync(sidecar, "utf8")) as HostInfo;
|
|
116
118
|
if (info.mode && info.skathi && info.variant) {
|
|
117
|
-
return {
|
|
119
|
+
return {
|
|
120
|
+
info,
|
|
121
|
+
unverified: `${platform} workload described by ${sidecar}, not run (this is ${process.platform})`,
|
|
122
|
+
};
|
|
118
123
|
}
|
|
119
124
|
} catch {}
|
|
120
125
|
}
|
|
@@ -133,7 +138,7 @@ export function crossHostInfo(
|
|
|
133
138
|
return {
|
|
134
139
|
info,
|
|
135
140
|
unverified:
|
|
136
|
-
`a ${platform}
|
|
141
|
+
`a ${platform} workload cannot be run on ${process.platform} to check it — ${exe} is taken to be a prod ${variant} workload ` +
|
|
137
142
|
`of Skathi ${CLI_VERSION}. Put its \`--sk-host-info\` output in ${sidecar} to have it checked.`,
|
|
138
143
|
};
|
|
139
144
|
}
|
|
@@ -141,7 +146,7 @@ export function crossHostInfo(
|
|
|
141
146
|
export function hostInfo(exe: string): HostInfo {
|
|
142
147
|
if (!existsSync(exe)) throw new HostError(`${exe} does not exist`);
|
|
143
148
|
if (isStamped(exe)) {
|
|
144
|
-
throw new HostError(`${exe} is a packaged app, not a bare
|
|
149
|
+
throw new HostError(`${exe} is a packaged app, not a bare workload (it already carries a SKPAYLOAD)`);
|
|
145
150
|
}
|
|
146
151
|
const r = spawnSync(exe, ["--sk-host-info"], { encoding: "utf8", timeout: 30_000, windowsHide: true });
|
|
147
152
|
if (r.error) throw new HostError(`${exe} could not be run: ${r.error.message}`);
|
|
@@ -152,7 +157,7 @@ export function hostInfo(exe: string): HostInfo {
|
|
|
152
157
|
return info;
|
|
153
158
|
} catch {
|
|
154
159
|
throw new HostError(
|
|
155
|
-
`${exe} did not answer --sk-host-info (exit ${r.status}).
|
|
160
|
+
`${exe} did not answer --sk-host-info (exit ${r.status}). Workloads older than this CLI do not know the flag — ` +
|
|
156
161
|
`rebuild it.\n${(r.stderr ?? "").trim().split(/\r?\n/).slice(-5).join("\n")}`,
|
|
157
162
|
);
|
|
158
163
|
}
|
|
@@ -172,20 +177,20 @@ export function checkHost(exe: string, info: HostInfo, variant: Variant | null,
|
|
|
172
177
|
const mismatch =
|
|
173
178
|
info.skathi !== CLI_VERSION && !allowMismatch
|
|
174
179
|
? `${exe} is Skathi ${info.skathi}, this CLI is ${CLI_VERSION} — the bundle carries the JS half of the ` +
|
|
175
|
-
`
|
|
180
|
+
`workload protocol, so the two must match (--allow-workload-mismatch overrides, for maintainers)`
|
|
176
181
|
: null;
|
|
177
182
|
if (variant === DEV_HOST) {
|
|
178
183
|
return info.mode === "dev"
|
|
179
184
|
? mismatch
|
|
180
|
-
: `${exe} is a ${info.mode}
|
|
185
|
+
: `${exe} is a ${info.mode} workload — sk dev needs one built without --features prod`;
|
|
181
186
|
}
|
|
182
|
-
if (info.mode !== "prod") return `${exe} is a ${info.mode}
|
|
187
|
+
if (info.mode !== "prod") return `${exe} is a ${info.mode} workload — sk build needs one built with --features prod`;
|
|
183
188
|
if (variant && info.variant !== variant) return `${exe} is the ${info.variant} variant, not ${variant}`;
|
|
184
189
|
if (!VARIANTS.includes(info.variant)) {
|
|
185
|
-
return `${exe} is the ${info.variant} variant, which leaves engine parts out — sk build stamps only ${VARIANTS.join(" or ")}
|
|
190
|
+
return `${exe} is the ${info.variant} variant, which leaves engine parts out — sk build stamps only ${VARIANTS.join(" or ")} workloads`;
|
|
186
191
|
}
|
|
187
192
|
const missing = ENGINE_FEATURES.filter((f) => !info.features?.includes(f));
|
|
188
|
-
if (missing.length) return `${exe} lacks ${missing.join(", ")} — rebuild or replace the cached
|
|
193
|
+
if (missing.length) return `${exe} lacks ${missing.join(", ")} — rebuild or replace the cached workload`;
|
|
189
194
|
return mismatch;
|
|
190
195
|
}
|
|
191
196
|
|
|
@@ -229,6 +234,7 @@ export interface ResolveOptions {
|
|
|
229
234
|
allowMismatch?: boolean | undefined;
|
|
230
235
|
platform?: Platform | undefined;
|
|
231
236
|
log?: (line: string) => void;
|
|
237
|
+
onBytes?: ((done: number, total: number) => void) | undefined;
|
|
232
238
|
}
|
|
233
239
|
|
|
234
240
|
export function resolveHost(options: ResolveOptions): ResolvedHost {
|
|
@@ -239,11 +245,11 @@ export function resolveHost(options: ResolveOptions): ResolvedHost {
|
|
|
239
245
|
const explicit = options.host ?? process.env.SK_HOST;
|
|
240
246
|
if (explicit) {
|
|
241
247
|
const exe = resolve(explicit);
|
|
242
|
-
const source = options.host ? "--
|
|
248
|
+
const source = options.host ? "--workload" : "SK_HOST";
|
|
243
249
|
if (cross) {
|
|
244
250
|
if (!existsSync(exe)) throw new HostError(`${exe} does not exist`);
|
|
245
251
|
if (isStamped(exe))
|
|
246
|
-
throw new HostError(`${exe} is a packaged app, not a bare
|
|
252
|
+
throw new HostError(`${exe} is a packaged app, not a bare workload (it already carries an app payload)`);
|
|
247
253
|
const { info, unverified } = crossHostInfo(exe, options.variant, platform);
|
|
248
254
|
const problem = checkHost(exe, info, options.variant, allow);
|
|
249
255
|
if (problem) throw new HostError(problem);
|
|
@@ -258,8 +264,8 @@ export function resolveHost(options: ResolveOptions): ResolvedHost {
|
|
|
258
264
|
}
|
|
259
265
|
if (cross) {
|
|
260
266
|
throw new HostError(
|
|
261
|
-
`a ${platform} build on ${process.platform} needs the
|
|
262
|
-
`(or SK_HOST). This machine's checkout and cache hold ${currentPlatform()}
|
|
267
|
+
`a ${platform} build on ${process.platform} needs the workload named: --workload <path to a ${platform} sk-app> ` +
|
|
268
|
+
`(or SK_HOST). This machine's checkout and cache hold ${currentPlatform()} workloads.`,
|
|
263
269
|
);
|
|
264
270
|
}
|
|
265
271
|
|
|
@@ -272,7 +278,7 @@ export function resolveHost(options: ResolveOptions): ResolvedHost {
|
|
|
272
278
|
if (statSync(REPO_RELEASE_EXE).mtimeMs < newestHostSource()) {
|
|
273
279
|
log(
|
|
274
280
|
`warning: ${REPO_RELEASE_EXE} is older than the sources it is built from — ` +
|
|
275
|
-
"`bun packages/cli/cli/sk.ts
|
|
281
|
+
"`bun packages/cli/cli/sk.ts workload build` rebuilds it",
|
|
276
282
|
);
|
|
277
283
|
}
|
|
278
284
|
return { exe: REPO_RELEASE_EXE, info, source: "repo" };
|
|
@@ -295,18 +301,20 @@ export function resolveHost(options: ResolveOptions): ResolvedHost {
|
|
|
295
301
|
tried.push(`cache: ${cached} does not exist`);
|
|
296
302
|
}
|
|
297
303
|
|
|
304
|
+
const remedies: [string, string][] = [
|
|
305
|
+
[`--workload <${hostsFor(platform).exeFile}>`, "(or SK_HOST=<exe>) a prod workload built from this version"],
|
|
306
|
+
[`sk workload install ${options.variant}`, `download it from the Skathi ${CLI_VERSION} release`],
|
|
307
|
+
["sk workload add <exe>", "import one into the local cache"],
|
|
308
|
+
...(REPO_ROOT
|
|
309
|
+
? [[`sk workload build ${options.variant}`, "build it from this checkout (cargo)"] as [string, string]]
|
|
310
|
+
: []),
|
|
311
|
+
];
|
|
312
|
+
const width = Math.max(...remedies.map(([how]) => how.length));
|
|
298
313
|
throw new HostError(
|
|
299
|
-
`no ${options.variant} Skathi ${CLI_VERSION}
|
|
314
|
+
`no ${options.variant} Skathi ${CLI_VERSION} workload found.\n` +
|
|
300
315
|
tried.map((t) => ` - ${t}`).join("\n") +
|
|
301
316
|
"\nSupply one of:\n" +
|
|
302
|
-
` ${
|
|
303
|
-
` sk host fetch download it from the Skathi ${CLI_VERSION} release\n` +
|
|
304
|
-
" sk host add <exe> import one into the local cache\n" +
|
|
305
|
-
(REPO_ROOT
|
|
306
|
-
? options.variant === "standard" || options.variant === "no-devtools"
|
|
307
|
-
? " sk host build build both variants from this checkout (cargo)\n"
|
|
308
|
-
: ` sk host build --variant ${options.variant} build this one from this checkout (cargo)\n`
|
|
309
|
-
: ""),
|
|
317
|
+
remedies.map(([how, what]) => ` ${how.padEnd(width)} ${what}\n`).join(""),
|
|
310
318
|
);
|
|
311
319
|
}
|
|
312
320
|
|
|
@@ -324,7 +332,7 @@ export function addHost(exe: string, log: (line: string) => void = () => {}): {
|
|
|
324
332
|
rmSync(dest, { force: true });
|
|
325
333
|
renameSync(tmp, dest);
|
|
326
334
|
writeFileSync(join(dirname(dest), "host.json"), JSON.stringify(info, null, 2) + "\n");
|
|
327
|
-
log(`cached ${info.variant}
|
|
335
|
+
log(`cached ${info.variant} workload ${info.skathi} (${info.profile}) → ${dest}`);
|
|
328
336
|
return { path: dest, info };
|
|
329
337
|
}
|
|
330
338
|
|
|
@@ -334,7 +342,7 @@ function cargo(): string {
|
|
|
334
342
|
const home = process.env.CARGO_HOME ?? join(process.env.USERPROFILE ?? homedir(), ".cargo");
|
|
335
343
|
const exe = join(home, "bin", process.platform === "win32" ? "cargo.exe" : "cargo");
|
|
336
344
|
if (existsSync(exe)) return exe;
|
|
337
|
-
throw new HostError("cargo is not on PATH — building a
|
|
345
|
+
throw new HostError("cargo is not on PATH — building a workload needs the Rust toolchain (sk build does not)");
|
|
338
346
|
}
|
|
339
347
|
|
|
340
348
|
/** The cargo command line for `variant`, plus `extra` features (`native-inspector` for a release host). */
|
|
@@ -360,7 +368,9 @@ export function cargoBuildHost(
|
|
|
360
368
|
extras: CargoExtras = {},
|
|
361
369
|
): { exe: string; ms: number } {
|
|
362
370
|
if (!REPO_ROOT || !REPO_RELEASE_EXE) {
|
|
363
|
-
throw new HostError(
|
|
371
|
+
throw new HostError(
|
|
372
|
+
"sk workload build runs from a Skathi checkout; elsewhere, use sk workload install or sk workload add <exe>",
|
|
373
|
+
);
|
|
364
374
|
}
|
|
365
375
|
const args = hostCargoArgs(variant, extras.features);
|
|
366
376
|
log(`cargo ${args.join(" ")}`);
|