import { SUPPORTED_LEAN } from "./ir.ts"; export type PlatformKey = "darwin_aarch64" | "darwin_x86_64" | "linux_x86_64" | "linux_aarch64"; export type LeanRelease = { version: string; assets: Record; }; export const SUPPORTED_RELEASES: Readonly> = { [SUPPORTED_LEAN]: { version: SUPPORTED_LEAN, assets: { darwin_aarch64: { filename: "lean-4.34.1-darwin_aarch64.zip", sha256: "9019fcd34e93fddf0ecf9d40d28f05a86ba563ac3b701a9c5116ce1c96379360", }, darwin_x86_64: { filename: "lean-4.34.1-darwin.zip", sha256: "60b45c76003a4561fb66d7ec2003569006d255d2860179445e56d3e2a029090e", }, linux_x86_64: { filename: "lean-4.34.1-linux.zip", sha256: "3013aba02bb8bf31b1cf8c9d956d60fb95bb1c10920dfe91abcaa59cb461ddac", }, linux_aarch64: { filename: "lean-4.34.1-linux_aarch64.zip", sha256: "b4bcf1d79f1b5859c04625058d3707701d87a65815f7f0686a1f14df821954c5", }, }, }, }; export function parseLeanToolchain(raw: string): string { const line = raw .split(/\r?\n/) .map((entry) => entry.trim()) .find((entry) => entry.length > 0 && !entry.startsWith("#")); if (!line) throw new Error("lean-toolchain is empty."); const colon = line.lastIndexOf(":"); const tag = colon === -1 ? line : line.slice(colon + 1); if (!tag) throw new Error(`Cannot read Lean version from lean-toolchain entry ${line}.`); return tag.startsWith("v") ? tag : `v${tag}`; } export function assertSupportedLean(version: string): string { if (!(version in SUPPORTED_RELEASES)) throw new Error( `Unsupported Lean toolchain ${version}. statechart supports only ${SUPPORTED_LEAN}.`, ); return version; } export function platformKeyOf(input: { platform: string; arch: string }): PlatformKey | undefined { if (input.platform === "darwin" && input.arch === "arm64") return "darwin_aarch64"; if (input.platform === "darwin" && input.arch === "x64") return "darwin_x86_64"; if (input.platform === "linux" && input.arch === "x64") return "linux_x86_64"; if (input.platform === "linux" && input.arch === "arm64") return "linux_aarch64"; return undefined; } export function miseLeanTool(input: { version: string; platform: PlatformKey; }): string | undefined { const release = SUPPORTED_RELEASES[input.version]; if (!release) return undefined; const asset = release.assets[input.platform]; const bare = input.version.replace(/^v/, ""); const url = `https://github.com/leanprover/lean4/releases/download/${input.version}/${asset.filename}`; return `http:lean[url=${url},checksum=sha256:${asset.sha256}]@${bare}`; }