@typesol/cli 0.44.1 → 0.46.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/CHANGELOG.md +343 -0
- package/NOTICE +14 -1
- package/README.md +115 -26
- package/SECURITY.md +10 -8
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +9 -0
- package/dist/cli.js +226 -62
- package/dist/compiler/analyze.js +57 -6
- package/dist/compiler/diagnostics.d.ts +4 -3
- package/dist/compiler/diagnostics.js +10 -6
- package/dist/compiler/emit/base.d.ts +1 -1
- package/dist/compiler/emit/calls.js +18 -5
- package/dist/compiler/emit/cpi-core.d.ts +3 -1
- package/dist/compiler/emit/cpi-core.js +8 -4
- package/dist/compiler/emit/expressions.d.ts +14 -0
- package/dist/compiler/emit/expressions.js +52 -4
- package/dist/compiler/emit/shared.d.ts +8 -1
- package/dist/compiler/emit/shared.js +8 -1
- package/dist/compiler/emit/statements.d.ts +8 -3
- package/dist/compiler/emit/statements.js +68 -3
- package/dist/compiler/emit/storage.js +5 -1
- package/dist/compiler/hints.d.ts +7 -0
- package/dist/compiler/hints.js +58 -9
- package/dist/compiler/index.d.ts +56 -1
- package/dist/compiler/index.js +27 -3
- package/dist/compiler/model.js +3 -2
- package/dist/compiler/toolchain.d.ts +73 -2
- package/dist/compiler/toolchain.js +222 -17
- package/dist/node-version.d.ts +4 -0
- package/dist/node-version.js +12 -0
- package/dist/tools/docker.d.ts +183 -0
- package/dist/tools/docker.js +442 -0
- package/dist/tools/doctor.d.ts +44 -0
- package/dist/tools/doctor.js +108 -14
- package/dist/workspace.d.ts +11 -3
- package/dist/workspace.js +46 -9
- package/docker/Dockerfile +163 -0
- package/docker/deps/0.43.0.lock.json +1206 -0
- package/docker/deps/0.44.0.lock.json +1206 -0
- package/docker/deps/0.44.1.lock.json +1206 -0
- package/docker/deps/0.45.0.lock.json +1206 -0
- package/docker/deps/0.46.0.lock.json +1206 -0
- package/docs/ai.md +2 -1
- package/docs/architecture.md +18 -6
- package/docs/audit.md +15 -7
- package/docs/case-study-phoenix.md +1 -1
- package/docs/case-study-raydium-amm.md +1 -1
- package/docs/case-study-spl-stake-pool.md +1 -1
- package/docs/cli.md +71 -6
- package/docs/errors.md +22 -8
- package/docs/glossary.md +210 -0
- package/docs/language-accounts.md +499 -0
- package/docs/language-basics.md +389 -0
- package/docs/language-builtins.md +411 -0
- package/docs/language-chain.md +198 -0
- package/docs/language-cpi.md +470 -0
- package/docs/language-errors-events.md +184 -0
- package/docs/language-native.md +493 -0
- package/docs/language-pdas.md +198 -0
- package/docs/language-statements.md +620 -0
- package/docs/language-types.md +601 -0
- package/docs/language.md +190 -467
- package/docs/mainnet.md +103 -8
- package/docs/migrate-from-anchor.md +7 -6
- package/docs/security-model.md +4 -4
- package/docs/stability.md +64 -3
- package/docs/test-your-program.md +52 -15
- package/docs/testing.md +49 -2
- package/docs/troubleshooting.md +210 -42
- package/lib/typesol.d.ts +67 -22
- package/llms-full.txt +5084 -591
- package/llms.txt +12 -1
- package/package.json +4 -2
- package/releases/0.43.0.json +669 -0
- package/releases/0.44.0.json +672 -0
- package/releases/0.44.1.json +672 -0
- package/releases/0.45.0.json +732 -0
- package/runtime/LICENSE-compiler-builtins.txt +275 -0
- package/runtime/typesol_builtins.c +484 -0
- package/ts-plugin/index.js +16 -5
|
@@ -7,8 +7,25 @@ export const RUNTIME_DIR = fileURLToPath(new URL("../../runtime/", import.meta.u
|
|
|
7
7
|
/** Executable names: platform-tools ship .exe files on Windows. */
|
|
8
8
|
const EXE = (name) => (process.platform === "win32" ? `${name}.exe` : name);
|
|
9
9
|
export const SBPF_VERSIONS = ["v0", "v1", "v2"];
|
|
10
|
+
/** The runtime's compiler builtins, compiled with each program and linked in place of compiler-builtins. */
|
|
11
|
+
export const BUILTINS_SOURCE = path.join(RUNTIME_DIR, "typesol_builtins.c");
|
|
12
|
+
/** What is missing when there is no toolchain to build with, so `doctor` and `init` can say which commands to run. */
|
|
13
|
+
export class ToolchainMissing extends Error {
|
|
14
|
+
kind;
|
|
15
|
+
summary;
|
|
16
|
+
constructor(
|
|
17
|
+
/** "agave": no Agave CLI (no SDK); "platform-tools": the CLI without its platform-tools; "sbpf-libraries": platform-tools without this SBPF version. */
|
|
18
|
+
kind,
|
|
19
|
+
/** What is missing, in one clause. */
|
|
20
|
+
summary, fix) {
|
|
21
|
+
super(`${summary}. ${fix}`);
|
|
22
|
+
this.kind = kind;
|
|
23
|
+
this.summary = summary;
|
|
24
|
+
this.name = "ToolchainMissing";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
10
27
|
/** Locate the Solana C SDK that ships with the Agave CLI's platform-tools. */
|
|
11
|
-
export function findToolchain(sbpf = "v0") {
|
|
28
|
+
export function findToolchain(sbpf = "v0", host = process) {
|
|
12
29
|
// Where the Agave installer puts it, or next to `cargo-build-sbf` on PATH (custom --data-dir, Homebrew, Docker…).
|
|
13
30
|
const onPath = (process.env.PATH ?? "")
|
|
14
31
|
.split(path.delimiter)
|
|
@@ -26,11 +43,17 @@ export function findToolchain(sbpf = "v0") {
|
|
|
26
43
|
].filter((p) => !!p);
|
|
27
44
|
const sdk = candidates.find((p) => existsSync(path.join(p, "c/sbf.mk")));
|
|
28
45
|
if (!sdk)
|
|
29
|
-
throw
|
|
46
|
+
throw linuxArm64(host)
|
|
47
|
+
? new ToolchainMissing("agave", "no Solana SBF SDK: TYPESOL_SBF_SDK is not set, and there is no Agave CLI for Linux arm64", `Install the platform-tools' linux-aarch64 package and the SDK's C files:${block(installLines("agave", host))}`)
|
|
48
|
+
: new ToolchainMissing("agave", "the Agave CLI is not installed (no Solana SBF SDK under ~/.local/share/solana/install/active_release or next to cargo-build-sbf on PATH)", `Set TYPESOL_SBF_SDK to a platform-tools-sdk/sbf directory, or install the Agave CLI and its platform-tools:${block(installLines("agave", host))}`);
|
|
30
49
|
const llvm = path.join(sdk, "dependencies/platform-tools/llvm");
|
|
31
50
|
const clang = path.join(llvm, "bin", EXE("clang"));
|
|
32
51
|
if (!existsSync(clang))
|
|
33
|
-
throw new
|
|
52
|
+
throw new ToolchainMissing("platform-tools",
|
|
53
|
+
// On Linux arm64 there is no Agave CLI: the SDK found is the one TYPESOL_SBF_SDK names.
|
|
54
|
+
linuxArm64(host)
|
|
55
|
+
? `the SBF SDK at ${sdk} has no platform-tools (nothing under ${sdk}/dependencies)`
|
|
56
|
+
: `the Agave CLI is installed, but not its platform-tools (nothing under ${sdk}/dependencies)`, `Install them once:${block(installLines("platform-tools", host))}`);
|
|
34
57
|
// Newest clang resource directory (numeric order: "9" < "19").
|
|
35
58
|
const clangInc = readdirSync(path.join(llvm, "lib/clang"))
|
|
36
59
|
.sort((a, b) => Number.parseFloat(a) - Number.parseFloat(b))
|
|
@@ -39,7 +62,7 @@ export function findToolchain(sbpf = "v0") {
|
|
|
39
62
|
const rustlib = path.join(sdk, `dependencies/platform-tools/rust/lib/rustlib/${target}-solana-solana/lib`);
|
|
40
63
|
const builtins = existsSync(rustlib) ? readdirSync(rustlib).find((f) => f.startsWith("libcompiler_builtins-") && f.endsWith(".rlib")) : undefined;
|
|
41
64
|
if (!builtins)
|
|
42
|
-
throw new
|
|
65
|
+
throw new ToolchainMissing("sbpf-libraries", `these platform-tools have no SBPF ${sbpf} libraries (${rustlib})`, `Build for another --sbpf, or install the tested ones:${block(installLines("platform-tools", host))}`);
|
|
43
66
|
return {
|
|
44
67
|
sdk,
|
|
45
68
|
clang,
|
|
@@ -53,9 +76,9 @@ export function findToolchain(sbpf = "v0") {
|
|
|
53
76
|
/** Compile generated C to an SBF shared object (same flags as the SDK's sbf.mk for the chosen SBPF version). */
|
|
54
77
|
/** The SBF stack frame of one function. */
|
|
55
78
|
export const STACK_FRAME = 4096;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
79
|
+
/** clang's flags for SBF objects (the SDK's sbf.mk for the chosen SBPF version, plus TypeSOL's warnings). */
|
|
80
|
+
export function sbfCflags(sbpf = "v0") {
|
|
81
|
+
return [
|
|
59
82
|
"-Werror",
|
|
60
83
|
"-Wno-parentheses-equality",
|
|
61
84
|
// Generated checks may be always true/false (`a === a`, `enumByte >= 256` for a 256-variant enum); that is not an error.
|
|
@@ -74,6 +97,15 @@ export function buildSharedObject(cFile, outSo, sbpf = "v0", tc = findToolchain(
|
|
|
74
97
|
"-fPIC",
|
|
75
98
|
...(sbpf === "v0" ? [] : [`-mcpu=${sbpf}`]),
|
|
76
99
|
];
|
|
100
|
+
}
|
|
101
|
+
/** The flags runtime/typesol_builtins.c is compiled with: the program's, and the SBPF version (its assembly differs). */
|
|
102
|
+
export function builtinsCflags(sbpf = "v0") {
|
|
103
|
+
return [...sbfCflags(sbpf), `-DTS_SBPF_${sbpf.toUpperCase()}`];
|
|
104
|
+
}
|
|
105
|
+
export function buildSharedObject(cFile, outSo, sbpf = "v0", tc = findToolchain(sbpf)) {
|
|
106
|
+
const obj = outSo.replace(/\.so$/, ".o");
|
|
107
|
+
const builtinsObj = outSo.replace(/\.so$/, ".builtins.o");
|
|
108
|
+
const cflags = sbfCflags(sbpf);
|
|
77
109
|
const incs = tc.includes.flatMap((i, n) => (n < 2 ? ["-isystem", i] : ["-I", i]));
|
|
78
110
|
try {
|
|
79
111
|
run(tc.clang, [...cflags, ...incs, "-o", obj, "-c", cFile]);
|
|
@@ -92,6 +124,20 @@ export function buildSharedObject(cFile, outSo, sbpf = "v0", tc = findToolchain(
|
|
|
92
124
|
rmSync(obj, { force: true });
|
|
93
125
|
throw stackError(message, frameLayouts(res.stderr ?? ""), readFileSync(cFile, "utf8"));
|
|
94
126
|
}
|
|
127
|
+
try {
|
|
128
|
+
// The builtins (128-bit multiplication, division and shifts, signed 64-bit division) from the runtime's C, after
|
|
129
|
+
// the program's object. platform-tools' compiler-builtins library has the same instructions in each host package
|
|
130
|
+
// but split into other archive members, so the linker laid them out in another order on each host; this does not.
|
|
131
|
+
run(tc.clang, [...builtinsCflags(sbpf), "-o", builtinsObj, "-c", BUILTINS_SOURCE]);
|
|
132
|
+
linkSharedObject([obj, builtinsObj], outSo, tc);
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
rmSync(obj, { force: true }); // the object files are only intermediates
|
|
136
|
+
rmSync(builtinsObj, { force: true });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** Link SBF objects into a program: libc from platform-tools, nothing from its Rust libraries. */
|
|
140
|
+
export function linkSharedObject(objects, outSo, tc, extra = []) {
|
|
95
141
|
run(tc.lld, [
|
|
96
142
|
"-z",
|
|
97
143
|
"notext",
|
|
@@ -104,17 +150,113 @@ export function buildSharedObject(cFile, outSo, sbpf = "v0", tc = findToolchain(
|
|
|
104
150
|
tc.libDir,
|
|
105
151
|
"-z",
|
|
106
152
|
"max-page-size=4096",
|
|
107
|
-
// Drop unreachable code (
|
|
108
|
-
//
|
|
153
|
+
// Drop unreachable code (the builtins a program does not call) and the symbol tables, which the loader never
|
|
154
|
+
// reads: smaller programs cost less rent and upload time.
|
|
109
155
|
"--gc-sections",
|
|
110
156
|
"--strip-all",
|
|
111
157
|
"-lc",
|
|
112
158
|
"-o",
|
|
113
159
|
outSo,
|
|
114
|
-
|
|
115
|
-
|
|
160
|
+
...objects,
|
|
161
|
+
...extra,
|
|
116
162
|
]);
|
|
117
|
-
|
|
163
|
+
const missing = unresolvedSymbols(readFileSync(outSo)).filter((s) => !isSyscall(s));
|
|
164
|
+
if (missing.length) {
|
|
165
|
+
rmSync(outSo, { force: true });
|
|
166
|
+
// Another clang may call a builtin the tested one never does: say that first, as it is then the likely cause.
|
|
167
|
+
let info;
|
|
168
|
+
try {
|
|
169
|
+
info = toolchainInfo(tc);
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
/* the version cannot be read: no claim about it */
|
|
173
|
+
}
|
|
174
|
+
const t = TESTED_TOOLCHAIN;
|
|
175
|
+
throw new Error((info && !info.tested
|
|
176
|
+
? `this toolchain is not the tested one (${shortClang(info.clang)}${info.platformTools ? `, platform-tools ${info.platformTools}` : ""}; ` +
|
|
177
|
+
`TESTED_TOOLCHAIN is ${shortClang(t.clang)}, platform-tools ${t.platformTools}), and its clang may call compiler builtins the tested one ` +
|
|
178
|
+
`does not, which runtime/typesol_builtins.c does not define: build with the tested toolchain (the command is below). `
|
|
179
|
+
: "") +
|
|
180
|
+
`the program calls ${missing.join(", ")}, which neither the runtime nor libc defines and the SBF loader cannot resolve as a syscall ` +
|
|
181
|
+
`(with the tested toolchain, a compiler builtin missing from runtime/typesol_builtins.c is a TypeSOL bug: please report it with the program)` +
|
|
182
|
+
(info && !info.tested ? `. The tested toolchain:${block([INSTALL_TESTED_TOOLCHAIN[1]])}` : ""));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The syscalls a TypeSOL program may leave to the SBF loader: every one the SDK's headers declare (`@SYSCALL` in
|
|
187
|
+
* platform-tools-sdk/sbf/c/inc/sol/inc/*.inc) and every one runtime/typesol_rt.h declares itself, with `abort`.
|
|
188
|
+
* test/cli/toolchain.test.ts checks that this is exactly that set.
|
|
189
|
+
*/
|
|
190
|
+
export const SYSCALLS = [
|
|
191
|
+
"abort",
|
|
192
|
+
"sol_alt_bn128_compression",
|
|
193
|
+
"sol_alt_bn128_group_op",
|
|
194
|
+
"sol_big_mod_exp",
|
|
195
|
+
"sol_blake3",
|
|
196
|
+
"sol_create_program_address",
|
|
197
|
+
"sol_curve_validate_point",
|
|
198
|
+
"sol_get_clock_sysvar",
|
|
199
|
+
"sol_get_epoch_rewards_sysvar",
|
|
200
|
+
"sol_get_epoch_schedule_sysvar",
|
|
201
|
+
"sol_get_last_restart_slot",
|
|
202
|
+
"sol_get_rent_sysvar",
|
|
203
|
+
"sol_get_return_data",
|
|
204
|
+
"sol_get_stack_height",
|
|
205
|
+
"sol_invoke_signed_c",
|
|
206
|
+
"sol_keccak256",
|
|
207
|
+
"sol_log_",
|
|
208
|
+
"sol_log_64_",
|
|
209
|
+
"sol_log_compute_units_",
|
|
210
|
+
"sol_log_data",
|
|
211
|
+
"sol_log_pubkey",
|
|
212
|
+
"sol_memcpy_",
|
|
213
|
+
"sol_memmove_",
|
|
214
|
+
"sol_memset_",
|
|
215
|
+
"sol_panic_",
|
|
216
|
+
"sol_poseidon",
|
|
217
|
+
"sol_remaining_compute_units",
|
|
218
|
+
"sol_secp256k1_recover",
|
|
219
|
+
"sol_set_return_data",
|
|
220
|
+
"sol_sha256",
|
|
221
|
+
"sol_try_find_program_address",
|
|
222
|
+
];
|
|
223
|
+
/** Whether the SBF loader resolves `name` as a syscall for a TypeSOL program (one of SYSCALLS). */
|
|
224
|
+
export function isSyscall(name) {
|
|
225
|
+
return SYSCALLS.includes(name);
|
|
226
|
+
}
|
|
227
|
+
/** The undefined symbols of an SBF shared object's dynamic symbol table (what the loader resolves as syscalls). */
|
|
228
|
+
export function unresolvedSymbols(elf) {
|
|
229
|
+
if (elf.length < 0x40 || elf.readUInt32BE(0) !== 0x7f454c46)
|
|
230
|
+
throw new Error("not an ELF file");
|
|
231
|
+
const shoff = Number(elf.readBigUInt64LE(0x28));
|
|
232
|
+
const shentsize = elf.readUInt16LE(0x3a);
|
|
233
|
+
const shnum = elf.readUInt16LE(0x3c);
|
|
234
|
+
const section = (i) => {
|
|
235
|
+
const at = shoff + i * shentsize;
|
|
236
|
+
return {
|
|
237
|
+
type: elf.readUInt32LE(at + 4),
|
|
238
|
+
offset: Number(elf.readBigUInt64LE(at + 0x18)),
|
|
239
|
+
size: Number(elf.readBigUInt64LE(at + 0x20)),
|
|
240
|
+
link: elf.readUInt32LE(at + 0x28),
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
const out = [];
|
|
244
|
+
for (let i = 0; i < shnum; i++) {
|
|
245
|
+
const s = section(i);
|
|
246
|
+
if (s.type !== 11)
|
|
247
|
+
continue; // SHT_DYNSYM
|
|
248
|
+
const strtab = section(s.link);
|
|
249
|
+
for (let at = s.offset + 24; at + 24 <= s.offset + s.size; at += 24) {
|
|
250
|
+
if (elf.readUInt16LE(at + 6) !== 0)
|
|
251
|
+
continue; // st_shndx: defined
|
|
252
|
+
const nameAt = strtab.offset + elf.readUInt32LE(at);
|
|
253
|
+
const end = elf.indexOf(0, nameAt);
|
|
254
|
+
const name = elf.toString("latin1", nameAt, end);
|
|
255
|
+
if (name)
|
|
256
|
+
out.push(name);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return out;
|
|
118
260
|
}
|
|
119
261
|
/**
|
|
120
262
|
* The toolchain this release is tested with: CI installs exactly this Agave CLI and platform-tools, and every
|
|
@@ -132,6 +274,68 @@ export const INSTALL_TESTED_TOOLCHAIN = [
|
|
|
132
274
|
`sh -c "$(curl -sSfL https://release.anza.xyz/v${TESTED_TOOLCHAIN.agave}/install)"`,
|
|
133
275
|
`cargo-build-sbf --install-only --force-tools-install --tools-version ${TESTED_TOOLCHAIN.platformTools}`,
|
|
134
276
|
];
|
|
277
|
+
/**
|
|
278
|
+
* The Agave installer adds its bin directory to PATH in ~/.profile only, which the shell that ran it does not read:
|
|
279
|
+
* without this line the next command is "cargo-build-sbf: command not found".
|
|
280
|
+
*/
|
|
281
|
+
export const AGAVE_PATH = 'export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"';
|
|
282
|
+
/**
|
|
283
|
+
* Linux arm64: Anza publishes no Agave CLI for it (its installer fails with a 404), but platform-tools has a
|
|
284
|
+
* linux-aarch64 package. The C SDK (headers and linker script, text) comes from the x86_64 Agave release, as in the
|
|
285
|
+
* --docker image, and TYPESOL_SBF_SDK points the compiler at the result. Building and LiteSVM tests work; deploying
|
|
286
|
+
* needs a Solana CLI from another host.
|
|
287
|
+
*/
|
|
288
|
+
const ARM64_SDK = "$HOME/.local/share/typesol-sdk";
|
|
289
|
+
/** A path under ARM64_SDK as a shell word: quoted, as AGAVE_PATH quotes $HOME, so a HOME with a space works. */
|
|
290
|
+
const arm64Path = (rest) => `"${ARM64_SDK}${rest}"`;
|
|
291
|
+
export const linuxArm64 = (host = process) => host.platform === "linux" && host.arch === "arm64";
|
|
292
|
+
export const LINUX_ARM64_INSTALL = [
|
|
293
|
+
`mkdir -p ${arm64Path("/sbf/dependencies/platform-tools")}`,
|
|
294
|
+
`curl -sSfL https://github.com/anza-xyz/agave/releases/download/v${TESTED_TOOLCHAIN.agave}/solana-release-x86_64-unknown-linux-gnu.tar.bz2 | tar -xj -C ${arm64Path("")} --strip-components=3 solana-release/bin/platform-tools-sdk/sbf/c`,
|
|
295
|
+
`curl -sSfL https://github.com/anza-xyz/platform-tools/releases/download/${TESTED_TOOLCHAIN.platformTools}/platform-tools-linux-aarch64.tar.bz2 | tar -xj -C ${arm64Path("/sbf/dependencies/platform-tools")}`,
|
|
296
|
+
`touch ${arm64Path(`/sbf/dependencies/platform-tools-${TESTED_TOOLCHAIN.platformTools}.md`)}`,
|
|
297
|
+
`export TYPESOL_SBF_SDK=${arm64Path("/sbf")}`,
|
|
298
|
+
];
|
|
299
|
+
/**
|
|
300
|
+
* What to run to get the tested toolchain on this host: from nothing ("agave"), or when the Agave CLI is there and
|
|
301
|
+
* its platform-tools are not. `cargo-build-sbf --version` downloads nothing and `cargo-build-sbf --force-tools-install`
|
|
302
|
+
* alone needs a Cargo project; only `--install-only` installs the platform-tools by themselves.
|
|
303
|
+
*/
|
|
304
|
+
export function installCommands(from, host = process) {
|
|
305
|
+
if (linuxArm64(host))
|
|
306
|
+
return [...LINUX_ARM64_INSTALL];
|
|
307
|
+
return from === "agave" ? [INSTALL_TESTED_TOOLCHAIN[0], AGAVE_PATH, INSTALL_TESTED_TOOLCHAIN[1]] : [INSTALL_TESTED_TOOLCHAIN[1]];
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* The note printed on its own line above an install command, when what it does is not obvious; undefined for the
|
|
311
|
+
* others. A note is a `#` line holding no character a shell treats specially (no parentheses, `;`, `$`, quotes,
|
|
312
|
+
* `<`, `>`, `|`, `&`, `!`, `*`, `?`, brackets or braces), so a pasted block runs the same: bash and fish skip it as
|
|
313
|
+
* a comment, and zsh, whose interactive shells do not read comments unless `interactive_comments` is set (the macOS
|
|
314
|
+
* default), answers "command not found: #" and runs nothing from that line. A command line never carries a trailing
|
|
315
|
+
* comment: zsh would hand it to the command as arguments (test/cli/doctor.test.ts pastes the blocks into each shell).
|
|
316
|
+
*/
|
|
317
|
+
export function installNote(command) {
|
|
318
|
+
if (command === AGAVE_PATH)
|
|
319
|
+
return "# The installer adds this line to ~/.profile for new shells, and this shell needs it now:";
|
|
320
|
+
if (command === INSTALL_TESTED_TOOLCHAIN[1])
|
|
321
|
+
return "# Once: this downloads the platform-tools, about 0.5 GB and up to 1.6 GB unpacked, and prints nothing for a minute or two:";
|
|
322
|
+
if (command.startsWith("export TYPESOL_SBF_SDK="))
|
|
323
|
+
return "# Add this line to ~/.profile too, for new shells:";
|
|
324
|
+
if (command.includes("/platform-tools-linux-aarch64."))
|
|
325
|
+
return "# About 515 MB, 1.6 GB unpacked, and quiet for a minute or two:";
|
|
326
|
+
if (command.includes("/solana-release-"))
|
|
327
|
+
return "# About 215 MB, for the C headers and linker script of the SDK only:";
|
|
328
|
+
return undefined;
|
|
329
|
+
}
|
|
330
|
+
/** installCommands with each command's note on the line above it: the lines `init`, `doctor` and the build print. */
|
|
331
|
+
export function installLines(from, host = process) {
|
|
332
|
+
return installCommands(from, host).flatMap((c) => {
|
|
333
|
+
const note = installNote(c);
|
|
334
|
+
return note ? [note, c] : [c];
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
/** An install block inside an error message: each line on its own, indented, after the sentence that ends with ":". */
|
|
338
|
+
const block = (lines) => lines.map((l) => `\n ${l}`).join("");
|
|
135
339
|
// One `clang --version` per clang a process uses: up-to-date checks and manifests ask for it on every build.
|
|
136
340
|
const clangVersions = new Map();
|
|
137
341
|
/** The clang version string (the first line of `clang --version`), for build manifests. */
|
|
@@ -181,14 +385,15 @@ export function toolchainInfo(tc = findToolchain()) {
|
|
|
181
385
|
return { clang, platformTools: platformToolsVersion(tc), tested: clang === TESTED_TOOLCHAIN.clang };
|
|
182
386
|
}
|
|
183
387
|
/** What to say about a toolchain that is not the tested one; undefined for the tested one. */
|
|
184
|
-
export function untestedToolchainMessage(info) {
|
|
388
|
+
export function untestedToolchainMessage(info, strict = false) {
|
|
185
389
|
if (info.tested)
|
|
186
390
|
return undefined;
|
|
187
391
|
const t = TESTED_TOOLCHAIN;
|
|
188
|
-
return (
|
|
392
|
+
return (`${strict ? "refusing to build with" : "this build uses"} ${shortClang(info.clang)}${info.platformTools ? ` (platform-tools ${info.platformTools})` : ""}; ` +
|
|
189
393
|
`TypeSOL is tested with ${shortClang(t.clang)} (platform-tools ${t.platformTools}, Agave ${t.agave}). ` +
|
|
190
|
-
`Binaries from an untested toolchain are not covered by the project's tests
|
|
191
|
-
|
|
394
|
+
`Binaries from an untested toolchain are not covered by the project's tests` +
|
|
395
|
+
(strict ? ", and an untested toolchain is an error with --toolchain-strict or TYPESOL_TOOLCHAIN=strict" : "") +
|
|
396
|
+
`. Install the tested one:${block([INSTALL_TESTED_TOOLCHAIN[1]])}`);
|
|
192
397
|
}
|
|
193
398
|
let strictFlag = false;
|
|
194
399
|
let warned = false;
|
|
@@ -212,7 +417,7 @@ export function checkToolchain(info = toolchainInfo(), warn = (m) => console.err
|
|
|
212
417
|
if (!message)
|
|
213
418
|
return info;
|
|
214
419
|
if (toolchainStrict())
|
|
215
|
-
throw new Error(
|
|
420
|
+
throw new Error(untestedToolchainMessage(info, true));
|
|
216
421
|
if (!warned) {
|
|
217
422
|
warned = true;
|
|
218
423
|
warn(message);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The oldest Node.js the CLI runs on (package.json "engines"). */
|
|
2
|
+
export declare const MIN_NODE: readonly [22, 12];
|
|
3
|
+
/** The one line to print when `version` (process.versions.node) is too old, or undefined when it is new enough. */
|
|
4
|
+
export declare function nodeVersionProblem(version: string): string | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// The Node.js check the CLI runs before it loads anything else: on an older Node the compiler or its dependencies
|
|
2
|
+
// fail later with errors that do not say why (npm crashing during an install, `Map.groupBy is not a function`).
|
|
3
|
+
// No imports here, so nothing can fail before the check.
|
|
4
|
+
/** The oldest Node.js the CLI runs on (package.json "engines"). */
|
|
5
|
+
export const MIN_NODE = [22, 12];
|
|
6
|
+
/** The one line to print when `version` (process.versions.node) is too old, or undefined when it is new enough. */
|
|
7
|
+
export function nodeVersionProblem(version) {
|
|
8
|
+
const [major = 0, minor = 0] = version.split(".").map(Number);
|
|
9
|
+
if (major > MIN_NODE[0] || (major === MIN_NODE[0] && minor >= MIN_NODE[1]))
|
|
10
|
+
return undefined;
|
|
11
|
+
return `error: TypeSOL needs Node.js ${MIN_NODE.join(".")} or later, and this is Node.js ${version}. Install a newer one from https://nodejs.org (or \`nvm install 22\` with nvm), then run the command again.`;
|
|
12
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { BuildManifest, ContainerIdentity, Sbpf } from "../compiler/index.js";
|
|
2
|
+
export declare const DOCKER_PLATFORM = "linux/amd64";
|
|
3
|
+
export declare const DOCKERFILE: string;
|
|
4
|
+
/** The release records the package ships (releases/<version>.json): the TypeSOL versions an image can install. */
|
|
5
|
+
export declare const RELEASES_DIR: string;
|
|
6
|
+
/**
|
|
7
|
+
* The dependency locks the package ships (docker/deps/<version>.lock.json): for each TypeSOL version, the npm lockfile
|
|
8
|
+
* of its runtime dependencies, which the image installs with `npm ci` (every package checked against its integrity).
|
|
9
|
+
* The lock of version N ships in package N (it does not contain N's own tarball); a version newer than the package
|
|
10
|
+
* carries its own, checked with the rest of its tarball against the release record.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEPS_DIR: string;
|
|
13
|
+
/** Docker is missing or failed: the message says what to do. Never answered by building locally instead. */
|
|
14
|
+
export declare class DockerError extends Error {
|
|
15
|
+
}
|
|
16
|
+
export type DockerStatus = {
|
|
17
|
+
ok: true;
|
|
18
|
+
version: string;
|
|
19
|
+
platform: string;
|
|
20
|
+
} | {
|
|
21
|
+
ok: false;
|
|
22
|
+
reason: string;
|
|
23
|
+
fix: string;
|
|
24
|
+
};
|
|
25
|
+
/** Whether `docker` is there and its daemon answers. */
|
|
26
|
+
export declare function dockerStatus(): DockerStatus;
|
|
27
|
+
/** Throws a DockerError with the fix when Docker cannot run builds. */
|
|
28
|
+
export declare function needDocker(): void;
|
|
29
|
+
/** The pinned inputs a Dockerfile names: its base images (FROM …@sha256:…) and its checksummed downloads (ADD --checksum). */
|
|
30
|
+
export declare function dockerfileInputs(text: string): {
|
|
31
|
+
base: string[];
|
|
32
|
+
downloads: {
|
|
33
|
+
url: string;
|
|
34
|
+
sha256: string;
|
|
35
|
+
}[];
|
|
36
|
+
};
|
|
37
|
+
/** What `--docker` needs of a release record: the tarball's hashes and every file's sha256. */
|
|
38
|
+
export interface ReleaseRecord {
|
|
39
|
+
version: string;
|
|
40
|
+
commit: string;
|
|
41
|
+
tarball: {
|
|
42
|
+
shasum: string;
|
|
43
|
+
integrity: string;
|
|
44
|
+
};
|
|
45
|
+
files: {
|
|
46
|
+
path: string;
|
|
47
|
+
sha256: string;
|
|
48
|
+
}[];
|
|
49
|
+
}
|
|
50
|
+
/** The versions whose records ship with this package, oldest first. */
|
|
51
|
+
export declare function recordedVersions(dir?: string): string[];
|
|
52
|
+
/** Where a release record came from: this package, a file given with --release-record, or the repository's main branch. */
|
|
53
|
+
export interface RecordSource {
|
|
54
|
+
kind: "package" | "file" | "repository";
|
|
55
|
+
/** `releases/<version>.json` (in the package), the file as given, or the URL it was fetched from. */
|
|
56
|
+
location: string;
|
|
57
|
+
/** sha256 of the record's bytes, as read or served (what `sha256sum` of the file gives). */
|
|
58
|
+
sha256: string;
|
|
59
|
+
}
|
|
60
|
+
/** A release record, its bytes (what the image build checks the tarball against), and where it came from. */
|
|
61
|
+
export interface FoundRecord {
|
|
62
|
+
record: ReleaseRecord;
|
|
63
|
+
bytes: Buffer;
|
|
64
|
+
source: RecordSource;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Where a release's record is fetched from when this package does not ship it: the repository's main branch, where it
|
|
68
|
+
* is committed after the release is published (the package of version N cannot contain releases/N.json).
|
|
69
|
+
*/
|
|
70
|
+
export declare const RELEASES_URL = "https://raw.githubusercontent.com/typesol-lang/typesol/main/releases";
|
|
71
|
+
/** The fetch a record lookup uses (tests pass their own: no network). */
|
|
72
|
+
export type FetchText = (url: string, init: {
|
|
73
|
+
signal: AbortSignal;
|
|
74
|
+
}) => Promise<{
|
|
75
|
+
ok: boolean;
|
|
76
|
+
status: number;
|
|
77
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* The release record of `version`: `file` (`--release-record`, e.g. releases/<version>.json from the repository), or
|
|
81
|
+
* the one this package ships. A version without one is refused: its tarball could not be checked. (findReleaseRecord
|
|
82
|
+
* also fetches a newer release's record from the repository.)
|
|
83
|
+
*/
|
|
84
|
+
export declare function releaseRecord(version: string, file?: string, dir?: string): FoundRecord;
|
|
85
|
+
/**
|
|
86
|
+
* The release record of `version` for a container build: `file` when given, else the package's, else (a release newer
|
|
87
|
+
* than this package, whose record was committed after the package was published) releases/<version>.json fetched from
|
|
88
|
+
* the repository's main branch over HTTPS. The check then rests on two independent sources agreeing: the tarball npm
|
|
89
|
+
* serves and the record the repository holds. Offline, or when the repository has no record for the version, it is an
|
|
90
|
+
* error that names --release-record. Where the record came from goes to `log` and into the build's manifest.
|
|
91
|
+
*/
|
|
92
|
+
export declare function findReleaseRecord(version: string, opts?: {
|
|
93
|
+
file?: string;
|
|
94
|
+
dir?: string;
|
|
95
|
+
fetch?: FetchText;
|
|
96
|
+
log?: (s: string) => void;
|
|
97
|
+
timeoutMs?: number;
|
|
98
|
+
}): Promise<FoundRecord>;
|
|
99
|
+
/**
|
|
100
|
+
* The TypeSOL version a container build uses: `--typesol-version`, else the version of the deployed build's manifest
|
|
101
|
+
* (verify), else this CLI's. A project that installs another typesol than the CLI that runs is an error rather than a
|
|
102
|
+
* guess: the project's own (`npx --no-install typesol`) is the one its builds were made with.
|
|
103
|
+
*/
|
|
104
|
+
export declare function chooseTypesolVersion(opts: {
|
|
105
|
+
given?: string;
|
|
106
|
+
deployed?: {
|
|
107
|
+
version: string;
|
|
108
|
+
from: string;
|
|
109
|
+
};
|
|
110
|
+
projectRoot?: string;
|
|
111
|
+
cliVersion: string;
|
|
112
|
+
}): {
|
|
113
|
+
version: string;
|
|
114
|
+
why: string;
|
|
115
|
+
};
|
|
116
|
+
/** The image a container build runs in, and what to record about it. */
|
|
117
|
+
export interface BuildImage {
|
|
118
|
+
tag: string;
|
|
119
|
+
identity: ContainerIdentity;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The dependency lock of `version`'s image: this package's docker/deps/<version>.lock.json, else the one in that
|
|
123
|
+
* version's own tarball, whose sha256 the release record lists (the image takes it from the checked tarball). Neither:
|
|
124
|
+
* a DockerError, as the image would have to resolve the dependencies unpinned.
|
|
125
|
+
*/
|
|
126
|
+
export declare function dependencyLock(record: ReleaseRecord, dir?: string): {
|
|
127
|
+
bytes?: Buffer;
|
|
128
|
+
lock: NonNullable<ContainerIdentity["deps"]>;
|
|
129
|
+
};
|
|
130
|
+
/** The versions whose dependency locks ship with this package. */
|
|
131
|
+
export declare function lockedVersions(dir?: string): string[];
|
|
132
|
+
/** sha256 of a record's file list (path and sha256 of each, in order): one label for "every file as recorded". */
|
|
133
|
+
export declare function filesDigest(record: ReleaseRecord): string;
|
|
134
|
+
/**
|
|
135
|
+
* The labels an image is built with: everything the image build checked. A cached image is used only when all of
|
|
136
|
+
* them are this record's and this lock's.
|
|
137
|
+
*/
|
|
138
|
+
export declare function imageLabels(dockerfileSha: string, record: ReleaseRecord, lockSha: string): Record<string, string>;
|
|
139
|
+
/**
|
|
140
|
+
* The image for `version`, built first when this machine has none (`typesol-build:<version>-<Dockerfile sha256>`).
|
|
141
|
+
* Progress goes to stderr. Building needs the network (base images, release files, npm); running it does not.
|
|
142
|
+
*/
|
|
143
|
+
export declare function ensureImage(version: string, found?: FoundRecord, log?: (s: string) => void): BuildImage;
|
|
144
|
+
/** One program to build in the container. Paths are the host's. */
|
|
145
|
+
export interface ContainerJob {
|
|
146
|
+
entry: string;
|
|
147
|
+
outDir: string;
|
|
148
|
+
address: string;
|
|
149
|
+
sbpf: Sbpf;
|
|
150
|
+
profile?: boolean;
|
|
151
|
+
}
|
|
152
|
+
export interface ContainerResult {
|
|
153
|
+
name: string;
|
|
154
|
+
soPath: string;
|
|
155
|
+
manifestPath: string;
|
|
156
|
+
manifest: BuildManifest;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Build `jobs` in the image: `root` mounted read-only (the only sources the container sees), each output directory
|
|
160
|
+
* writable, no network, a read-only root file system, no capabilities, the caller's uid and gid (containerUser). The files are
|
|
161
|
+
* the ones `build` writes; each manifest gets the container's identity.
|
|
162
|
+
*/
|
|
163
|
+
export declare function containerBuild(image: BuildImage, root: string, jobs: ContainerJob[]): ContainerResult[];
|
|
164
|
+
/**
|
|
165
|
+
* The user the container runs as: the caller's uid:gid, so that it can write the output directories the caller made
|
|
166
|
+
* and the outputs are the caller's. That is root (0:0) for a root caller, still without capabilities, with
|
|
167
|
+
* no-new-privileges and a read-only root file system. Where there is no uid (Windows), the image's `node` user.
|
|
168
|
+
*/
|
|
169
|
+
export declare function containerUser(ids?: {
|
|
170
|
+
uid?: number;
|
|
171
|
+
gid?: number;
|
|
172
|
+
}): string;
|
|
173
|
+
/** TYPESOL_DOCKER_CPUS / TYPESOL_DOCKER_MEMORY: limits for the build container on a shared machine. */
|
|
174
|
+
export declare function limits(): string[];
|
|
175
|
+
/** The git commit of a source directory and whether its files differ from it, when it is in a checkout. */
|
|
176
|
+
export declare function sourceRevision(dir: string): {
|
|
177
|
+
commit: string;
|
|
178
|
+
clean: boolean;
|
|
179
|
+
} | undefined;
|
|
180
|
+
/** The `typesol verify` command that repeats a container verify: the arguments and every option that changes the result. */
|
|
181
|
+
export declare function repeatCommand(args: string[], v: Record<string, unknown>, version: string): string;
|
|
182
|
+
/** Quote a command-line word for a POSIX shell when it needs it. */
|
|
183
|
+
export declare function shellQuote(s: string): string;
|