eutaxy 0.17.2 → 0.19.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/README.md +15 -12
- package/dist/aws.d.mts +2 -2
- package/dist/aws.mjs +3 -2
- package/dist/aws.mjs.map +1 -1
- package/dist/bin.mjs +1 -1
- package/dist/check-zkHLdWyf.mjs +1281 -0
- package/dist/check-zkHLdWyf.mjs.map +1 -0
- package/dist/cli-CNAKqV9R.mjs +297 -0
- package/dist/cli-CNAKqV9R.mjs.map +1 -0
- package/dist/cli.d.mts.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/cloudflare.d.mts +56 -5
- package/dist/cloudflare.d.mts.map +1 -1
- package/dist/cloudflare.mjs +6417 -3
- package/dist/cloudflare.mjs.map +1 -0
- package/dist/{delivery-invariants-DO3j1mmD.mjs → delivery-invariants-BJDck0K8.mjs} +2 -2
- package/dist/{delivery-invariants-DO3j1mmD.mjs.map → delivery-invariants-BJDck0K8.mjs.map} +1 -1
- package/dist/{delivery-invariants-D7DI7i8x.d.mts → delivery-invariants-C3GXJIbg.d.mts} +2 -2
- package/dist/{delivery-invariants-D7DI7i8x.d.mts.map → delivery-invariants-C3GXJIbg.d.mts.map} +1 -1
- package/dist/draft-DEUDffHa.mjs +467 -0
- package/dist/draft-DEUDffHa.mjs.map +1 -0
- package/dist/{src-fxWc6oGc.mjs → generate-TBJM3-2P.mjs} +3 -574
- package/dist/generate-TBJM3-2P.mjs.map +1 -0
- package/dist/index.d.mts +45 -37
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +7 -4
- package/dist/index.mjs.map +1 -1
- package/dist/install-DkzpGA5D.mjs +611 -0
- package/dist/install-DkzpGA5D.mjs.map +1 -0
- package/dist/{explore-CkKiOuz6.d.mts → ir-KpC2epGn.d.mts} +88 -53
- package/dist/ir-KpC2epGn.d.mts.map +1 -0
- package/dist/keys-xtanNmuR.mjs +111 -0
- package/dist/keys-xtanNmuR.mjs.map +1 -0
- package/dist/mcp-B64Ko6y7.mjs +539 -0
- package/dist/mcp-B64Ko6y7.mjs.map +1 -0
- package/dist/{platform-D4hlJjm3.d.mts → platform-Cs9V9t2k.d.mts} +92 -11
- package/dist/platform-Cs9V9t2k.d.mts.map +1 -0
- package/dist/pool-CXN4CwGY.mjs +61 -0
- package/dist/pool-CXN4CwGY.mjs.map +1 -0
- package/dist/{provers-DS44OeEm.mjs → provers-D8VaY_OM.mjs} +18 -2
- package/dist/provers-D8VaY_OM.mjs.map +1 -0
- package/dist/reader-B9FSoEYW.mjs +1 -0
- package/dist/reader-Cz6_bLf6.mjs +3774 -0
- package/dist/reader-Cz6_bLf6.mjs.map +1 -0
- package/dist/report-_Vzavqg0.mjs +310 -0
- package/dist/report-_Vzavqg0.mjs.map +1 -0
- package/dist/src-B2DpVbMN.mjs +2 -0
- package/dist/src-BFGTvuA_.mjs +1235 -0
- package/dist/src-BFGTvuA_.mjs.map +1 -0
- package/dist/src-BtLZPRyG.mjs +120 -0
- package/dist/src-BtLZPRyG.mjs.map +1 -0
- package/dist/src-CB8DcvsK.mjs +1 -0
- package/dist/src-COuquJvI.mjs +269 -0
- package/dist/src-COuquJvI.mjs.map +1 -0
- package/dist/src-Chn-m_r1.mjs +1082 -0
- package/dist/src-Chn-m_r1.mjs.map +1 -0
- package/dist/src-DwYD3QQJ.mjs +346 -0
- package/dist/src-DwYD3QQJ.mjs.map +1 -0
- package/dist/{src-D_hHC_-3.mjs → src-Dx4QvrQb.mjs} +945 -548
- package/dist/src-Dx4QvrQb.mjs.map +1 -0
- package/dist/toolchain-DWfymxAJ.mjs +80 -0
- package/dist/toolchain-DWfymxAJ.mjs.map +1 -0
- package/dist/verdict-evEM5Gxx.mjs +12 -0
- package/dist/verdict-evEM5Gxx.mjs.map +1 -0
- package/package.json +4 -1
- package/dist/cli-B0Gs2mhT.mjs +0 -9445
- package/dist/cli-B0Gs2mhT.mjs.map +0 -1
- package/dist/explore-CkKiOuz6.d.mts.map +0 -1
- package/dist/platform-D4hlJjm3.d.mts.map +0 -1
- package/dist/provers-DS44OeEm.mjs.map +0 -1
- package/dist/src-D_hHC_-3.mjs.map +0 -1
- package/dist/src-fxWc6oGc.mjs.map +0 -1
- package/dist/workerd-DhrzU6AZ.mjs +0 -6300
- package/dist/workerd-DhrzU6AZ.mjs.map +0 -1
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
import "./src-COuquJvI.mjs";
|
|
2
|
+
import { n as exitCodes } from "./check-zkHLdWyf.mjs";
|
|
3
|
+
import { a as markerFile, c as toolchainDir, i as installed, n as executableName, o as platformOf, r as host, s as platforms, t as cacheDir } from "./toolchain-DWfymxAJ.mjs";
|
|
4
|
+
import { C as elanCandidates, D as leanDigests, E as elanVersion, O as toolchainDigest, T as elanHome, b as leanVersion, w as elanDownloads, y as leanToolchain } from "./src-BFGTvuA_.mjs";
|
|
5
|
+
import { l as z3Downloads } from "./src-Chn-m_r1.mjs";
|
|
6
|
+
import { Readable } from "node:stream";
|
|
7
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
8
|
+
import { chmodSync, closeSync, createReadStream, existsSync, mkdirSync, mkdtempSync, openSync, readFileSync, renameSync, rmSync, writeFileSync, writeSync } from "node:fs";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { dirname, join, resolve, sep } from "node:path";
|
|
11
|
+
import { crc32, gunzipSync, inflateRawSync } from "node:zlib";
|
|
12
|
+
import { spawn } from "node:child_process";
|
|
13
|
+
// packages/cli/src/archive.ts
|
|
14
|
+
/**
|
|
15
|
+
* Reading the two archive formats the release files come in, with Node's
|
|
16
|
+
* standard library alone: a zip (Z3; elan's installer on Windows) and a
|
|
17
|
+
* gzip-compressed tar (elan's installer elsewhere). From either, only the
|
|
18
|
+
* files the caller names are taken, each to the path the caller gives: the
|
|
19
|
+
* archive chooses no path and makes no link, so nothing in it can write
|
|
20
|
+
* anywhere else. A named entry that is missing, there twice, a link or a
|
|
21
|
+
* directory, or whose data does not match what its headers say, is refused,
|
|
22
|
+
* and nothing is written until every named entry has been read.
|
|
23
|
+
*/
|
|
24
|
+
var ArchiveError = class extends Error {};
|
|
25
|
+
const inside = (dest, path) => path === dest || path.startsWith(dest + sep);
|
|
26
|
+
/** Each named entry's place under `dest`, checked before the archive is read. */
|
|
27
|
+
function placesOf(entries, dest) {
|
|
28
|
+
const root = resolve(dest);
|
|
29
|
+
const places = /* @__PURE__ */ new Map();
|
|
30
|
+
for (const [name, to] of Object.entries(entries)) {
|
|
31
|
+
const place = resolve(root, to);
|
|
32
|
+
if (place === root || !inside(root, place)) throw new ArchiveError(`${JSON.stringify(to)} is not a path under the toolchain directory`);
|
|
33
|
+
places.set(name, place);
|
|
34
|
+
}
|
|
35
|
+
return places;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Write what was read, once every named entry has been: files with mode
|
|
39
|
+
* 0644 (the caller makes its executable runnable). Returns how many.
|
|
40
|
+
*/
|
|
41
|
+
function writeFound(kind, places, found) {
|
|
42
|
+
const missing = [...places.keys()].filter((name) => !found.has(name));
|
|
43
|
+
if (missing.length > 0) throw new ArchiveError(`the ${kind} holds no ${missing.map((m) => JSON.stringify(m)).join(", ")}`);
|
|
44
|
+
for (const [name, data] of found) {
|
|
45
|
+
const place = places.get(name);
|
|
46
|
+
mkdirSync(dirname(place), { recursive: true });
|
|
47
|
+
writeFileSync(place, data, { mode: 420 });
|
|
48
|
+
}
|
|
49
|
+
return found.size;
|
|
50
|
+
}
|
|
51
|
+
const ZIP_EOCD = 101010256;
|
|
52
|
+
const ZIP64_EOCD = 101075792;
|
|
53
|
+
const ZIP64_LOCATOR = 117853008;
|
|
54
|
+
const ZIP_CENTRAL = 33639248;
|
|
55
|
+
const ZIP_LOCAL = 67324752;
|
|
56
|
+
/** The central directory's position and entry count, through the zip64 records when the plain ones overflow. */
|
|
57
|
+
function centralDirectory(zip) {
|
|
58
|
+
const start = Math.max(0, zip.length - 22 - 65535);
|
|
59
|
+
let eocd = -1;
|
|
60
|
+
for (let i = zip.length - 22; i >= start; i--) if (zip.readUInt32LE(i) === ZIP_EOCD) {
|
|
61
|
+
eocd = i;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
if (eocd < 0) throw new ArchiveError("not a zip file: no end-of-central-directory record");
|
|
65
|
+
let entries = zip.readUInt16LE(eocd + 10);
|
|
66
|
+
let offset = zip.readUInt32LE(eocd + 16);
|
|
67
|
+
if (entries === 65535 || offset === 4294967295) {
|
|
68
|
+
const locator = eocd - 20;
|
|
69
|
+
if (locator < 0 || zip.readUInt32LE(locator) !== ZIP64_LOCATOR) throw new ArchiveError("zip64 archive without its locator");
|
|
70
|
+
const at = Number(zip.readBigUInt64LE(locator + 8));
|
|
71
|
+
if (at + 56 > zip.length || zip.readUInt32LE(at) !== ZIP64_EOCD) throw new ArchiveError("zip64 archive without its end record");
|
|
72
|
+
entries = Number(zip.readBigUInt64LE(at + 32));
|
|
73
|
+
offset = Number(zip.readBigUInt64LE(at + 48));
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
offset,
|
|
77
|
+
entries
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** Sizes and offset of one entry, from its zip64 extra field when the plain ones overflow. */
|
|
81
|
+
function zip64Fields(extra, plain) {
|
|
82
|
+
let at = 0;
|
|
83
|
+
while (at + 4 <= extra.length) {
|
|
84
|
+
const id = extra.readUInt16LE(at);
|
|
85
|
+
const size = extra.readUInt16LE(at + 2);
|
|
86
|
+
const end = at + 4 + size;
|
|
87
|
+
if (end > extra.length) throw new ArchiveError("an entry's extra field is cut short");
|
|
88
|
+
if (id === 1) {
|
|
89
|
+
let p = at + 4;
|
|
90
|
+
const next = () => {
|
|
91
|
+
if (p + 8 > end) throw new ArchiveError("an entry's zip64 field is cut short");
|
|
92
|
+
const value = Number(extra.readBigUInt64LE(p));
|
|
93
|
+
p += 8;
|
|
94
|
+
return value;
|
|
95
|
+
};
|
|
96
|
+
const out = { ...plain };
|
|
97
|
+
if (out.uncompressed === 4294967295) out.uncompressed = next();
|
|
98
|
+
if (out.compressed === 4294967295) out.compressed = next();
|
|
99
|
+
if (out.offset === 4294967295) out.offset = next();
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
at += 4 + size;
|
|
103
|
+
}
|
|
104
|
+
return plain;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Take the named files of a zip, and nothing else: `entries` maps each
|
|
108
|
+
* file's path in the archive to the path under `dest` it is written to.
|
|
109
|
+
* Every named entry must be there exactly once, must be a plain file
|
|
110
|
+
* (a directory or a link is refused), and must inflate to its declared
|
|
111
|
+
* size and CRC-32; nothing is written until all of them have. Files are
|
|
112
|
+
* written with mode 0644 (the caller makes its executable runnable).
|
|
113
|
+
* Returns how many files were written.
|
|
114
|
+
*/
|
|
115
|
+
function extractZipEntries(file, entries, dest) {
|
|
116
|
+
const places = placesOf(entries, dest);
|
|
117
|
+
const zip = readFileSync(file);
|
|
118
|
+
const { offset, entries: count } = centralDirectory(zip);
|
|
119
|
+
const found = /* @__PURE__ */ new Map();
|
|
120
|
+
let at = offset;
|
|
121
|
+
for (let i = 0; i < count; i++) {
|
|
122
|
+
if (at + 46 > zip.length || zip.readUInt32LE(at) !== ZIP_CENTRAL) throw new ArchiveError("a central directory entry is not where the zip says it is");
|
|
123
|
+
const madeBy = zip.readUInt16LE(at + 4) >> 8;
|
|
124
|
+
const method = zip.readUInt16LE(at + 10);
|
|
125
|
+
const crc = zip.readUInt32LE(at + 16);
|
|
126
|
+
const nameLength = zip.readUInt16LE(at + 28);
|
|
127
|
+
const extraLength = zip.readUInt16LE(at + 30);
|
|
128
|
+
const commentLength = zip.readUInt16LE(at + 32);
|
|
129
|
+
const externalAttributes = zip.readUInt32LE(at + 38);
|
|
130
|
+
const name = zip.subarray(at + 46, at + 46 + nameLength).toString("utf8");
|
|
131
|
+
const sizes = zip64Fields(zip.subarray(at + 46 + nameLength, at + 46 + nameLength + extraLength), {
|
|
132
|
+
compressed: zip.readUInt32LE(at + 20),
|
|
133
|
+
uncompressed: zip.readUInt32LE(at + 24),
|
|
134
|
+
offset: zip.readUInt32LE(at + 42)
|
|
135
|
+
});
|
|
136
|
+
at += 46 + nameLength + extraLength + commentLength;
|
|
137
|
+
if (!places.has(name)) continue;
|
|
138
|
+
const quoted = JSON.stringify(name);
|
|
139
|
+
if (found.has(name)) throw new ArchiveError(`entry ${quoted} is in the zip twice`);
|
|
140
|
+
const type = (madeBy === 3 ? externalAttributes >>> 16 : 0) & 61440;
|
|
141
|
+
if (name.endsWith("/") || type === 16384) throw new ArchiveError(`entry ${quoted} is a directory, not a file`);
|
|
142
|
+
if (type === 40960) throw new ArchiveError(`entry ${quoted} is a link, not a file`);
|
|
143
|
+
const local = sizes.offset;
|
|
144
|
+
if (local + 30 > zip.length || zip.readUInt32LE(local) !== ZIP_LOCAL) throw new ArchiveError(`entry ${quoted} has no local header where the zip says`);
|
|
145
|
+
const dataStart = local + 30 + zip.readUInt16LE(local + 26) + zip.readUInt16LE(local + 28);
|
|
146
|
+
const raw = zip.subarray(dataStart, dataStart + sizes.compressed);
|
|
147
|
+
let data;
|
|
148
|
+
if (method === 0) data = raw;
|
|
149
|
+
else if (method === 8) try {
|
|
150
|
+
data = inflateRawSync(raw, { maxOutputLength: Math.max(1, sizes.uncompressed) });
|
|
151
|
+
} catch (err) {
|
|
152
|
+
throw new ArchiveError(`entry ${quoted} did not inflate within its declared size: ${err instanceof Error ? err.message : String(err)}`);
|
|
153
|
+
}
|
|
154
|
+
else throw new ArchiveError(`entry ${quoted} uses compression method ${method}; only stored and deflated entries are read`);
|
|
155
|
+
if (data.length !== sizes.uncompressed) throw new ArchiveError(`entry ${quoted} did not inflate to its declared size`);
|
|
156
|
+
if (crc32(data) !== crc) throw new ArchiveError(`entry ${quoted} fails its CRC-32 check`);
|
|
157
|
+
found.set(name, data);
|
|
158
|
+
}
|
|
159
|
+
return writeFound("zip", places, found);
|
|
160
|
+
}
|
|
161
|
+
/** The largest tar a release's installer comes in, uncompressed; elan's is 6 to 14 MB. */
|
|
162
|
+
const maxTarBytes = 268435456;
|
|
163
|
+
const text = (block, start, length) => {
|
|
164
|
+
const slice = block.subarray(start, start + length);
|
|
165
|
+
const end = slice.indexOf(0);
|
|
166
|
+
return slice.subarray(0, end < 0 ? slice.length : end).toString("utf8");
|
|
167
|
+
};
|
|
168
|
+
/** An octal field, or GNU base-256 when the high bit of the first byte is set. */
|
|
169
|
+
const numeric = (block, start, length) => {
|
|
170
|
+
if (block[start] & 128) {
|
|
171
|
+
let n = 0;
|
|
172
|
+
for (let i = start + 1; i < start + length; i++) n = n * 256 + block[i];
|
|
173
|
+
return n;
|
|
174
|
+
}
|
|
175
|
+
const t = text(block, start, length).trim();
|
|
176
|
+
if (t.length === 0) return 0;
|
|
177
|
+
if (!/^[0-7]+$/.test(t)) throw new ArchiveError(`a tar header holds ${JSON.stringify(t)} where a number goes`);
|
|
178
|
+
return Number.parseInt(t, 8);
|
|
179
|
+
};
|
|
180
|
+
/** `length key=value\n` records of a pax extended header. */
|
|
181
|
+
function paxRecords(data) {
|
|
182
|
+
const out = /* @__PURE__ */ new Map();
|
|
183
|
+
let at = 0;
|
|
184
|
+
while (at < data.length) {
|
|
185
|
+
const space = data.indexOf(32, at);
|
|
186
|
+
if (space < 0) break;
|
|
187
|
+
const length = Number.parseInt(data.subarray(at, space).toString("latin1"), 10);
|
|
188
|
+
if (!Number.isInteger(length) || length <= 0) break;
|
|
189
|
+
const record = data.subarray(space + 1, at + length - 1).toString("utf8");
|
|
190
|
+
const eq = record.indexOf("=");
|
|
191
|
+
if (eq > 0) out.set(record.slice(0, eq), record.slice(eq + 1));
|
|
192
|
+
at += length;
|
|
193
|
+
}
|
|
194
|
+
return out;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Take the named files of a gzip-compressed tar, and nothing else, as
|
|
198
|
+
* `extractZipEntries` does for a zip: `entries` maps each file's path in
|
|
199
|
+
* the archive (after any pax or GNU long name) to its path under `dest`.
|
|
200
|
+
* Every header's checksum is checked; a named entry must be a regular file.
|
|
201
|
+
*/
|
|
202
|
+
function extractTarGzEntries(file, entries, dest) {
|
|
203
|
+
const places = placesOf(entries, dest);
|
|
204
|
+
let tar;
|
|
205
|
+
try {
|
|
206
|
+
tar = gunzipSync(readFileSync(file), { maxOutputLength: maxTarBytes });
|
|
207
|
+
} catch (err) {
|
|
208
|
+
throw new ArchiveError(`not a gzip-compressed tar within ${maxTarBytes} bytes: ${err instanceof Error ? err.message : String(err)}`);
|
|
209
|
+
}
|
|
210
|
+
const found = /* @__PURE__ */ new Map();
|
|
211
|
+
let next = {};
|
|
212
|
+
let at = 0;
|
|
213
|
+
while (at + 512 <= tar.length) {
|
|
214
|
+
const block = tar.subarray(at, at + 512);
|
|
215
|
+
if (block.every((b) => b === 0)) break;
|
|
216
|
+
let sum = 0;
|
|
217
|
+
for (let i = 0; i < 512; i++) sum += i >= 148 && i < 156 ? 32 : block[i];
|
|
218
|
+
if (sum !== numeric(block, 148, 8)) throw new ArchiveError("a tar header fails its checksum");
|
|
219
|
+
const type = block[156] === 0 ? "0" : String.fromCharCode(block[156]);
|
|
220
|
+
const size = type === "x" || type === "L" ? numeric(block, 124, 12) : next.size ?? numeric(block, 124, 12);
|
|
221
|
+
const start = at + 512;
|
|
222
|
+
if (start + size > tar.length) throw new ArchiveError("the tar ends inside an entry; the file is truncated");
|
|
223
|
+
const data = tar.subarray(start, start + size);
|
|
224
|
+
at = start + Math.ceil(size / 512) * 512;
|
|
225
|
+
if (type === "x") {
|
|
226
|
+
const records = paxRecords(data);
|
|
227
|
+
const path = records.get("path");
|
|
228
|
+
const declared = records.get("size");
|
|
229
|
+
if (declared !== void 0 && !/^\d+$/.test(declared)) throw new ArchiveError(`a pax header gives the size ${JSON.stringify(declared)}`);
|
|
230
|
+
next = {
|
|
231
|
+
...path === void 0 ? {} : { path },
|
|
232
|
+
...declared === void 0 ? {} : { size: Number(declared) }
|
|
233
|
+
};
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (type === "L") {
|
|
237
|
+
next = {
|
|
238
|
+
...next,
|
|
239
|
+
path: text(data, 0, data.length)
|
|
240
|
+
};
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (type === "g") continue;
|
|
244
|
+
const prefix = text(block, 257, 6) === "ustar" ? text(block, 345, 155) : "";
|
|
245
|
+
const plain = text(block, 0, 100);
|
|
246
|
+
const name = next.path ?? (prefix.length > 0 ? `${prefix}/${plain}` : plain);
|
|
247
|
+
next = {};
|
|
248
|
+
if (!places.has(name)) continue;
|
|
249
|
+
const quoted = JSON.stringify(name);
|
|
250
|
+
if (found.has(name)) throw new ArchiveError(`entry ${quoted} is in the tar twice`);
|
|
251
|
+
if (type === "5") throw new ArchiveError(`entry ${quoted} is a directory, not a file`);
|
|
252
|
+
if (type === "1" || type === "2") throw new ArchiveError(`entry ${quoted} is a link, not a file`);
|
|
253
|
+
if (type !== "0" && type !== "7") throw new ArchiveError(`entry ${quoted} is of tar type ${JSON.stringify(type)}, not a file`);
|
|
254
|
+
found.set(name, Buffer.from(data));
|
|
255
|
+
}
|
|
256
|
+
return writeFound("tar", places, found);
|
|
257
|
+
}
|
|
258
|
+
// packages/cli/src/install.ts
|
|
259
|
+
/**
|
|
260
|
+
* `eutaxy prover install <lean|smt>`: the pinned toolchain of a prover put
|
|
261
|
+
* on this machine, where the engines look first.
|
|
262
|
+
*
|
|
263
|
+
* `installToolchain` installs a pinned upstream release file into Eutaxy's
|
|
264
|
+
* cache: the file for this platform is downloaded (or copied from a mirror
|
|
265
|
+
* or an offline directory given with `--from`), its SHA-256 checked against
|
|
266
|
+
* the table before anything is unpacked, the files the table names taken
|
|
267
|
+
* from it (a zip or a `tar.gz`) beside a marker written last, and the
|
|
268
|
+
* download deleted. A mismatch or a failed download installs nothing, and
|
|
269
|
+
* nothing is run. Z3 comes this way, and so does elan's installer.
|
|
270
|
+
*
|
|
271
|
+
* `installLean` installs Lean through elan, Lean's toolchain manager: the
|
|
272
|
+
* machine's elan if it has one, else elan installed into Eutaxy's cache
|
|
273
|
+
* from its pinned installer (without touching the PATH or the shell's
|
|
274
|
+
* profile); then `elan toolchain install` of the pinned toolchain, whose
|
|
275
|
+
* files' digest is checked against the pinned one, since elan checks no
|
|
276
|
+
* pinned checksum itself.
|
|
277
|
+
*/
|
|
278
|
+
/** The engines the command installs, by the name it takes. */
|
|
279
|
+
const engines = ["lean", "smt"];
|
|
280
|
+
var InstallError = class extends Error {};
|
|
281
|
+
const isUrl = (s) => /^https?:\/\//.test(s);
|
|
282
|
+
/** Write a byte stream to `path`, hashing it as it goes; the hash and the byte count come back. */
|
|
283
|
+
async function store(bytes, path, progress) {
|
|
284
|
+
const hash = createHash("sha256");
|
|
285
|
+
const fd = openSync(path, "w");
|
|
286
|
+
let written = 0;
|
|
287
|
+
let reported = 0;
|
|
288
|
+
try {
|
|
289
|
+
for await (const chunk of bytes) {
|
|
290
|
+
writeSync(fd, chunk);
|
|
291
|
+
hash.update(chunk);
|
|
292
|
+
written += chunk.byteLength;
|
|
293
|
+
if (progress && written - reported >= 5e7) {
|
|
294
|
+
reported = written;
|
|
295
|
+
progress(written);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
} finally {
|
|
299
|
+
closeSync(fd);
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
sha256: hash.digest("hex"),
|
|
303
|
+
bytes: written
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
async function installToolchain(options) {
|
|
307
|
+
const { toolchain } = options;
|
|
308
|
+
const h = options.host ?? host();
|
|
309
|
+
const platform = platformOf(h);
|
|
310
|
+
const release = platform === void 0 ? void 0 : toolchain.files[platform];
|
|
311
|
+
if (platform === void 0 || release === void 0) throw new InstallError(`no ${toolchain.name} ${toolchain.version} release for ${h.platform}-${h.arch}; the platforms are ${platforms.join(", ")}`);
|
|
312
|
+
const cache = cacheDir(h);
|
|
313
|
+
const dir = toolchainDir(cache, toolchain);
|
|
314
|
+
const already = installed(toolchain, h);
|
|
315
|
+
if (already) return {
|
|
316
|
+
name: toolchain.name,
|
|
317
|
+
version: toolchain.version,
|
|
318
|
+
platform,
|
|
319
|
+
file: already.marker.file,
|
|
320
|
+
source: already.marker.source,
|
|
321
|
+
sha256: already.marker.sha256,
|
|
322
|
+
bytes: release.bytes,
|
|
323
|
+
dir,
|
|
324
|
+
executable: already.executable,
|
|
325
|
+
downloaded: false
|
|
326
|
+
};
|
|
327
|
+
const source = options.from === void 0 ? release.url : isUrl(options.from) ? `${options.from.replace(/\/+$/, "")}/${release.file}` : join(options.from, release.file);
|
|
328
|
+
const stamp = `${process.pid}-${randomBytes(4).toString("hex")}`;
|
|
329
|
+
const downloads = join(cache, "downloads");
|
|
330
|
+
const archive = join(downloads, `${release.file}.${stamp}.part`);
|
|
331
|
+
const mb = (n) => `${Math.round(n / 1e6)} MB`;
|
|
332
|
+
try {
|
|
333
|
+
mkdirSync(downloads, { recursive: true });
|
|
334
|
+
let bytes;
|
|
335
|
+
if (isUrl(source)) {
|
|
336
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
337
|
+
let response;
|
|
338
|
+
try {
|
|
339
|
+
response = await fetchImpl(source);
|
|
340
|
+
} catch (err) {
|
|
341
|
+
throw new InstallError(`could not download ${source}: ${err instanceof Error ? err.message : String(err)}`);
|
|
342
|
+
}
|
|
343
|
+
if (!response.ok || response.body === null) throw new InstallError(`could not download ${source}: HTTP ${response.status} ${response.statusText}`);
|
|
344
|
+
options.progress?.(`downloading ${release.file} (${mb(release.bytes)}) from ${source}`);
|
|
345
|
+
bytes = Readable.fromWeb(response.body);
|
|
346
|
+
} else {
|
|
347
|
+
if (!existsSync(source)) throw new InstallError(`no ${release.file} in ${options.from}`);
|
|
348
|
+
bytes = createReadStream(source);
|
|
349
|
+
}
|
|
350
|
+
let stored;
|
|
351
|
+
try {
|
|
352
|
+
stored = await store(bytes, archive, (n) => options.progress?.(`${mb(n)} of ${mb(release.bytes)}`));
|
|
353
|
+
} catch (err) {
|
|
354
|
+
throw new InstallError(`could not download ${source}: ${err instanceof Error ? err.message : String(err)}; nothing was installed`);
|
|
355
|
+
}
|
|
356
|
+
if (stored.sha256 !== release.sha256) throw new InstallError(`checksum mismatch for ${release.file} from ${source}: expected sha256 ${release.sha256}, got ${stored.sha256} (${stored.bytes} bytes, ${release.bytes} expected); nothing was installed`);
|
|
357
|
+
const partial = `${dir}.partial-${stamp}`;
|
|
358
|
+
mkdirSync(partial, { recursive: true });
|
|
359
|
+
try {
|
|
360
|
+
options.progress?.(`unpacking ${release.file}`);
|
|
361
|
+
const extract = release.file.endsWith(".zip") ? extractZipEntries : release.file.endsWith(".tar.gz") ? extractTarGzEntries : void 0;
|
|
362
|
+
if (extract === void 0) throw new InstallError(`${release.file} is neither a .zip nor a .tar.gz`);
|
|
363
|
+
if (release.entries === void 0) throw new InstallError(`the table names no files to take from ${release.file}; nothing was installed`);
|
|
364
|
+
extract(archive, release.entries, partial);
|
|
365
|
+
const executable = executableName(toolchain, h);
|
|
366
|
+
if (!existsSync(join(partial, executable))) throw new InstallError(`${release.file} holds no ${executable}; nothing was installed`);
|
|
367
|
+
if (h.platform !== "win32") chmodSync(join(partial, executable), 493);
|
|
368
|
+
const marker = {
|
|
369
|
+
name: toolchain.name,
|
|
370
|
+
version: toolchain.version,
|
|
371
|
+
platform,
|
|
372
|
+
file: release.file,
|
|
373
|
+
sha256: stored.sha256,
|
|
374
|
+
source
|
|
375
|
+
};
|
|
376
|
+
writeFileSync(join(partial, markerFile), `${JSON.stringify(marker, null, 2)}\n`);
|
|
377
|
+
rmSync(dir, {
|
|
378
|
+
recursive: true,
|
|
379
|
+
force: true
|
|
380
|
+
});
|
|
381
|
+
renameSync(partial, dir);
|
|
382
|
+
} catch (err) {
|
|
383
|
+
rmSync(partial, {
|
|
384
|
+
recursive: true,
|
|
385
|
+
force: true
|
|
386
|
+
});
|
|
387
|
+
throw err instanceof InstallError ? err : new InstallError(`could not unpack ${release.file}: ${err instanceof Error ? err.message : String(err)}; nothing was installed`);
|
|
388
|
+
}
|
|
389
|
+
return {
|
|
390
|
+
name: toolchain.name,
|
|
391
|
+
version: toolchain.version,
|
|
392
|
+
platform,
|
|
393
|
+
file: release.file,
|
|
394
|
+
source,
|
|
395
|
+
sha256: stored.sha256,
|
|
396
|
+
bytes: stored.bytes,
|
|
397
|
+
dir,
|
|
398
|
+
executable: join(dir, executableName(toolchain, h)),
|
|
399
|
+
downloaded: true
|
|
400
|
+
};
|
|
401
|
+
} catch (err) {
|
|
402
|
+
throw err instanceof InstallError ? err : new InstallError(`could not install ${toolchain.name} ${toolchain.version} in ${cache}: ${err instanceof Error ? err.message : String(err)}`);
|
|
403
|
+
} finally {
|
|
404
|
+
try {
|
|
405
|
+
rmSync(archive, { force: true });
|
|
406
|
+
} catch {}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
/** How long a quick elan command (a version, a list, a path) may take. */
|
|
410
|
+
const quickMs = 6e4;
|
|
411
|
+
/** How long elan may take to install the toolchain: a 600 MB download and 2.8 GB unpacked. */
|
|
412
|
+
const toolchainInstallMs = 36e5;
|
|
413
|
+
const exec = (command, args, options = {}) => new Promise((resolve) => {
|
|
414
|
+
let child;
|
|
415
|
+
try {
|
|
416
|
+
child = spawn(command, args, {
|
|
417
|
+
stdio: [
|
|
418
|
+
"ignore",
|
|
419
|
+
"pipe",
|
|
420
|
+
"pipe"
|
|
421
|
+
],
|
|
422
|
+
...options.cwd === void 0 ? {} : { cwd: options.cwd },
|
|
423
|
+
...options.env === void 0 ? {} : { env: {
|
|
424
|
+
...process.env,
|
|
425
|
+
...options.env
|
|
426
|
+
} }
|
|
427
|
+
});
|
|
428
|
+
} catch (err) {
|
|
429
|
+
resolve({
|
|
430
|
+
code: null,
|
|
431
|
+
stdout: "",
|
|
432
|
+
stderr: String(err)
|
|
433
|
+
});
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
let stdout = "";
|
|
437
|
+
let stderr = "";
|
|
438
|
+
let timedOut = false;
|
|
439
|
+
const timer = setTimeout(() => {
|
|
440
|
+
timedOut = true;
|
|
441
|
+
child.kill("SIGKILL");
|
|
442
|
+
}, options.timeoutMs ?? quickMs);
|
|
443
|
+
child.stdout?.on("data", (d) => {
|
|
444
|
+
stdout += d.toString();
|
|
445
|
+
});
|
|
446
|
+
child.stderr?.on("data", (d) => {
|
|
447
|
+
stderr += d.toString();
|
|
448
|
+
});
|
|
449
|
+
child.on("error", (err) => {
|
|
450
|
+
clearTimeout(timer);
|
|
451
|
+
resolve({
|
|
452
|
+
code: null,
|
|
453
|
+
stdout,
|
|
454
|
+
stderr: `${stderr}${String(err)}`
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
child.on("close", (code) => {
|
|
458
|
+
clearTimeout(timer);
|
|
459
|
+
resolve(timedOut ? {
|
|
460
|
+
code: null,
|
|
461
|
+
stdout,
|
|
462
|
+
stderr: `${stderr}timed out`,
|
|
463
|
+
timedOut: true
|
|
464
|
+
} : {
|
|
465
|
+
code,
|
|
466
|
+
stdout,
|
|
467
|
+
stderr
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
/** The last lines of a command's error output, for a message. */
|
|
472
|
+
const tail = (text) => text.trim().split("\n").slice(-5).join("\n");
|
|
473
|
+
/**
|
|
474
|
+
* Lean through elan. The result's `file` is the toolchain's name, `source`
|
|
475
|
+
* the elan that installed it, `sha256` the digest of the toolchain's files,
|
|
476
|
+
* `bytes` their size and `dir` the toolchain's directory.
|
|
477
|
+
*/
|
|
478
|
+
async function installLean(options = {}) {
|
|
479
|
+
const h = options.host ?? host();
|
|
480
|
+
const platform = platformOf(h);
|
|
481
|
+
const expected = platform === void 0 ? void 0 : (options.digests ?? leanDigests)[platform];
|
|
482
|
+
if (platform === void 0 || expected === void 0) throw new InstallError(`no lean ${leanVersion} toolchain for ${h.platform}-${h.arch}; the platforms are ${platforms.join(", ")}`);
|
|
483
|
+
if (options.from !== void 0) throw new InstallError(`--from applies to smt only: Lean is installed by elan, which downloads it from releases.lean-lang.org; offline, unpack Lean's release by hand and register it with elan toolchain link`);
|
|
484
|
+
const run = options.exec ?? exec;
|
|
485
|
+
const say = options.progress ?? (() => {});
|
|
486
|
+
let elan;
|
|
487
|
+
for (const candidate of elanCandidates(h)) if ((await run(candidate.command, ["--version"], { env: candidate.env })).code === 0) {
|
|
488
|
+
elan = candidate;
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
491
|
+
if (elan === void 0) {
|
|
492
|
+
const installer = await installToolchain({
|
|
493
|
+
toolchain: options.elanInstaller ?? elanDownloads,
|
|
494
|
+
host: h,
|
|
495
|
+
...options.fetch === void 0 ? {} : { fetch: options.fetch },
|
|
496
|
+
...options.progress === void 0 ? {} : { progress: options.progress }
|
|
497
|
+
});
|
|
498
|
+
const home = elanHome(h);
|
|
499
|
+
say(`installing elan ${elanVersion} in ${home}`);
|
|
500
|
+
const made = await run(installer.executable, [
|
|
501
|
+
"-y",
|
|
502
|
+
"--no-modify-path",
|
|
503
|
+
"--default-toolchain",
|
|
504
|
+
"none"
|
|
505
|
+
], {
|
|
506
|
+
env: { ELAN_HOME: home },
|
|
507
|
+
timeoutMs: 6e5
|
|
508
|
+
});
|
|
509
|
+
elan = elanCandidates(h)[0];
|
|
510
|
+
if (made.code !== 0 || (await run(elan.command, ["--version"], { env: elan.env })).code !== 0) throw new InstallError(`elan's installer did not install elan in ${home} (exit ${made.code}): ${tail(made.stderr)}`);
|
|
511
|
+
}
|
|
512
|
+
const list = await run(elan.command, ["toolchain", "list"], { env: elan.env });
|
|
513
|
+
if (list.code !== 0) throw new InstallError(`elan (${elan.command}) could not list its toolchains (exit ${list.code}): ${tail(list.stderr)}`);
|
|
514
|
+
const had = list.stdout.split("\n").some((line) => line.trim().split(" ")[0] === leanToolchain);
|
|
515
|
+
if (!had) {
|
|
516
|
+
say(`installing ${leanToolchain} through ${elan.command} (about 600 MB to download, 2.8 GB unpacked)`);
|
|
517
|
+
const installed = await run(elan.command, [
|
|
518
|
+
"toolchain",
|
|
519
|
+
"install",
|
|
520
|
+
leanToolchain
|
|
521
|
+
], {
|
|
522
|
+
env: elan.env,
|
|
523
|
+
timeoutMs: toolchainInstallMs
|
|
524
|
+
});
|
|
525
|
+
if (installed.code !== 0) throw new InstallError(`elan could not install ${leanToolchain} (exit ${installed.code}): ${tail(installed.stderr)}`);
|
|
526
|
+
}
|
|
527
|
+
const pinned = mkdtempSync(join(tmpdir(), "eutaxy-lean-toolchain-"));
|
|
528
|
+
let where;
|
|
529
|
+
try {
|
|
530
|
+
writeFileSync(join(pinned, "lean-toolchain"), `${leanToolchain}\n`);
|
|
531
|
+
where = await run(elan.command, ["which", "lean"], {
|
|
532
|
+
env: {
|
|
533
|
+
...elan.env,
|
|
534
|
+
ELAN_TOOLCHAIN: leanToolchain
|
|
535
|
+
},
|
|
536
|
+
cwd: pinned
|
|
537
|
+
});
|
|
538
|
+
} finally {
|
|
539
|
+
rmSync(pinned, {
|
|
540
|
+
recursive: true,
|
|
541
|
+
force: true
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
const leanPath = where.stdout.trim();
|
|
545
|
+
const prefix = dirname(dirname(leanPath));
|
|
546
|
+
if (where.code !== 0 || !/[\\/]bin[\\/]lean(\.exe)?$/.test(leanPath) || !existsSync(prefix)) throw new InstallError(`elan has ${leanToolchain} but did not say where (exit ${where.code}): ${tail(where.stderr) || leanPath}`);
|
|
547
|
+
say(`checking the files of ${leanToolchain} in ${prefix}`);
|
|
548
|
+
const found = toolchainDigest(prefix);
|
|
549
|
+
const digests = options.digests ?? leanDigests;
|
|
550
|
+
const sameSystem = Object.entries(digests).find(([p, d]) => d === found.digest && p.startsWith(`${h.platform}-`))?.[0];
|
|
551
|
+
if (sameSystem !== void 0 && sameSystem !== platform) say(`the toolchain is the pinned release for ${sameSystem}, the architecture ${elan.command} installs for, not ${platform}; it runs here too`);
|
|
552
|
+
if (sameSystem === void 0) {
|
|
553
|
+
let fate = "it was there before this command, so it was left as it is";
|
|
554
|
+
if (!had) {
|
|
555
|
+
const removed = await run(elan.command, [
|
|
556
|
+
"toolchain",
|
|
557
|
+
"uninstall",
|
|
558
|
+
leanToolchain
|
|
559
|
+
], { env: elan.env });
|
|
560
|
+
fate = removed.code === 0 ? "it was uninstalled" : `uninstalling it failed (exit ${removed.code}): remove it with elan toolchain uninstall ${leanToolchain}`;
|
|
561
|
+
}
|
|
562
|
+
throw new InstallError(`the toolchain in ${prefix} is not the pinned ${leanToolchain}: the digest of its files is ${found.digest}, expected ${expected}; ${fate}`);
|
|
563
|
+
}
|
|
564
|
+
return {
|
|
565
|
+
name: "lean",
|
|
566
|
+
version: leanVersion,
|
|
567
|
+
platform,
|
|
568
|
+
file: leanToolchain,
|
|
569
|
+
source: elan.command,
|
|
570
|
+
sha256: found.digest,
|
|
571
|
+
bytes: found.bytes,
|
|
572
|
+
dir: prefix,
|
|
573
|
+
executable: join(prefix, "bin", h.platform === "win32" ? "lean.exe" : "lean"),
|
|
574
|
+
downloaded: !had
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
/** The command: the result as text or `--json` on stdout, progress and errors on stderr; exit 0, or 3 on an error. */
|
|
578
|
+
async function runInstall(options) {
|
|
579
|
+
try {
|
|
580
|
+
const shared = {
|
|
581
|
+
...options.host === void 0 ? {} : { host: options.host },
|
|
582
|
+
...options.fetch === void 0 ? {} : { fetch: options.fetch },
|
|
583
|
+
...options.from === void 0 ? {} : { from: options.from },
|
|
584
|
+
progress: (text) => options.stderr(`${text}\n`)
|
|
585
|
+
};
|
|
586
|
+
const result = options.engine === "lean" ? await installLean({
|
|
587
|
+
...shared,
|
|
588
|
+
...options.exec === void 0 ? {} : { exec: options.exec },
|
|
589
|
+
...options.digests === void 0 ? {} : { digests: options.digests }
|
|
590
|
+
}) : await installToolchain({
|
|
591
|
+
...shared,
|
|
592
|
+
toolchain: z3Downloads
|
|
593
|
+
});
|
|
594
|
+
if (options.json) options.stdout(`${JSON.stringify({
|
|
595
|
+
schemaVersion: 1,
|
|
596
|
+
command: "prover install",
|
|
597
|
+
...result
|
|
598
|
+
}, null, 2)}\n`);
|
|
599
|
+
else if (options.engine === "lean") options.stdout(`${result.name} ${result.version} ${result.downloaded ? "installed" : "already installed"} in ${result.dir}\n ${result.file} through ${result.source}\n files checked, digest ${result.sha256}\n`);
|
|
600
|
+
else if (result.downloaded) options.stdout(`${result.name} ${result.version} installed in ${result.dir}\n ${result.file} from ${result.source}\n sha256 ${result.sha256}\n`);
|
|
601
|
+
else options.stdout(`${result.name} ${result.version} already installed in ${result.dir} (${result.file}, sha256 ${result.sha256})\n`);
|
|
602
|
+
return exitCodes.BOUNDED;
|
|
603
|
+
} catch (err) {
|
|
604
|
+
if (!(err instanceof InstallError)) throw err;
|
|
605
|
+
options.stderr(`${err.message}\n`);
|
|
606
|
+
return exitCodes.error;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
export { InstallError, engines, installLean, installToolchain, runInstall };
|
|
610
|
+
|
|
611
|
+
//# sourceMappingURL=install-DkzpGA5D.mjs.map
|