@smoothbricks/nx-plugin 0.7.1 → 0.7.3

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 (73) hide show
  1. package/README.md +140 -137
  2. package/dist/.build-inputs.json +18 -18
  3. package/dist/cargo-toolchain-paths.d.ts +1 -1
  4. package/dist/cargo-toolchain-paths.js +1 -1
  5. package/dist/cargo-toolchain-policy.d.ts +2 -2
  6. package/dist/cargo-toolchain-policy.js +2 -2
  7. package/dist/cross-check-policy.d.ts +25 -30
  8. package/dist/cross-check-policy.d.ts.map +1 -1
  9. package/dist/cross-check-policy.js +27 -31
  10. package/dist/ensure-built-witness.js +727 -450
  11. package/dist/ensure-built.js +2 -2
  12. package/dist/executors/bounded-exec/bounds.d.ts +6 -3
  13. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
  14. package/dist/executors/bounded-exec/bounds.js +9 -2
  15. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  16. package/dist/executors/bounded-exec/executor.js +24 -19
  17. package/dist/executors/bounded-exec/mbx-pool.d.ts +13 -16
  18. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  19. package/dist/executors/bounded-exec/mbx-pool.js +24 -28
  20. package/dist/executors/bounded-exec/runner-lifecycle.d.ts +2 -0
  21. package/dist/executors/bounded-exec/runner-lifecycle.d.ts.map +1 -1
  22. package/dist/executors/bounded-exec/runner-lifecycle.js +9 -5
  23. package/dist/executors/bounded-exec/runner-sizing.d.ts +6 -1
  24. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
  25. package/dist/executors/bounded-exec/runner-sizing.js +7 -2
  26. package/dist/executors/bounded-exec/schema.d.ts +12 -3
  27. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  28. package/dist/executors/cargo-zigbuild/executor.d.ts +10 -0
  29. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  30. package/dist/executors/cargo-zigbuild/executor.js +36 -2
  31. package/dist/index.js +24 -11
  32. package/dist/managed-files/files.d.ts +4 -4
  33. package/dist/managed-files/files.js +4 -4
  34. package/dist/owned-installation.d.ts.map +1 -1
  35. package/dist/owned-installation.js +4 -2
  36. package/dist/producer-receipts.js +476 -402
  37. package/dist/task-graph-policy.js +1 -1
  38. package/dist/testing.d.ts +8 -0
  39. package/dist/testing.d.ts.map +1 -1
  40. package/dist/testing.js +15 -0
  41. package/dist/workspace-config-policy.d.ts +1 -1
  42. package/dist/workspace-config-policy.js +1 -1
  43. package/dist/workspace-manifest.d.ts +5 -0
  44. package/dist/workspace-manifest.d.ts.map +1 -1
  45. package/managed/raw/patches/{nx@23.2.1.patch → nx@24.0.3.patch} +1397 -2174
  46. package/managed/raw/tooling/direnv/devenv.smoo.nix +30 -31
  47. package/managed/raw/tooling/git-hooks/pre-push.sh +21 -21
  48. package/managed/templates/github/actions/setup-devenv/action.yml +20 -5
  49. package/package.json +4 -3
  50. package/runtime/nx-publish/.build-inputs.json +2 -2
  51. package/runtime/nx-publish/cache_adapter.js +24 -11
  52. package/runtime/nx-publish/nx_publish.js +2 -1
  53. package/runtime-input.sh +1 -1
  54. package/src/cargo-toolchain-paths.ts +1 -1
  55. package/src/cargo-toolchain-policy.ts +2 -2
  56. package/src/cross-check-policy.ts +29 -32
  57. package/src/ensure-built.ts +2 -2
  58. package/src/executors/bounded-exec/bounds.ts +13 -4
  59. package/src/executors/bounded-exec/executor.ts +27 -29
  60. package/src/executors/bounded-exec/mbx-pool.ts +36 -30
  61. package/src/executors/bounded-exec/runner-lifecycle.ts +13 -6
  62. package/src/executors/bounded-exec/runner-sizing.ts +8 -2
  63. package/src/executors/bounded-exec/schema.json +5 -1
  64. package/src/executors/bounded-exec/schema.ts +12 -3
  65. package/src/executors/cargo-zigbuild/executor.ts +42 -2
  66. package/src/index.ts +27 -9
  67. package/src/managed-files/files.ts +4 -4
  68. package/src/owned-installation.ts +4 -2
  69. package/src/task-graph-policy.ts +1 -1
  70. package/src/testing.ts +13 -0
  71. package/src/workspace-config-policy.ts +1 -1
  72. package/src/workspace-manifest.ts +5 -0
  73. package/test-timings.json +2 -0
@@ -38,15 +38,7 @@ import type { HangDiagnostics } from './hang-diagnostics.js';
38
38
  import { captureHangDiagnostics, HANG_CAPTURE_MS } from './hang-diagnostics.js';
39
39
  import type { CpuWaitRow } from './lease-wait.js';
40
40
  import type { LockWait } from './lock-wait.js';
41
- import {
42
- MBX_GRANT_FD,
43
- mbxIdleGated,
44
- mbxLeaf,
45
- mbxPool,
46
- nxTaskCores,
47
- runsPrebuiltNextest,
48
- withMbxLeaf,
49
- } from './mbx-pool.js';
41
+ import { MBX_GRANT_FD, mbxIdleGated, mbxLeaf, mbxPool, withCountedReservation, withMbxLeaf } from './mbx-pool.js';
50
42
  import { MBX_QUEUE_POLL_MS, type MbxQueuedRequest, snapshotMbxQueue } from './mbx-queue.js';
51
43
  import { createNoSpaceWatch } from './no-space.js';
52
44
  import {
@@ -367,13 +359,14 @@ export async function runBoundedExec(
367
359
  };
368
360
 
369
361
  // The fixture pair names one segment: a fixture with no build budget, or a budget with no fixture, is a
370
- // target that does not say what it runs, so it does not run.
362
+ // target that does not say what it runs, so it does not run. Units are counted at the end of that segment.
371
363
  if (
372
364
  (options.fixtureCommand === undefined) !== (options.fixtureTimeoutMs === undefined) ||
365
+ (options.unitsCommand !== undefined && options.fixtureCommand === undefined) ||
373
366
  (fixture !== null && !(fixture.timeoutMs > 0))
374
367
  ) {
375
368
  appendStderr(
376
- 'bounded-exec: fixtureCommand and a positive fixtureTimeoutMs must be named together; refusing to run the command\n',
369
+ 'bounded-exec: fixtureCommand and a positive fixtureTimeoutMs must be named together, and unitsCommand only with them; refusing to run the command\n',
377
370
  );
378
371
  if (context.record !== undefined) {
379
372
  const { task, directory: recordDirectory } = context.record;
@@ -386,7 +379,7 @@ export async function runBoundedExec(
386
379
  // CPU tokens: a refusal that waited in its pool's queue first would say nothing for minutes.
387
380
  const runtime = await checkRuntimePin({
388
381
  root: context.root,
389
- command: fixture === null ? requested : `${fixture.command} && ${requested}`,
382
+ command: [fixture?.command, options.unitsCommand, requested].filter((part) => part !== undefined).join(' && '),
390
383
  env: { ...withoutPoolEnv(process.env), ...options.env },
391
384
  cwd,
392
385
  pathSource: options.env?.PATH === undefined ? 'the inherited environment' : "the target's env",
@@ -537,12 +530,8 @@ export async function runBoundedExec(
537
530
  // (`run-cpu-pool.ts`), so a task takes its tokens from a parent's pool; a command that inherits none runs exactly as
538
531
  // asked and nothing is said.
539
532
  const cores = availableParallelism();
540
- // A prebuilt nextest leaf under mbx asks for its task's share of the host (`nxTaskCores`), not every core: it knows
541
- // no count of its tests. A declared or named count still wins.
542
533
  const mbx = mbxPool(process.env);
543
- const leafCores =
544
- mbx !== null && runsPrebuiltNextest(requested) ? nxTaskCores(cores, { ...process.env, ...options.env }) : cores;
545
- const demand = runnerDemand(requested, options.parallelism, leafCores, process.env, options.env);
534
+ const demand = runnerDemand(requested, options.parallelism, cores, process.env, options.env);
546
535
  const asked = Date.now();
547
536
  // A pool that answered and refused is a live budget, and running beside it would count the run twice: the run fails
548
537
  // instead. A pool whose endpoint is gone (its holder exited) lends nothing, and the run goes on as asked.
@@ -718,21 +707,27 @@ export async function runBoundedExec(
718
707
  ...(leaf?.kind === 'cargo' ? { MBX_GRANT_FD: String(MBX_GRANT_FD) } : {}),
719
708
  };
720
709
  // A fixture rides as segment 0 of the lifecycle. Without the channel (Windows) it is plain shell text ahead
721
- // of the command: the progress bound runs during it and its own ceiling does not.
722
- const hooked =
723
- process.platform === 'win32'
724
- ? null
725
- : fixture === null
726
- ? withRunnerLifecycle(command)
727
- : withFixtureLifecycle(fixture.command, command);
710
+ // of the command: the progress bound runs during it and its own ceiling does not. Under mbx a leaf that names its
711
+ // units counts them at the end of that segment, under the fixture's ceiling, its fixture's own output on stderr, and
712
+ // reserves after it (`withCountedReservation`).
713
+ const counted =
714
+ process.platform !== 'win32' && leaf?.kind === 'reserve' && fixture !== null && options.unitsCommand !== undefined;
715
+ const segment =
716
+ fixture === null ? null : counted ? `{ ${fixture.command}; } >&2 && ${options.unitsCommand}` : fixture.command;
717
+ const fixtureHooked =
718
+ process.platform === 'win32' || segment === null ? null : withFixtureLifecycle(segment, command);
719
+ const hooked = process.platform === 'win32' ? null : (fixtureHooked ?? withRunnerLifecycle(command));
728
720
  const lifecycle = hooked === null ? null : createRunnerLifecycle(hooked.runners);
729
721
  let lifecycleFailure: string | null = null;
730
722
  const isTesting = (): boolean => lifecycleFailure !== null || (lifecycle?.isTesting() ?? true);
731
723
  const startedAt = Date.now();
732
724
  // With a supervisor, `cowshed subtree-root` asks it for a handle on itself, writes the answer to the handle
733
725
  // descriptor, and execs `/bin/sh -c command` in the same process: the command's pid, group and life are unchanged.
734
- const unadmitted = hooked?.command ?? (fixture === null ? command : `${fixture.command} && ${command}`);
735
- const shellCommand = withMbxLeaf(unadmitted, leaf);
726
+ const unadmitted = hooked?.command ?? (segment === null ? command : `${segment} && ${command}`);
727
+ const shellCommand =
728
+ leaf?.kind === 'reserve' && counted && fixtureHooked !== null
729
+ ? withCountedReservation(fixtureHooked.fixture, fixtureHooked.main, leaf)
730
+ : withMbxLeaf(unadmitted, leaf);
736
731
  // Only leaves known to be scheduled can exclude zero-hold time. Others keep lifecycle hang protection.
737
732
  const queued = mbxIdleGated(leaf, sized.command, { ...process.env, ...env });
738
733
  // fd 4 is unused without a subtree admission, so the grant takes fd 5 either way.
@@ -942,6 +937,8 @@ export async function runBoundedExec(
942
937
  };
943
938
  const refreshQueue = async (fresh: boolean): Promise<void> => {
944
939
  if (fresh && queueSnapshot !== null) await queueSnapshot;
940
+ // A leaf that counts its units before reserving waits in no reservation queue while its fixture builds.
941
+ if (counted && !fixtureDone) return;
945
942
  if (state.settled || state.expiry !== null || queueAbort.signal.aborted || child.pid === undefined) return;
946
943
  const pid = child.pid;
947
944
  queueSnapshot ??= (async () => {
@@ -1158,7 +1155,7 @@ export async function runBoundedExec(
1158
1155
  : `The last mbx admission snapshot failed (${unconfirmedAdmission}), so the wait it could not confirm earned no idle credit\n`
1159
1156
  }`
1160
1157
  : bound.kind === 'fixture'
1161
- ? `\nFixture command timed out after ${elapsedMs}ms (fixtureTimeoutMs=${bound.limitMs}, cwd=${cwd}): ${fixture?.command ?? command}\n`
1158
+ ? `\nFixture command timed out after ${elapsedMs}ms (fixtureTimeoutMs=${bound.limitMs}, cwd=${cwd}): ${segment ?? command}\n`
1162
1159
  : `\nCommand timed out after ${elapsedMs}ms (timeoutMs=${bound.limitMs}, cwd=${cwd}): ${command}\n`,
1163
1160
  );
1164
1161
  if (bound.kind === 'idle') {
@@ -1257,6 +1254,7 @@ export async function runBoundedExec(
1257
1254
  at: Date.now(),
1258
1255
  testing: isTesting(),
1259
1256
  fixture: fixture !== null && lifecycle !== null,
1257
+ fixtureFirst: counted && lifecycle !== null,
1260
1258
  queued,
1261
1259
  });
1262
1260
  // Read every byte after spawn accounting: a chunk can contain several grants and releases. EOF is neither.
@@ -1278,7 +1276,7 @@ export async function runBoundedExec(
1278
1276
  said = true;
1279
1277
  tell(
1280
1278
  leaf.kind === 'reserve'
1281
- ? `cowshed: mbx reserve granted elapsed=${Date.now() - startedAt}ms asked=${leaf.demand.want} priority=${leaf.priority}\n`
1279
+ ? `cowshed: mbx reserve granted elapsed=${Date.now() - startedAt}ms priority=${leaf.priority}\n`
1282
1280
  : `cowshed: mbx cargo granted elapsed=${Date.now() - startedAt}ms\n`,
1283
1281
  );
1284
1282
  }
@@ -1336,7 +1334,7 @@ export async function runBoundedExec(
1336
1334
  if (code !== 0 && state.expiry === null) {
1337
1335
  appendStderr(
1338
1336
  fixture !== null && !mainStarted
1339
- ? `Fixture command exited with status ${code}: ${fixture.command}\n`
1337
+ ? `Fixture command exited with status ${code}: ${segment ?? fixture.command}\n`
1340
1338
  : `Command exited with status ${code}: ${command}\n`,
1341
1339
  );
1342
1340
  }
@@ -1,5 +1,12 @@
1
1
  import { shellTokens } from '../../runtime-input-policy.js';
2
- import { CPU_TOKENS_ENV, type Demand, grantedSizing, invocationSpan, type ReservedDemand } from './runner-sizing.js';
2
+ import {
3
+ CPU_TOKENS_ENV,
4
+ type Demand,
5
+ grantedSizing,
6
+ invocationSpan,
7
+ type ReservedDemand,
8
+ WANT_ENV,
9
+ } from './runner-sizing.js';
3
10
  import { shellQuote } from './verdict.js';
4
11
 
5
12
  /**
@@ -45,6 +52,9 @@ export type MbxLeaf =
45
52
  readonly demand: ReservedDemand;
46
53
  };
47
54
 
55
+ /** A leaf mbx's pool reserves for. */
56
+ export type ReservedLeaf = Extract<MbxLeaf, { kind: 'reserve' }>;
57
+
48
58
  /** A nextest invocation that runs test binaries already built, from extracted archive metadata or an archive file. */
49
59
  const PREBUILT_NEXTEST = /(?<![\w-])--(?:binaries-metadata|archive-file)(?=[=\s]|$)/;
50
60
 
@@ -81,28 +91,6 @@ export function mbxLeaf(pool: MbxPool, demand: Demand, command: string): MbxLeaf
81
91
  return reserve(demand);
82
92
  }
83
93
  }
84
-
85
- /** Nx's own default count of tasks at once, when nothing names one. */
86
- const NX_DEFAULT_PARALLEL = 3;
87
-
88
- /**
89
- * The cores one task of an Nx run counts as its own: the host's cores divided among the tasks Nx runs at once, at
90
- * least one. Nx reads that count from `NX_PARALLEL`, a number or a share of the cores (`100%`), else runs three.
91
- *
92
- * A prebuilt nextest leaf asks for this share rather than its runner's own count, every core by default, because it
93
- * does not know how many tests it runs: mbx grants a reservation as many of its cores as are free, so a leaf of a few
94
- * long tests asking for every core would hold the idle rest for its whole run (specs/cowshed/05_gateway.md, "Open
95
- * questions"). Before mbx granted reservations their free cores, every cargo-test leaf of a gate reserved the whole
96
- * pool and they ran one at a time: on 2026-10-30 a gate's 18-core host ran 4.2 cores busy, its leaves each holding
97
- * `mbx reserve --cpus 18`.
98
- */
99
- export function nxTaskCores(cores: number, environment: Readonly<NodeJS.ProcessEnv>): number {
100
- const named = environment.NX_PARALLEL?.trim() ?? '';
101
- const share = /^(\d+)%$/.exec(named);
102
- const count = share?.[1] !== undefined ? (cores * Number(share[1])) / 100 : /^\d+$/.test(named) ? Number(named) : 0;
103
- const parallel = count >= 1 ? Math.floor(count) : NX_DEFAULT_PARALLEL;
104
- return Math.max(1, Math.floor(cores / parallel));
105
- }
106
94
  /**
107
95
  * The value an in-place runner gives `--target-dir-remap`: smoo-nx-nextest-binaries' answer, quoted. The plugin infers
108
96
  * the native helper; a repository's own runner may name its script through bun, which prints the same path.
@@ -174,16 +162,34 @@ export function mbxIdleGated(leaf: MbxLeaf | null, command: string, environment:
174
162
  export const MBX_GRANT_FD = 5;
175
163
 
176
164
  /**
177
- * `command` as the shell runs it under its leaf's admission, or as it is for a leaf in no pool (`null`). A reserved leaf
178
- * asks for its runner's count, and its reservation first sizes the runner to what mbx granted (`grantedSizing`) and says
179
- * so on stderr. `mbx` is the canonical environment's, whose realpath cowshed's admission proved to be the host's pinned
180
- * mbx; it writes the grant on this descriptor itself.
165
+ * `command` as the shell runs it under its leaf's admission, or as it is for a leaf in no pool (`null`): a reserved
166
+ * leaf asks for its runner's count (`reservation`).
181
167
  */
182
168
  export function withMbxLeaf(command: string, leaf: MbxLeaf | null): string {
183
169
  if (leaf === null || leaf.kind === 'cargo') {
184
170
  return command;
185
171
  }
186
- const asked = leaf.demand.want;
187
- const said = `printf 'cowshed: mbx reserve running cpus=%s asked=${asked}\\n' "$${CPU_TOKENS_ENV}" >&2; `;
188
- return `mbx reserve --grant-fd ${MBX_GRANT_FD} --cpus ${asked} --priority ${leaf.priority} -- /bin/sh -c ${shellQuote(`${grantedSizing(leaf.demand)}${said}${command}`)}`;
172
+ return `${WANT_ENV}=${leaf.demand.want} && ${reservation(command, leaf)}`;
173
+ }
174
+
175
+ /**
176
+ * A reserved leaf whose `fixture` segment ends by printing one line per unit its `command` runs (`unitsCommand`): the
177
+ * segment runs first, outside the reservation, since a build's compilers are admitted by mbx one by one, and the leaf
178
+ * asks for its units, at most its runner's count and at least one. A segment that fails fails the run before anything
179
+ * is reserved.
180
+ */
181
+ export function withCountedReservation(fixture: string, command: string, leaf: ReservedLeaf): string {
182
+ const most = leaf.demand.want;
183
+ const count = `n=0; while IFS= read -r unit; do if [ -n "$unit" ]; then n=$((n + 1)); fi; done; echo "$(( n < 1 ? 1 : n < ${most} ? n : ${most} ))"`;
184
+ return `bounded_exec_units=$(${fixture}) && ${WANT_ENV}=$(printf '%s\\n' "$bounded_exec_units" | { ${count}; }) && ${reservation(command, leaf)}`;
185
+ }
186
+
187
+ /**
188
+ * The reservation of `WANT_ENV` cores, set by the caller, that runs `command` once mbx grants it: the reservation sizes
189
+ * the runner to what mbx granted (`grantedSizing`) and says so on stderr. `mbx` is the canonical environment's, whose
190
+ * realpath cowshed's admission proved to be the host's pinned mbx; it writes the grant on this descriptor itself.
191
+ */
192
+ function reservation(command: string, leaf: ReservedLeaf): string {
193
+ const said = `printf 'cowshed: mbx reserve running cpus=%s asked=%s\\n' "$${CPU_TOKENS_ENV}" "$${WANT_ENV}" >&2; `;
194
+ return `export ${WANT_ENV} && mbx reserve --grant-fd ${MBX_GRANT_FD} --cpus "$${WANT_ENV}" --priority ${leaf.priority} -- /bin/sh -c ${shellQuote(`${grantedSizing(leaf.demand)}${said}${command}`)}`;
189
195
  }
@@ -69,13 +69,20 @@ export function withRunnerLifecycle(command: string, firstId = 0): { command: st
69
69
  * descendant holding the private descriptor. The fixture is arbitrary shell, so it rides under `/bin/sh -c`;
70
70
  * this lifecycle is POSIX-only, as the channel itself is.
71
71
  */
72
- export function withFixtureLifecycle(fixtureCommand: string, command: string): { command: string; runners: number } {
72
+ export function withFixtureLifecycle(
73
+ fixtureCommand: string,
74
+ command: string,
75
+ ): { command: string; runners: number; fixture: string; main: string } {
73
76
  const fixture = hookInvocation(0, 'build', `/bin/sh -c ${shellWord(fixtureCommand)}`);
74
- const main = withRunnerLifecycle(command, 1);
75
- if (main !== null) {
76
- return { command: `${fixture} && { ${main.command}; }`, runners: main.runners + 1 };
77
- }
78
- return { command: `${fixture} && ${hookInvocation(1, 'run', `/bin/sh -c ${shellWord(command)}`)}`, runners: 2 };
77
+ const hooked = withRunnerLifecycle(command, 1);
78
+ const main = hooked?.command ?? hookInvocation(1, 'run', `/bin/sh -c ${shellWord(command)}`);
79
+ const runners = (hooked?.runners ?? 1) + 1;
80
+ return {
81
+ command: hooked === null ? `${fixture} && ${main}` : `${fixture} && { ${main}; }`,
82
+ runners,
83
+ fixture,
84
+ main,
85
+ };
79
86
  }
80
87
 
81
88
  /** A private supervisor channel, not runner output, grants authority to pause the test clock. */
@@ -61,6 +61,12 @@ export const CPU_TOKENS_ENV = 'BOUNDED_EXEC_CPU_TOKENS';
61
61
  */
62
62
  export const GRANTED_CPUS_ENV = 'MBX_RESERVE_CPUS';
63
63
 
64
+ /**
65
+ * The most cores a reserved leaf asks mbx for, as its reservation's shell sets it before reserving: its runner's own
66
+ * count, or fewer when it has fewer units than that (`unitsCommand`).
67
+ */
68
+ export const WANT_ENV = 'BOUNDED_EXEC_CPU_WANT';
69
+
64
70
  const CARGO_BUILD =
65
71
  /(?<=^|[\s;&|()])(?:cargo(?:\s+-\S+)*\s+(?:build|test|check|clippy|rustc|doc|run|nextest\s+archive)|napi\s+build)(?=\s|$)/;
66
72
  const TEST_THREADS = /--test-threads(?:=|\s+)(\d+)/g;
@@ -363,12 +369,12 @@ export function sizeRunner(
363
369
  /**
364
370
  * The shell statements that run first in a reserved leaf's reservation and size its runner to the grant, which only
365
371
  * the command learns as it starts: `CPU_TOKENS_ENV` becomes the cores mbx granted (`GRANTED_CPUS_ENV`), never more
366
- * than the leaf asked for, its `--cpus` (the runner's own count), which also stands in under an mbx that grants a
372
+ * than the leaf asked for (`WANT_ENV`, set before it reserved), which also stands in under an mbx that grants a
367
373
  * reservation whole and names none. The test-thread variables a sizing sets follow from it, under their inherited
368
374
  * ceilings, outranking the target's own as a numeric grant's do (`sizeRunner`).
369
375
  */
370
376
  export function grantedSizing(demand: ReservedDemand): string {
371
- const asked = demand.want;
377
+ const asked = `$${WANT_ENV}`;
372
378
  const named = `\${${GRANTED_CPUS_ENV}:-${asked}}`;
373
379
  const tokens = `$${CPU_TOKENS_ENV}`;
374
380
  const atMost = (ceiling: number | null): string =>
@@ -42,13 +42,17 @@
42
42
  },
43
43
  "fixtureCommand": {
44
44
  "type": "string",
45
- "description": "A compiler-fixture producer for command: a shell command run first, in the same cwd, environment and CPU grant, as a lifecycle build interval the progress bound does not run during. Its failure fails the run and command starts only after it exits 0. For warmth outside Nx outputs (a compiler plugin cache, a Cargo target directory): inside the consumer's task a cache hit restores the verdict and warms nothing, an execution warms first. Requires fixtureTimeoutMs."
45
+ "description": "A compiler-fixture producer for command: a shell command run first, in the same cwd and environment, as a lifecycle build interval the progress bound does not run during. Under mbx it runs inside its leaf's CPU reservation, or before it when unitsCommand counts the leaf's units. Its failure fails the run and command starts only after it exits 0. For warmth outside Nx outputs (a compiler plugin cache, a Cargo target directory): inside the consumer's task a cache hit restores the verdict and warms nothing, an execution warms first. Requires fixtureTimeoutMs."
46
46
  },
47
47
  "fixtureTimeoutMs": {
48
48
  "type": "number",
49
49
  "minimum": 1,
50
50
  "description": "The fixture segment's own wall-clock ceiling in milliseconds: a build budget bounding only the fixture interval, never the command it prepares. Required with fixtureCommand."
51
51
  },
52
+ "unitsCommand": {
53
+ "type": "string",
54
+ "description": "A shell command that prints one line per unit command runs (a test, a file), run at the end of the fixture segment, under its ceiling; refused without fixtureCommand. A leaf mbx's pool reserves for asks for no more cores than it prints lines, at least one. Its failure fails the run before anything is reserved."
55
+ },
52
56
  "parallelism": {
53
57
  "type": "integer",
54
58
  "minimum": 1,
@@ -28,9 +28,11 @@ export interface BoundedExecCommand {
28
28
  killAfterMs?: number;
29
29
 
30
30
  /**
31
- * A compiler-fixture producer for `command`: a shell command run first, in the same cwd, environment and CPU
32
- * grant, whose whole life is a lifecycle build interval — the progress bound does not run during it, as it does
33
- * not run during a `cargo test` build. Its failure fails the run; `command` starts only after it exits 0.
31
+ * A compiler-fixture producer for `command`: a shell command run first, in the same cwd and environment, inside
32
+ * the run's CPU grant; under mbx inside its leaf's reservation, or before it when `unitsCommand` counts the leaf's
33
+ * units, since then the fixture is a build whose compilers mbx admits one by one.
34
+ * Its whole life is a lifecycle build interval — the progress bound does not run during it, as it does not run
35
+ * during a `cargo test` build. Its failure fails the run; `command` starts only after it exits 0.
34
36
  *
35
37
  * It exists for warmth that lives outside Nx outputs (a compiler plugin cache, a Cargo target directory). As a
36
38
  * separate `cache: false` prerequisite that warmth was paid even when every consumer then hit the cache, since
@@ -44,6 +46,13 @@ export interface BoundedExecCommand {
44
46
  * only the fixture interval, never the command it prepares.
45
47
  */
46
48
  fixtureTimeoutMs?: number;
49
+ /**
50
+ * A shell command that prints one line per unit `command` runs (a test, a file), run at the end of the fixture
51
+ * segment, under its ceiling; refused without `fixtureCommand`. A leaf that mbx's pool reserves for asks for no more
52
+ * cores than it prints lines, at least one: a run of two slow tests holds two cores, not every core its runner could
53
+ * use. Its failure fails the run before anything is reserved.
54
+ */
55
+ unitsCommand?: string;
47
56
  /**
48
57
  * The most threads or processes the command runs at once, which is how many CPU tokens it asks
49
58
  * its live parent pool for. Absent, the runner in the command decides:
@@ -74,6 +74,44 @@ export function cargoTriple(target: string): string {
74
74
  return glibcSuffix === null ? target : target.slice(0, glibcSuffix.index);
75
75
  }
76
76
 
77
+ /**
78
+ * The remedy for a failed build of `target` on this host, when rustc has no standard library for its triple: every
79
+ * managed shell carries `x86_64-unknown-linux-gnu`'s, and on macOS the rest of the Linux set is the `linux-cross`
80
+ * profile's. A build outside it fails in rustc, which names the missing target but not the profile. `libdir` is what
81
+ * `rustc --print target-libdir --target <triple>` printed, or null when rustc could not answer.
82
+ */
83
+ export function missingRustStdRemedy(
84
+ command: string,
85
+ target: string,
86
+ platform: NodeJS.Platform,
87
+ libdir: { readonly path: string; readonly exists: boolean } | null,
88
+ ): string | null {
89
+ if (platform !== 'darwin' || libdir === null || libdir.exists) return null;
90
+ return (
91
+ `${command}: rustc has no standard library for ${cargoTriple(target)} (${libdir.path} is absent). On macOS the ` +
92
+ "Linux rust-std set beyond x86_64-unknown-linux-gnu is the linux-cross profile's: tooling/devenv -P linux-cross " +
93
+ 'shell -- nx run <project>:<target>'
94
+ );
95
+ }
96
+
97
+ /** What `rustc --print target-libdir` names for the triple of `target`, and whether it exists; null if rustc failed. */
98
+ async function rustLibdir(target: string): Promise<{ readonly path: string; readonly exists: boolean } | null> {
99
+ const child = spawn('rustc', ['--print', 'target-libdir', '--target', cargoTriple(target)], {
100
+ stdio: ['ignore', 'pipe', 'ignore'],
101
+ });
102
+ let printed = '';
103
+ child.stdout.setEncoding('utf8');
104
+ child.stdout.on('data', (chunk: string) => {
105
+ printed += chunk;
106
+ });
107
+ // eslint-disable-next-line deadline/no-unbounded-wait -- WHY unbounded: rustc answers a --print query from its own sysroot without compiling; the enclosing runner's bound ends a hung one
108
+ const code = await new Promise<number | null>((resolve) => {
109
+ child.once('error', () => resolve(null));
110
+ child.once('close', resolve);
111
+ });
112
+ const libdir = printed.trim();
113
+ return code === 0 && libdir !== '' ? { path: libdir, exists: existsSync(libdir) } : null;
114
+ }
77
115
  /**
78
116
  * The environment without any compiler or linker named for this triple.
79
117
  *
@@ -215,8 +253,8 @@ export default async function cargoZigbuildExecutor(
215
253
  } catch (error) {
216
254
  if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
217
255
  console.error(
218
- `${command}: cargo-zigbuild is not on PATH. Linux artifacts build with the linux-cross toolchain; ` +
219
- 'on macOS run the target inside it: tooling/devenv -P linux-cross shell -- nx run <project>:<target>',
256
+ `${command}: cargo-zigbuild is not on PATH, which every managed devenv shell carries; run the target in the ` +
257
+ "checkout's shell: direnv exec <checkout> nx run <project>:<target>",
220
258
  );
221
259
  return { success: false };
222
260
  }
@@ -224,6 +262,8 @@ export default async function cargoZigbuildExecutor(
224
262
  }
225
263
  if (status.code !== 0) {
226
264
  console.error(`${command}: exited with ${status.signal ?? `status ${status.code}`}`);
265
+ const remedy = missingRustStdRemedy(command, options.target, process.platform, await rustLibdir(options.target));
266
+ if (remedy !== null) console.error(remedy);
227
267
  return { success: false };
228
268
  }
229
269
  if (built === null) {
package/src/index.ts CHANGED
@@ -1638,7 +1638,10 @@ async function createProjectTargets(
1638
1638
  packageJson.private === true && WRANGLER_CONFIG_FILES.some((file) => existsSync(join(absoluteProjectRoot, file)));
1639
1639
 
1640
1640
  if (hasLibTsconfig) {
1641
- const executableOutputs = packageBinOutputs(packageJson, packageJsonPath);
1641
+ const libOutDir = typescriptOutDir(libTsconfigPath, packageJsonPath);
1642
+ const executableOutputs = packageBinOutputs(packageJson, packageJsonPath).filter((bin) =>
1643
+ typescriptEmitWrites(libOutDir, bin),
1644
+ );
1642
1645
  // Dependency packages may publish bundled entries that raw tsc does not produce.
1643
1646
  // Build every JavaScript output lane before resolving package exports, without pulling
1644
1647
  // unrelated Wasm, N-API, native, or web outputs onto the compiler critical path.
@@ -1648,7 +1651,7 @@ async function createProjectTargets(
1648
1651
  executor: '@smoothbricks/nx-plugin:typescript-emit',
1649
1652
  cache: true,
1650
1653
  inputs: ['production', '^production', ...toolchainInputs, '{projectRoot}/tsconfig.lib.json'],
1651
- outputs: inferTypescriptOutputs(libTsconfigPath, packageJsonPath),
1654
+ outputs: inferTypescriptOutputs(libOutDir),
1652
1655
  dependsOn: ['^*-js', ...(cargoWasmConfig ? ['cargo-wasm'] : [])],
1653
1656
  options: {
1654
1657
  ...(executableOutputs.length > 0 ? { executableOutputs } : {}),
@@ -2640,8 +2643,7 @@ interface ResolvedNapiConfig {
2640
2643
  targets: string[];
2641
2644
  }
2642
2645
 
2643
- function inferTypescriptOutputs(tsconfigPath: string, packageJsonPath: string): string[] {
2644
- const outDir = typescriptOutDir(tsconfigPath, packageJsonPath);
2646
+ function inferTypescriptOutputs(outDir: string | null): string[] {
2645
2647
  // No .tsbuildinfo here: the emit executor overlays incremental: false, so
2646
2648
  // tsc-js never writes one and a declared-but-absent output fails the
2647
2649
  // release-candidate output inspection.
@@ -2650,6 +2652,18 @@ function inferTypescriptOutputs(tsconfigPath: string, packageJsonPath: string):
2650
2652
  : [`{projectRoot}/${outDir}/`];
2651
2653
  }
2652
2654
 
2655
+ /**
2656
+ * Whether the emit `inferTypescriptOutputs(outDir)` declares writes the project-relative `path`: a file beneath
2657
+ * outDir, or JavaScript beneath dist for a config that states no outDir. A package bin a second emit, a bundler or Git
2658
+ * puts elsewhere is not this emit's: a tsc-js that claimed one stat'ed it on a clean checkout before anything wrote it.
2659
+ */
2660
+ function typescriptEmitWrites(outDir: string | null, path: string): boolean {
2661
+ const emitted = posix.normalize(path.replaceAll('\\', '/'));
2662
+ return outDir === null
2663
+ ? emitted.startsWith('dist/') && /\.(?:[cm]?js|jsx)$/.test(emitted)
2664
+ : emitted.startsWith(`${outDir}/`);
2665
+ }
2666
+
2653
2667
  /** The project-relative `compilerOptions.outDir` the config itself states, or null when it states none. */
2654
2668
  function typescriptOutDir(tsconfigPath: string, packageJsonPath: string): string | null {
2655
2669
  const tsconfig: unknown = readJsonFile(tsconfigPath);
@@ -3329,11 +3343,12 @@ function nextestRunnerFixture(workspace: CargoWorkspace, nativeTools: NativeTool
3329
3343
  }
3330
3344
 
3331
3345
  /**
3332
- * One `nextest run` over a filterset against the workspace's test build. Every runner of the
3333
- * workspace builds its command here, so the reuse-build, the remap, the tool config and the cwd
3334
- * cannot drift between the per-crate pieces and the serial groups.
3346
+ * One `nextest run`, or `nextest list`, over a filterset against the workspace's test build. Every runner of the
3347
+ * workspace builds its command here, so the reuse-build, the remap, the tool config and the cwd cannot drift between
3348
+ * the per-crate pieces, their test lists and the serial groups.
3335
3349
  */
3336
3350
  function nextestRunnerCommand(
3351
+ verb: 'run' | 'list',
3337
3352
  workspace: CargoWorkspace,
3338
3353
  nativeTools: NativeTools | null,
3339
3354
  selector: string,
@@ -3346,7 +3361,7 @@ function nextestRunnerCommand(
3346
3361
  `--binaries-metadata ${NEXTEST_BINARIES_METADATA} --cargo-metadata ${NEXTEST_CARGO_METADATA} ` +
3347
3362
  `--target-dir-remap "$(${helper} target-dir)"`;
3348
3363
  return cargoFrozen(
3349
- `nextest run ${reuseBuild} --workspace-remap . -E ${shellWord(selector)}${flags} --user-config-file none ${toolConfig}`,
3364
+ `nextest ${verb} ${reuseBuild} --workspace-remap . -E ${shellWord(selector)}${flags} --user-config-file none ${toolConfig}`,
3350
3365
  );
3351
3366
  }
3352
3367
 
@@ -3365,6 +3380,7 @@ function cargoTestRunnerTarget(
3365
3380
  dependsOn: [build, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
3366
3381
  options: {
3367
3382
  command: nextestRunnerCommand(
3383
+ 'run',
3368
3384
  workspace,
3369
3385
  nativeTools,
3370
3386
  piece.selector,
@@ -3373,6 +3389,8 @@ function cargoTestRunnerTarget(
3373
3389
  cwd: workspace.projectRoot,
3374
3390
  fixtureCommand: nextestRunnerFixture(workspace, nativeTools),
3375
3391
  fixtureTimeoutMs: NEXTEST_BINARIES_FIXTURE_TIMEOUT_MS,
3392
+ // One line per test the piece runs, so under mbx it reserves no more cores than it has tests.
3393
+ unitsCommand: nextestRunnerCommand('list', workspace, nativeTools, piece.selector, `${piece.extra} -T oneline`),
3376
3394
  idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
3377
3395
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
3378
3396
  },
@@ -3399,7 +3417,7 @@ function cargoTestGroupTarget(
3399
3417
  inputs: [...inputs, fileHashInput(PLUGIN_NEXTEST_CODE_BOUND)],
3400
3418
  dependsOn: [CARGO_TEST_BUILD_TARGET, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
3401
3419
  options: {
3402
- command: nextestRunnerCommand(workspace, nativeTools, group.filter, ' --no-fail-fast --no-tests=fail'),
3420
+ command: nextestRunnerCommand('run', workspace, nativeTools, group.filter, ' --no-fail-fast --no-tests=fail'),
3403
3421
  cwd: workspace.projectRoot,
3404
3422
  fixtureCommand: nextestRunnerFixture(workspace, nativeTools),
3405
3423
  fixtureTimeoutMs: NEXTEST_BINARIES_FIXTURE_TIMEOUT_MS,
@@ -74,11 +74,11 @@ export const managedTtscPatch = {
74
74
  path: 'patches/ttsc@0.34.1.patch',
75
75
  } as const;
76
76
 
77
- /** Maintained Nx 23.2.1 repairs, applied as an ordinary Bun patchedDependency over the registry release. */
77
+ /** Maintained Nx 24.0.3 repairs, applied as an ordinary Bun patchedDependency over the registry release. */
78
78
  export const managedNxPatch = {
79
- version: '23.2.1',
80
- key: 'nx@23.2.1',
81
- path: 'patches/nx@23.2.1.patch',
79
+ version: '24.0.3',
80
+ key: 'nx@24.0.3',
81
+ path: 'patches/nx@24.0.3.patch',
82
82
  } as const;
83
83
 
84
84
  const managedFiles: ManagedFileDescriptor[] = [
@@ -9,7 +9,7 @@
9
9
  * test reads it. A fixture must not take an input it does not own.
10
10
  *
11
11
  * So the closure is copied, exactly as the witness's own census resolves it from the workspace that names it: each
12
- * package once, with the census's own exclusions (`node_modules`, `.git`, `.nx`), each dependency edge relinked beside
12
+ * package once, without its `node_modules` and `.git`, each dependency edge relinked beside
13
13
  * its copy as Bun's isolated layout does, the top-level packages' bins in `.bin`. Every copy is a new inode, cloned
14
14
  * where the volume allows and written otherwise, so no link count is shared with anything outside its owner.
15
15
  *
@@ -307,7 +307,9 @@ function copyPackage(source: string, root: string, { place }: Placement): Promis
307
307
  recursive: true,
308
308
  verbatimSymlinks: true,
309
309
  mode: constants.COPYFILE_FICLONE,
310
- filter: (path) => path === source || !['node_modules', '.git', '.nx'].includes(basename(path)),
310
+ // A package's own .nx is content, not Nx state: @nx/workspace 24.0.3 ships templates under one, and the census
311
+ // selects their directories through the package's `files` (expandOutputs), so a copy without them holds less.
312
+ filter: (path) => path === source || !['node_modules', '.git'].includes(basename(path)),
311
313
  });
312
314
  }
313
315
 
@@ -78,7 +78,7 @@ export function buildTestDependencies(inputGraph: ProjectGraph, workspaceRoot: s
78
78
  if (!from) throw new Error(`Nx task edge has no source: ${source}`);
79
79
  const fromTarget = graph.nodes[from.target.project]?.data.targets?.[from.target.target];
80
80
  if (!fromTarget || isTestWork(from.target.target, fromTarget)) continue;
81
- for (const test of dependencies) {
81
+ for (const { id: test } of dependencies) {
82
82
  const to = tasks.tasks[test];
83
83
  if (!to) throw new Error(`Nx task edge has no dependency: ${test}`);
84
84
  const toTarget = graph.nodes[to.target.project]?.data.targets?.[to.target.target];
package/src/testing.ts CHANGED
@@ -742,6 +742,14 @@ export function fixtureSocketDirectory(workspace: string): string {
742
742
  * {@link retireFixtureSocketDirectory}. The alias points at the workspace's own
743
743
  * `.nx/sockets`, made mode 0700; a symlinked `.nx` or `.nx/sockets` is refused
744
744
  * before anything is written through it. Nx makes the `nx` leaf itself.
745
+ *
746
+ * `.nx/sockets` holds a `.gitignore` that ignores everything in it, itself
747
+ * included, so nothing the fixture's processes make there is a workspace file:
748
+ * Nx 24's workspace context reads every path its watch reports created, and a
749
+ * jobserver fifo the run CPU pool makes there (`executors/bounded-exec/cpu-pool.ts`)
750
+ * blocks that read, and the daemon's only thread with it, until the pool ends.
751
+ * In a cowshed shed the same namespace is `.cowshed/run`, which cowshed's git
752
+ * exclude keeps out the same way.
745
753
  */
746
754
  export async function publishFixtureSocketDirectory(workspace: string): Promise<string> {
747
755
  refuseWhileRetiring();
@@ -766,6 +774,11 @@ export async function publishFixtureSocketDirectory(workspace: string): Promise<
766
774
  throw new Error(`fixture socket target ${state} is not a real directory in its physical workspace`);
767
775
  }
768
776
  }
777
+ try {
778
+ await writeFile(join(target, '.gitignore'), '*\n', { flag: 'wx', mode: 0o600 });
779
+ } catch (error) {
780
+ if (errorCode(error) !== 'EEXIST') throw error;
781
+ }
769
782
  try {
770
783
  await symlink(target, alias, 'dir');
771
784
  } catch (error) {
@@ -109,7 +109,7 @@ const impreciseProductionInputs = new Set(['default', '{projectRoot}/**/*', '{pr
109
109
 
110
110
  /**
111
111
  * Every checkout keeps its Nx state in its own `.nx` (specs/cowshed/16_build_volumes.md, "Every checkout has exactly
112
- * one Nx state"). With no `NX_*_DIRECTORY` set, as in a host shell, the pinned Nx 23.2.1 otherwise moves the task cache
112
+ * one Nx state"). With no `NX_*_DIRECTORY` set, as in a host shell, the pinned Nx 24.0.3 otherwise moves the task cache
113
113
  * and its database to a per-user `~/.nx/<id>` keyed by the repository's remote (`utils/cache-directory.js`,
114
114
  * `computeSharedDataLocation`), shared by every checkout of the repository. A configured `cacheDirectory` keeps both
115
115
  * local: the cache here, the task database in Nx's default `.nx/workspace-data`. nx.json has no key for the latter.
@@ -347,6 +347,11 @@ export interface NxDependsOnObject {
347
347
  projects?: string | string[];
348
348
  /** The same target of every dependency project, as the `^target` string form says. */
349
349
  dependencies?: boolean;
350
+ /**
351
+ * The configuration the dependency runs in, which it passes on to its own dependencies; without it, the one the run
352
+ * asked for (the dependsOn-configuration hunk of `patches/nx@24.0.3.patch`).
353
+ */
354
+ configuration?: string;
350
355
  }
351
356
 
352
357
  export type NxDependsOn = string | NxDependsOnObject;
package/test-timings.json CHANGED
@@ -12,6 +12,7 @@
12
12
  "src/ensure-built-receipt.test.ts": 20391,
13
13
  "src/cargo-resolve-cache.test.ts": 20246,
14
14
  "src/cargo-source-hash.test.ts": 16053,
15
+ "src/managed-files/setup-devenv-stable-path.test.ts": 12535,
15
16
  "src/linked-snapshots.nx.test.ts": 11920,
16
17
  "src/index.test.ts": 8528,
17
18
  "src/cargo-closure-input.test.ts": 8157,
@@ -23,6 +24,7 @@
23
24
  "src/task-history-namespace.test.ts": 5246,
24
25
  "src/executors/bounded-exec/run-cpu-pool.test.ts": 5185,
25
26
  "src/task-results.test.ts": 4915,
27
+ "src/nx-depends-on-configuration.test.ts": 4601,
26
28
  "src/nx-daemon-start-never.test.ts": 4590,
27
29
  "src/serial-group-wiring.test.ts": 4153,
28
30
  "src/nx-daemon-ignore-files.test.ts": 4149,