@smoothbricks/nx-plugin 0.4.30 → 0.5.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 (58) hide show
  1. package/README.md +36 -21
  2. package/dist/cargo-toolchain-policy.d.ts +6 -6
  3. package/dist/cargo-toolchain-policy.js +6 -6
  4. package/dist/cross-check-policy.d.ts +31 -14
  5. package/dist/cross-check-policy.d.ts.map +1 -1
  6. package/dist/cross-check-policy.js +43 -15
  7. package/dist/executors/bounded-exec/cpu-tokens.d.ts +22 -5
  8. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -1
  9. package/dist/executors/bounded-exec/cpu-tokens.js +189 -18
  10. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  11. package/dist/executors/bounded-exec/executor.js +3 -2
  12. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +10 -0
  13. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -0
  14. package/dist/executors/bounded-exec/run-cpu-pool.js +63 -0
  15. package/dist/executors/cargo-zigbuild/executor.d.ts +60 -0
  16. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -0
  17. package/dist/executors/cargo-zigbuild/executor.js +266 -0
  18. package/dist/executors/cargo-zigbuild/schema.d.ts +15 -0
  19. package/dist/executors/cargo-zigbuild/schema.d.ts.map +1 -0
  20. package/dist/index.d.ts +3 -16
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +69 -92
  23. package/dist/testing.d.ts.map +1 -1
  24. package/dist/testing.js +3 -2
  25. package/executors.json +4 -4
  26. package/managed/raw/patches/nx@23.2.1.patch +177 -9
  27. package/managed/raw/tooling/direnv/devenv.smoo.nix +46 -46
  28. package/managed/raw/tooling/direnv/setup-environment.ts +13 -0
  29. package/managed/raw/tooling/git-hooks/pre-push.sh +41 -23
  30. package/package.json +1 -1
  31. package/src/cargo-closure-key.test.ts +3 -2
  32. package/src/cargo-toolchain-policy.ts +6 -6
  33. package/src/cross-check-policy.test.ts +90 -11
  34. package/src/cross-check-policy.ts +47 -17
  35. package/src/executors/bounded-exec/cpu-tokens.test.ts +205 -0
  36. package/src/executors/bounded-exec/cpu-tokens.ts +229 -22
  37. package/src/executors/bounded-exec/executor.ts +3 -2
  38. package/src/executors/bounded-exec/run-cpu-pool.test.ts +76 -0
  39. package/src/executors/bounded-exec/run-cpu-pool.ts +75 -0
  40. package/src/executors/cargo-zigbuild/executor.test.ts +129 -0
  41. package/src/executors/cargo-zigbuild/executor.ts +176 -0
  42. package/src/executors/cargo-zigbuild/schema.json +35 -0
  43. package/src/executors/cargo-zigbuild/schema.ts +14 -0
  44. package/src/index.test.ts +41 -63
  45. package/src/index.ts +73 -101
  46. package/src/nx-daemon-validity.test.ts +65 -0
  47. package/src/testing.ts +3 -2
  48. package/test-timings.json +2 -1
  49. package/dist/executors/napi-cross-toolchain/executor.d.ts +0 -42
  50. package/dist/executors/napi-cross-toolchain/executor.d.ts.map +0 -1
  51. package/dist/executors/napi-cross-toolchain/executor.js +0 -126
  52. package/dist/executors/napi-cross-toolchain/schema.d.ts +0 -4
  53. package/dist/executors/napi-cross-toolchain/schema.d.ts.map +0 -1
  54. package/src/executors/napi-cross-toolchain/executor.test.ts +0 -112
  55. package/src/executors/napi-cross-toolchain/executor.ts +0 -165
  56. package/src/executors/napi-cross-toolchain/schema.json +0 -15
  57. package/src/executors/napi-cross-toolchain/schema.ts +0 -3
  58. /package/dist/executors/{napi-cross-toolchain → cargo-zigbuild}/schema.js +0 -0
@@ -0,0 +1,266 @@
1
+ import * as _validateReport_1 from "typia/lib/internal/_validateReport";
2
+ import * as _createStandardSchema_1 from "typia/lib/internal/_createStandardSchema";
3
+ import { spawn } from 'node:child_process';
4
+ import { realpathSync } from 'node:fs';
5
+ import { chmod, copyFile, mkdir, rename } from 'node:fs/promises';
6
+ import path from 'node:path';
7
+ import { createInterface } from 'node:readline';
8
+ import typia from 'typia';
9
+ const validateReason = (() => {
10
+ const _io0 = input => "string" === typeof input.reason;
11
+ const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.reason || _report(_exceptionable, {
12
+ path: _path + ".reason",
13
+ expected: "string",
14
+ value: input.reason
15
+ })].every(flag => flag);
16
+ const __is = input => "object" === typeof input && null !== input && _io0(input);
17
+ let errors;
18
+ let _report;
19
+ return _createStandardSchema_1._createStandardSchema(input => {
20
+ if (false === __is(input)) {
21
+ errors = [];
22
+ _report = _validateReport_1._validateReport(errors);
23
+ ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
24
+ path: _path + "",
25
+ expected: "{ reason: string; }",
26
+ value: input
27
+ })) && _vo0(input, _path + "", true) || _report(true, {
28
+ path: _path + "",
29
+ expected: "{ reason: string; }",
30
+ value: input
31
+ }))(input, "$input", true);
32
+ const success = 0 === errors.length;
33
+ return success ? {
34
+ success,
35
+ data: input
36
+ } : {
37
+ success,
38
+ errors,
39
+ data: input
40
+ };
41
+ }
42
+ return {
43
+ success: true,
44
+ data: input
45
+ };
46
+ });
47
+ })();
48
+ const validateArtifact = (() => {
49
+ const _io0 = input => "compiler-artifact" === input.reason && "string" === typeof input.manifest_path && ("object" === typeof input.target && null !== input.target && _io1(input.target)) && (Array.isArray(input.filenames) && input.filenames.every(elem => "string" === typeof elem)) && (null === input.executable || "string" === typeof input.executable);
50
+ const _io1 = input => Array.isArray(input.kind) && input.kind.every(elem => "string" === typeof elem) && "string" === typeof input.name;
51
+ const _vo0 = (input, _path, _exceptionable = true) => ["compiler-artifact" === input.reason || _report(_exceptionable, {
52
+ path: _path + ".reason",
53
+ expected: "\"compiler-artifact\"",
54
+ value: input.reason
55
+ }), "string" === typeof input.manifest_path || _report(_exceptionable, {
56
+ path: _path + ".manifest_path",
57
+ expected: "string",
58
+ value: input.manifest_path
59
+ }), ("object" === typeof input.target && null !== input.target || _report(_exceptionable, {
60
+ path: _path + ".target",
61
+ expected: "{ kind: string[]; name: string; }",
62
+ value: input.target
63
+ })) && _vo1(input.target, _path + ".target", true && _exceptionable) || _report(_exceptionable, {
64
+ path: _path + ".target",
65
+ expected: "{ kind: string[]; name: string; }",
66
+ value: input.target
67
+ }), (Array.isArray(input.filenames) || _report(_exceptionable, {
68
+ path: _path + ".filenames",
69
+ expected: "Array<string>",
70
+ value: input.filenames
71
+ })) && input.filenames.map((elem, _index3) => "string" === typeof elem || _report(_exceptionable, {
72
+ path: _path + ".filenames[" + _index3 + "]",
73
+ expected: "string",
74
+ value: elem
75
+ })).every(flag => flag) || _report(_exceptionable, {
76
+ path: _path + ".filenames",
77
+ expected: "Array<string>",
78
+ value: input.filenames
79
+ }), null === input.executable || "string" === typeof input.executable || _report(_exceptionable, {
80
+ path: _path + ".executable",
81
+ expected: "(null | string)",
82
+ value: input.executable
83
+ })].every(flag => flag);
84
+ const _vo1 = (input, _path, _exceptionable = true) => [(Array.isArray(input.kind) || _report(_exceptionable, {
85
+ path: _path + ".kind",
86
+ expected: "Array<string>",
87
+ value: input.kind
88
+ })) && input.kind.map((elem, _index4) => "string" === typeof elem || _report(_exceptionable, {
89
+ path: _path + ".kind[" + _index4 + "]",
90
+ expected: "string",
91
+ value: elem
92
+ })).every(flag => flag) || _report(_exceptionable, {
93
+ path: _path + ".kind",
94
+ expected: "Array<string>",
95
+ value: input.kind
96
+ }), "string" === typeof input.name || _report(_exceptionable, {
97
+ path: _path + ".name",
98
+ expected: "string",
99
+ value: input.name
100
+ })].every(flag => flag);
101
+ const __is = input => "object" === typeof input && null !== input && _io0(input);
102
+ let errors;
103
+ let _report;
104
+ return _createStandardSchema_1._createStandardSchema(input => {
105
+ if (false === __is(input)) {
106
+ errors = [];
107
+ _report = _validateReport_1._validateReport(errors);
108
+ ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
109
+ path: _path + "",
110
+ expected: "CargoArtifactMessage",
111
+ value: input
112
+ })) && _vo0(input, _path + "", true) || _report(true, {
113
+ path: _path + "",
114
+ expected: "CargoArtifactMessage",
115
+ value: input
116
+ }))(input, "$input", true);
117
+ const success = 0 === errors.length;
118
+ return success ? {
119
+ success,
120
+ data: input
121
+ } : {
122
+ success,
123
+ errors,
124
+ data: input
125
+ };
126
+ }
127
+ return {
128
+ success: true,
129
+ data: input
130
+ };
131
+ });
132
+ })();
133
+ export function zigbuildArtifact(options) {
134
+ return options.bin === undefined ? { kind: 'cdylib' } : { kind: 'bin', name: options.bin };
135
+ }
136
+ /**
137
+ * `cargo-zigbuild zigbuild`, not `cargo zigbuild`. Run through cargo, the
138
+ * subcommand inherits `CARGO` naming the real cargo binary and calls it
139
+ * directly, bypassing the `cargo` on PATH; run directly, its inner `cargo` is
140
+ * the PATH one every other cargo target runs. `--locked` keeps Cargo.lock
141
+ * exactly as committed. The glibc suffix stays on `--target`: it is how
142
+ * cargo-zigbuild pins the symbol versions, and cargo itself sees the bare
143
+ * triple.
144
+ */
145
+ export function zigbuildArgs(options, manifestPath) {
146
+ const artifact = zigbuildArtifact(options);
147
+ return [
148
+ 'zigbuild',
149
+ '--locked',
150
+ '--message-format=json-render-diagnostics',
151
+ '--target',
152
+ options.target,
153
+ '--manifest-path',
154
+ manifestPath,
155
+ '--package',
156
+ options.package,
157
+ ...(options.release === true ? ['--release'] : []),
158
+ ...(artifact.kind === 'bin' ? ['--bin', artifact.name] : ['--lib']),
159
+ ];
160
+ }
161
+ /** `x86_64-unknown-linux-gnu.2.17` → `x86_64-unknown-linux-gnu`. */
162
+ export function cargoTriple(target) {
163
+ const glibcSuffix = /\.\d+\.\d+$/.exec(target);
164
+ return glibcSuffix === null ? target : target.slice(0, glibcSuffix.index);
165
+ }
166
+ /**
167
+ * The environment without any compiler or linker named for this triple.
168
+ *
169
+ * cargo-zigbuild supplies the triple's `CC_`/`CXX_`/`AR_`/`RANLIB_` and
170
+ * linker only where none is set, and cc-rs reads the hyphenated spelling
171
+ * before cargo-zigbuild's underscored one. A shell that pins its host
172
+ * compiler for the same triple — a Linux devenv shell pins
173
+ * `CC_x86_64_unknown_linux_gnu` to Nix's cc wrapper for host builds — would
174
+ * otherwise compile the artifact's C against the build host's glibc headers,
175
+ * which is exactly the build-host leak the zig toolchain exists to remove.
176
+ */
177
+ export function zigbuildEnv(env, target) {
178
+ const triple = cargoTriple(target);
179
+ const underscored = triple.replaceAll('-', '_');
180
+ const owned = new Set([
181
+ ...['CC', 'CXX', 'AR', 'RANLIB'].flatMap((tool) => [`${tool}_${triple}`, `${tool}_${underscored}`]),
182
+ `CARGO_TARGET_${underscored.toUpperCase()}_LINKER`,
183
+ ]);
184
+ return Object.fromEntries(Object.entries(env).filter(([name]) => !owned.has(name)));
185
+ }
186
+ /**
187
+ * The artifact file one cargo JSON message names, or null when the message is
188
+ * about anything else. `manifestPath` must be canonical, as cargo reports it.
189
+ */
190
+ export function artifactFile(line, manifestPath, artifact) {
191
+ if (!line.startsWith('{'))
192
+ return null;
193
+ const parsed = JSON.parse(line);
194
+ const header = validateReason(parsed);
195
+ if (!header.success) {
196
+ throw new Error(`cargo emitted a JSON message without a reason: ${line}`);
197
+ }
198
+ if (header.data.reason !== 'compiler-artifact')
199
+ return null;
200
+ const message = validateArtifact(parsed);
201
+ if (!message.success) {
202
+ throw new Error(`cargo compiler-artifact message does not match the artifact contract: ${JSON.stringify(message.errors)}`);
203
+ }
204
+ const { data } = message;
205
+ if (data.manifest_path !== manifestPath)
206
+ return null;
207
+ if (artifact.kind === 'bin') {
208
+ return data.target.kind.includes('bin') && data.target.name === artifact.name ? data.executable : null;
209
+ }
210
+ if (!data.target.kind.includes('cdylib'))
211
+ return null;
212
+ return data.filenames.find((file) => file.endsWith('.so')) ?? null;
213
+ }
214
+ export default async function cargoZigbuildExecutor(options, context) {
215
+ const manifestPath = realpathSync(path.resolve(context.root, options.manifestPath));
216
+ const output = path.resolve(context.root, options.output);
217
+ const artifact = zigbuildArtifact(options);
218
+ const args = zigbuildArgs(options, manifestPath);
219
+ const command = `cargo-zigbuild ${args.join(' ')}`;
220
+ // Cargo discovers `.cargo/config.toml` from its working directory upward,
221
+ // so the crate's own directory sees every config a build of it would.
222
+ const child = spawn('cargo-zigbuild', args, {
223
+ cwd: path.dirname(manifestPath),
224
+ env: zigbuildEnv(process.env, options.target),
225
+ stdio: ['ignore', 'pipe', 'inherit'],
226
+ });
227
+ const exited = new Promise((resolve, reject) => {
228
+ child.once('error', reject);
229
+ child.once('close', (code, signal) => resolve({ code, signal }));
230
+ });
231
+ let built = null;
232
+ for await (const line of createInterface({ input: child.stdout })) {
233
+ built = artifactFile(line, manifestPath, artifact) ?? built;
234
+ }
235
+ let status;
236
+ try {
237
+ status = await exited;
238
+ }
239
+ catch (error) {
240
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
241
+ console.error(`${command}: cargo-zigbuild is not on PATH. Linux artifacts build with the linux-cross toolchain; ` +
242
+ 'on macOS run the target inside it: tooling/devenv -P linux-cross shell -- nx run <project>:<target>');
243
+ return { success: false };
244
+ }
245
+ throw error;
246
+ }
247
+ if (status.code !== 0) {
248
+ console.error(`${command}: exited with ${status.signal ?? `status ${status.code}`}`);
249
+ return { success: false };
250
+ }
251
+ if (built === null) {
252
+ const wanted = artifact.kind === 'bin' ? `binary ${artifact.name}` : 'cdylib';
253
+ console.error(`${command}: cargo reported no ${wanted} artifact for ${options.package} at ${manifestPath}`);
254
+ return { success: false };
255
+ }
256
+ // Copy then rename, so the output path never holds a partial file.
257
+ await mkdir(path.dirname(output), { recursive: true });
258
+ const staging = `${output}.partial`;
259
+ await copyFile(built, staging);
260
+ if (artifact.kind === 'bin') {
261
+ await chmod(staging, 0o755);
262
+ }
263
+ await rename(staging, output);
264
+ console.log(`${path.relative(context.root, built)} -> ${path.relative(context.root, output)}`);
265
+ return { success: true };
266
+ }
@@ -0,0 +1,15 @@
1
+ export interface CargoZigbuildOptions {
2
+ /** Rust target triple, with cargo-zigbuild's glibc suffix where it pins one: `x86_64-unknown-linux-gnu.2.17`. */
3
+ target: string;
4
+ /** The crate's Cargo.toml, relative to the workspace root. */
5
+ manifestPath: string;
6
+ /** Cargo package to build. */
7
+ package: string;
8
+ /** Build this binary and copy its executable; absent, build the package's cdylib. */
9
+ bin?: string;
10
+ /** Destination file for the artifact, relative to the workspace root. */
11
+ output: string;
12
+ /** Compile cargo's `release` profile instead of `dev`. */
13
+ release?: boolean;
14
+ }
15
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/executors/cargo-zigbuild/schema.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,iHAAiH;IACjH,MAAM,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,YAAY,EAAE,MAAM,CAAC;IACrB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
package/dist/index.d.ts CHANGED
@@ -6,21 +6,6 @@ export { CARGO_TEST_COMPILE_TARGET };
6
6
  export declare const DEPLOY_TARGET = "deploy";
7
7
  /** The purely file-derived half a deploy needs built first; cached. */
8
8
  export declare const DEPLOY_BUILD_TARGET = "deploy-build";
9
- type NapiArchitecture = 'arm64' | 'x64';
10
- type NapiTargetFamily = 'linux' | 'macos';
11
- interface NapiPlatform {
12
- architecture: NapiArchitecture;
13
- targetFamily: NapiTargetFamily;
14
- }
15
- interface NapiTargetConvention extends NapiPlatform {
16
- outputName: string;
17
- }
18
- /**
19
- * Prerequisite target that extracts the cross toolchain one triple needs. The
20
- * platform suffix keeps it inside its own platform family, so it can be a
21
- * dependency of `napi-<arch>-linux` and package-local `cli-<arch>-linux`.
22
- */
23
- export declare function napiToolchainTargetName(convention: NapiTargetConvention): string;
24
9
  /**
25
10
  * The npm packages a cached cargo target runs, for its `externalDependencies`.
26
11
  * Cargo runs none. A target this plugin's executor runs, or whose command reads
@@ -35,7 +20,9 @@ export declare const createNodesV2: CreateNodesV2;
35
20
  /**
36
21
  * Nx accepts one pre/post task-hook pair per plugin. Two independent observers share it: the controller's task-results
37
22
  * hint and the opt-in producer completion receipts. Each sees the same options and run context; neither reads the
38
- * other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence.
23
+ * other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence. The
24
+ * pair also serves a run on a host without a gateway its own CPU pool, which every task inherits
25
+ * (`run-cpu-pool.ts`), and closes it when the run ends.
39
26
  */
40
27
  export declare const preTasksExecution: PreTasksExecution<ProducerReceiptsOptions>;
41
28
  export declare const postTasksExecution: PostTasksExecution<ProducerReceiptsOptions>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAEtB,KAAK,mBAAmB,EACzB,MAAM,0BAA0B,CAAC;AAkBlC,OAAO,EAKL,yBAAyB,EAiB1B,MAAM,sBAAsB,CAAC;AAqB9B,OAAO,EACL,KAAK,uBAAuB,EAG7B,MAAM,wBAAwB,CAAC;AAahC,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,gEAAgE;AAChE,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AA2VlD,KAAK,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AACxC,KAAK,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C,UAAU,YAAY;IACpB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,gBAAgB,CAAC;CAChC;AA4ID,UAAU,oBAAqB,SAAQ,YAAY;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AA0CD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,oBAAoB,GAAG,MAAM,CAEhF;AAoRD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,mBAAmB,EAC3B,WAAW,EAAE,MAAM,EACnB,SAAS,UAAsB,GAC9B,MAAM,EAAE,CAKV;AAkID,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAEvG;AAED,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC;AAeF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,iBAAiB,CAAC,uBAAuB,CAGxE,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,kBAAkB,CAAC,uBAAuB,CAG1E,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAEtB,KAAK,mBAAmB,EACzB,MAAM,0BAA0B,CAAC;AAkBlC,OAAO,EAKL,yBAAyB,EAiB1B,MAAM,sBAAsB,CAAC;AAsB9B,OAAO,EACL,KAAK,uBAAuB,EAG7B,MAAM,wBAAwB,CAAC;AAahC,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,gEAAgE;AAChE,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAmyBlD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,mBAAmB,EAC3B,WAAW,EAAE,MAAM,EACnB,SAAS,UAAsB,GAC9B,MAAM,EAAE,CAKV;AAkID,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAEvG;AAED,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC;AAeF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,EAAE,iBAAiB,CAAC,uBAAuB,CAIxE,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,kBAAkB,CAAC,uBAAuB,CAI1E,CAAC"}
package/dist/index.js CHANGED
@@ -11,7 +11,8 @@ import { BOUNDED_TEST_IDLE_TIMEOUT_MS, BOUNDED_TEST_KILL_AFTER_MS } from './boun
11
11
  import { CARGO_CLOSURE_INPUT, cargoClosureInputs, indexedCargoManifests, resolveCargoClosureSource, } from './cargo-closure-input.js';
12
12
  import { CARGO_TOOLCHAIN_NAMED_INPUT, CARGO_TOOLCHAIN_PIN_INPUTS, cargoRuntimeInput, } from './cargo-toolchain-policy.js';
13
13
  import { attributeCargoWorkspacePackages, CARGO_TEST_ARCHIVE_FILE, CARGO_TEST_ARCHIVE_TARGET, CARGO_TEST_COMPILE_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestGroupTargetName, cargoTestPackageTargetName, createCargoInputsCache, exceptionalTestFilter, listCargoCrossTestTargets, listCargoWorkspacePackages, NEXTEST_REPO_CONFIG_PATH, nextestToolConfigArg, PLUGIN_NEXTEST_CONFIG_PATH, serialTestGroups, } from './cargo-workspace.js';
14
- import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND, CARGO_FETCH_TARGET, CARGO_FROZEN_PREFIX, CARGO_LINT_CLIPPY_COMMAND, cargoCrossTestArchiveFile, cargoCrossTestArchiveTargetName, cargoCrossTestTargetName, cargoFrozen, } from './cross-check-policy.js';
14
+ import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND, CARGO_FETCH_TARGET, CARGO_LINT_CLIPPY_COMMAND, cargoCrossTestArchiveFile, cargoCrossTestArchiveTargetName, cargoCrossTestTargetName, cargoFrozen, runsFrozenCargo, } from './cross-check-policy.js';
15
+ import { closeRunCpuPool, serveRunCpuPool } from './executors/bounded-exec/run-cpu-pool.js';
15
16
  import { hashVersionlessCrateManifests } from './manifest-hash.js';
16
17
  import { EXTRACTED_BINARIES_METADATA, EXTRACTED_CARGO_METADATA, EXTRACTED_TARGET_DIR, NEXTEST_EXTRACT_BIN, } from './nextest-extraction.js';
17
18
  import { postTasksExecution as postProducerReceipts, preTasksExecution as preProducerReceipts, } from './producer-receipts.js';
@@ -346,13 +347,7 @@ function hostPlatformTargetNames(targetNames, hostPlatform) {
346
347
  if (hostPlatform === null)
347
348
  return [];
348
349
  const suffix = `-${hostPlatform.architecture}-${hostPlatform.targetFamily}`;
349
- return [...new Set(targetNames)]
350
- .filter(
351
- // Binary targets only. A toolchain prerequisite carries the same platform
352
- // suffix but produces no artifact: the cross builds that need it depend
353
- // on it directly, so the aggregate stays a list of outputs.
354
- (name) => name.endsWith(suffix) && !name.startsWith(NAPI_TOOLCHAIN_TARGET_PREFIX))
355
- .sort();
350
+ return [...new Set(targetNames)].filter((name) => name.endsWith(suffix)).sort();
356
351
  }
357
352
  /**
358
353
  * The reserved suffixes name targets that EMIT an artifact, and the `build`
@@ -400,6 +395,8 @@ const CARGO_INPUTS = [
400
395
  // build really reads is the package's `napi` block (binary name, targets) and
401
396
  // the `@napi-rs/cli` it runs; those are hashed as such by napiInputs().
402
397
  const CARGO_OUTPUT_INPUTS = CARGO_INPUTS;
398
+ /** A full cargo-mutants sweep's wall-clock backstop: a sweep takes hours, and a hung one must still end. */
399
+ const MUTATION_TIMEOUT_MS = 6 * 60 * 60 * 1000;
403
400
  // The toolchain half of a cargo task's identity lives in its own module
404
401
  // because `smoo monorepo validate` reads the same two constants to refuse a
405
402
  // declaration that drops it. See cargo-toolchain-policy.ts for why it is the
@@ -436,18 +433,19 @@ function targetCommandText(target) {
436
433
  }
437
434
  /**
438
435
  * The N-API build's inputs beyond the Cargo sources: the toolchain pin, the
439
- * package's `napi` block, which names the binary and the targets, and the napi
440
- * CLI's resolved version from the lockfile. Neither the package version nor
441
- * any other lockfile entry is part of the artifact.
436
+ * package's `napi` block, which names the binary and the targets, and the
437
+ * resolved version of the npm package that drives the build (the napi CLI on
438
+ * macOS; none on Linux, where devenv's zig and cargo-zigbuild are covered by
439
+ * the pin). Neither the package version nor any other lockfile entry is part
440
+ * of the artifact.
442
441
  *
443
- * The pin is stated here rather than inherited: `napi build` compiles with the
444
- * same rustc and links against the same SDK as any other cargo target, but its
445
- * command does not spell `cargo --frozen`, which is how every other cached
446
- * cargo target acquires its toolchain identity. Without it a `.node` linked
447
- * against one toolchain hashed equal to the same sources linked against the
448
- * next one.
442
+ * The pin is stated here rather than inherited: neither `napi build` nor the
443
+ * `cargo-zigbuild` executor spells `cargo --frozen`, which is how every other
444
+ * cached cargo target acquires its toolchain identity. Without it a `.node`
445
+ * linked against one toolchain hashed equal to the same sources linked against
446
+ * the next one.
449
447
  */
450
- function napiInputs(projectRoot, repoRooted) {
448
+ function napiInputs(projectRoot, repoRooted, externalDependencies) {
451
449
  // Runtime inputs execute from the workspace root, so the manifest is named
452
450
  // by its path from there whichever way the Cargo invocation is rooted.
453
451
  const packageJson = `./${posix.join(projectRoot, 'package.json')}`;
@@ -457,7 +455,7 @@ function napiInputs(projectRoot, repoRooted) {
457
455
  ...(repoRooted ? ['{workspaceRoot}/scripts/*.sh'] : []),
458
456
  ...CARGO_TOOLCHAIN_PIN_INPUTS,
459
457
  runtimeInput(`bun -e 'console.log(JSON.stringify(require(${JSON.stringify(packageJson)}).napi ?? null))'`),
460
- { externalDependencies: ['@napi-rs/cli'] },
458
+ { externalDependencies: [...externalDependencies] },
461
459
  ];
462
460
  }
463
461
  const NAPI_TARGET_CONVENTIONS = {
@@ -482,25 +480,14 @@ const NAPI_TARGET_CONVENTIONS = {
482
480
  targetFamily: 'linux',
483
481
  },
484
482
  };
485
- const NATIVE_LINUX_COMPILER_ENV = Object.freeze({ CC: 'cc', CXX: 'c++' });
486
- const CROSS_LINUX_COMPILER_ENV = Object.freeze({ TARGET_CC: 'clang', TARGET_CXX: 'clang++' });
487
- function usesNapiCross(target, hostPlatform) {
488
- return target.targetFamily === 'linux' && !sameNapiPlatform(target, hostPlatform);
489
- }
490
- function napiCompilerEnv(target, hostPlatform) {
491
- if (target?.targetFamily !== 'linux')
492
- return undefined;
493
- return sameNapiPlatform(target, hostPlatform) ? NATIVE_LINUX_COMPILER_ENV : CROSS_LINUX_COMPILER_ENV;
494
- }
495
- const NAPI_TOOLCHAIN_TARGET_PREFIX = 'napi-toolchain-';
496
483
  /**
497
- * Prerequisite target that extracts the cross toolchain one triple needs. The
498
- * platform suffix keeps it inside its own platform family, so it can be a
499
- * dependency of `napi-<arch>-linux` and package-local `cli-<arch>-linux`.
484
+ * The glibc symbol-version floor every Linux N-API addon links against.
485
+ * cargo-zigbuild reads it from the target triple's suffix
486
+ * (`x86_64-unknown-linux-gnu.2.17`) and links zig's stubs for exactly that
487
+ * glibc, so the floor is this literal on every host rather than whatever glibc
488
+ * the build machine carries. 2.17 is below Node ≥ 18's own 2.28 floor.
500
489
  */
501
- export function napiToolchainTargetName(convention) {
502
- return `${NAPI_TOOLCHAIN_TARGET_PREFIX}${convention.architecture}-${convention.targetFamily}`;
503
- }
490
+ const LINUX_GLIBC_FLOOR = '2.17';
504
491
  const CARGO_PROFILE_FLAG = { dev: '', release: ' --release' };
505
492
  /** The directory under `target/<triple>/` each profile writes. */
506
493
  const CARGO_PROFILE_OUTPUT_DIR = { dev: 'debug', release: 'release' };
@@ -849,15 +836,19 @@ function isBuildOutputPackageJson(packageJsonPath) {
849
836
  /**
850
837
  * Nx accepts one pre/post task-hook pair per plugin. Two independent observers share it: the controller's task-results
851
838
  * hint and the opt-in producer completion receipts. Each sees the same options and run context; neither reads the
852
- * other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence.
839
+ * other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence. The
840
+ * pair also serves a run on a host without a gateway its own CPU pool, which every task inherits
841
+ * (`run-cpu-pool.ts`), and closes it when the run ends.
853
842
  */
854
843
  export const preTasksExecution = async (options, context) => {
855
844
  preTaskResults(options, context);
856
845
  await preProducerReceipts(options, context);
846
+ await serveRunCpuPool(context);
857
847
  };
858
848
  export const postTasksExecution = async (options, context) => {
859
849
  await postTaskResults(options, context);
860
850
  await postProducerReceipts(options, context);
851
+ await closeRunCpuPool(context);
861
852
  };
862
853
  export default { createNodesV2, postTasksExecution, preTasksExecution };
863
854
  function packageBinOutputs(packageJson, packageJsonPath) {
@@ -1209,8 +1200,8 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1209
1200
  // than a silent absence.
1210
1201
  //
1211
1202
  // Deliberately NOT pushed to validationTargets: joining the lint aggregate
1212
- // would make `bun run lint` — and CI's own Linux lint, already native — demand
1213
- // the 0.4 GiB cross toolchain that the devenv profile exists to keep opt-in.
1203
+ // would make `bun run lint` — and CI's own Linux lint, already native — on a
1204
+ // macOS host demand the zig toolchain that the devenv profile keeps opt-in.
1214
1205
  targets[CARGO_CROSS_LINT_TARGET] = {
1215
1206
  executor: 'nx:run-commands',
1216
1207
  cache: true,
@@ -1223,10 +1214,13 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1223
1214
  };
1224
1215
  // Mutation runs are minutes-to-hours: never cached, never part of build/lint.
1225
1216
  // CI runs these per-PR via `cargo mutants --in-diff` (see mutants.toml docs).
1217
+ // bounded-exec sizes cargo-mutants' own jobserver to its CPU grant (its `cargo-mutants` runner kind), which
1218
+ // otherwise starts one task per core whatever else runs on the host. It reports no test bounded-exec can read as
1219
+ // progress, so its bound is a wall-clock backstop, not a performance budget.
1226
1220
  targets.mutation = {
1227
- executor: 'nx:run-commands',
1221
+ executor: '@smoothbricks/nx-plugin:bounded-exec',
1228
1222
  cache: false,
1229
- options: { command: cargoFrozen('mutants --workspace'), cwd: cargoWorkspaceRoot },
1223
+ options: { command: cargoFrozen('mutants --workspace'), cwd: cargoWorkspaceRoot, timeoutMs: MUTATION_TIMEOUT_MS },
1230
1224
  };
1231
1225
  targets.bench = {
1232
1226
  executor: 'nx:run-commands',
@@ -1328,9 +1322,8 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1328
1322
  targets[CARGO_FETCH_TARGET] = {
1329
1323
  executor: 'nx:run-commands',
1330
1324
  // The download lands in CARGO_HOME, outside the workspace: a cache hit
1331
- // would skip work a cold registry still needs — same reason
1332
- // napi-toolchain-* is uncached. Nothing here is a workspace output, so
1333
- // there is nothing for Nx to restore in its place.
1325
+ // would skip work a cold registry still needs. Nothing here is a
1326
+ // workspace output, so there is nothing for Nx to restore in its place.
1334
1327
  cache: false,
1335
1328
  options: {
1336
1329
  // One fetch per manifest, independent of the others: Cargo's own
@@ -1348,7 +1341,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1348
1341
  continue;
1349
1342
  }
1350
1343
  const text = targetCommandText(target);
1351
- if (text.includes(CARGO_FROZEN_PREFIX)) {
1344
+ if (runsFrozenCargo(text)) {
1352
1345
  target.dependsOn = [CARGO_FETCH_TARGET, ...(target.dependsOn ?? [])];
1353
1346
  }
1354
1347
  }
@@ -1360,7 +1353,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1360
1353
  });
1361
1354
  for (const target of Object.values(targets)) {
1362
1355
  const text = targetCommandText(target);
1363
- if (text.includes(CARGO_FROZEN_PREFIX)) {
1356
+ if (runsFrozenCargo(text)) {
1364
1357
  target.dependsOn = [rootFetch, ...(target.dependsOn ?? [])];
1365
1358
  }
1366
1359
  }
@@ -1371,7 +1364,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1371
1364
  // the target already does.
1372
1365
  for (const [name, target] of Object.entries(targets)) {
1373
1366
  const text = targetCommandText(target);
1374
- if (!text.includes(CARGO_FROZEN_PREFIX))
1367
+ if (!runsFrozenCargo(text))
1375
1368
  continue;
1376
1369
  target.outputs ??= [];
1377
1370
  if (!target.cache)
@@ -1820,26 +1813,17 @@ function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
1820
1813
  // that stale local artifacts can mask for months.
1821
1814
  const packageJsonPath = repoRooted ? posix.join(projectRoot, 'package.json') : 'package.json';
1822
1815
  const commonCommand = `--manifest-path ${config.manifestPath} --package ${config.cargoPackage} --package-json-path ${packageJsonPath}`;
1823
- const cargoInputs = napiInputs(projectRoot, repoRooted);
1816
+ const cargoInputs = napiInputs(projectRoot, repoRooted, ['@napi-rs/cli']);
1824
1817
  const cargoCwd = repoRooted ? '.' : projectRoot;
1825
1818
  // A repository-root Cargo invocation runs outside the owning npm package, so
1826
1819
  // Nx's root-only PATH cannot resolve that package's napi CLI.
1827
1820
  const napiCommand = repoRooted ? posix.join(projectRoot, 'node_modules/.bin/napi') : 'napi';
1828
1821
  const outputPath = (projectOutput) => (repoRooted ? posix.join(projectRoot, projectOutput) : projectOutput);
1829
- const hostPlatformTargetName = hostPlatform === null ? null : `napi-${hostPlatform.architecture}-${hostPlatform.targetFamily}`;
1830
- let nativeHostTargetName = null;
1831
- if (hostPlatformTargetName !== null) {
1832
- for (const triple of config.targets) {
1833
- const convention = NAPI_TARGET_CONVENTIONS[triple];
1834
- const targetName = convention ? `napi-${convention.architecture}-${convention.targetFamily}` : null;
1835
- if (targetName === hostPlatformTargetName && convention && !usesNapiCross(convention, hostPlatform)) {
1836
- nativeHostTargetName = targetName;
1837
- break;
1838
- }
1839
- }
1840
- }
1822
+ const hasHostPlatformTarget = config.targets.some((triple) => {
1823
+ const convention = NAPI_TARGET_CONVENTIONS[triple];
1824
+ return convention !== undefined && sameNapiPlatform(convention, hostPlatform);
1825
+ });
1841
1826
  const targets = {};
1842
- const hostCompilerEnv = napiCompilerEnv(hostPlatform, hostPlatform);
1843
1827
  // The addon the test suite loads. A plain dev build shares target/debug with
1844
1828
  // cargo-test's dependency graph, so after the tests compile this is nearly
1845
1829
  // free, where a `--target <triple>` platform build compiles the graph again
@@ -1857,10 +1841,9 @@ function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
1857
1841
  options: {
1858
1842
  cwd: cargoCwd,
1859
1843
  command: `${napiCommand} build --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputPath('.cache/native-debug')}`,
1860
- ...(hostCompilerEnv ? { env: hostCompilerEnv } : {}),
1861
1844
  },
1862
1845
  };
1863
- if (nativeHostTargetName === null) {
1846
+ if (!hasHostPlatformTarget) {
1864
1847
  // The platform target for this host triple is the same compilation, so a
1865
1848
  // second cargo-napi invocation only buys a duplicate dependency graph
1866
1849
  // (a plain build and a `--target` build write different target/
@@ -1877,30 +1860,10 @@ function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
1877
1860
  options: {
1878
1861
  cwd: cargoCwd,
1879
1862
  command: hostBuild('dev'),
1880
- ...(hostCompilerEnv ? { env: hostCompilerEnv } : {}),
1881
1863
  },
1882
1864
  configurations: { [RELEASE_CONFIGURATION]: { command: hostBuild('release') } },
1883
1865
  };
1884
1866
  }
1885
- for (const triple of config.targets) {
1886
- const convention = NAPI_TARGET_CONVENTIONS[triple];
1887
- if (!convention || !usesNapiCross(convention, hostPlatform)) {
1888
- continue;
1889
- }
1890
- // One toolchain target per triple, shared by every cross build that needs
1891
- // it: the inferred napi-<arch>-linux plus any package-local cli-<arch>-linux.
1892
- // Nx runs a shared dependency once, which is what stops those builds from
1893
- // racing inside the Bun store. See the executor for the failure it removes.
1894
- // The name carries the platform suffix so a Linux platform target's
1895
- // dependency closure stays Linux-only (package-target-policy).
1896
- targets[napiToolchainTargetName(convention)] = {
1897
- executor: '@smoothbricks/nx-plugin:napi-cross-toolchain',
1898
- // Extraction lands in ~/.napi-rs, outside the workspace: a cache hit
1899
- // would skip work a cold home directory still needs.
1900
- cache: false,
1901
- options: { triple },
1902
- };
1903
- }
1904
1867
  for (const triple of config.targets) {
1905
1868
  const convention = NAPI_TARGET_CONVENTIONS[triple];
1906
1869
  if (!convention) {
@@ -1908,23 +1871,37 @@ function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
1908
1871
  }
1909
1872
  const targetName = `napi-${convention.architecture}-${convention.targetFamily}`;
1910
1873
  const outputDirectory = `dist/native/${convention.outputName}`;
1911
- const useNapiCross = usesNapiCross(convention, hostPlatform);
1912
- const crossFlag = useNapiCross ? ' --use-napi-cross' : '';
1913
- const compilerEnv = napiCompilerEnv(convention, hostPlatform);
1914
- const platformBuild = (profile) => `${napiCommand} build${CARGO_PROFILE_FLAG[profile]} --platform --no-js --dts ${config.binaryName}.${convention.outputName}.d.ts --target ${triple}${crossFlag} ${commonCommand} --output-dir ${outputPath(outputDirectory)}`;
1874
+ if (convention.targetFamily === 'linux') {
1875
+ // Every host builds a Linux addon the same way: devenv's zig through
1876
+ // cargo-zigbuild, glibc pinned by the triple suffix. The napi CLI cannot
1877
+ // carry that suffix (it looks for the artifact under
1878
+ // target/<triple>.2.17/), so the executor names the `.node` itself.
1879
+ targets[targetName] = {
1880
+ executor: '@smoothbricks/nx-plugin:cargo-zigbuild',
1881
+ cache: true,
1882
+ inputs: napiInputs(projectRoot, repoRooted, []),
1883
+ outputs: [`{projectRoot}/${outputDirectory}`],
1884
+ options: {
1885
+ target: `${triple}.${LINUX_GLIBC_FLOOR}`,
1886
+ manifestPath: posix.join(cargoCwd, config.manifestPath),
1887
+ package: config.cargoPackage,
1888
+ output: `{projectRoot}/${outputDirectory}/${config.binaryName}.${convention.outputName}.node`,
1889
+ },
1890
+ configurations: { [RELEASE_CONFIGURATION]: { release: true } },
1891
+ };
1892
+ continue;
1893
+ }
1894
+ // macOS addons need Apple's SDK, which zig does not carry: the napi CLI
1895
+ // drives the host's own toolchain and writes the platform `.d.ts`.
1896
+ const platformBuild = (profile) => `${napiCommand} build${CARGO_PROFILE_FLAG[profile]} --platform --no-js --dts ${config.binaryName}.${convention.outputName}.d.ts --target ${triple} ${commonCommand} --output-dir ${outputPath(outputDirectory)}`;
1915
1897
  targets[targetName] = {
1916
1898
  executor: 'nx:run-commands',
1917
1899
  cache: true,
1918
- ...(useNapiCross ? { dependsOn: [napiToolchainTargetName(convention)] } : {}),
1919
1900
  inputs: cargoInputs,
1920
1901
  outputs: [`{projectRoot}/${outputDirectory}`],
1921
1902
  options: {
1922
1903
  cwd: cargoCwd,
1923
1904
  command: platformBuild('dev'),
1924
- // Genuine Linux cross-compiles use Clang plus napi-rs's downloaded
1925
- // GNU sysroot. A native Linux target uses Nix's cc wrapper so C build
1926
- // scripts resolve the host libc headers instead.
1927
- ...(compilerEnv ? { env: compilerEnv } : {}),
1928
1905
  },
1929
1906
  configurations: { [RELEASE_CONFIGURATION]: { command: platformBuild('release') } },
1930
1907
  };