@crewhaus/single-binary-cli 0.1.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/package.json +42 -0
- package/src/cli.ts +60 -0
- package/src/index.test.ts +220 -0
- package/src/index.ts +327 -0
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@crewhaus/single-binary-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "bun build --compile wrapper producing self-contained crewhaus binaries for linux/macos/windows × x64/arm64; auto-generated Homebrew/apt/Scoop/Winget manifests (Section 32)",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.ts"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "bun test src",
|
|
13
|
+
"build:binary": "bun src/cli.ts"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@crewhaus/errors": "0.0.0"
|
|
17
|
+
},
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"author": {
|
|
20
|
+
"name": "Max Meier",
|
|
21
|
+
"email": "max@studiomax.io",
|
|
22
|
+
"url": "https://studiomax.io"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/crewhaus/factory.git",
|
|
27
|
+
"directory": "packages/single-binary-cli"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/crewhaus/factory/tree/main/packages/single-binary-cli#readme",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/crewhaus/factory/issues"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "restricted"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"src",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE",
|
|
40
|
+
"NOTICE"
|
|
41
|
+
]
|
|
42
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `bun run build:binary` entry point. Builds the requested target, or
|
|
3
|
+
* the full BUILD_MATRIX when no target flag is passed.
|
|
4
|
+
*
|
|
5
|
+
* Examples:
|
|
6
|
+
* bun run build:binary --target macos-arm64
|
|
7
|
+
* bun run build:binary --version 1.0.0 # builds every entry in BUILD_MATRIX
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
ARCHES,
|
|
11
|
+
type Arch,
|
|
12
|
+
BUILD_MATRIX,
|
|
13
|
+
type BuildTarget,
|
|
14
|
+
PLATFORMS,
|
|
15
|
+
type Platform,
|
|
16
|
+
buildBinary,
|
|
17
|
+
formatTarget,
|
|
18
|
+
} from "./index";
|
|
19
|
+
|
|
20
|
+
function parseFlag(name: string, argv: string[]): string | undefined {
|
|
21
|
+
const idx = argv.findIndex((a) => a === `--${name}`);
|
|
22
|
+
return idx >= 0 ? argv[idx + 1] : undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function parseTarget(value: string): BuildTarget | undefined {
|
|
26
|
+
const [platform, arch] = value.split("-") as [string, string | undefined];
|
|
27
|
+
if (!platform || !arch) return undefined;
|
|
28
|
+
if (!(PLATFORMS as readonly string[]).includes(platform)) return undefined;
|
|
29
|
+
if (!(ARCHES as readonly string[]).includes(arch)) return undefined;
|
|
30
|
+
return { platform: platform as Platform, arch: arch as Arch };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function main() {
|
|
34
|
+
const argv = process.argv.slice(2);
|
|
35
|
+
const version = parseFlag("version", argv) ?? "";
|
|
36
|
+
const targetArg = parseFlag("target", argv);
|
|
37
|
+
const targets: readonly BuildTarget[] = targetArg
|
|
38
|
+
? (() => {
|
|
39
|
+
const t = parseTarget(targetArg);
|
|
40
|
+
if (!t) {
|
|
41
|
+
console.error(`unknown target: ${targetArg}`);
|
|
42
|
+
process.exit(2);
|
|
43
|
+
}
|
|
44
|
+
return [t];
|
|
45
|
+
})()
|
|
46
|
+
: BUILD_MATRIX;
|
|
47
|
+
|
|
48
|
+
for (const t of targets) {
|
|
49
|
+
process.stdout.write(`building crewhaus-${formatTarget(t)}...\n`);
|
|
50
|
+
try {
|
|
51
|
+
const result = await buildBinary({ target: t, version });
|
|
52
|
+
process.stdout.write(` → ${result.outPath}\n`);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.error(` ✗ ${formatTarget(t)} failed: ${(err as Error).message}`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
main();
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdtempSync, readFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
ARCHES,
|
|
8
|
+
BUILD_MATRIX,
|
|
9
|
+
type BuildBinaryRunner,
|
|
10
|
+
type BuildTarget,
|
|
11
|
+
PLATFORMS,
|
|
12
|
+
SingleBinaryError,
|
|
13
|
+
binaryName,
|
|
14
|
+
buildBinary,
|
|
15
|
+
bunCompileTarget,
|
|
16
|
+
formatTarget,
|
|
17
|
+
isBuildTarget,
|
|
18
|
+
renderDebianControl,
|
|
19
|
+
renderHomebrewFormula,
|
|
20
|
+
renderScoopManifest,
|
|
21
|
+
renderWingetManifest,
|
|
22
|
+
sha256OfFile,
|
|
23
|
+
writeAllManifests,
|
|
24
|
+
} from "./index";
|
|
25
|
+
|
|
26
|
+
describe("BUILD_MATRIX shape", () => {
|
|
27
|
+
test("has 5 entries (windows-arm64 intentionally absent)", () => {
|
|
28
|
+
expect(BUILD_MATRIX.length).toBe(5);
|
|
29
|
+
expect(
|
|
30
|
+
BUILD_MATRIX.find((m) => m.platform === "windows" && m.arch === "arm64"),
|
|
31
|
+
).toBeUndefined();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("PLATFORMS and ARCHES are tightly typed enums", () => {
|
|
35
|
+
expect(PLATFORMS).toEqual(["linux", "macos", "windows"]);
|
|
36
|
+
expect(ARCHES).toEqual(["x64", "arm64"]);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("bunCompileTarget", () => {
|
|
41
|
+
test.each(BUILD_MATRIX.map((t): [BuildTarget, string] => [t, `bun-${t.platform}-${t.arch}`]))(
|
|
42
|
+
"%j → %s",
|
|
43
|
+
(t, expected) => {
|
|
44
|
+
expect(bunCompileTarget(t)).toBe(expected);
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("binaryName", () => {
|
|
50
|
+
test("appends version + .exe on windows", () => {
|
|
51
|
+
expect(binaryName({ platform: "windows", arch: "x64" }, "1.0.0")).toBe(
|
|
52
|
+
"crewhaus-windows-x64-1.0.0.exe",
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("no .exe on linux/macos", () => {
|
|
57
|
+
expect(binaryName({ platform: "linux", arch: "x64" }, "1.0.0")).toBe(
|
|
58
|
+
"crewhaus-linux-x64-1.0.0",
|
|
59
|
+
);
|
|
60
|
+
expect(binaryName({ platform: "macos", arch: "arm64" }, "0.0.1")).toBe(
|
|
61
|
+
"crewhaus-macos-arm64-0.0.1",
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("empty version → no trailing dash", () => {
|
|
66
|
+
expect(binaryName({ platform: "linux", arch: "x64" }, "")).toBe("crewhaus-linux-x64");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("isBuildTarget guard", () => {
|
|
71
|
+
test("accepts every entry in BUILD_MATRIX", () => {
|
|
72
|
+
for (const t of BUILD_MATRIX) {
|
|
73
|
+
expect(isBuildTarget(t)).toBe(true);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("rejects windows-arm64 (not supported by Bun)", () => {
|
|
78
|
+
expect(isBuildTarget({ platform: "windows", arch: "arm64" })).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("buildBinary() (T2 dry-run)", () => {
|
|
83
|
+
test("happy path — argv is bun build --compile --target=<platform>-<arch> ...", async () => {
|
|
84
|
+
let captured: readonly string[] = [];
|
|
85
|
+
const runner: BuildBinaryRunner = async (argv) => {
|
|
86
|
+
captured = argv;
|
|
87
|
+
return { exitCode: 0, stdout: "", stderr: "" };
|
|
88
|
+
};
|
|
89
|
+
const result = await buildBinary({
|
|
90
|
+
target: { platform: "linux", arch: "x64" },
|
|
91
|
+
version: "1.2.3",
|
|
92
|
+
outDir: "/tmp/dist",
|
|
93
|
+
runner,
|
|
94
|
+
});
|
|
95
|
+
expect(captured[0]).toBe("bun");
|
|
96
|
+
expect(captured).toContain("build");
|
|
97
|
+
expect(captured).toContain("--compile");
|
|
98
|
+
expect(captured).toContain("--target");
|
|
99
|
+
expect(captured).toContain("bun-linux-x64");
|
|
100
|
+
expect(captured).toContain("--outfile");
|
|
101
|
+
expect(captured).toContain("/tmp/dist/crewhaus-linux-x64-1.2.3");
|
|
102
|
+
expect(result.outPath).toBe("/tmp/dist/crewhaus-linux-x64-1.2.3");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("rejects unsupported target windows-arm64", async () => {
|
|
106
|
+
await expect(
|
|
107
|
+
buildBinary({
|
|
108
|
+
target: { platform: "windows", arch: "arm64" },
|
|
109
|
+
runner: async () => ({ exitCode: 0, stdout: "", stderr: "" }),
|
|
110
|
+
}),
|
|
111
|
+
).rejects.toThrow(/unsupported build target/);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("non-zero exit → SingleBinaryError with stderr", async () => {
|
|
115
|
+
await expect(
|
|
116
|
+
buildBinary({
|
|
117
|
+
target: { platform: "linux", arch: "x64" },
|
|
118
|
+
runner: async () => ({ exitCode: 2, stdout: "", stderr: "bun not found" }),
|
|
119
|
+
}),
|
|
120
|
+
).rejects.toThrow(/bun not found/);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("formatTarget round-trip", () => {
|
|
124
|
+
expect(formatTarget({ platform: "linux", arch: "arm64" })).toBe("linux-arm64");
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("manifest rendering (T1)", () => {
|
|
129
|
+
const sha256 = {
|
|
130
|
+
"macos-arm64": "a".repeat(64),
|
|
131
|
+
"macos-x64": "b".repeat(64),
|
|
132
|
+
"linux-arm64": "c".repeat(64),
|
|
133
|
+
"linux-x64": "d".repeat(64),
|
|
134
|
+
"windows-x64": "e".repeat(64),
|
|
135
|
+
} as const;
|
|
136
|
+
|
|
137
|
+
const inputs = {
|
|
138
|
+
version: "1.0.0",
|
|
139
|
+
homepage: "https://github.com/crewhaus/factory",
|
|
140
|
+
downloadBaseUrl: "https://github.com/crewhaus/factory/releases/download/v1.0.0",
|
|
141
|
+
sha256,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
test("Homebrew formula has on_macos / on_linux blocks with correct shas", () => {
|
|
145
|
+
const formula = renderHomebrewFormula(inputs);
|
|
146
|
+
expect(formula).toContain("class Crewhaus < Formula");
|
|
147
|
+
expect(formula).toContain('version "1.0.0"');
|
|
148
|
+
expect(formula).toContain("on_macos");
|
|
149
|
+
expect(formula).toContain("on_linux");
|
|
150
|
+
expect(formula).toContain(sha256["macos-arm64"]);
|
|
151
|
+
expect(formula).toContain(sha256["macos-x64"]);
|
|
152
|
+
expect(formula).toContain(sha256["linux-arm64"]);
|
|
153
|
+
expect(formula).toContain(sha256["linux-x64"]);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("Homebrew rejects non-semver versions", () => {
|
|
157
|
+
expect(() => renderHomebrewFormula({ ...inputs, version: "v1" })).toThrow();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("Debian control has correct Architecture/Description", () => {
|
|
161
|
+
const ctl = renderDebianControl(inputs);
|
|
162
|
+
expect(ctl).toContain("Package: crewhaus");
|
|
163
|
+
expect(ctl).toContain("Version: 1.0.0");
|
|
164
|
+
expect(ctl).toContain("Architecture: any");
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("Scoop manifest exposes 64bit url + hash", () => {
|
|
168
|
+
const scoop = renderScoopManifest(inputs) as {
|
|
169
|
+
version: string;
|
|
170
|
+
architecture: { "64bit": { url: string; hash: string } };
|
|
171
|
+
};
|
|
172
|
+
expect(scoop.version).toBe("1.0.0");
|
|
173
|
+
expect(scoop.architecture["64bit"].hash).toBe(sha256["windows-x64"]);
|
|
174
|
+
expect(scoop.architecture["64bit"].url).toContain("crewhaus-windows-x64-1.0.0.exe");
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("Winget manifest is valid YAML-shaped text with InstallerSha256 uppercase", () => {
|
|
178
|
+
const winget = renderWingetManifest(inputs);
|
|
179
|
+
expect(winget).toContain("PackageIdentifier: CrewHaus.CLI");
|
|
180
|
+
expect(winget).toContain("PackageVersion: 1.0.0");
|
|
181
|
+
expect(winget).toContain(sha256["windows-x64"].toUpperCase());
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test("manifest rendering refuses missing/short shas", () => {
|
|
185
|
+
expect(() =>
|
|
186
|
+
renderHomebrewFormula({ ...inputs, sha256: { "macos-arm64": sha256["macos-arm64"] } }),
|
|
187
|
+
).toThrow(/missing sha256/);
|
|
188
|
+
expect(() => renderScoopManifest({ ...inputs, sha256: { "windows-x64": "short" } })).toThrow(
|
|
189
|
+
/malformed sha256/,
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test("writeAllManifests writes deterministic files", () => {
|
|
194
|
+
const dir = mkdtempSync(join(tmpdir(), "crewhaus-pkg-"));
|
|
195
|
+
const out = writeAllManifests(inputs, dir);
|
|
196
|
+
const formulaText = readFileSync(out.homebrew, "utf8");
|
|
197
|
+
const scoopText = readFileSync(out.scoop, "utf8");
|
|
198
|
+
expect(formulaText).toContain('version "1.0.0"');
|
|
199
|
+
expect(scoopText).toContain(
|
|
200
|
+
'"hash": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"',
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe("sha256OfFile", () => {
|
|
206
|
+
test("rejects missing files", async () => {
|
|
207
|
+
await expect(sha256OfFile("/nonexistent/path/to/file")).rejects.toThrow(SingleBinaryError);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("hashes a real file deterministically", async () => {
|
|
211
|
+
const dir = mkdtempSync(join(tmpdir(), "crewhaus-sha-"));
|
|
212
|
+
const path = join(dir, "test.bin");
|
|
213
|
+
const { writeFileSync } = await import("node:fs");
|
|
214
|
+
writeFileSync(path, "deterministic test bytes");
|
|
215
|
+
const a = await sha256OfFile(path);
|
|
216
|
+
const b = await sha256OfFile(path);
|
|
217
|
+
expect(a).toBe(b);
|
|
218
|
+
expect(a).toMatch(/^[0-9a-f]{64}$/);
|
|
219
|
+
});
|
|
220
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
/**
|
|
5
|
+
* Section 32 — `@crewhaus/single-binary-cli`
|
|
6
|
+
*
|
|
7
|
+
* `bun build --compile` wrapper that produces self-contained
|
|
8
|
+
* `dist/crewhaus-{linux,macos,windows}-{x64,arm64}` binaries for the
|
|
9
|
+
* `crewhaus` CLI. Each binary is ~80 MB; no Bun/Node prereq on the
|
|
10
|
+
* target host.
|
|
11
|
+
*
|
|
12
|
+
* Bun 1.2's `--compile` cross-compile matrix:
|
|
13
|
+
* - linux-x64 ✅
|
|
14
|
+
* - linux-arm64 ✅
|
|
15
|
+
* - macos-x64 ✅
|
|
16
|
+
* - macos-arm64 ✅
|
|
17
|
+
* - windows-x64 ✅ (named "bun-windows-x64" target)
|
|
18
|
+
* - windows-arm64 ❌ (Bun does not produce windows-arm64; documented
|
|
19
|
+
* gap — use linux-arm64 in WSL or skip)
|
|
20
|
+
*
|
|
21
|
+
* The auto-generated package manifests (Homebrew formula, Debian
|
|
22
|
+
* control, Scoop manifest, Winget manifest) live under
|
|
23
|
+
* `packaging/` and are templated against the binaries this package
|
|
24
|
+
* builds. `renderHomebrewFormula({version, sha256ByPlatform})` etc.
|
|
25
|
+
* regenerate them deterministically on every release.
|
|
26
|
+
*/
|
|
27
|
+
import { CrewhausError } from "@crewhaus/errors";
|
|
28
|
+
|
|
29
|
+
export class SingleBinaryError extends CrewhausError {
|
|
30
|
+
override readonly name = "SingleBinaryError";
|
|
31
|
+
constructor(message: string, cause?: unknown) {
|
|
32
|
+
super("config", message, cause);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const PLATFORMS = ["linux", "macos", "windows"] as const;
|
|
37
|
+
export const ARCHES = ["x64", "arm64"] as const;
|
|
38
|
+
export type Platform = (typeof PLATFORMS)[number];
|
|
39
|
+
export type Arch = (typeof ARCHES)[number];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The (platform, arch) pairs Bun --compile actually produces. The
|
|
43
|
+
* `windows-arm64` slot is intentionally absent because Bun has no
|
|
44
|
+
* `bun-windows-arm64` target as of Bun 1.2.
|
|
45
|
+
*/
|
|
46
|
+
export type BuildTarget = { readonly platform: Platform; readonly arch: Arch };
|
|
47
|
+
export const BUILD_MATRIX: readonly BuildTarget[] = [
|
|
48
|
+
{ platform: "linux", arch: "x64" },
|
|
49
|
+
{ platform: "linux", arch: "arm64" },
|
|
50
|
+
{ platform: "macos", arch: "x64" },
|
|
51
|
+
{ platform: "macos", arch: "arm64" },
|
|
52
|
+
{ platform: "windows", arch: "x64" },
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
/** Bun's --target string for a given (platform, arch) pair. */
|
|
56
|
+
export function bunCompileTarget(t: BuildTarget): string {
|
|
57
|
+
return `bun-${t.platform}-${t.arch}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Output filename of a built binary. Adds `.exe` on windows.
|
|
62
|
+
*/
|
|
63
|
+
export function binaryName(t: BuildTarget, version: string): string {
|
|
64
|
+
const base = `crewhaus-${t.platform}-${t.arch}`;
|
|
65
|
+
const versioned = version ? `${base}-${version}` : base;
|
|
66
|
+
return t.platform === "windows" ? `${versioned}.exe` : versioned;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const PACKAGE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
70
|
+
const REPO_ROOT = resolve(PACKAGE_ROOT, "..", "..");
|
|
71
|
+
const CLI_ENTRYPOINT_REL = "apps/cli/src/index.ts";
|
|
72
|
+
|
|
73
|
+
export type BuildBinaryRunner = (
|
|
74
|
+
argv: readonly string[],
|
|
75
|
+
cwd: string,
|
|
76
|
+
) => Promise<{ exitCode: number; stdout: string; stderr: string }>;
|
|
77
|
+
|
|
78
|
+
export type BuildBinaryOptions = {
|
|
79
|
+
readonly target: BuildTarget;
|
|
80
|
+
readonly version?: string;
|
|
81
|
+
readonly outDir?: string;
|
|
82
|
+
/** Test injection point. Defaults to spawning bun via node:child_process. */
|
|
83
|
+
readonly runner?: BuildBinaryRunner;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export type BuildBinaryResult = {
|
|
87
|
+
readonly target: BuildTarget;
|
|
88
|
+
readonly outPath: string;
|
|
89
|
+
readonly buildArgv: readonly string[];
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export async function buildBinary(opts: BuildBinaryOptions): Promise<BuildBinaryResult> {
|
|
93
|
+
const t = opts.target;
|
|
94
|
+
if (!isBuildTarget(t)) {
|
|
95
|
+
throw new SingleBinaryError(
|
|
96
|
+
`unsupported build target: ${t.platform}-${t.arch} (allowed: ${BUILD_MATRIX.map(formatTarget).join(", ")})`,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
const outDir = opts.outDir ?? join(REPO_ROOT, "dist");
|
|
100
|
+
const version = (opts.version ?? "").trim();
|
|
101
|
+
const outPath = join(outDir, binaryName(t, version));
|
|
102
|
+
const argv: string[] = [
|
|
103
|
+
"bun",
|
|
104
|
+
"build",
|
|
105
|
+
"--compile",
|
|
106
|
+
"--target",
|
|
107
|
+
bunCompileTarget(t),
|
|
108
|
+
CLI_ENTRYPOINT_REL,
|
|
109
|
+
"--outfile",
|
|
110
|
+
outPath,
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
const runner = opts.runner ?? defaultRunner;
|
|
114
|
+
const { exitCode, stderr } = await runner(argv, REPO_ROOT);
|
|
115
|
+
if (exitCode !== 0) {
|
|
116
|
+
throw new SingleBinaryError(
|
|
117
|
+
`bun build --compile (${formatTarget(t)}) exited with ${exitCode}: ${stderr.slice(0, 1024)}`,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
return { target: t, outPath, buildArgv: argv };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function isBuildTarget(t: BuildTarget): boolean {
|
|
124
|
+
return BUILD_MATRIX.some((m) => m.platform === t.platform && m.arch === t.arch);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function formatTarget(t: BuildTarget): string {
|
|
128
|
+
return `${t.platform}-${t.arch}`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const defaultRunner: BuildBinaryRunner = async (argv, cwd) => {
|
|
132
|
+
const { spawn } = await import("node:child_process");
|
|
133
|
+
return new Promise((resolve_) => {
|
|
134
|
+
const head = argv[0] ?? "bun";
|
|
135
|
+
const child = spawn(head, argv.slice(1), { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
136
|
+
const out: Buffer[] = [];
|
|
137
|
+
const err: Buffer[] = [];
|
|
138
|
+
child.stdout.on("data", (b) => out.push(b));
|
|
139
|
+
child.stderr.on("data", (b) => err.push(b));
|
|
140
|
+
child.on("error", (e) =>
|
|
141
|
+
resolve_({ exitCode: 1, stdout: "", stderr: String((e as Error).message) }),
|
|
142
|
+
);
|
|
143
|
+
child.on("close", (code) =>
|
|
144
|
+
resolve_({
|
|
145
|
+
exitCode: code ?? 1,
|
|
146
|
+
stdout: Buffer.concat(out).toString("utf8"),
|
|
147
|
+
stderr: Buffer.concat(err).toString("utf8"),
|
|
148
|
+
}),
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// ─── package manifest generation ─────────────────────────────────────────────
|
|
154
|
+
|
|
155
|
+
export type ShaByTarget = Readonly<Partial<Record<string, string>>>;
|
|
156
|
+
|
|
157
|
+
export type ManifestInputs = {
|
|
158
|
+
readonly version: string;
|
|
159
|
+
readonly homepage: string;
|
|
160
|
+
readonly downloadBaseUrl: string;
|
|
161
|
+
readonly sha256: ShaByTarget;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export function renderHomebrewFormula(inputs: ManifestInputs): string {
|
|
165
|
+
const { version, homepage, downloadBaseUrl, sha256 } = inputs;
|
|
166
|
+
if (!/^\d+\.\d+\.\d+/.test(version)) {
|
|
167
|
+
throw new SingleBinaryError(`homebrew version must be semver-shaped: ${version}`);
|
|
168
|
+
}
|
|
169
|
+
const macosArm64 = requireSha(sha256, "macos-arm64");
|
|
170
|
+
const macosX64 = requireSha(sha256, "macos-x64");
|
|
171
|
+
const linuxArm64 = requireSha(sha256, "linux-arm64");
|
|
172
|
+
const linuxX64 = requireSha(sha256, "linux-x64");
|
|
173
|
+
return `class Crewhaus < Formula
|
|
174
|
+
desc "Modular meta-harness — compile a single spec into multiple agent runtimes"
|
|
175
|
+
homepage "${homepage}"
|
|
176
|
+
version "${version}"
|
|
177
|
+
license "MIT"
|
|
178
|
+
|
|
179
|
+
on_macos do
|
|
180
|
+
on_arm do
|
|
181
|
+
url "${downloadBaseUrl}/crewhaus-macos-arm64-${version}"
|
|
182
|
+
sha256 "${macosArm64}"
|
|
183
|
+
end
|
|
184
|
+
on_intel do
|
|
185
|
+
url "${downloadBaseUrl}/crewhaus-macos-x64-${version}"
|
|
186
|
+
sha256 "${macosX64}"
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
on_linux do
|
|
191
|
+
on_arm do
|
|
192
|
+
url "${downloadBaseUrl}/crewhaus-linux-arm64-${version}"
|
|
193
|
+
sha256 "${linuxArm64}"
|
|
194
|
+
end
|
|
195
|
+
on_intel do
|
|
196
|
+
url "${downloadBaseUrl}/crewhaus-linux-x64-${version}"
|
|
197
|
+
sha256 "${linuxX64}"
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def install
|
|
202
|
+
bin.install Dir["*"].first => "crewhaus"
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
test do
|
|
206
|
+
system "#{bin}/crewhaus", "--version"
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
`;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function renderDebianControl(inputs: ManifestInputs): string {
|
|
213
|
+
const { version } = inputs;
|
|
214
|
+
return `Package: crewhaus
|
|
215
|
+
Version: ${version}
|
|
216
|
+
Section: utils
|
|
217
|
+
Priority: optional
|
|
218
|
+
Architecture: any
|
|
219
|
+
Maintainer: CrewHaus Maintainers <maintainers@crewhaus.io>
|
|
220
|
+
Depends: libc6 (>= 2.31)
|
|
221
|
+
Description: Modular meta-harness — compile a single spec into multiple agent runtimes
|
|
222
|
+
CrewHaus compiles a single high-level harness spec into multiple
|
|
223
|
+
runtime targets (graph, workflow, channel bot, eval, batch worker,
|
|
224
|
+
voice service, browser-driver, research-runner). The binary is a
|
|
225
|
+
self-contained Bun bundle requiring no Node/Bun on the target host.
|
|
226
|
+
`;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export function renderScoopManifest(inputs: ManifestInputs): unknown {
|
|
230
|
+
const { version, homepage, downloadBaseUrl, sha256 } = inputs;
|
|
231
|
+
const winX64 = requireSha(sha256, "windows-x64");
|
|
232
|
+
return {
|
|
233
|
+
version,
|
|
234
|
+
description: "Modular meta-harness — compile a single spec into multiple agent runtimes",
|
|
235
|
+
homepage,
|
|
236
|
+
license: "MIT",
|
|
237
|
+
architecture: {
|
|
238
|
+
"64bit": {
|
|
239
|
+
url: `${downloadBaseUrl}/crewhaus-windows-x64-${version}.exe`,
|
|
240
|
+
hash: winX64,
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
bin: "crewhaus.exe",
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function renderWingetManifest(inputs: ManifestInputs): string {
|
|
248
|
+
const { version, homepage, downloadBaseUrl, sha256 } = inputs;
|
|
249
|
+
const winX64 = requireSha(sha256, "windows-x64");
|
|
250
|
+
return `# yaml-language-server: $schema=https://aka.ms/winget-manifest.installer.1.4.0.schema.json
|
|
251
|
+
PackageIdentifier: CrewHaus.CLI
|
|
252
|
+
PackageVersion: ${version}
|
|
253
|
+
Publisher: CrewHaus
|
|
254
|
+
Author: CrewHaus
|
|
255
|
+
PackageName: crewhaus
|
|
256
|
+
PackageUrl: ${homepage}
|
|
257
|
+
License: MIT
|
|
258
|
+
ShortDescription: Modular meta-harness — compile a single spec into multiple agent runtimes
|
|
259
|
+
Description: |
|
|
260
|
+
CrewHaus compiles a single high-level harness spec into multiple runtime targets.
|
|
261
|
+
Tags:
|
|
262
|
+
- cli
|
|
263
|
+
- llm
|
|
264
|
+
- agent-framework
|
|
265
|
+
Installers:
|
|
266
|
+
- Architecture: x64
|
|
267
|
+
InstallerType: portable
|
|
268
|
+
InstallerUrl: ${downloadBaseUrl}/crewhaus-windows-x64-${version}.exe
|
|
269
|
+
InstallerSha256: ${winX64.toUpperCase()}
|
|
270
|
+
ManifestType: installer
|
|
271
|
+
ManifestVersion: 1.4.0
|
|
272
|
+
`;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function requireSha(map: ShaByTarget, target: string): string {
|
|
276
|
+
const sha = map[target];
|
|
277
|
+
if (!sha) {
|
|
278
|
+
throw new SingleBinaryError(`missing sha256 for ${target} in package manifest inputs`);
|
|
279
|
+
}
|
|
280
|
+
if (!/^[0-9a-f]{64}$/i.test(sha)) {
|
|
281
|
+
throw new SingleBinaryError(`malformed sha256 for ${target}: ${sha}`);
|
|
282
|
+
}
|
|
283
|
+
return sha;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ─── on-disk manifest writers ────────────────────────────────────────────────
|
|
287
|
+
|
|
288
|
+
export function packagingDir(): string {
|
|
289
|
+
return join(PACKAGE_ROOT, "packaging");
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function writeAllManifests(
|
|
293
|
+
inputs: ManifestInputs,
|
|
294
|
+
root: string = packagingDir(),
|
|
295
|
+
): {
|
|
296
|
+
homebrew: string;
|
|
297
|
+
debian: string;
|
|
298
|
+
scoop: string;
|
|
299
|
+
winget: string;
|
|
300
|
+
} {
|
|
301
|
+
mkdirSync(join(root, "Formula"), { recursive: true });
|
|
302
|
+
mkdirSync(join(root, "debian"), { recursive: true });
|
|
303
|
+
const homebrew = join(root, "Formula", "crewhaus.rb");
|
|
304
|
+
const debian = join(root, "debian", "control");
|
|
305
|
+
const scoop = join(root, "scoop.json");
|
|
306
|
+
const winget = join(root, "winget.yaml");
|
|
307
|
+
writeFileSync(homebrew, renderHomebrewFormula(inputs), { mode: 0o644 });
|
|
308
|
+
writeFileSync(debian, renderDebianControl(inputs), { mode: 0o644 });
|
|
309
|
+
writeFileSync(scoop, `${JSON.stringify(renderScoopManifest(inputs), null, 2)}\n`, {
|
|
310
|
+
mode: 0o644,
|
|
311
|
+
});
|
|
312
|
+
writeFileSync(winget, renderWingetManifest(inputs), { mode: 0o644 });
|
|
313
|
+
return { homebrew, debian, scoop, winget };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// ─── helpers consumed by the binary CLI ─────────────────────────────────────
|
|
317
|
+
|
|
318
|
+
/** Read a file's sha256 — used by release tooling to populate manifests. */
|
|
319
|
+
export async function sha256OfFile(path: string): Promise<string> {
|
|
320
|
+
if (!existsSync(path)) {
|
|
321
|
+
throw new SingleBinaryError(`file not found: ${path}`);
|
|
322
|
+
}
|
|
323
|
+
const { createHash } = await import("node:crypto");
|
|
324
|
+
const hash = createHash("sha256");
|
|
325
|
+
hash.update(readFileSync(path));
|
|
326
|
+
return hash.digest("hex");
|
|
327
|
+
}
|