@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.
Files changed (80) hide show
  1. package/CHANGELOG.md +343 -0
  2. package/NOTICE +14 -1
  3. package/README.md +115 -26
  4. package/SECURITY.md +10 -8
  5. package/dist/bin.d.ts +2 -0
  6. package/dist/bin.js +9 -0
  7. package/dist/cli.js +226 -62
  8. package/dist/compiler/analyze.js +57 -6
  9. package/dist/compiler/diagnostics.d.ts +4 -3
  10. package/dist/compiler/diagnostics.js +10 -6
  11. package/dist/compiler/emit/base.d.ts +1 -1
  12. package/dist/compiler/emit/calls.js +18 -5
  13. package/dist/compiler/emit/cpi-core.d.ts +3 -1
  14. package/dist/compiler/emit/cpi-core.js +8 -4
  15. package/dist/compiler/emit/expressions.d.ts +14 -0
  16. package/dist/compiler/emit/expressions.js +52 -4
  17. package/dist/compiler/emit/shared.d.ts +8 -1
  18. package/dist/compiler/emit/shared.js +8 -1
  19. package/dist/compiler/emit/statements.d.ts +8 -3
  20. package/dist/compiler/emit/statements.js +68 -3
  21. package/dist/compiler/emit/storage.js +5 -1
  22. package/dist/compiler/hints.d.ts +7 -0
  23. package/dist/compiler/hints.js +58 -9
  24. package/dist/compiler/index.d.ts +56 -1
  25. package/dist/compiler/index.js +27 -3
  26. package/dist/compiler/model.js +3 -2
  27. package/dist/compiler/toolchain.d.ts +73 -2
  28. package/dist/compiler/toolchain.js +222 -17
  29. package/dist/node-version.d.ts +4 -0
  30. package/dist/node-version.js +12 -0
  31. package/dist/tools/docker.d.ts +183 -0
  32. package/dist/tools/docker.js +442 -0
  33. package/dist/tools/doctor.d.ts +44 -0
  34. package/dist/tools/doctor.js +108 -14
  35. package/dist/workspace.d.ts +11 -3
  36. package/dist/workspace.js +46 -9
  37. package/docker/Dockerfile +163 -0
  38. package/docker/deps/0.43.0.lock.json +1206 -0
  39. package/docker/deps/0.44.0.lock.json +1206 -0
  40. package/docker/deps/0.44.1.lock.json +1206 -0
  41. package/docker/deps/0.45.0.lock.json +1206 -0
  42. package/docker/deps/0.46.0.lock.json +1206 -0
  43. package/docs/ai.md +2 -1
  44. package/docs/architecture.md +18 -6
  45. package/docs/audit.md +15 -7
  46. package/docs/case-study-phoenix.md +1 -1
  47. package/docs/case-study-raydium-amm.md +1 -1
  48. package/docs/case-study-spl-stake-pool.md +1 -1
  49. package/docs/cli.md +71 -6
  50. package/docs/errors.md +22 -8
  51. package/docs/glossary.md +210 -0
  52. package/docs/language-accounts.md +499 -0
  53. package/docs/language-basics.md +389 -0
  54. package/docs/language-builtins.md +411 -0
  55. package/docs/language-chain.md +198 -0
  56. package/docs/language-cpi.md +470 -0
  57. package/docs/language-errors-events.md +184 -0
  58. package/docs/language-native.md +493 -0
  59. package/docs/language-pdas.md +198 -0
  60. package/docs/language-statements.md +620 -0
  61. package/docs/language-types.md +601 -0
  62. package/docs/language.md +190 -467
  63. package/docs/mainnet.md +103 -8
  64. package/docs/migrate-from-anchor.md +7 -6
  65. package/docs/security-model.md +4 -4
  66. package/docs/stability.md +64 -3
  67. package/docs/test-your-program.md +52 -15
  68. package/docs/testing.md +49 -2
  69. package/docs/troubleshooting.md +210 -42
  70. package/lib/typesol.d.ts +67 -22
  71. package/llms-full.txt +5084 -591
  72. package/llms.txt +12 -1
  73. package/package.json +4 -2
  74. package/releases/0.43.0.json +669 -0
  75. package/releases/0.44.0.json +672 -0
  76. package/releases/0.44.1.json +672 -0
  77. package/releases/0.45.0.json +732 -0
  78. package/runtime/LICENSE-compiler-builtins.txt +275 -0
  79. package/runtime/typesol_builtins.c +484 -0
  80. package/ts-plugin/index.js +16 -5
@@ -3,13 +3,16 @@
3
3
  import { readFileSync } from "node:fs";
4
4
  import ts from "typescript";
5
5
  let libNames;
6
- /** The functions and values lib/typesol.d.ts exports, so "Cannot find name 'log'" can say where log comes from. */
6
+ /**
7
+ * The names lib/typesol.d.ts exports: values (functions, constants, enums) and types (types, interfaces), so
8
+ * "Cannot find name 'Signer'" can say where Signer comes from. u64 and the other integer casts are both.
9
+ */
7
10
  function typesolExports(libPath) {
8
11
  if (!libNames) {
9
- libNames = new Set();
12
+ libNames = { values: new Set(), types: new Set() };
10
13
  try {
11
- for (const m of readFileSync(libPath, "utf8").matchAll(/^export declare (?:function|const) (\w+)/gm))
12
- libNames.add(m[1]);
14
+ for (const m of readFileSync(libPath, "utf8").matchAll(/^export (?:declare )?(function|const|enum|type|interface|class) (\w+)/gm))
15
+ (m[1] === "type" || m[1] === "interface" ? libNames.types : libNames.values).add(m[2]);
13
16
  }
14
17
  catch {
15
18
  // Without the library file there is nothing to suggest.
@@ -19,6 +22,38 @@ function typesolExports(libPath) {
19
22
  }
20
23
  const MINMAX_HINT = 'Math works on numbers; use min(a, b) and max(a, b) from "typesol", which take bigints';
21
24
  const BIGINT_HINT = "integers (u64, u32, i64 …) are bigint in TypeSOL: write 1n, not 1, and take u64, not number";
25
+ /** Date.now() and new Date() have no meaning on chain; the cluster's clock does. */
26
+ export const CLOCK_HINT = 'the time on chain is the cluster\'s clock: now() from "typesol" gives its Unix timestamp in seconds (an i64)';
27
+ export const ASYNC_HINT = "async and generators are not supported: an instruction runs start to finish within one call; remove async (or the *) and return void or a value, not a Promise";
28
+ /**
29
+ * Globals a program does not have, which TypeScript reports with advice to add a library or @types/node: the
30
+ * compiler's message in place of TypeScript's, and what to write instead (undefined: nothing to suggest).
31
+ */
32
+ const MISSING_GLOBALS = {
33
+ console: 'a program writes logs with log("…") from "typesol"',
34
+ process: 'a program has no process: stop with require(condition, error) from "typesol", which fails the transaction',
35
+ Buffer: "a program has no Buffer: account data is typed fields (FixedArray<u8, N> for raw bytes)",
36
+ setTimeout: "an instruction runs start to finish within one call: there is nothing to wait for",
37
+ setInterval: "an instruction runs start to finish within one call: there is nothing to wait for",
38
+ fetch: "a program cannot reach the network: what it reads comes in as accounts",
39
+ window: undefined,
40
+ document: undefined,
41
+ };
42
+ /** The message to show for a TypeScript diagnostic: TypeScript's own, except where its advice points the wrong way. */
43
+ export function messageForTypeScript(d, message) {
44
+ const name = /^Cannot find name '([^']+)'/.exec(message)?.[1];
45
+ if (name !== undefined && Object.hasOwn(MISSING_GLOBALS, name))
46
+ return `'${name}' does not exist in a Solana program`;
47
+ return message;
48
+ }
49
+ /** A hint for a struct field whose type cannot be account data. */
50
+ export function fieldTypeHint(node) {
51
+ if (node.kind === ts.SyntaxKind.NumberKeyword)
52
+ return 'integers are bigint types from "typesol": u64 for amounts and counts, or u8, u16, u32, i64 … (write 1n, not 1)';
53
+ if (ts.isTypeReferenceNode(node) && ts.isIdentifier(node.typeName) && node.typeName.text === "Date")
54
+ return 'store a time as an i64 of Unix seconds; now() from "typesol" gives the cluster\'s clock';
55
+ return undefined;
56
+ }
22
57
  /** A sentence to add to a TypeScript diagnostic, or undefined when TypeScript's own message says enough. */
23
58
  export function hintForTypeScript(d, message, libPath) {
24
59
  // The whole source line, so a Math.max(…) is seen even when TypeScript marks only the assignment around it.
@@ -33,12 +68,22 @@ export function hintForTypeScript(d, message, libPath) {
33
68
  // (2582, 2593) or the dom library (2584).
34
69
  const name = /^Cannot find name '([^']+)'/.exec(message)?.[1];
35
70
  if (name !== undefined) {
36
- if (name === "console")
37
- return 'a program writes logs with log("…") from "typesol"';
71
+ if (Object.hasOwn(MISSING_GLOBALS, name))
72
+ return MISSING_GLOBALS[name];
38
73
  if (name === "Math")
39
74
  return MINMAX_HINT;
40
- if (typesolExports(libPath).has(name))
75
+ const lib = typesolExports(libPath);
76
+ if (lib.values.has(name))
41
77
  return `import { ${name} } from "typesol"`;
78
+ if (lib.types.has(name))
79
+ return `import { type ${name} } from "typesol"`;
80
+ return undefined;
81
+ }
82
+ // 'u64' cannot be used as a value because it was imported using 'import type' (1361; 1362 for 'export type').
83
+ const typeOnly = /^'([^']+)' cannot be used as a value because it was (?:imported|exported) using '(?:import|export) type'/.exec(message)?.[1];
84
+ if (typeOnly !== undefined) {
85
+ if (typesolExports(libPath).values.has(typeOnly))
86
+ return `${typeOnly} is a type and a function: import it without "type" to call it (import { ${typeOnly} } from "typesol"; "type ${typeOnly}" brings in only the type)`;
42
87
  return undefined;
43
88
  }
44
89
  switch (d.code) {
@@ -46,6 +91,8 @@ export function hintForTypeScript(d, message, libPath) {
46
91
  case 2365: // Operator '+=' cannot be applied to types 'bigint' and 'number'.
47
92
  case 2322: // Type 'number' is not assignable to type 'bigint'.
48
93
  case 2345: // Argument of type 'bigint' is not assignable to parameter of type 'number'.
94
+ if (/\bDate\.now\(|\bnew Date\b/.test(line))
95
+ return CLOCK_HINT;
49
96
  if (/\bMath\.\w+\(/.test(line))
50
97
  return MINMAX_HINT;
51
98
  if (/\bbigint\b/.test(message) && (/\bnumber\b/.test(message) || /'-?\d+'/.test(message)))
@@ -70,14 +117,16 @@ export function hintForTypeScript(d, message, libPath) {
70
117
  return undefined;
71
118
  }
72
119
  }
120
+ /** A function written where the compiler takes a value (in parentheses, say): where functions are allowed instead. */
121
+ const FUNCTION_VALUE = "a function cannot be used here: bind it with const (const f = (…) => …, without parentheses around it) or write it in the call that takes it (xs.map((x) => …), a helper's function parameter)";
73
122
  /** Plain words for the syntax kinds the compiler refuses, and what to use instead. */
74
123
  const SYNTAX = {
75
124
  [ts.SyntaxKind.ClassDeclaration]: "classes are not supported: describe account data with an interface and logic with functions",
76
125
  [ts.SyntaxKind.ElementAccessExpression]: "indexing with [ ] is not supported: use .get(i) and .set(i, value) (i is a bigint)",
77
- [ts.SyntaxKind.TemplateExpression]: "template strings are not supported: log the parts one by one, or use an error enum member for a message",
78
126
  [ts.SyntaxKind.SpreadElement]: "spread (...) is not supported: copy the fields one by one",
79
127
  [ts.SyntaxKind.ArrayLiteralExpression]: "array literals are only allowed inline as seeds or CPI lists; declare local arrays with fixedArray<T, N>(fill)",
80
- [ts.SyntaxKind.FunctionExpression]: "function expressions are not supported: declare a function at the top level",
128
+ [ts.SyntaxKind.FunctionExpression]: FUNCTION_VALUE,
129
+ [ts.SyntaxKind.ArrowFunction]: FUNCTION_VALUE,
81
130
  [ts.SyntaxKind.AwaitExpression]: "await is not supported: an instruction runs start to finish within one call",
82
131
  [ts.SyntaxKind.TypeOfExpression]: "typeof is not supported at run time: the types are known when the program compiles",
83
132
  [ts.SyntaxKind.DeleteExpression]: "delete is not supported: account fields always exist; set the value instead",
@@ -8,6 +8,11 @@ export type { ProgramModel } from "./model.js";
8
8
  export { SBPF_VERSIONS, TESTED_TOOLCHAIN, type Sbpf } from "./toolchain.js";
9
9
  /** The hint the CLI adds under a TypeScript error (what to write instead in a TypeSOL program), for the editor plugin. */
10
10
  export declare function typescriptHint(d: ts.Diagnostic): string | undefined;
11
+ /**
12
+ * The message the CLI shows in place of a TypeScript error's, where TypeScript's advice points the wrong way (add the
13
+ * dom library, install @types/node, for a global a program does not have); undefined to keep TypeScript's.
14
+ */
15
+ export declare function typescriptMessage(d: ts.Diagnostic): string | undefined;
11
16
  export interface Generated {
12
17
  model: ProgramModel;
13
18
  c: string;
@@ -37,6 +42,54 @@ export interface BuildManifest {
37
42
  sources: Record<string, string>;
38
43
  /** sha256 of the .so. */
39
44
  binary: string;
45
+ /** Set when the build ran in the pinned container (`typesol build --docker`, after 0.44.0): what that environment is. */
46
+ container?: ContainerIdentity;
47
+ }
48
+ /**
49
+ * The build container of `--docker` (docker/Dockerfile): everything that decides what is inside it, so that another
50
+ * machine can build the same environment and compare. `image` is this machine's local image id; it can differ between
51
+ * machines that built the same Dockerfile (layer dates), so it identifies the image used, not the environment.
52
+ */
53
+ export interface ContainerIdentity {
54
+ /** The container platform: `linux/amd64` (before 0.45.0 some programs' binaries depended on the platform-tools host package). */
55
+ platform: string;
56
+ /** sha256 of docker/Dockerfile. */
57
+ dockerfile: string;
58
+ /** The local image id (`sha256:…`). */
59
+ image: string;
60
+ /** The base images, each pinned by digest (`node:24.22.2-bookworm-slim@sha256:…`). */
61
+ base: string[];
62
+ /** The Agave and platform-tools release files, with the sha256 the Dockerfile requires of them. */
63
+ downloads: {
64
+ url: string;
65
+ sha256: string;
66
+ }[];
67
+ /**
68
+ * The TypeSOL package installed in the image, as its release record (releases/<version>.json) describes it, and where
69
+ * that record came from (this package, a --release-record file, or the repository's main branch) with its sha256
70
+ * (recorded from 0.45.0 on).
71
+ */
72
+ typesol: {
73
+ version: string;
74
+ shasum: string;
75
+ integrity: string;
76
+ commit: string;
77
+ record?: {
78
+ kind: "package" | "file" | "repository";
79
+ location: string;
80
+ sha256: string;
81
+ };
82
+ };
83
+ /**
84
+ * The TypeSOL package's npm dependencies, installed by `npm ci` from this lock (every package checked against the
85
+ * integrity it records): `docker/deps/<version>.lock.json`, its sha256, and whether it came from the running
86
+ * package or from the version's own (checked) tarball (recorded from 0.45.0 on).
87
+ */
88
+ deps?: {
89
+ path: string;
90
+ sha256: string;
91
+ source: "package" | "tarball";
92
+ };
40
93
  }
41
94
  export interface BuildResult extends Generated {
42
95
  manifest: BuildManifest;
@@ -54,9 +107,11 @@ export declare function build(entry: string, outDir: string, programAddress: str
54
107
  /** The package version (one source: package.json), recorded in build manifests and shown by the CLI. */
55
108
  export declare const COMPILER_VERSION: string;
56
109
  /** A build's toolchain in one line: `clang 20.1.7-rust-dev (…), platform-tools v1.52, darwin-arm64, TypeSOL 0.44.0`. */
57
- export declare function describeToolchain(m: Pick<BuildManifest, "clang" | "platformTools" | "host" | "compiler">): string;
110
+ export declare function describeToolchain(m: Pick<BuildManifest, "clang" | "platformTools" | "host" | "compiler" | "container">): string;
58
111
  /** What differs between two builds' toolchains and compilers (the fields both record), e.g. ["clang", "TypeSOL version"]. */
59
112
  export declare function toolchainDifferences(a: Partial<BuildManifest>, b: Partial<BuildManifest>): string[];
113
+ /** The hosts (`<os>-<arch>`) on which programs were measured to build to the same bytes (docs/stability.md). */
114
+ export declare const MEASURED_HOSTS: readonly string[];
60
115
  /** The ELF's own length (it ends with the section header table): a program account keeps it zero-padded. */
61
116
  export declare function elfLength(elf: Buffer): number;
62
117
  /**
@@ -4,17 +4,26 @@ import ts from "typescript";
4
4
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
5
  import path from "node:path";
6
6
  import { analyze, LIB_PATH } from "./analyze.js";
7
- import { hintForTypeScript } from "./hints.js";
7
+ import { hintForTypeScript, messageForTypeScript } from "./hints.js";
8
8
  import { emitProgram } from "./emit/index.js";
9
9
  import { buildIdl } from "./idl.js";
10
10
  import { buildSharedObject, checkToolchain, shortClang, TESTED_TOOLCHAIN } from "./toolchain.js";
11
- import { RUNTIME_DIR } from "./toolchain.js";
11
+ import { BUILTINS_SOURCE, RUNTIME_DIR } from "./toolchain.js";
12
12
  export { CompileError, formatDiagnostic } from "./diagnostics.js";
13
13
  export { SBPF_VERSIONS, TESTED_TOOLCHAIN } from "./toolchain.js";
14
14
  /** The hint the CLI adds under a TypeScript error (what to write instead in a TypeSOL program), for the editor plugin. */
15
15
  export function typescriptHint(d) {
16
16
  return hintForTypeScript(d, ts.flattenDiagnosticMessageText(d.messageText, "\n"), LIB_PATH);
17
17
  }
18
+ /**
19
+ * The message the CLI shows in place of a TypeScript error's, where TypeScript's advice points the wrong way (add the
20
+ * dom library, install @types/node, for a global a program does not have); undefined to keep TypeScript's.
21
+ */
22
+ export function typescriptMessage(d) {
23
+ const flat = ts.flattenDiagnosticMessageText(d.messageText, "\n");
24
+ const shown = messageForTypeScript(d, flat);
25
+ return shown === flat ? undefined : shown;
26
+ }
18
27
  /** Typecheck, enforce the TypeSOL subset, and generate C. Throws CompileError with every diagnostic. */
19
28
  export function generate(entry, opts = {}) {
20
29
  const analysis = analyze(entry, opts.files);
@@ -43,6 +52,7 @@ export function build(entry, outDir, programAddress, opts = {}) {
43
52
  for (const f of gen.files)
44
53
  sources[path.relative(root, f)] = sha256(readFileSync(f));
45
54
  sources["<runtime>/typesol_rt.h"] = sha256(readFileSync(path.join(RUNTIME_DIR, "typesol_rt.h")));
55
+ sources["<runtime>/typesol_builtins.c"] = sha256(readFileSync(BUILTINS_SOURCE));
46
56
  const manifest = {
47
57
  program: gen.model.name,
48
58
  compiler: COMPILER_VERSION,
@@ -69,6 +79,7 @@ export function describeToolchain(m) {
69
79
  m.host ? `${m.host.os}-${m.host.arch}` : "host unknown",
70
80
  `TypeSOL ${m.compiler}`,
71
81
  ...(m.clang === TESTED_TOOLCHAIN.clang ? ["the tested toolchain"] : []),
82
+ ...(m.container ? [`in the build container (Dockerfile ${m.container.dockerfile.slice(0, 12)}…)`] : []),
72
83
  ].join(", ");
73
84
  }
74
85
  /** What differs between two builds' toolchains and compilers (the fields both record), e.g. ["clang", "TypeSOL version"]. */
@@ -84,9 +95,22 @@ export function toolchainDifferences(a, b) {
84
95
  out.push("TypeScript");
85
96
  if (a.sbpf !== b.sbpf)
86
97
  out.push("SBPF version");
87
- // The host is recorded, not compared: one clang version is meant to give the same bytes on every host.
98
+ // The same clang gives the same object code on each host measured. Before 0.45.0 programs linked platform-tools'
99
+ // compiler-builtins, which each host package splits into archive members differently, so one with 128-bit or signed
100
+ // division linked to another layout on another host; a build that links the runtime's builtins (its manifest lists
101
+ // them among the sources) gives the same bytes on each host measured (docs/stability.md). Between two such builds
102
+ // the host is not a difference when both hosts were measured, and "host (not measured)" when one was not.
103
+ const linksRuntimeBuiltins = (m) => !!m.sources?.["<runtime>/typesol_builtins.c"];
104
+ if (a.host && b.host && (a.host.os !== b.host.os || a.host.arch !== b.host.arch)) {
105
+ if (!(linksRuntimeBuiltins(a) && linksRuntimeBuiltins(b)))
106
+ out.push("host");
107
+ else if (!MEASURED_HOSTS.includes(`${a.host.os}-${a.host.arch}`) || !MEASURED_HOSTS.includes(`${b.host.os}-${b.host.arch}`))
108
+ out.push("host (not measured)");
109
+ }
88
110
  return out;
89
111
  }
112
+ /** The hosts (`<os>-<arch>`) on which programs were measured to build to the same bytes (docs/stability.md). */
113
+ export const MEASURED_HOSTS = ["darwin-arm64", "linux-arm64", "linux-x64"];
90
114
  /** The ELF's own length (it ends with the section header table): a program account keeps it zero-padded. */
91
115
  export function elfLength(elf) {
92
116
  if (elf.length < 0x40 || elf.readUInt32BE(0) !== 0x7f454c46)
@@ -37,7 +37,7 @@ export function isWritable(k) {
37
37
  export function typeName(t) {
38
38
  switch (t.kind) {
39
39
  case "int":
40
- return t.name;
40
+ return t.f64 ? "f64" : t.name;
41
41
  case "bool":
42
42
  return "boolean";
43
43
  case "pubkey":
@@ -97,7 +97,8 @@ export function sameType(a, b) {
97
97
  return false;
98
98
  switch (a.kind) {
99
99
  case "int":
100
- return a.name === b.name;
100
+ // An f64 is held as a u64 of its bits, but it is not an integer: neither converts to the other implicitly.
101
+ return a.name === b.name && !a.f64 === !b.f64;
101
102
  case "array": {
102
103
  const o = b;
103
104
  return a.len === o.len && sameType(a.elem, o.elem);
@@ -9,14 +9,52 @@ export interface Toolchain {
9
9
  linkerScript: string;
10
10
  includes: string[];
11
11
  libDir: string;
12
+ /**
13
+ * platform-tools' compiler-builtins Rust library for this SBPF version. Not linked (programs link the runtime's own
14
+ * builtins, runtime/typesol_builtins.c, which build the same on each host measured); its presence tells that the
15
+ * platform-tools have this SBPF version's libraries, and the builtins tests compare against it.
16
+ */
12
17
  compilerBuiltins: string;
13
18
  }
19
+ /** The runtime's compiler builtins, compiled with each program and linked in place of compiler-builtins. */
20
+ export declare const BUILTINS_SOURCE: string;
21
+ /** What is missing when there is no toolchain to build with, so `doctor` and `init` can say which commands to run. */
22
+ export declare class ToolchainMissing extends Error {
23
+ /** "agave": no Agave CLI (no SDK); "platform-tools": the CLI without its platform-tools; "sbpf-libraries": platform-tools without this SBPF version. */
24
+ readonly kind: "agave" | "platform-tools" | "sbpf-libraries";
25
+ /** What is missing, in one clause. */
26
+ readonly summary: string;
27
+ constructor(
28
+ /** "agave": no Agave CLI (no SDK); "platform-tools": the CLI without its platform-tools; "sbpf-libraries": platform-tools without this SBPF version. */
29
+ kind: "agave" | "platform-tools" | "sbpf-libraries",
30
+ /** What is missing, in one clause. */
31
+ summary: string, fix: string);
32
+ }
14
33
  /** Locate the Solana C SDK that ships with the Agave CLI's platform-tools. */
15
- export declare function findToolchain(sbpf?: Sbpf): Toolchain;
34
+ export declare function findToolchain(sbpf?: Sbpf, host?: {
35
+ platform: string;
36
+ arch: string;
37
+ }): Toolchain;
16
38
  /** Compile generated C to an SBF shared object (same flags as the SDK's sbf.mk for the chosen SBPF version). */
17
39
  /** The SBF stack frame of one function. */
18
40
  export declare const STACK_FRAME = 4096;
41
+ /** clang's flags for SBF objects (the SDK's sbf.mk for the chosen SBPF version, plus TypeSOL's warnings). */
42
+ export declare function sbfCflags(sbpf?: Sbpf): string[];
43
+ /** The flags runtime/typesol_builtins.c is compiled with: the program's, and the SBPF version (its assembly differs). */
44
+ export declare function builtinsCflags(sbpf?: Sbpf): string[];
19
45
  export declare function buildSharedObject(cFile: string, outSo: string, sbpf?: Sbpf, tc?: Toolchain): void;
46
+ /** Link SBF objects into a program: libc from platform-tools, nothing from its Rust libraries. */
47
+ export declare function linkSharedObject(objects: string[], outSo: string, tc: Toolchain, extra?: string[]): void;
48
+ /**
49
+ * The syscalls a TypeSOL program may leave to the SBF loader: every one the SDK's headers declare (`@SYSCALL` in
50
+ * platform-tools-sdk/sbf/c/inc/sol/inc/*.inc) and every one runtime/typesol_rt.h declares itself, with `abort`.
51
+ * test/cli/toolchain.test.ts checks that this is exactly that set.
52
+ */
53
+ export declare const SYSCALLS: readonly string[];
54
+ /** Whether the SBF loader resolves `name` as a syscall for a TypeSOL program (one of SYSCALLS). */
55
+ export declare function isSyscall(name: string): boolean;
56
+ /** The undefined symbols of an SBF shared object's dynamic symbol table (what the loader resolves as syscalls). */
57
+ export declare function unresolvedSymbols(elf: Buffer): string[];
20
58
  /**
21
59
  * The toolchain this release is tested with: CI installs exactly this Agave CLI and platform-tools, and every
22
60
  * execution, differential and fuzz test runs on binaries this clang built. The C TypeSOL emits is only checked
@@ -30,6 +68,39 @@ export declare const TESTED_TOOLCHAIN: {
30
68
  };
31
69
  /** The commands that install the tested toolchain (the Agave CLI, then its platform-tools). */
32
70
  export declare const INSTALL_TESTED_TOOLCHAIN: readonly ["sh -c \"$(curl -sSfL https://release.anza.xyz/v3.1.10/install)\"", "cargo-build-sbf --install-only --force-tools-install --tools-version v1.52"];
71
+ /**
72
+ * The Agave installer adds its bin directory to PATH in ~/.profile only, which the shell that ran it does not read:
73
+ * without this line the next command is "cargo-build-sbf: command not found".
74
+ */
75
+ export declare const AGAVE_PATH = "export PATH=\"$HOME/.local/share/solana/install/active_release/bin:$PATH\"";
76
+ export declare const linuxArm64: (host?: {
77
+ platform: string;
78
+ arch: string;
79
+ }) => boolean;
80
+ export declare const LINUX_ARM64_INSTALL: readonly string[];
81
+ /**
82
+ * What to run to get the tested toolchain on this host: from nothing ("agave"), or when the Agave CLI is there and
83
+ * its platform-tools are not. `cargo-build-sbf --version` downloads nothing and `cargo-build-sbf --force-tools-install`
84
+ * alone needs a Cargo project; only `--install-only` installs the platform-tools by themselves.
85
+ */
86
+ export declare function installCommands(from: "agave" | "platform-tools", host?: {
87
+ platform: string;
88
+ arch: string;
89
+ }): string[];
90
+ /**
91
+ * The note printed on its own line above an install command, when what it does is not obvious; undefined for the
92
+ * others. A note is a `#` line holding no character a shell treats specially (no parentheses, `;`, `$`, quotes,
93
+ * `<`, `>`, `|`, `&`, `!`, `*`, `?`, brackets or braces), so a pasted block runs the same: bash and fish skip it as
94
+ * a comment, and zsh, whose interactive shells do not read comments unless `interactive_comments` is set (the macOS
95
+ * default), answers "command not found: #" and runs nothing from that line. A command line never carries a trailing
96
+ * comment: zsh would hand it to the command as arguments (test/cli/doctor.test.ts pastes the blocks into each shell).
97
+ */
98
+ export declare function installNote(command: string): string | undefined;
99
+ /** installCommands with each command's note on the line above it: the lines `init`, `doctor` and the build print. */
100
+ export declare function installLines(from: "agave" | "platform-tools", host?: {
101
+ platform: string;
102
+ arch: string;
103
+ }): string[];
33
104
  /** The clang version string (the first line of `clang --version`), for build manifests. */
34
105
  export declare function toolchainVersion(tc?: Toolchain): string;
35
106
  /**
@@ -49,7 +120,7 @@ export interface ToolchainInfo {
49
120
  /** The active toolchain's versions, and whether it is the tested one (the clang is what compiles, so it decides). */
50
121
  export declare function toolchainInfo(tc?: Toolchain): ToolchainInfo;
51
122
  /** What to say about a toolchain that is not the tested one; undefined for the tested one. */
52
- export declare function untestedToolchainMessage(info: ToolchainInfo): string | undefined;
123
+ export declare function untestedToolchainMessage(info: ToolchainInfo, strict?: boolean): string | undefined;
53
124
  /** `--toolchain-strict`: refuse an untested toolchain for the rest of the process, as TYPESOL_TOOLCHAIN=strict does. */
54
125
  export declare function setToolchainStrict(on?: boolean): void;
55
126
  /** Whether an untested toolchain is an error: `--toolchain-strict` or TYPESOL_TOOLCHAIN=strict ("warn", the default). */