@skathi-native/cli 0.1.0-beta.2 → 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.
Files changed (50) hide show
  1. package/aot/host-globals.json +105 -0
  2. package/aot/native.ts +142 -0
  3. package/aot/pin.ts +67 -0
  4. package/aot/toolchain.lock.json +17 -0
  5. package/aot/transform.ts +69 -0
  6. package/check/codes.ts +19 -0
  7. package/check/command.ts +5 -3
  8. package/check/index.ts +44 -1
  9. package/cli/aot-build.ts +192 -0
  10. package/cli/build-app.ts +102 -31
  11. package/cli/config.ts +45 -102
  12. package/cli/create.ts +12 -54
  13. package/cli/dev.ts +109 -19
  14. package/cli/effects.ts +162 -0
  15. package/cli/elf.ts +3 -2
  16. package/cli/help.ts +56 -148
  17. package/cli/host-fetch.ts +116 -54
  18. package/cli/host.ts +59 -39
  19. package/cli/sk.ts +440 -246
  20. package/cli/skpk.ts +6 -0
  21. package/cli/stamp.ts +2 -2
  22. package/cli/term.ts +169 -38
  23. package/cli/workload-cache.ts +258 -0
  24. package/effects/compile.ts +952 -0
  25. package/effects/redslangc.json +23 -0
  26. package/effects/redslangc.ts +220 -0
  27. package/effects/sk.slang +558 -0
  28. package/package.json +6 -2
  29. package/templates/icon.png +0 -0
  30. package/templates/minimal/.vscode/settings.json +3 -0
  31. package/templates/minimal/src/App.vue +2 -2
  32. package/templates/showcase/.vscode/settings.json +3 -0
  33. package/templates/showcase/shaders/sheen.slang +23 -0
  34. package/templates/showcase/src/components/Titlebar.vue +7 -3
  35. package/templates/showcase/src/engine.ts +3 -26
  36. package/templates/showcase/src/pages/AudioPage.vue +6 -9
  37. package/templates/showcase/src/pages/FilesPage.vue +11 -15
  38. package/templates/showcase/src/pages/FormsPage.vue +2 -3
  39. package/templates/showcase/src/pages/GraphicsPage.vue +13 -15
  40. package/templates/showcase/src/pages/HomePage.vue +1 -2
  41. package/templates/showcase/src/pages/LocalePage.vue +2 -2
  42. package/templates/showcase/src/pages/MediaPage.vue +1 -1
  43. package/templates/showcase/src/pages/MotionPage.vue +1 -1
  44. package/templates/showcase/src/pages/NetworkPage.vue +6 -5
  45. package/templates/showcase/src/pages/PermissionsPage.vue +2 -2
  46. package/templates/showcase/src/pages/StoragePage.vue +23 -36
  47. package/templates/showcase/src/pages/StylesPage.vue +9 -1
  48. package/templates/showcase/src/pages/SystemPage.vue +3 -3
  49. package/templates/showcase/src/styles.css +2 -2
  50. package/templates/showcase/src/components/Missing.vue +0 -26
@@ -0,0 +1,23 @@
1
+ {
2
+ "version": "0.1.1",
3
+ "slang": "2026.12",
4
+ "release": "https://github.com/argon-chat/redslangc/releases/download/v0.1.1",
5
+ "assets": {
6
+ "windows-x64": {
7
+ "file": "redslangc-v0.1.1-x86_64-pc-windows-msvc.zip",
8
+ "sha256": "61909202663fcb79ed6fdac0a87cc513faa02007dcb2e29f75a2f7c17ac69634"
9
+ },
10
+ "linux-x64": {
11
+ "file": "redslangc-v0.1.1-x86_64-unknown-linux-gnu.tar.gz",
12
+ "sha256": "72f29044d8332f91fe6a522097f985905fc7385edeb44681a9715d9275b29fd9"
13
+ },
14
+ "macos-arm64": {
15
+ "file": "redslangc-v0.1.1-aarch64-apple-darwin.tar.gz",
16
+ "sha256": "18c452081921557cbf215e658a9368ff524faec5b5092df6fdaba2a5803760e4"
17
+ },
18
+ "macos-x64": {
19
+ "file": "redslangc-v0.1.1-x86_64-apple-darwin.tar.gz",
20
+ "sha256": "6a70a840b09f3d25cebce9822d2d3dad0ba2e10e0ced377e0a62487d234b5f90"
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,220 @@
1
+ // redslangc, the Slang compiler the effect toolchain runs: pinned by version and sha256 per platform
2
+ // in redslangc.json, downloaded from its GitHub release into <cache>/skathi/redslangc/<version>/.
3
+ // `--compiler <exe>` or SK_REDSLANGC names another build (a checkout's `cargo build` of
4
+ // vendor/redslangc, or `cargo install redslangc`).
5
+
6
+ import { spawnSync } from "node:child_process";
7
+ import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
8
+ import { dirname, join, resolve } from "node:path";
9
+ import { inflateRawSync } from "node:zlib";
10
+ import { cacheRoot } from "../cli/host";
11
+ import type { OnBytes } from "../cli/host-fetch";
12
+ import { currentPlatform, type Platform } from "../cli/platform";
13
+
14
+ export class ShaderCompilerError extends Error {}
15
+
16
+ interface PinnedAsset {
17
+ file: string;
18
+ sha256: string;
19
+ }
20
+
21
+ export interface Pin {
22
+ version: string;
23
+ slang: string;
24
+ release: string;
25
+ assets: Record<string, PinnedAsset>;
26
+ }
27
+
28
+ export const PIN: Pin = JSON.parse(readFileSync(join(import.meta.dir, "redslangc.json"), "utf8"));
29
+
30
+ export interface ShaderCompiler {
31
+ path: string;
32
+ version: string;
33
+ source: "--compiler" | "SK_REDSLANGC" | "cache" | "release";
34
+ }
35
+
36
+ const exeName = (platform: Platform) => (platform === "windows" ? "redslangc.exe" : "redslangc");
37
+
38
+ /** `<cache>/skathi/redslangc`, beside the workloads. */
39
+ export const compilerCacheRoot = (platform: Platform = currentPlatform()) =>
40
+ join(dirname(cacheRoot(platform)), "redslangc");
41
+
42
+ export const cachedCompiler = (version: string = PIN.version, platform: Platform = currentPlatform()) =>
43
+ join(compilerCacheRoot(platform), version, exeName(platform));
44
+
45
+ export const compilerExe = exeName;
46
+
47
+ function assetKey(platform: Platform = currentPlatform(), arch: string = process.arch): string {
48
+ return `${platform}-${arch}`;
49
+ }
50
+
51
+ /** What `redslangc --version` says: `redslangc 0.1.0 (Slang 2026.12)`. */
52
+ export function compilerVersion(path: string): { version: string; slang: string } {
53
+ const r = spawnSync(path, ["--version"], { encoding: "utf8", timeout: 30_000, windowsHide: true });
54
+ if (r.error) throw new ShaderCompilerError(`${path} could not be run: ${r.error.message}`);
55
+ const m = /redslangc\s+(\S+)\s+\(Slang\s+([^)]+)\)/.exec(r.stdout ?? "");
56
+ if (r.status !== 0 || !m) throw new ShaderCompilerError(`${path} is not redslangc (--version: ${r.stdout.trim()})`);
57
+ return { version: m[1]!, slang: m[2]!.trim() };
58
+ }
59
+
60
+ const sha256 = (bytes: Uint8Array): string =>
61
+ new Bun.CryptoHasher("sha256").update(new Uint8Array(bytes)).digest("hex");
62
+
63
+ async function download(url: string, onBytes?: OnBytes): Promise<Uint8Array<ArrayBuffer>> {
64
+ const res = await fetch(url, { headers: { "User-Agent": "skathi-cli" } });
65
+ if (!res.ok) throw new ShaderCompilerError(`downloading ${url}: HTTP ${res.status}`);
66
+ if (!onBytes || !res.body) return new Uint8Array(await res.arrayBuffer());
67
+ const total = Number(res.headers.get("content-length")) || 0;
68
+ const chunks: Uint8Array[] = [];
69
+ let done = 0;
70
+ for await (const chunk of res.body) {
71
+ chunks.push(chunk);
72
+ done += chunk.length;
73
+ onBytes(done, total || done);
74
+ }
75
+ const bytes = new Uint8Array(done);
76
+ let at = 0;
77
+ for (const chunk of chunks) {
78
+ bytes.set(chunk, at);
79
+ at += chunk.length;
80
+ }
81
+ return bytes;
82
+ }
83
+
84
+ export interface ArchiveFile {
85
+ /** Relative to the archive's top directory. */
86
+ name: string;
87
+ data: Uint8Array;
88
+ }
89
+
90
+ /** The regular files of a release archive, its top-level directory stripped. */
91
+ export function unpack(archive: Uint8Array<ArrayBuffer>, file: string): ArchiveFile[] {
92
+ const raw = file.endsWith(".zip") ? unzip(archive) : untar(Bun.gunzipSync(archive));
93
+ const out: ArchiveFile[] = [];
94
+ for (const { name, data } of raw) {
95
+ const parts = name.replace(/\\/g, "/").split("/").filter(Boolean);
96
+ if (parts.length < 2 || parts.some((p) => p === ".." || p === ".") || parts.at(-1)!.startsWith("._")) continue;
97
+ out.push({ name: parts.slice(1).join("/"), data });
98
+ }
99
+ return out;
100
+ }
101
+
102
+ function unzip(zip: Uint8Array): ArchiveFile[] {
103
+ const dv = new DataView(zip.buffer, zip.byteOffset, zip.byteLength);
104
+ let eocd = -1;
105
+ for (let i = zip.length - 22; i >= Math.max(0, zip.length - 22 - 0xffff); i--) {
106
+ if (dv.getUint32(i, true) === 0x06054b50) {
107
+ eocd = i;
108
+ break;
109
+ }
110
+ }
111
+ if (eocd < 0) throw new ShaderCompilerError("the redslangc archive is not a zip file");
112
+ const count = dv.getUint16(eocd + 10, true);
113
+ let at = dv.getUint32(eocd + 16, true);
114
+ const decoder = new TextDecoder();
115
+ const out: ArchiveFile[] = [];
116
+ for (let i = 0; i < count; i++) {
117
+ if (dv.getUint32(at, true) !== 0x02014b50) throw new ShaderCompilerError("the redslangc zip is damaged");
118
+ const method = dv.getUint16(at + 10, true);
119
+ const compressed = dv.getUint32(at + 20, true);
120
+ const nameLen = dv.getUint16(at + 28, true);
121
+ const extraLen = dv.getUint16(at + 30, true);
122
+ const commentLen = dv.getUint16(at + 32, true);
123
+ const local = dv.getUint32(at + 42, true);
124
+ const name = decoder.decode(zip.subarray(at + 46, at + 46 + nameLen));
125
+ at += 46 + nameLen + extraLen + commentLen;
126
+ if (name.endsWith("/")) continue;
127
+ const start = local + 30 + dv.getUint16(local + 26, true) + dv.getUint16(local + 28, true);
128
+ const body = zip.subarray(start, start + compressed);
129
+ if (method === 0) out.push({ name, data: body });
130
+ else if (method === 8) out.push({ name, data: new Uint8Array(inflateRawSync(body)) });
131
+ else throw new ShaderCompilerError(`the redslangc zip stores ${name} with method ${method}`);
132
+ }
133
+ return out;
134
+ }
135
+
136
+ function untar(tar: Uint8Array): ArchiveFile[] {
137
+ const decoder = new TextDecoder();
138
+ const field = (at: number, len: number) => decoder.decode(tar.subarray(at, at + len)).replace(/\0.*$/s, "");
139
+ const out: ArchiveFile[] = [];
140
+ let at = 0;
141
+ while (at + 512 <= tar.length) {
142
+ const name = field(at, 100);
143
+ if (!name) break;
144
+ const size = parseInt(field(at + 124, 12).trim() || "0", 8);
145
+ const type = String.fromCharCode(tar[at + 156]!);
146
+ const prefix = field(at + 257, 6).startsWith("ustar") ? field(at + 345, 155) : "";
147
+ if (type === "0" || type === "\0") {
148
+ out.push({ name: prefix ? `${prefix}/${name}` : name, data: tar.slice(at + 512, at + 512 + size) });
149
+ }
150
+ at += 512 + Math.ceil(size / 512) * 512;
151
+ }
152
+ return out;
153
+ }
154
+
155
+ /** Downloads the pinned redslangc for this machine into the cache, checked against redslangc.json. */
156
+ export async function fetchCompiler(
157
+ options: { log?: (line: string) => void; onBytes?: OnBytes; platform?: Platform; arch?: string } = {},
158
+ ): Promise<string> {
159
+ const platform = options.platform ?? currentPlatform();
160
+ const key = assetKey(platform, options.arch);
161
+ const asset = PIN.assets[key];
162
+ if (!asset) {
163
+ throw new ShaderCompilerError(
164
+ `redslangc ${PIN.version} has no prebuilt binary for ${key} (there are: ${Object.keys(PIN.assets).join(", ")}) — ` +
165
+ `build it with \`cargo install --locked redslangc@${PIN.version}\` and set SK_REDSLANGC to its path`,
166
+ );
167
+ }
168
+ const url = `${PIN.release}/${asset.file}`;
169
+ options.log?.(`downloading ${asset.file} from ${PIN.release}`);
170
+ const archive = await download(url, options.onBytes);
171
+ if (sha256(archive) !== asset.sha256) {
172
+ throw new ShaderCompilerError(`${asset.file} does not match the sha256 sk pins for it; nothing was cached`);
173
+ }
174
+ const files = unpack(archive, asset.file);
175
+ const exe = exeName(platform);
176
+ if (!files.some((f) => f.name === exe)) throw new ShaderCompilerError(`${asset.file} has no ${exe}`);
177
+ const dest = cachedCompiler(PIN.version, platform);
178
+ const dir = dirname(dest);
179
+ const partial = `${dir}.partial`;
180
+ rmSync(partial, { recursive: true, force: true });
181
+ for (const f of files) {
182
+ const path = join(partial, f.name);
183
+ mkdirSync(dirname(path), { recursive: true });
184
+ writeFileSync(path, f.data);
185
+ }
186
+ if (platform !== "windows") chmodSync(join(partial, exe), 0o755);
187
+ rmSync(dir, { recursive: true, force: true });
188
+ mkdirSync(dirname(dir), { recursive: true });
189
+ renameSync(partial, dir);
190
+ options.log?.(`cached redslangc ${PIN.version} → ${dest}`);
191
+ return dest;
192
+ }
193
+
194
+ /** The redslangc to run, first hit wins: `named` or SK_REDSLANGC; the cache; a download. */
195
+ export async function resolveCompiler(
196
+ options: { named?: string | undefined; log?: (line: string) => void; onBytes?: OnBytes } = {},
197
+ ): Promise<ShaderCompiler> {
198
+ const named = options.named ?? process.env.SK_REDSLANGC;
199
+ if (named) {
200
+ const explicit = resolve(named);
201
+ if (!existsSync(explicit)) throw new ShaderCompilerError(`no redslangc at ${explicit}`);
202
+ const { version, slang } = compilerVersion(explicit);
203
+ if (slang !== PIN.slang) {
204
+ options.log?.(
205
+ `warning: ${explicit} is Slang ${slang}; the effects sk ships are compiled with Slang ${PIN.slang}`,
206
+ );
207
+ }
208
+ return { path: explicit, version, source: options.named ? "--compiler" : "SK_REDSLANGC" };
209
+ }
210
+ const cached = cachedCompiler();
211
+ if (existsSync(cached)) return { path: cached, version: PIN.version, source: "cache" };
212
+ if (process.env.SK_HOST_OFFLINE === "1") {
213
+ throw new ShaderCompilerError(
214
+ `the app has effect shaders and redslangc ${PIN.version} is not cached (${cached}); SK_HOST_OFFLINE=1 ` +
215
+ "forbids downloading it — set SK_REDSLANGC to a redslangc binary",
216
+ );
217
+ }
218
+ const path = await fetchCompiler(options);
219
+ return { path, version: PIN.version, source: "release" };
220
+ }