@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
package/dist/tools/doctor.js
CHANGED
|
@@ -5,12 +5,13 @@ import { execFileSync } from "node:child_process";
|
|
|
5
5
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
6
6
|
import os from "node:os";
|
|
7
7
|
import path from "node:path";
|
|
8
|
-
import { findToolchain, INSTALL_TESTED_TOOLCHAIN, shortClang, TESTED_TOOLCHAIN, toolchainInfo, toolchainStrict } from "../compiler/toolchain.js";
|
|
8
|
+
import { findToolchain, INSTALL_TESTED_TOOLCHAIN, installLines, linuxArm64, shortClang, TESTED_TOOLCHAIN, ToolchainMissing, toolchainInfo, toolchainStrict, } from "../compiler/toolchain.js";
|
|
9
9
|
import { base58, readKeypair } from "../keys.js";
|
|
10
|
+
import { DOCKER_PLATFORM, dockerStatus } from "./docker.js";
|
|
10
11
|
import { findWorkspace } from "../workspace.js";
|
|
12
|
+
import { MIN_NODE } from "../node-version.js";
|
|
11
13
|
/** The Agave CLI release TypeSOL is tested with (its platform-tools are the tested ones). */
|
|
12
14
|
export const INSTALL_AGAVE = INSTALL_TESTED_TOOLCHAIN[0];
|
|
13
|
-
const MIN_NODE = [22, 12];
|
|
14
15
|
/** The platform-tools the compiler needs: found, or what to run. */
|
|
15
16
|
export function toolchainCheck() {
|
|
16
17
|
try {
|
|
@@ -27,14 +28,21 @@ export function toolchainCheck() {
|
|
|
27
28
|
return { ok: true, what: "platform-tools", detail: version || tc.sdk };
|
|
28
29
|
}
|
|
29
30
|
catch (e) {
|
|
30
|
-
|
|
31
|
-
ok: false,
|
|
32
|
-
|
|
33
|
-
detail: e.message.split(". ")[0],
|
|
34
|
-
fix: [INSTALL_AGAVE, "cargo-build-sbf --version # once: downloads the platform-tools TypeSOL compiles with"],
|
|
35
|
-
};
|
|
31
|
+
if (!(e instanceof ToolchainMissing))
|
|
32
|
+
return { ok: false, what: "platform-tools", detail: e.message };
|
|
33
|
+
return { ok: false, what: "platform-tools", detail: e.summary, fix: installSteps(e.kind === "agave" ? "agave" : "platform-tools") };
|
|
36
34
|
}
|
|
37
35
|
}
|
|
36
|
+
/** The install commands for this host, each with its note on the line above when what it does is not obvious. */
|
|
37
|
+
export function installSteps(from, host = process) {
|
|
38
|
+
return installLines(from, host);
|
|
39
|
+
}
|
|
40
|
+
/** The Solana CLI (deploying only): the Agave installer, or on Linux arm64, where there is none, what to do instead. */
|
|
41
|
+
export function solanaCliFix(host = process) {
|
|
42
|
+
return linuxArm64(host)
|
|
43
|
+
? "no Agave CLI is published for Linux arm64: deploy from macOS or Linux x86_64, or build it from source (https://docs.anza.xyz/cli/install)"
|
|
44
|
+
: INSTALL_AGAVE;
|
|
45
|
+
}
|
|
38
46
|
/**
|
|
39
47
|
* Whether the active platform-tools are the ones TypeSOL is tested with. An untested one is a warning, or an error
|
|
40
48
|
* under TYPESOL_TOOLCHAIN=strict (as it is for a build then). Undefined when there are no platform-tools at all.
|
|
@@ -62,7 +70,17 @@ export function testedToolchainCheck() {
|
|
|
62
70
|
optional: !strict,
|
|
63
71
|
what: "toolchain",
|
|
64
72
|
detail: `untested: ${shortClang(info.clang)}, platform-tools ${info.platformTools ?? "unknown"}; TypeSOL is tested with ${tested} (Agave ${TESTED_TOOLCHAIN.agave}): binaries from another toolchain are not covered by its tests${strict ? " (TYPESOL_TOOLCHAIN=strict refuses it)" : ""}`,
|
|
65
|
-
fix: [
|
|
73
|
+
fix: ["# The tested platform-tools:", INSTALL_TESTED_TOOLCHAIN[1]],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Docker for `build --docker` / `verify --docker`: optional, a row either way. */
|
|
77
|
+
export function dockerCheck(status = dockerStatus()) {
|
|
78
|
+
if (!status.ok)
|
|
79
|
+
return { ok: false, optional: true, what: "docker", detail: `${status.reason}; needed only for --docker builds`, fix: [status.fix] };
|
|
80
|
+
return {
|
|
81
|
+
ok: true,
|
|
82
|
+
what: "docker",
|
|
83
|
+
detail: `${status.version} (${status.platform}): --docker builds run in ${DOCKER_PLATFORM}${status.platform === DOCKER_PLATFORM ? "" : ", emulated here"}`,
|
|
66
84
|
};
|
|
67
85
|
}
|
|
68
86
|
/** json_rpc_url / keypair_path from a Solana CLI config (the given file, or the CLI's default one). */
|
|
@@ -155,6 +173,61 @@ export async function cliRpc(url) {
|
|
|
155
173
|
const sol = (lamports) => lamports === 0 ? "0 SOL" : lamports < 100_000 ? `${lamports} lamports` : `${(lamports / 1e9).toFixed(lamports < 1e7 ? 4 : 2)} SOL`;
|
|
156
174
|
/** A cost, rounded up so the advice is enough. */
|
|
157
175
|
const solUp = (lamports) => `${(Math.ceil(lamports / 1e7) / 100).toFixed(2)} SOL`;
|
|
176
|
+
/**
|
|
177
|
+
* Whether a `--keypair` / `keypair_path` value is a signer the Solana CLI resolves itself rather than a file: `ASK`,
|
|
178
|
+
* `-` (stdin) or a `usb:`, `prompt:` or `stdin:` URI (`usb://ledger?key=0`, `prompt://`, `stdin://`; the scheme in any
|
|
179
|
+
* case, as the Solana CLI reads it). Anything else is a file: `file:` through keypairFile.
|
|
180
|
+
*/
|
|
181
|
+
export function isSignerUri(source) {
|
|
182
|
+
return source === "ASK" || source === "-" || /^(?:usb|prompt|stdin):/i.test(source);
|
|
183
|
+
}
|
|
184
|
+
/** The file a `--keypair` / `keypair_path` value names: the path of a `file:` URI (`file:id.json`, `file:///abs/id.json`), as the Solana CLI reads it, else the value. */
|
|
185
|
+
export function keypairFile(source) {
|
|
186
|
+
const m = /^file:(?:\/\/[^/?#]*)?([^?#]*)/i.exec(source);
|
|
187
|
+
return m ? m[1] : source;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* A deploy's payer keypair file must exist: without it `solana program deploy` refuses only after the build, mid-way.
|
|
191
|
+
* A signer URI (a Ledger, a prompt, stdin) is the Solana CLI's to resolve, so it is passed through unchecked.
|
|
192
|
+
*/
|
|
193
|
+
export function requirePayer(url, payer, source = { from: "default" }) {
|
|
194
|
+
if (isSignerUri(payer))
|
|
195
|
+
return;
|
|
196
|
+
const file = keypairFile(payer);
|
|
197
|
+
if (!file.trim()) {
|
|
198
|
+
if (source.from === "config")
|
|
199
|
+
throw new Error(`keypair_path in ${source.config.replace(os.homedir(), "~")} is empty: set it to the payer's keypair file, or pass --keypair <file>. Nothing was sent.`);
|
|
200
|
+
throw new Error("--keypair is empty: give the path of the payer's keypair file. Nothing was sent.");
|
|
201
|
+
}
|
|
202
|
+
if (existsSync(file))
|
|
203
|
+
return;
|
|
204
|
+
const shown = file.replace(os.homedir(), "~");
|
|
205
|
+
if (source.from === "flag")
|
|
206
|
+
throw new Error(`no keypair file at ${shown} (given with --keypair): check the path. Nothing was sent.`);
|
|
207
|
+
const cluster = clusterOf(url);
|
|
208
|
+
if (source.from === "config")
|
|
209
|
+
throw new Error(`no payer keypair at ${shown} (keypair_path in ${source.config.replace(os.homedir(), "~")}): create it with \`solana-keygen new --outfile ${shown}\`, or pass --keypair <file>` +
|
|
210
|
+
(cluster ? `; fund it with \`solana airdrop 2 --keypair ${shown} --url ${cluster}\`` : "") +
|
|
211
|
+
". Nothing was sent.");
|
|
212
|
+
throw new Error(`no payer keypair at ${shown}: create one with \`solana-keygen new\` (or pass --keypair <file>)` +
|
|
213
|
+
(cluster ? `, then fund it with \`solana airdrop 2 --url ${cluster}\`` : "") +
|
|
214
|
+
". Nothing was sent.");
|
|
215
|
+
}
|
|
216
|
+
/** `deploy` runs `solana program deploy`: without the Solana CLI on PATH it stops before building. */
|
|
217
|
+
export function requireSolanaCli() {
|
|
218
|
+
try {
|
|
219
|
+
execFileSync("solana", ["--version"], { stdio: "ignore" });
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
222
|
+
if (e.code !== "ENOENT")
|
|
223
|
+
return; // there, if unwell: its own run says why
|
|
224
|
+
throw new Error(solanaNotFound());
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/** The error for a missing `solana`, with how to get it on this host. */
|
|
228
|
+
export function solanaNotFound(host = process) {
|
|
229
|
+
return `\`solana\` was not found on PATH${linuxArm64(host) ? `: ${solanaCliFix(host)}` : `. Install the Agave CLI: ${solanaCliFix(host)}`}`;
|
|
230
|
+
}
|
|
158
231
|
/**
|
|
159
232
|
* Before `solana program deploy`: the RPC answers, and the payer holds enough for the program's rent (a first deploy
|
|
160
233
|
* holds about twice the binary's rent while the buffer exists; an upgrade, the buffer's). Throws with what to do.
|
|
@@ -171,9 +244,10 @@ export async function deployPreflight(opts) {
|
|
|
171
244
|
? "Start a local validator in another terminal: `solana-test-validator`, or deploy to devnet with --url devnet."
|
|
172
245
|
: "Check --url (or json_rpc_url in the Solana CLI config); for a test deploy use --url devnet or a local `solana-test-validator`."));
|
|
173
246
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
247
|
+
// A signer URI (a Ledger, a prompt) has no address to read here: the Solana CLI resolves it and reports a shortfall.
|
|
248
|
+
if (!opts.payer || isSignerUri(opts.payer) || !existsSync(keypairFile(opts.payer)))
|
|
249
|
+
return;
|
|
250
|
+
const payer = base58(readKeypair(keypairFile(opts.payer)).subarray(32));
|
|
177
251
|
let need = 0;
|
|
178
252
|
for (const p of opts.programs) {
|
|
179
253
|
const size = statSync(p.soPath).size;
|
|
@@ -215,7 +289,8 @@ export async function doctorChecks(opts) {
|
|
|
215
289
|
}
|
|
216
290
|
checks.push(solanaVersion
|
|
217
291
|
? { ok: true, what: "Solana CLI", detail: solanaVersion }
|
|
218
|
-
: { ok: false, optional: true, what: "Solana CLI", detail: "not on PATH (needed to deploy, not to build or test)", fix: [
|
|
292
|
+
: { ok: false, optional: true, what: "Solana CLI", detail: "not on PATH (needed to deploy, not to build or test)", fix: [solanaCliFix()] });
|
|
293
|
+
checks.push(dockerCheck());
|
|
219
294
|
const cfg = solanaConfig(opts.config);
|
|
220
295
|
const keypair = cfg.keypair ?? path.join(os.homedir(), ".config/solana/id.json");
|
|
221
296
|
if (existsSync(keypair)) {
|
|
@@ -270,7 +345,7 @@ export async function doctorChecks(opts) {
|
|
|
270
345
|
optional: true,
|
|
271
346
|
what: "RPC",
|
|
272
347
|
detail: `${rpcHost(url)} does not answer (${errText(e)})`,
|
|
273
|
-
fix: cluster === "localhost" ? ["
|
|
348
|
+
fix: cluster === "localhost" ? ["# In another terminal:", "solana-test-validator"] : ["pass --url devnet, or fix json_rpc_url in the Solana CLI config"],
|
|
274
349
|
});
|
|
275
350
|
}
|
|
276
351
|
}
|
|
@@ -280,6 +355,25 @@ export async function doctorChecks(opts) {
|
|
|
280
355
|
: { ok: true, optional: true, what: "project", detail: "none here (typesol init <dir> creates one)" });
|
|
281
356
|
return checks;
|
|
282
357
|
}
|
|
358
|
+
/** The last line of `doctor`: what is ready, and what the warnings are about. */
|
|
359
|
+
export function doctorSummary(checks) {
|
|
360
|
+
const list = (cs) => cs.map((c) => c.what).join(", ");
|
|
361
|
+
const failed = checks.filter((c) => !c.ok && !c.optional);
|
|
362
|
+
if (failed.length)
|
|
363
|
+
return `Not ready to build or test: fix the ERR rows (${list(failed)}) first.`;
|
|
364
|
+
const warned = checks.filter((c) => !c.ok);
|
|
365
|
+
const deploy = warned.filter((c) => ["Solana CLI", "keypair", "RPC", "balance"].includes(c.what));
|
|
366
|
+
const notes = [];
|
|
367
|
+
if (deploy.length)
|
|
368
|
+
notes.push(`deploying still needs: ${list(deploy)}`);
|
|
369
|
+
if (warned.some((c) => c.what === "docker"))
|
|
370
|
+
notes.push("Docker is only for --docker builds");
|
|
371
|
+
if (warned.some((c) => c.what === "toolchain"))
|
|
372
|
+
notes.push("the toolchain is not the tested one (builds work; their binaries are not covered by the tests)");
|
|
373
|
+
if (!notes.length)
|
|
374
|
+
return "Ready to build, test and deploy.";
|
|
375
|
+
return `Ready to build and test. The ! rows: ${notes.join("; ")}.`;
|
|
376
|
+
}
|
|
283
377
|
export function formatChecks(checks) {
|
|
284
378
|
const mark = (c) => (c.ok ? "ok " : c.optional ? " ! " : "ERR");
|
|
285
379
|
const width = Math.max(...checks.map((c) => c.what.length));
|
package/dist/workspace.d.ts
CHANGED
|
@@ -63,7 +63,8 @@ export interface BuiltProgram {
|
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* The program built for a test: the existing build when it is up to date (same sources, runtime header, TypeSOL,
|
|
66
|
-
* TypeScript, clang and platform-tools versions, host, SBPF version and address, not a --profile build, and the .so the manifest records
|
|
66
|
+
* TypeScript, clang and platform-tools versions, host, SBPF version and address, not a --profile build, and the .so the manifest records;
|
|
67
|
+
* for a `build --docker` build, the same sources, SBPF version and address and the .so it records, on any host),
|
|
67
68
|
* else a fresh one. Concurrent callers (parallel test workers) wait for each other instead of building over each other.
|
|
68
69
|
*/
|
|
69
70
|
export declare function buildForTest(ws: Workspace, name: string): BuiltProgram;
|
|
@@ -79,8 +80,15 @@ export declare function deployArgs(soPath: string, keypair: string, opts: {
|
|
|
79
80
|
payer?: string;
|
|
80
81
|
config?: string;
|
|
81
82
|
}): string[];
|
|
82
|
-
/**
|
|
83
|
-
export declare
|
|
83
|
+
/** The files `scaffold` writes for AI coding agents (left out with `agentFiles: false`, `init --no-agent-files`). */
|
|
84
|
+
export declare const AGENT_FILES: readonly ["AGENTS.md", "CLAUDE.md", ".cursor/rules/typesol.mdc", ".mcp.json", ".cursor/mcp.json"];
|
|
85
|
+
/**
|
|
86
|
+
* Create a project: typesol.json, one program from a template, its LiteSVM test, configs (editor settings included)
|
|
87
|
+
* and, unless `agentFiles` is false, the AGENT_FILES. Refuses to overwrite files.
|
|
88
|
+
*/
|
|
89
|
+
export declare function scaffold(dir: string, name: string, template?: TemplateName, opts?: {
|
|
90
|
+
agentFiles?: boolean;
|
|
91
|
+
}): string[];
|
|
84
92
|
/**
|
|
85
93
|
* Add a program to an existing project: programs/<name>.ts and tests/<name>.test.ts from a template, and its entry in
|
|
86
94
|
* typesol.json. Returns the files written and the template's extra devDependencies the package.json lacks.
|
package/dist/workspace.js
CHANGED
|
@@ -121,7 +121,8 @@ export function buildWorkspace(ws, names = Object.keys(ws.programs), opts = {})
|
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
123
123
|
* The program built for a test: the existing build when it is up to date (same sources, runtime header, TypeSOL,
|
|
124
|
-
* TypeScript, clang and platform-tools versions, host, SBPF version and address, not a --profile build, and the .so the manifest records
|
|
124
|
+
* TypeScript, clang and platform-tools versions, host, SBPF version and address, not a --profile build, and the .so the manifest records;
|
|
125
|
+
* for a `build --docker` build, the same sources, SBPF version and address and the .so it records, on any host),
|
|
125
126
|
* else a fresh one. Concurrent callers (parallel test workers) wait for each other instead of building over each other.
|
|
126
127
|
*/
|
|
127
128
|
export function buildForTest(ws, name) {
|
|
@@ -131,12 +132,26 @@ export function buildForTest(ws, name) {
|
|
|
131
132
|
const current = upToDateBuild(paths, address, ws.sbpf);
|
|
132
133
|
if (current)
|
|
133
134
|
return { ...current, rebuilt: false };
|
|
135
|
+
// A container build whose sources changed is out of date: the test builds locally over it, and says so.
|
|
136
|
+
if (hasContainerBuild(paths))
|
|
137
|
+
console.error(`note: ${path.relative(process.cwd(), paths.outDir) || "."} held a --docker build that is out of date (its sources, SBPF version or address changed); ` +
|
|
138
|
+
`the test builds it with the local toolchain: run \`typesol build --docker\` again before deploying`);
|
|
134
139
|
const result = build(paths.entry, paths.outDir, address, { sbpf: ws.sbpf });
|
|
135
140
|
writeClient(result.idl, path.join(paths.outDir, `${result.model.name}.client.ts`));
|
|
136
141
|
return { address, soPath: result.soPath, idl: result.idl, rebuilt: true };
|
|
137
142
|
});
|
|
138
143
|
}
|
|
139
144
|
const sha256 = (data) => createHash("sha256").update(data).digest("hex");
|
|
145
|
+
/** Whether the program's build manifest records a container (`build --docker`). */
|
|
146
|
+
function hasContainerBuild(paths) {
|
|
147
|
+
try {
|
|
148
|
+
const file = path.join(paths.outDir, `${path.basename(paths.entry).replace(/\.ts$/, "")}.build.json`);
|
|
149
|
+
return !!JSON.parse(readFileSync(file, "utf8")).container;
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
140
155
|
/** The existing build of a program if building it again would give the same files, else undefined. */
|
|
141
156
|
function upToDateBuild(paths, address, sbpf) {
|
|
142
157
|
// The compiler names a program's files after its entry file (programs/counter.ts → counter.so).
|
|
@@ -153,21 +168,33 @@ function upToDateBuild(paths, address, sbpf) {
|
|
|
153
168
|
catch {
|
|
154
169
|
return undefined;
|
|
155
170
|
}
|
|
156
|
-
if (manifest.
|
|
171
|
+
if (manifest.sbpf !== sbpf || manifest.profile)
|
|
157
172
|
return undefined;
|
|
158
173
|
if (idl.address !== address || !manifest.sources || typeof manifest.sources !== "object")
|
|
159
174
|
return undefined;
|
|
160
175
|
if (sha256(readFileSync(files.so)) !== manifest.binary)
|
|
161
176
|
return undefined;
|
|
177
|
+
// A `build --docker` build was made by the container's TypeSOL, TypeScript and toolchain, on its linux/x64: none of
|
|
178
|
+
// those is this machine's, so they are not compared. It is up to date while the program's sources are the ones it
|
|
179
|
+
// records (and its binary the one it records, above); a test never replaces it with a local build because of the
|
|
180
|
+
// host. Its runtime files are the container's TypeSOL version's: compared only when that is this version.
|
|
181
|
+
const container = !!manifest.container;
|
|
182
|
+
if (!container && (manifest.compiler !== COMPILER_VERSION || manifest.typescript !== ts.version))
|
|
183
|
+
return undefined;
|
|
162
184
|
const root = path.dirname(paths.entry);
|
|
163
185
|
for (const [rel, hash] of Object.entries(manifest.sources)) {
|
|
164
|
-
const
|
|
186
|
+
const runtime = rel.startsWith("<runtime>/");
|
|
187
|
+
if (runtime && container && manifest.compiler !== COMPILER_VERSION)
|
|
188
|
+
continue;
|
|
189
|
+
const file = runtime ? path.join(RUNTIME_DIR, rel.slice("<runtime>/".length)) : path.resolve(root, rel);
|
|
165
190
|
if (!existsSync(file) || sha256(readFileSync(file)) !== hash)
|
|
166
191
|
return undefined;
|
|
167
192
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
193
|
+
if (container)
|
|
194
|
+
return manifest.sources[path.basename(paths.entry)] ? { address, soPath: files.so, idl } : undefined;
|
|
195
|
+
// A new import changes the importing file, so every source of the current program is in the list; the runtime (its
|
|
196
|
+
// header and its builtins) and the entry must be there too (a manifest from another layout or an older release).
|
|
197
|
+
if (!manifest.sources["<runtime>/typesol_rt.h"] || !manifest.sources["<runtime>/typesol_builtins.c"] || !manifest.sources[path.basename(paths.entry)])
|
|
171
198
|
return undefined;
|
|
172
199
|
// A manifest from before 0.44.0 has no host: rebuild once to record the toolchain in full.
|
|
173
200
|
if (!manifest.host || manifest.host.os !== process.platform || manifest.host.arch !== process.arch)
|
|
@@ -289,8 +316,13 @@ export function deployArgs(soPath, keypair, opts) {
|
|
|
289
316
|
args.push("--keypair", opts.payer);
|
|
290
317
|
return args;
|
|
291
318
|
}
|
|
292
|
-
/**
|
|
293
|
-
export
|
|
319
|
+
/** The files `scaffold` writes for AI coding agents (left out with `agentFiles: false`, `init --no-agent-files`). */
|
|
320
|
+
export const AGENT_FILES = ["AGENTS.md", "CLAUDE.md", ".cursor/rules/typesol.mdc", ".mcp.json", ".cursor/mcp.json"];
|
|
321
|
+
/**
|
|
322
|
+
* Create a project: typesol.json, one program from a template, its LiteSVM test, configs (editor settings included)
|
|
323
|
+
* and, unless `agentFiles` is false, the AGENT_FILES. Refuses to overwrite files.
|
|
324
|
+
*/
|
|
325
|
+
export function scaffold(dir, name, template = "counter", opts = {}) {
|
|
294
326
|
const t = TEMPLATES[template];
|
|
295
327
|
if (!/^[a-z][a-z0-9_]*$/.test(name))
|
|
296
328
|
throw new Error(`program name "${name}" must be snake_case`);
|
|
@@ -362,9 +394,14 @@ export function scaffold(dir, name, template = "counter") {
|
|
|
362
394
|
include: ["tests/**/*.ts"],
|
|
363
395
|
}, null, 2) + "\n",
|
|
364
396
|
};
|
|
397
|
+
if (opts.agentFiles === false)
|
|
398
|
+
for (const f of AGENT_FILES)
|
|
399
|
+
delete files[f];
|
|
365
400
|
const existing = Object.keys(files).filter((f) => existsSync(path.join(dir, f)));
|
|
401
|
+
// An agent file in the way (a repository with its own AGENTS.md): the flag that leaves them out.
|
|
402
|
+
const agent = existing.some((f) => AGENT_FILES.includes(f));
|
|
366
403
|
if (existing.length)
|
|
367
|
-
throw new Error(`refusing to overwrite: ${existing.join(", ")}`);
|
|
404
|
+
throw new Error(`refusing to overwrite: ${existing.join(", ")}${agent ? " (--no-agent-files leaves out the files for AI coding agents)" : ""}`);
|
|
368
405
|
for (const [file, text] of Object.entries(files)) {
|
|
369
406
|
mkdirSync(path.dirname(path.join(dir, file)), { recursive: true });
|
|
370
407
|
writeFileSync(path.join(dir, file), text);
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# The pinned build environment of `typesol build --docker` and `typesol verify --docker` (docs/mainnet.md).
|
|
2
|
+
#
|
|
3
|
+
# Every input is pinned: the base images by digest, the Agave and platform-tools release files by sha256 (BuildKit
|
|
4
|
+
# refuses a download whose checksum differs), the TypeSOL package by its release record (releases/<version>.json,
|
|
5
|
+
# copied into the build context as release.json): the npm tarball's sha512 integrity and sha1 shasum, and every file's
|
|
6
|
+
# sha256; and its npm dependencies by their lock (docker/deps/<version>.lock.json, copied as deps.lock.json, or an empty
|
|
7
|
+
# deps.lock.json to take the one in the version's own tarball), which `npm ci` installs with every package's integrity
|
|
8
|
+
# checked. Anyone can build the same environment from this file (from the package's or the repository's root):
|
|
9
|
+
#
|
|
10
|
+
# mkdir ctx && cp docker/Dockerfile ctx/ && cp releases/0.44.1.json ctx/release.json && cp docker/deps/0.44.1.lock.json ctx/deps.lock.json
|
|
11
|
+
# docker build --platform linux/amd64 --build-arg TYPESOL_VERSION=0.44.1 -t typesol-build:0.44.1 ctx
|
|
12
|
+
#
|
|
13
|
+
# The image is not published anywhere: it is built locally from these inputs. Its image id can differ between machines
|
|
14
|
+
# (BuildKit and Docker versions, layer dates), so a build records this file's sha256 and the pinned inputs, which do
|
|
15
|
+
# not. Docker Engine 23 or later (BuildKit, with ADD --checksum and heredocs) builds it.
|
|
16
|
+
#
|
|
17
|
+
# The toolchain is the one TypeSOL is tested with (TESTED_TOOLCHAIN in src/compiler/toolchain.ts): Agave 3.1.10,
|
|
18
|
+
# platform-tools v1.52. Only the C SDK (headers and linker script, text) is taken from the Agave release; the compiler
|
|
19
|
+
# runs clang and ld.lld from platform-tools directly, so cargo-build-sbf and the Solana CLI are not installed.
|
|
20
|
+
#
|
|
21
|
+
# One architecture, linux/amd64, on every machine (emulated on arm64 hosts), so that the environment is one recipe.
|
|
22
|
+
# From TypeSOL 0.45.0 on the programs measured build to the same bytes on macOS arm64, Linux arm64 and Linux x86_64
|
|
23
|
+
# too (76 for SBPF v0, 14 for v1 and v2; CI checks a set of them on every change); 0.44.1 and earlier linked the
|
|
24
|
+
# platform-tools compiler-builtins library, which each host package lays out differently, so a program with 128-bit
|
|
25
|
+
# or signed division got other bytes from each (docs/stability.md has both measurements). Every base image below is
|
|
26
|
+
# pinned by its linux/amd64 manifest digest, not by a multi-platform index.
|
|
27
|
+
|
|
28
|
+
# Unpacking: busybox's tar reads .tar.bz2, which the slim Node image cannot without installing bzip2.
|
|
29
|
+
FROM busybox:1.37.0-glibc@sha256:66a6306db78bf2dbf3487f293aa8d6990d8e506fdffab9cc43fe422becf886e4 AS sdk
|
|
30
|
+
ADD --checksum=sha256:a7205ff29bcf0f7199740225ecae2b85a28ea9668892d5ec21bd9749882984a1 \
|
|
31
|
+
https://github.com/anza-xyz/agave/releases/download/v3.1.10/solana-release-x86_64-unknown-linux-gnu.tar.bz2 /dl/agave.tar.bz2
|
|
32
|
+
RUN mkdir /out && tar -xjf /dl/agave.tar.bz2 -C /out solana-release/bin/platform-tools-sdk/sbf/c && rm /dl/agave.tar.bz2
|
|
33
|
+
|
|
34
|
+
FROM busybox:1.37.0-glibc@sha256:66a6306db78bf2dbf3487f293aa8d6990d8e506fdffab9cc43fe422becf886e4 AS platform-tools
|
|
35
|
+
ADD --checksum=sha256:8b3861e93daf085ec12b65c4fac374d9bec4587a3de16871da6b08ab0c1d907e \
|
|
36
|
+
https://github.com/anza-xyz/platform-tools/releases/download/v1.52/platform-tools-linux-x86_64.tar.bz2 /dl/platform-tools.tar.bz2
|
|
37
|
+
RUN mkdir -p /out/platform-tools && tar -xjf /dl/platform-tools.tar.bz2 -C /out/platform-tools && rm /dl/platform-tools.tar.bz2
|
|
38
|
+
|
|
39
|
+
# Node 24 (a supported line, engines >=22.12) on Debian bookworm.
|
|
40
|
+
FROM node:24.22.2-bookworm-slim@sha256:c0a93797ee78814ae6d32fcca2561fdbbe423149c3f5389aad32d86e9fd85bd4
|
|
41
|
+
|
|
42
|
+
# The layout cargo-build-sbf makes (platform-tools-sdk/sbf, its dependencies/platform-tools link into the versioned
|
|
43
|
+
# cache and the empty platform-tools-v1.52.md marker), so the compiler finds the SDK and reports the version.
|
|
44
|
+
COPY --from=sdk /out/solana-release/bin/platform-tools-sdk/sbf/c /opt/solana/platform-tools-sdk/sbf/c
|
|
45
|
+
COPY --from=platform-tools /out/platform-tools /opt/solana/v1.52/platform-tools
|
|
46
|
+
RUN test "$(uname -m)" = x86_64 || { echo "this image is linux/amd64 only (docker build --platform linux/amd64)" >&2; exit 1; } \
|
|
47
|
+
&& mkdir -p /opt/solana/platform-tools-sdk/sbf/dependencies \
|
|
48
|
+
&& ln -s /opt/solana/v1.52/platform-tools /opt/solana/platform-tools-sdk/sbf/dependencies/platform-tools \
|
|
49
|
+
&& touch /opt/solana/platform-tools-sdk/sbf/dependencies/platform-tools-v1.52.md \
|
|
50
|
+
&& /opt/solana/v1.52/platform-tools/llvm/bin/clang --version | head -1
|
|
51
|
+
ENV TYPESOL_SBF_SDK=/opt/solana/platform-tools-sdk/sbf
|
|
52
|
+
|
|
53
|
+
# The tarball check: the tarball npm serves for TYPESOL_VERSION must be the one release.json records, byte for byte
|
|
54
|
+
# (sha512 integrity and sha1 shasum), and each file in it must have the recorded sha256.
|
|
55
|
+
COPY <<'EOF' /opt/typesol/check-tarball.mjs
|
|
56
|
+
import { createHash } from "node:crypto";
|
|
57
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
58
|
+
import path from "node:path";
|
|
59
|
+
const [record, tgz, unpacked, version] = process.argv.slice(2);
|
|
60
|
+
const r = JSON.parse(readFileSync(record, "utf8"));
|
|
61
|
+
const fail = (m) => {
|
|
62
|
+
console.error(`typesol tarball check: ${m}`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
};
|
|
65
|
+
if (r.version !== version) fail(`release.json is the record of ${r.version}, not ${version}`);
|
|
66
|
+
const data = readFileSync(tgz);
|
|
67
|
+
const integrity = `sha512-${createHash("sha512").update(data).digest("base64")}`;
|
|
68
|
+
const shasum = createHash("sha1").update(data).digest("hex");
|
|
69
|
+
if (integrity !== r.tarball.integrity) fail(`integrity ${integrity}, the record has ${r.tarball.integrity}`);
|
|
70
|
+
if (shasum !== r.tarball.shasum) fail(`shasum ${shasum}, the record has ${r.tarball.shasum}`);
|
|
71
|
+
const walk = (d) => readdirSync(d).flatMap((f) => (statSync(path.join(d, f)).isDirectory() ? walk(path.join(d, f)) : [path.join(d, f)]));
|
|
72
|
+
const files = new Map(walk(unpacked).map((f) => [path.relative(unpacked, f), createHash("sha256").update(readFileSync(f)).digest("hex")]));
|
|
73
|
+
for (const f of r.files) if (files.get(f.path) !== f.sha256) fail(`${f.path}: sha256 ${files.get(f.path) ?? "missing"}, the record has ${f.sha256}`);
|
|
74
|
+
if (files.size !== r.files.length) fail(`the tarball has ${files.size} files, the record ${r.files.length}`);
|
|
75
|
+
console.log(`typesol tarball check: @typesol/cli@${version} ${shasum}, ${files.size} files as recorded (the record names commit ${r.commit})`);
|
|
76
|
+
EOF
|
|
77
|
+
|
|
78
|
+
# The script a container build runs: the given programs built with this image's TypeSOL, through its public API
|
|
79
|
+
# (typesol/compiler and typesol/client, there since before 0.43.0), so one recipe serves every recorded version.
|
|
80
|
+
COPY <<'EOF' /opt/typesol/container-build.mjs
|
|
81
|
+
const root = "/opt/typesol/node_modules/@typesol/cli";
|
|
82
|
+
const { build } = await import(`${root}/dist/compiler/index.js`);
|
|
83
|
+
const { writeClient } = await import(`${root}/dist/tools/clientgen.js`);
|
|
84
|
+
const path = await import("node:path");
|
|
85
|
+
const results = [];
|
|
86
|
+
for (const j of JSON.parse(process.argv[2])) {
|
|
87
|
+
try {
|
|
88
|
+
const res = build(j.entry, j.out, j.address, { sbpf: j.sbpf, profile: j.profile });
|
|
89
|
+
writeClient(res.idl, path.join(j.out, `${res.model.name}.client.ts`));
|
|
90
|
+
results.push({ name: res.model.name, so: res.soPath, manifest: res.manifestPath });
|
|
91
|
+
} catch (e) {
|
|
92
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
console.log(`TYPESOL_RESULT ${JSON.stringify(results)}`);
|
|
97
|
+
EOF
|
|
98
|
+
|
|
99
|
+
# The dependency install: the npm lockfile of the TypeSOL version's runtime dependencies (docker/deps/<version>.lock.json),
|
|
100
|
+
# from the build context when the running package ships it, else from the version's own tarball, checked above. When
|
|
101
|
+
# both are there they must be the same bytes. The lock must describe exactly the dependencies the tarball's
|
|
102
|
+
# package.json declares, and every package in it must come from the npm registry with an integrity value, which
|
|
103
|
+
# `npm ci` then checks each download against: nothing is resolved at build time.
|
|
104
|
+
COPY <<'EOF' /opt/typesol/install-deps.mjs
|
|
105
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
106
|
+
const [given, unpacked, version, out] = process.argv.slice(2);
|
|
107
|
+
const fail = (m) => {
|
|
108
|
+
console.error(`typesol dependency lock: ${m}`);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
};
|
|
111
|
+
const rel = `docker/deps/${version}.lock.json`;
|
|
112
|
+
const fromContext = existsSync(given) && readFileSync(given).length ? readFileSync(given) : undefined;
|
|
113
|
+
const fromTarball = existsSync(`${unpacked}/${rel}`) ? readFileSync(`${unpacked}/${rel}`) : undefined;
|
|
114
|
+
if (fromContext && fromTarball && !fromContext.equals(fromTarball)) fail(`the package's ${rel} and the tarball's differ`);
|
|
115
|
+
const bytes = fromContext ?? fromTarball;
|
|
116
|
+
if (!bytes) fail(`no ${rel}, in the build context or in the tarball`);
|
|
117
|
+
const lock = JSON.parse(bytes.toString("utf8"));
|
|
118
|
+
if (lock.lockfileVersion !== 3) fail(`lockfileVersion ${lock.lockfileVersion}, expected 3`);
|
|
119
|
+
const root = lock.packages?.[""];
|
|
120
|
+
const declared = JSON.parse(readFileSync(`${unpacked}/package.json`, "utf8")).dependencies ?? {};
|
|
121
|
+
const canonical = (o) => JSON.stringify(Object.keys(o ?? {}).sort().map((k) => [k, o[k]]));
|
|
122
|
+
if (canonical(root?.dependencies) !== canonical(declared)) fail(`the lock is for ${canonical(root?.dependencies)}, the package declares ${canonical(declared)}`);
|
|
123
|
+
const entries = Object.entries(lock.packages).filter(([p]) => p !== "");
|
|
124
|
+
for (const [p, e] of entries) {
|
|
125
|
+
if (e.link) fail(`${p} is a link`);
|
|
126
|
+
if (!/^https:\/\/registry\.npmjs\.org\//.test(e.resolved ?? "")) fail(`${p} resolves to ${e.resolved ?? "nothing"}, not the npm registry`);
|
|
127
|
+
if (!/^sha512-/.test(e.integrity ?? "")) fail(`${p} has no sha512 integrity`);
|
|
128
|
+
}
|
|
129
|
+
writeFileSync(`${out}/package-lock.json`, bytes);
|
|
130
|
+
writeFileSync(`${out}/package.json`, JSON.stringify({ name: root.name, version: root.version, private: true, dependencies: root.dependencies }, null, 2) + "\n");
|
|
131
|
+
console.log(`typesol dependency lock: ${rel} (${fromContext ? "the package's" : "the tarball's"}), ${entries.length} packages, each with its integrity`);
|
|
132
|
+
EOF
|
|
133
|
+
|
|
134
|
+
ARG TYPESOL_VERSION
|
|
135
|
+
COPY release.json deps.lock.json /opt/typesol/ctx/
|
|
136
|
+
# The TypeSOL tarball, checked against the release record, then its dependencies with `npm ci` from the lock (npm checks
|
|
137
|
+
# every package's integrity; no install scripts run), then the checked files moved to node_modules/@typesol/cli
|
|
138
|
+
# without a second resolution.
|
|
139
|
+
RUN test -n "$TYPESOL_VERSION" || { echo "--build-arg TYPESOL_VERSION=<version> is required" >&2; exit 1; } \
|
|
140
|
+
&& mkdir -p /tmp/typesol/unpacked && cd /tmp/typesol \
|
|
141
|
+
&& npm pack "@typesol/cli@${TYPESOL_VERSION}" --pack-destination /tmp/typesol --silent \
|
|
142
|
+
&& tar -xzf "typesol-cli-${TYPESOL_VERSION}.tgz" -C unpacked --strip-components=1 \
|
|
143
|
+
&& node /opt/typesol/check-tarball.mjs /opt/typesol/ctx/release.json "typesol-cli-${TYPESOL_VERSION}.tgz" unpacked "$TYPESOL_VERSION" \
|
|
144
|
+
&& node /opt/typesol/install-deps.mjs /opt/typesol/ctx/deps.lock.json unpacked "$TYPESOL_VERSION" /opt/typesol \
|
|
145
|
+
&& cd /opt/typesol \
|
|
146
|
+
&& npm ci --omit=peer --omit=optional --ignore-scripts --no-audit --no-fund --silent \
|
|
147
|
+
&& mkdir -p /opt/typesol/node_modules/@typesol \
|
|
148
|
+
&& mv /tmp/typesol/unpacked /opt/typesol/node_modules/@typesol/cli \
|
|
149
|
+
&& chmod 755 /opt/typesol/node_modules/@typesol/cli/dist/cli.js \
|
|
150
|
+
&& ln -s /opt/typesol/node_modules/@typesol/cli/dist/cli.js /usr/local/bin/typesol \
|
|
151
|
+
&& rm -rf /tmp/typesol /root/.npm \
|
|
152
|
+
&& typesol --version
|
|
153
|
+
|
|
154
|
+
LABEL org.opencontainers.image.title="typesol-build" \
|
|
155
|
+
org.opencontainers.image.description="TypeSOL ${TYPESOL_VERSION} with Agave 3.1.10 platform-tools v1.52, built from pinned inputs" \
|
|
156
|
+
org.opencontainers.image.source="https://github.com/typesol-lang/typesol" \
|
|
157
|
+
org.typesol.version="${TYPESOL_VERSION}"
|
|
158
|
+
|
|
159
|
+
# A build runs as the caller's uid and gid (passed by the CLI; this user where there is none), without network or
|
|
160
|
+
# capabilities, on a read-only root file system; HOME points at the writable /tmp.
|
|
161
|
+
USER node
|
|
162
|
+
ENV HOME=/tmp
|
|
163
|
+
WORKDIR /src
|