mvp-ai's picture
download
raw
3.64 kB
// Copyright (c) 2026 the Zuke contributors
// SPDX-License-Identifier: MIT
/**
* Compiling the released `zuke` CLI into standalone binaries.
*
* The binaries are compiled from the published `jsr:@zuke/cli@<version>`,
* not from this checkout: what Homebrew installs is then the same program
* `deno install -g` installs, resolved the same way, and JSR's own provenance
* covers its source. `-A` matches the JSR install's permissions, and is also
* what lets a compiled binary resolve its own path to tell a Homebrew install
* from another (`packages/cli/src/install_source.ts`).
*
* Deno looks for a configuration file from the working directory, and this
* checkout's would map `@zuke/*` onto the workspace instead of JSR, so the
* compile runs from an empty temporary directory.
*
* @module
*/
import { type DenoCompileSettings, DenoTasks } from "@zuke/deno";
import { type AbsolutePath, absolutePath } from "@zuke/core";
import { $ } from "@zuke/core/shell";
import { binaryPath } from "./cli_package.ts";
import { CLI_TARGETS, WINDOWS_TRIPLE } from "./cli_release.ts";
/** The published package a release's binaries are compiled from. */
export function cliSpecifier(version: string): string {
return `jsr:@zuke/cli@${version}`;
}
/** One `deno compile`, as {@link compileCliBinaries} runs it. */
export type Compile = (
configure: (s: DenoCompileSettings) => DenoCompileSettings,
) => Promise<unknown>;
/**
* Compile every target's binary into `binDir` — absolute, since the
* compile runs from a temporary directory — then run the one built for this
* machine, if any, to check it reports `version`.
*/
export async function compileCliBinaries(
version: string,
binDir: AbsolutePath,
compile: Compile = (configure) => DenoTasks.compile(configure),
): Promise<void> {
const scratch = await Deno.makeTempDir({ prefix: "zuke-compile-" });
try {
const triples = [...CLI_TARGETS.map((t) => t.triple), WINDOWS_TRIPLE];
for (const triple of triples) {
const output = binaryPath(binDir.path, triple);
await Deno.mkdir(binDir(triple).path, { recursive: true });
await compile((s) =>
s.allowAll().target(triple).output(output)
.script(cliSpecifier(version)).cwd(scratch)
);
}
const host = triples.find((triple) => triple === Deno.build.target);
if (host !== undefined) {
await assertReportsVersion(
absolutePath(binaryPath(binDir.path, host)),
version,
);
}
} finally {
await Deno.remove(scratch, { recursive: true });
}
}
/**
* Run `binary --version` outside any project and fail unless its first line
* is exactly `version`.
*
* `binary` is absolute because the check runs from an empty temporary
* directory, where a relative path would name nothing.
*
* This is the check that the compile resolved the release it was asked for.
* A Deno that holds back recently published versions (2.9 does by default)
* would otherwise build an older CLI under the new version's name.
*/
export async function assertReportsVersion(
binary: AbsolutePath,
version: string,
): Promise<void> {
const scratch = await Deno.makeTempDir({ prefix: "zuke-smoke-" });
try {
const reported = (await $`${binary.path} --version`.cwd(scratch).env({
ZUKE_PLAIN: "1",
}).text()).split("\n")[0];
if (reported !== version) {
throw new Error(
`${binary.path} reports version ${JSON.stringify(reported)}, not ` +
`${version}: the compile did not resolve the release it was asked for.`,
);
}
} finally {
await Deno.remove(scratch, { recursive: true });
}
}

Xet Storage Details

Size:
3.64 kB
·
Xet hash:
a8f6c00630a4fb04b1b6b200b690dfa2f2bd28f7ee7671b039bcb01aaf69a504

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.