@smoothbricks/nx-plugin 0.4.31 → 0.5.1

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 (74) hide show
  1. package/README.md +67 -46
  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/ensure-built.d.ts.map +1 -1
  8. package/dist/ensure-built.js +14 -9
  9. package/dist/executors/bounded-exec/cpu-pool.d.ts +14 -7
  10. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  11. package/dist/executors/bounded-exec/cpu-pool.js +297 -38
  12. package/dist/executors/bounded-exec/cpu-tokens.d.ts +19 -7
  13. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -1
  14. package/dist/executors/bounded-exec/cpu-tokens.js +21 -7
  15. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  16. package/dist/executors/bounded-exec/executor.js +12 -6
  17. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  18. package/dist/executors/bounded-exec/run-cpu-pool.js +5 -4
  19. package/dist/executors/cargo-zigbuild/executor.d.ts +60 -0
  20. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -0
  21. package/dist/executors/cargo-zigbuild/executor.js +266 -0
  22. package/dist/executors/cargo-zigbuild/schema.d.ts +15 -0
  23. package/dist/executors/cargo-zigbuild/schema.d.ts.map +1 -0
  24. package/dist/index.d.ts +0 -15
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +56 -89
  27. package/dist/producer-receipts.d.ts +10 -0
  28. package/dist/producer-receipts.d.ts.map +1 -1
  29. package/dist/producer-receipts.js +30 -5
  30. package/dist/testing.d.ts.map +1 -1
  31. package/dist/testing.js +3 -2
  32. package/executors.json +4 -4
  33. package/managed/raw/patches/nx@23.2.1.patch +177 -9
  34. package/managed/raw/tooling/direnv/devenv.smoo.nix +47 -49
  35. package/managed/raw/tooling/direnv/linked-snapshots.ts +18 -8
  36. package/managed/raw/tooling/direnv/repo-path +1 -1
  37. package/managed/raw/tooling/git-hooks/pre-push.sh +41 -23
  38. package/package.json +1 -1
  39. package/src/__tests__/counted-cargo.ts +1 -1
  40. package/src/cargo-closure-input.test.ts +1 -1
  41. package/src/cargo-toolchain-policy.ts +6 -6
  42. package/src/cross-check-policy.test.ts +90 -11
  43. package/src/cross-check-policy.ts +47 -17
  44. package/src/ensure-built.test.ts +39 -0
  45. package/src/ensure-built.ts +23 -9
  46. package/src/executors/bounded-exec/cpu-pool.test.ts +132 -4
  47. package/src/executors/bounded-exec/cpu-pool.ts +300 -46
  48. package/src/executors/bounded-exec/cpu-tokens.test.ts +60 -15
  49. package/src/executors/bounded-exec/cpu-tokens.ts +34 -11
  50. package/src/executors/bounded-exec/executor.test.ts +72 -4
  51. package/src/executors/bounded-exec/executor.ts +12 -6
  52. package/src/executors/bounded-exec/run-cpu-pool.test.ts +3 -0
  53. package/src/executors/bounded-exec/run-cpu-pool.ts +5 -4
  54. package/src/executors/cargo-zigbuild/executor.test.ts +129 -0
  55. package/src/executors/cargo-zigbuild/executor.ts +176 -0
  56. package/src/executors/cargo-zigbuild/schema.json +35 -0
  57. package/src/executors/cargo-zigbuild/schema.ts +14 -0
  58. package/src/index.test.ts +29 -61
  59. package/src/index.ts +60 -98
  60. package/src/nx-daemon-validity.test.ts +65 -0
  61. package/src/producer-receipts.test.ts +37 -15
  62. package/src/producer-receipts.ts +29 -5
  63. package/src/testing.ts +3 -2
  64. package/test-timings.json +1 -1
  65. package/dist/executors/napi-cross-toolchain/executor.d.ts +0 -42
  66. package/dist/executors/napi-cross-toolchain/executor.d.ts.map +0 -1
  67. package/dist/executors/napi-cross-toolchain/executor.js +0 -126
  68. package/dist/executors/napi-cross-toolchain/schema.d.ts +0 -4
  69. package/dist/executors/napi-cross-toolchain/schema.d.ts.map +0 -1
  70. package/src/executors/napi-cross-toolchain/executor.test.ts +0 -112
  71. package/src/executors/napi-cross-toolchain/executor.ts +0 -165
  72. package/src/executors/napi-cross-toolchain/schema.json +0 -15
  73. package/src/executors/napi-cross-toolchain/schema.ts +0 -3
  74. /package/dist/executors/{napi-cross-toolchain → cargo-zigbuild}/schema.js +0 -0
package/src/index.test.ts CHANGED
@@ -1918,79 +1918,47 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1918
1918
  // nothing from it, and a platform target's dependency closure may only reach
1919
1919
  // its own family (`validatePlatformTargetDependencies`).
1920
1920
  expect(targets['napi-arm64-macos']?.dependsOn).toBeUndefined();
1921
- // A macOS triple never gets a cross toolchain: `usesNapiCross` is
1922
- // `family === 'linux' && target !== host`, so the family decides this one
1923
- // and no host can change it.
1924
- expect(targets['napi-toolchain-x64-macos']).toBeUndefined();
1925
- // Everything else about the cross regime depends on WHICH host is
1926
- // inferring — on an x64 Linux runner `napi-x64-linux` is the native build,
1927
- // with no `--use-napi-cross` and no toolchain prerequisite at all. Those
1928
- // facts are asserted against forced platforms below instead of against
1929
- // whichever machine happens to run the suite.
1930
-
1931
- // Exercise both host branches explicitly: this suite usually runs on
1932
- // Darwin, but Linux's native compiler selection is the contract at risk.
1921
+ // Every host infers the SAME Linux addon target: devenv's zig through the
1922
+ // cargo-zigbuild executor, glibc pinned by the triple suffix. There is no
1923
+ // native-versus-cross branch to diverge on, so forcing a Linux host and a
1924
+ // macOS host must yield byte-identical Linux targets, and neither may
1925
+ // carry a compiler environment or a toolchain prerequisite.
1933
1926
  const linuxX64Targets = await inferProjectTargets(
1934
1927
  workspace,
1935
1928
  'packages/cowshed/package.json',
1936
1929
  createNodesV2ForPlatform('linux', 'x64'),
1937
1930
  );
1938
- expect(linuxX64Targets['napi-x64-linux']?.options?.command).not.toContain('--use-napi-cross');
1939
- expect(linuxX64Targets['napi-x64-linux']?.options?.env).toEqual({ CC: 'cc', CXX: 'c++' });
1940
- expect(linuxX64Targets['napi-x64-linux']?.dependsOn).toBeUndefined();
1941
- expect(linuxX64Targets['napi-toolchain-x64-linux']).toBeUndefined();
1942
- expect(linuxX64Targets['napi-arm64-linux']?.options?.command).toContain('--use-napi-cross');
1943
- expect(linuxX64Targets['napi-arm64-linux']?.options?.env).toEqual({
1944
- TARGET_CC: 'clang',
1945
- TARGET_CXX: 'clang++',
1946
- });
1947
- expect(linuxX64Targets['napi-debug']?.options?.env).toEqual({ CC: 'cc', CXX: 'c++' });
1948
-
1949
1931
  const darwinArm64Targets = await inferProjectTargets(
1950
1932
  workspace,
1951
1933
  'packages/cowshed/package.json',
1952
1934
  createNodesV2ForPlatform('darwin', 'arm64'),
1953
1935
  );
1954
- expect(darwinArm64Targets['napi-x64-linux']?.options?.command).toContain('--use-napi-cross');
1955
- expect(darwinArm64Targets['napi-x64-linux']?.options?.env).toEqual({
1956
- TARGET_CC: 'clang',
1957
- TARGET_CXX: 'clang++',
1958
- });
1959
- expect(darwinArm64Targets['napi-x64-linux']?.dependsOn).toEqual(['napi-toolchain-x64-linux']);
1960
- expect(darwinArm64Targets['napi-debug']?.options?.env).toBeUndefined();
1961
- expect(darwinArm64Targets['napi-toolchain-arm64-linux']).toEqual({
1962
- executor: '@smoothbricks/nx-plugin:napi-cross-toolchain',
1963
- cache: false,
1964
- options: { triple: 'aarch64-unknown-linux-gnu' },
1936
+ expect(darwinArm64Targets['napi-x64-linux']).toMatchObject({
1937
+ executor: '@smoothbricks/nx-plugin:cargo-zigbuild',
1938
+ cache: true,
1939
+ outputs: ['{projectRoot}/dist/native/linux-x64-gnu'],
1940
+ options: {
1941
+ target: 'x86_64-unknown-linux-gnu.2.17',
1942
+ manifestPath: 'packages/cowshed/crates/cowshed-napi/Cargo.toml',
1943
+ package: 'cowshed-napi',
1944
+ output: '{projectRoot}/dist/native/linux-x64-gnu/cowshed.linux-x64-gnu.node',
1945
+ },
1946
+ configurations: { [RELEASE_CONFIGURATION]: { release: true } },
1965
1947
  });
1966
- expect(darwinArm64Targets['napi-toolchain-x64-linux']).toEqual({
1967
- executor: '@smoothbricks/nx-plugin:napi-cross-toolchain',
1968
- cache: false,
1969
- options: { triple: 'x86_64-unknown-linux-gnu' },
1948
+ expect(darwinArm64Targets['napi-arm64-linux']?.options).toMatchObject({
1949
+ target: 'aarch64-unknown-linux-gnu.2.17',
1950
+ output: '{projectRoot}/dist/native/linux-arm64-gnu/cowshed.linux-arm64-gnu.node',
1970
1951
  });
1971
- expect(darwinArm64Targets['napi-arm64-linux']?.dependsOn).toEqual(['napi-toolchain-arm64-linux']);
1972
- expect(darwinArm64Targets['napi-x64-linux']?.outputs).toEqual(['{projectRoot}/dist/native/linux-x64-gnu']);
1973
- expect(darwinArm64Targets['napi-x64-linux']?.options?.command).toBe(
1974
- 'napi build --platform --no-js --dts cowshed.linux-x64-gnu.d.ts --target x86_64-unknown-linux-gnu --use-napi-cross --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --package-json-path package.json --output-dir dist/native/linux-x64-gnu',
1975
- );
1976
- expect(darwinArm64Targets['napi-x64-linux']?.configurations?.[RELEASE_CONFIGURATION]?.command).toContain(
1977
- 'napi build --release --platform',
1978
- );
1979
-
1980
- // The whole rule, stated once per forced host: a triple gets a cross
1981
- // toolchain exactly when it is a linux triple that is not this host's own.
1982
- // Asserting the pair by name is what broke on Linux, where
1983
- // napi-toolchain-x64-linux legitimately does not exist.
1984
- for (const [inferred, hostTriple] of [
1985
- [linuxX64Targets, 'x64-linux'],
1986
- [darwinArm64Targets, 'arm64-macos'],
1987
- ] as const) {
1988
- for (const suffix of ['arm64-linux', 'x64-linux', 'arm64-macos', 'x64-macos']) {
1989
- const expectsToolchain = suffix.endsWith('-linux') && suffix !== hostTriple;
1990
- expect(inferred[`napi-toolchain-${suffix}`] === undefined).toBe(!expectsToolchain);
1991
- expect(inferred[`napi-${suffix}`]?.options?.command).toContain(
1992
- expectsToolchain ? '--use-napi-cross' : '--target',
1993
- );
1952
+ for (const suffix of ['arm64-linux', 'x64-linux']) {
1953
+ expect(linuxX64Targets[`napi-${suffix}`]).toEqual(darwinArm64Targets[`napi-${suffix}`]);
1954
+ expect(darwinArm64Targets[`napi-${suffix}`]?.dependsOn).toBeUndefined();
1955
+ }
1956
+ for (const inferred of [linuxX64Targets, darwinArm64Targets]) {
1957
+ expect(Object.keys(inferred).filter((name) => name.startsWith('napi-toolchain-'))).toEqual([]);
1958
+ expect(inferred['napi-debug']?.options?.env).toBeUndefined();
1959
+ for (const suffix of ['arm64-macos', 'x64-macos']) {
1960
+ expect(inferred[`napi-${suffix}`]?.options?.command).toContain('napi build');
1961
+ expect(inferred[`napi-${suffix}`]?.options?.env).toBeUndefined();
1994
1962
  }
1995
1963
  }
1996
1964
  // The aggregate build pulls in exactly the inferring host's
package/src/index.ts CHANGED
@@ -58,12 +58,12 @@ import {
58
58
  CARGO_CROSS_LINT_TARGET,
59
59
  CARGO_FETCH_COMMAND,
60
60
  CARGO_FETCH_TARGET,
61
- CARGO_FROZEN_PREFIX,
62
61
  CARGO_LINT_CLIPPY_COMMAND,
63
62
  cargoCrossTestArchiveFile,
64
63
  cargoCrossTestArchiveTargetName,
65
64
  cargoCrossTestTargetName,
66
65
  cargoFrozen,
66
+ runsFrozenCargo,
67
67
  } from './cross-check-policy.js';
68
68
  import type { EslintFileSet } from './eslint-file-set.js';
69
69
  import { closeRunCpuPool, serveRunCpuPool } from './executors/bounded-exec/run-cpu-pool.js';
@@ -466,14 +466,7 @@ function sameNapiPlatform(left: NapiPlatform, right: NapiPlatform | null): boole
466
466
  function hostPlatformTargetNames(targetNames: Iterable<string>, hostPlatform: NapiPlatform | null): string[] {
467
467
  if (hostPlatform === null) return [];
468
468
  const suffix = `-${hostPlatform.architecture}-${hostPlatform.targetFamily}`;
469
- return [...new Set(targetNames)]
470
- .filter(
471
- // Binary targets only. A toolchain prerequisite carries the same platform
472
- // suffix but produces no artifact: the cross builds that need it depend
473
- // on it directly, so the aggregate stays a list of outputs.
474
- (name) => name.endsWith(suffix) && !name.startsWith(NAPI_TOOLCHAIN_TARGET_PREFIX),
475
- )
476
- .sort();
469
+ return [...new Set(targetNames)].filter((name) => name.endsWith(suffix)).sort();
477
470
  }
478
471
 
479
472
  /**
@@ -566,18 +559,23 @@ function targetCommandText(target: TargetConfiguration): string {
566
559
  }
567
560
  /**
568
561
  * The N-API build's inputs beyond the Cargo sources: the toolchain pin, the
569
- * package's `napi` block, which names the binary and the targets, and the napi
570
- * CLI's resolved version from the lockfile. Neither the package version nor
571
- * any other lockfile entry is part of the artifact.
562
+ * package's `napi` block, which names the binary and the targets, and the
563
+ * resolved version of the npm package that drives the build (the napi CLI on
564
+ * macOS; none on Linux, where devenv's zig and cargo-zigbuild are covered by
565
+ * the pin). Neither the package version nor any other lockfile entry is part
566
+ * of the artifact.
572
567
  *
573
- * The pin is stated here rather than inherited: `napi build` compiles with the
574
- * same rustc and links against the same SDK as any other cargo target, but its
575
- * command does not spell `cargo --frozen`, which is how every other cached
576
- * cargo target acquires its toolchain identity. Without it a `.node` linked
577
- * against one toolchain hashed equal to the same sources linked against the
578
- * next one.
568
+ * The pin is stated here rather than inherited: neither `napi build` nor the
569
+ * `cargo-zigbuild` executor spells `cargo --frozen`, which is how every other
570
+ * cached cargo target acquires its toolchain identity. Without it a `.node`
571
+ * linked against one toolchain hashed equal to the same sources linked against
572
+ * the next one.
579
573
  */
580
- function napiInputs(projectRoot: string, repoRooted: boolean): TargetConfiguration['inputs'] {
574
+ function napiInputs(
575
+ projectRoot: string,
576
+ repoRooted: boolean,
577
+ externalDependencies: readonly string[],
578
+ ): TargetConfiguration['inputs'] {
581
579
  // Runtime inputs execute from the workspace root, so the manifest is named
582
580
  // by its path from there whichever way the Cargo invocation is rooted.
583
581
  const packageJson = `./${posix.join(projectRoot, 'package.json')}`;
@@ -587,7 +585,7 @@ function napiInputs(projectRoot: string, repoRooted: boolean): TargetConfigurati
587
585
  ...(repoRooted ? ['{workspaceRoot}/scripts/*.sh'] : []),
588
586
  ...CARGO_TOOLCHAIN_PIN_INPUTS,
589
587
  runtimeInput(`bun -e 'console.log(JSON.stringify(require(${JSON.stringify(packageJson)}).napi ?? null))'`),
590
- { externalDependencies: ['@napi-rs/cli'] },
588
+ { externalDependencies: [...externalDependencies] },
591
589
  ];
592
590
  }
593
591
 
@@ -618,31 +616,14 @@ const NAPI_TARGET_CONVENTIONS: Readonly<Record<string, NapiTargetConvention>> =
618
616
  },
619
617
  };
620
618
 
621
- const NATIVE_LINUX_COMPILER_ENV = Object.freeze({ CC: 'cc', CXX: 'c++' });
622
- const CROSS_LINUX_COMPILER_ENV = Object.freeze({ TARGET_CC: 'clang', TARGET_CXX: 'clang++' });
623
-
624
- function usesNapiCross(target: NapiTargetConvention, hostPlatform: NapiPlatform | null): boolean {
625
- return target.targetFamily === 'linux' && !sameNapiPlatform(target, hostPlatform);
626
- }
627
-
628
- function napiCompilerEnv(
629
- target: NapiPlatform | null,
630
- hostPlatform: NapiPlatform | null,
631
- ): Readonly<Record<string, string>> | undefined {
632
- if (target?.targetFamily !== 'linux') return undefined;
633
- return sameNapiPlatform(target, hostPlatform) ? NATIVE_LINUX_COMPILER_ENV : CROSS_LINUX_COMPILER_ENV;
634
- }
635
-
636
- const NAPI_TOOLCHAIN_TARGET_PREFIX = 'napi-toolchain-';
637
-
638
619
  /**
639
- * Prerequisite target that extracts the cross toolchain one triple needs. The
640
- * platform suffix keeps it inside its own platform family, so it can be a
641
- * dependency of `napi-<arch>-linux` and package-local `cli-<arch>-linux`.
620
+ * The glibc symbol-version floor every Linux N-API addon links against.
621
+ * cargo-zigbuild reads it from the target triple's suffix
622
+ * (`x86_64-unknown-linux-gnu.2.17`) and links zig's stubs for exactly that
623
+ * glibc, so the floor is this literal on every host rather than whatever glibc
624
+ * the build machine carries. 2.17 is below Node ≥ 18's own 2.28 floor.
642
625
  */
643
- export function napiToolchainTargetName(convention: NapiTargetConvention): string {
644
- return `${NAPI_TOOLCHAIN_TARGET_PREFIX}${convention.architecture}-${convention.targetFamily}`;
645
- }
626
+ const LINUX_GLIBC_FLOOR = '2.17';
646
627
 
647
628
  /**
648
629
  * Cargo's two profiles. A build target's default options compile `dev`, the
@@ -1536,8 +1517,8 @@ async function createProjectTargets(
1536
1517
  // than a silent absence.
1537
1518
  //
1538
1519
  // Deliberately NOT pushed to validationTargets: joining the lint aggregate
1539
- // would make `bun run lint` — and CI's own Linux lint, already native — demand
1540
- // the 0.4 GiB cross toolchain that the devenv profile exists to keep opt-in.
1520
+ // would make `bun run lint` — and CI's own Linux lint, already native — on a
1521
+ // macOS host demand the zig toolchain that the devenv profile keeps opt-in.
1541
1522
  targets[CARGO_CROSS_LINT_TARGET] = {
1542
1523
  executor: 'nx:run-commands',
1543
1524
  cache: true,
@@ -1666,9 +1647,8 @@ async function createProjectTargets(
1666
1647
  targets[CARGO_FETCH_TARGET] = {
1667
1648
  executor: 'nx:run-commands',
1668
1649
  // The download lands in CARGO_HOME, outside the workspace: a cache hit
1669
- // would skip work a cold registry still needs — same reason
1670
- // napi-toolchain-* is uncached. Nothing here is a workspace output, so
1671
- // there is nothing for Nx to restore in its place.
1650
+ // would skip work a cold registry still needs. Nothing here is a
1651
+ // workspace output, so there is nothing for Nx to restore in its place.
1672
1652
  cache: false,
1673
1653
  options: {
1674
1654
  // One fetch per manifest, independent of the others: Cargo's own
@@ -1688,7 +1668,7 @@ async function createProjectTargets(
1688
1668
  continue;
1689
1669
  }
1690
1670
  const text = targetCommandText(target);
1691
- if (text.includes(CARGO_FROZEN_PREFIX)) {
1671
+ if (runsFrozenCargo(text)) {
1692
1672
  target.dependsOn = [CARGO_FETCH_TARGET, ...(target.dependsOn ?? [])];
1693
1673
  }
1694
1674
  }
@@ -1699,7 +1679,7 @@ async function createProjectTargets(
1699
1679
  });
1700
1680
  for (const target of Object.values(targets)) {
1701
1681
  const text = targetCommandText(target);
1702
- if (text.includes(CARGO_FROZEN_PREFIX)) {
1682
+ if (runsFrozenCargo(text)) {
1703
1683
  target.dependsOn = [rootFetch, ...(target.dependsOn ?? [])];
1704
1684
  }
1705
1685
  }
@@ -1711,7 +1691,7 @@ async function createProjectTargets(
1711
1691
  // the target already does.
1712
1692
  for (const [name, target] of Object.entries(targets)) {
1713
1693
  const text = targetCommandText(target);
1714
- if (!text.includes(CARGO_FROZEN_PREFIX)) continue;
1694
+ if (!runsFrozenCargo(text)) continue;
1715
1695
  target.outputs ??= [];
1716
1696
  if (!target.cache) continue;
1717
1697
  const cwd: unknown = target.options?.cwd;
@@ -2242,27 +2222,17 @@ function createNapiTargets(
2242
2222
  // that stale local artifacts can mask for months.
2243
2223
  const packageJsonPath = repoRooted ? posix.join(projectRoot, 'package.json') : 'package.json';
2244
2224
  const commonCommand = `--manifest-path ${config.manifestPath} --package ${config.cargoPackage} --package-json-path ${packageJsonPath}`;
2245
- const cargoInputs = napiInputs(projectRoot, repoRooted);
2225
+ const cargoInputs = napiInputs(projectRoot, repoRooted, ['@napi-rs/cli']);
2246
2226
  const cargoCwd = repoRooted ? '.' : projectRoot;
2247
2227
  // A repository-root Cargo invocation runs outside the owning npm package, so
2248
2228
  // Nx's root-only PATH cannot resolve that package's napi CLI.
2249
2229
  const napiCommand = repoRooted ? posix.join(projectRoot, 'node_modules/.bin/napi') : 'napi';
2250
2230
  const outputPath = (projectOutput: string) => (repoRooted ? posix.join(projectRoot, projectOutput) : projectOutput);
2251
- const hostPlatformTargetName =
2252
- hostPlatform === null ? null : `napi-${hostPlatform.architecture}-${hostPlatform.targetFamily}`;
2253
- let nativeHostTargetName: string | null = null;
2254
- if (hostPlatformTargetName !== null) {
2255
- for (const triple of config.targets) {
2256
- const convention = NAPI_TARGET_CONVENTIONS[triple];
2257
- const targetName = convention ? `napi-${convention.architecture}-${convention.targetFamily}` : null;
2258
- if (targetName === hostPlatformTargetName && convention && !usesNapiCross(convention, hostPlatform)) {
2259
- nativeHostTargetName = targetName;
2260
- break;
2261
- }
2262
- }
2263
- }
2231
+ const hasHostPlatformTarget = config.targets.some((triple) => {
2232
+ const convention = NAPI_TARGET_CONVENTIONS[triple];
2233
+ return convention !== undefined && sameNapiPlatform(convention, hostPlatform);
2234
+ });
2264
2235
  const targets: Record<string, TargetConfiguration> = {};
2265
- const hostCompilerEnv = napiCompilerEnv(hostPlatform, hostPlatform);
2266
2236
 
2267
2237
  // The addon the test suite loads. A plain dev build shares target/debug with
2268
2238
  // cargo-test's dependency graph, so after the tests compile this is nearly
@@ -2281,11 +2251,10 @@ function createNapiTargets(
2281
2251
  options: {
2282
2252
  cwd: cargoCwd,
2283
2253
  command: `${napiCommand} build --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputPath('.cache/native-debug')}`,
2284
- ...(hostCompilerEnv ? { env: hostCompilerEnv } : {}),
2285
2254
  },
2286
2255
  };
2287
2256
 
2288
- if (nativeHostTargetName === null) {
2257
+ if (!hasHostPlatformTarget) {
2289
2258
  // The platform target for this host triple is the same compilation, so a
2290
2259
  // second cargo-napi invocation only buys a duplicate dependency graph
2291
2260
  // (a plain build and a `--target` build write different target/
@@ -2303,32 +2272,11 @@ function createNapiTargets(
2303
2272
  options: {
2304
2273
  cwd: cargoCwd,
2305
2274
  command: hostBuild('dev'),
2306
- ...(hostCompilerEnv ? { env: hostCompilerEnv } : {}),
2307
2275
  },
2308
2276
  configurations: { [RELEASE_CONFIGURATION]: { command: hostBuild('release') } },
2309
2277
  };
2310
2278
  }
2311
2279
 
2312
- for (const triple of config.targets) {
2313
- const convention = NAPI_TARGET_CONVENTIONS[triple];
2314
- if (!convention || !usesNapiCross(convention, hostPlatform)) {
2315
- continue;
2316
- }
2317
- // One toolchain target per triple, shared by every cross build that needs
2318
- // it: the inferred napi-<arch>-linux plus any package-local cli-<arch>-linux.
2319
- // Nx runs a shared dependency once, which is what stops those builds from
2320
- // racing inside the Bun store. See the executor for the failure it removes.
2321
- // The name carries the platform suffix so a Linux platform target's
2322
- // dependency closure stays Linux-only (package-target-policy).
2323
- targets[napiToolchainTargetName(convention)] = {
2324
- executor: '@smoothbricks/nx-plugin:napi-cross-toolchain',
2325
- // Extraction lands in ~/.napi-rs, outside the workspace: a cache hit
2326
- // would skip work a cold home directory still needs.
2327
- cache: false,
2328
- options: { triple },
2329
- };
2330
- }
2331
-
2332
2280
  for (const triple of config.targets) {
2333
2281
  const convention = NAPI_TARGET_CONVENTIONS[triple];
2334
2282
  if (!convention) {
@@ -2336,24 +2284,38 @@ function createNapiTargets(
2336
2284
  }
2337
2285
  const targetName = `napi-${convention.architecture}-${convention.targetFamily}`;
2338
2286
  const outputDirectory = `dist/native/${convention.outputName}`;
2339
- const useNapiCross = usesNapiCross(convention, hostPlatform);
2340
- const crossFlag = useNapiCross ? ' --use-napi-cross' : '';
2341
- const compilerEnv = napiCompilerEnv(convention, hostPlatform);
2287
+ if (convention.targetFamily === 'linux') {
2288
+ // Every host builds a Linux addon the same way: devenv's zig through
2289
+ // cargo-zigbuild, glibc pinned by the triple suffix. The napi CLI cannot
2290
+ // carry that suffix (it looks for the artifact under
2291
+ // target/<triple>.2.17/), so the executor names the `.node` itself.
2292
+ targets[targetName] = {
2293
+ executor: '@smoothbricks/nx-plugin:cargo-zigbuild',
2294
+ cache: true,
2295
+ inputs: napiInputs(projectRoot, repoRooted, []),
2296
+ outputs: [`{projectRoot}/${outputDirectory}`],
2297
+ options: {
2298
+ target: `${triple}.${LINUX_GLIBC_FLOOR}`,
2299
+ manifestPath: posix.join(cargoCwd, config.manifestPath),
2300
+ package: config.cargoPackage,
2301
+ output: `{projectRoot}/${outputDirectory}/${config.binaryName}.${convention.outputName}.node`,
2302
+ },
2303
+ configurations: { [RELEASE_CONFIGURATION]: { release: true } },
2304
+ };
2305
+ continue;
2306
+ }
2307
+ // macOS addons need Apple's SDK, which zig does not carry: the napi CLI
2308
+ // drives the host's own toolchain and writes the platform `.d.ts`.
2342
2309
  const platformBuild = (profile: CargoProfile): string =>
2343
- `${napiCommand} build${CARGO_PROFILE_FLAG[profile]} --platform --no-js --dts ${config.binaryName}.${convention.outputName}.d.ts --target ${triple}${crossFlag} ${commonCommand} --output-dir ${outputPath(outputDirectory)}`;
2310
+ `${napiCommand} build${CARGO_PROFILE_FLAG[profile]} --platform --no-js --dts ${config.binaryName}.${convention.outputName}.d.ts --target ${triple} ${commonCommand} --output-dir ${outputPath(outputDirectory)}`;
2344
2311
  targets[targetName] = {
2345
2312
  executor: 'nx:run-commands',
2346
2313
  cache: true,
2347
- ...(useNapiCross ? { dependsOn: [napiToolchainTargetName(convention)] } : {}),
2348
2314
  inputs: cargoInputs,
2349
2315
  outputs: [`{projectRoot}/${outputDirectory}`],
2350
2316
  options: {
2351
2317
  cwd: cargoCwd,
2352
2318
  command: platformBuild('dev'),
2353
- // Genuine Linux cross-compiles use Clang plus napi-rs's downloaded
2354
- // GNU sysroot. A native Linux target uses Nix's cc wrapper so C build
2355
- // scripts resolve the host libc headers instead.
2356
- ...(compilerEnv ? { env: compilerEnv } : {}),
2357
2319
  },
2358
2320
  configurations: { [RELEASE_CONFIGURATION]: { command: platformBuild('release') } },
2359
2321
  };
@@ -800,6 +800,71 @@ it('stops a daemon once the workspace nx link points at a different version', as
800
800
  );
801
801
  });
802
802
 
803
+ it('restarts a daemon once a plugin linked from outside the workspace changes its bytes, in place or by a moved link, and only then', async () => {
804
+ await withNxFixture(
805
+ 'nx-daemon-validity-plugin-',
806
+ async ({ root, socketDirectory, workspace }) => {
807
+ const inference = (version: string) =>
808
+ `// inference ${version}\nmodule.exports = { name: 'linked-plugin', createNodesV2: ['**/never.json', () => []] };\n`;
809
+ // A developer link: the plugin is a package of another checkout, which has its own lockfile.
810
+ const checkout = async (name: string) => {
811
+ const plugin = join(root, name, 'plugin');
812
+ await mkdir(join(plugin, 'dist'), { recursive: true });
813
+ await writeFile(join(root, name, 'bun.lock'), 'checkout lock one\n');
814
+ await writeFile(
815
+ join(plugin, 'package.json'),
816
+ JSON.stringify({ name: 'linked-plugin', version: '1.0.0', main: 'dist/index.js', files: ['dist'] }),
817
+ );
818
+ await writeFile(join(plugin, 'dist', 'index.js'), inference('one'));
819
+ return { plugin, entry: join(plugin, 'dist', 'index.js'), lock: join(root, name, 'bun.lock') };
820
+ };
821
+ const first = await checkout('checkout-a');
822
+ const copy = await checkout('checkout-b');
823
+ const link = join(workspace, 'node_modules', 'linked-plugin');
824
+ const relink = async (target: string) => {
825
+ await unlink(link);
826
+ await symlink(target, link, 'dir');
827
+ };
828
+ await fixtureWorkspace(workspace, join(repositoryRoot, 'node_modules', 'nx'));
829
+ await symlink(first.plugin, link, 'dir');
830
+ await writeFile(join(workspace, 'nx.json'), JSON.stringify({ plugins: ['linked-plugin'] }));
831
+ const env = fixtureNxEnv(workspace, socketDirectory);
832
+ // Nothing in the workspace changes, so no watcher event reaches the daemon: each request judges the link.
833
+ const serves = async (daemon: Daemon, what: string) => {
834
+ expect(
835
+ await requestOnce(daemon.record.socketPath, ping(workspace), `a PING after ${what}`),
836
+ `${what} was refused`,
837
+ ).toEqual({ answered: true, message: true });
838
+ expect(await recordedPid(workspace), `${what} replaced the daemon`).toBe(daemon.record.processId);
839
+ };
840
+ const replaced = async (daemon: Daemon, what: string) => {
841
+ assertNotServed(
842
+ await requestOnce(daemon.record.socketPath, ping(workspace), `a PING sent after ${what}`),
843
+ `a PING sent after ${what}`,
844
+ );
845
+ await awaitExit([daemon.entry], `daemon ${daemon.record.processId} after ${what}`);
846
+ return readyDaemon(
847
+ workspace,
848
+ await replacementAfter({ workspace, previous: daemon.record.processId, what: `a successor after ${what}` }),
849
+ );
850
+ };
851
+ let daemon = await startDaemon(workspace, env);
852
+ await writeFile(first.entry, inference('one'));
853
+ await serves(daemon, 'a same-bytes rewrite of the linked plugin');
854
+ await relink(copy.plugin);
855
+ await serves(daemon, 'the link moving to a copy with the same bytes');
856
+ await writeFile(copy.entry, inference('two'));
857
+ daemon = await replaced(daemon, 'the linked plugin changing in place');
858
+ await relink(first.plugin);
859
+ daemon = await replaced(daemon, 'the link moving to a plugin with other bytes');
860
+ // The checkout's lockfile selects the plugin's dependencies, so its change restarts the daemon as well.
861
+ await writeFile(first.lock, 'checkout lock two\n');
862
+ await replaced(daemon, "the linked plugin checkout's lockfile changing");
863
+ },
864
+ FIXTURE_WORKSPACE,
865
+ );
866
+ });
867
+
803
868
  it('leaves a successor record and socket in place when another process takes the record', async () => {
804
869
  await withNxFixture(
805
870
  'nx-daemon-validity-successor-',
@@ -9,6 +9,7 @@ import type { TaskResults } from 'nx/src/tasks-runner/life-cycle';
9
9
  import type { EnsureBuiltProducerReceipt } from './ensure-built.js';
10
10
  import {
11
11
  completedProducerTasks,
12
+ PRODUCER_RECORDS,
12
13
  postTasksExecution,
13
14
  preTasksExecution,
14
15
  producerEnvironmentIdentity,
@@ -116,16 +117,14 @@ describe('actual producer completion evidence', () => {
116
117
  });
117
118
  it('publishes a refusal beside a published receipt, never over it, and names it in the miss', async () => {
118
119
  const root = await realpath(await mkdtemp(join(tmpdir(), 'producer-refusal-')));
119
- const inherited = process.env.NX_WORKSPACE_DATA_DIRECTORY;
120
- delete process.env.NX_WORKSPACE_DATA_DIRECTORY;
121
120
  try {
122
121
  await writeFile(join(root, 'package.json'), JSON.stringify({ name: 'refusal-fixture' }));
123
122
  await writeFile(join(root, 'nx.json'), '{}');
124
123
  await symlink(join(repoRoot, 'node_modules'), join(root, 'node_modules'), 'dir');
125
- const data = join(root, '.nx', 'workspace-data');
126
- await mkdir(data, { recursive: true });
124
+ const records = join(root, PRODUCER_RECORDS);
125
+ await mkdir(records, { recursive: true });
127
126
  const name = createHash('sha256').update(JSON.stringify(task.id)).digest('hex');
128
- const receiptPath = join(data, `producer-receipt-${name}.json`);
127
+ const receiptPath = join(records, `producer-receipt-${name}.json`);
129
128
  // What an earlier run published; this run's refusal is no evidence about it.
130
129
  const published = JSON.stringify({ version: 1, disposition: 'published', receipt: 'an earlier run' });
131
130
  await writeFile(receiptPath, published);
@@ -143,21 +142,44 @@ describe('actual producer completion evidence', () => {
143
142
  },
144
143
  );
145
144
  expect(await readFile(receiptPath, 'utf8')).toBe(published);
146
- expect((await readdir(data)).sort()).toEqual([`producer-receipt-${name}.json`, `producer-refusal-${name}.json`]);
145
+ expect((await readdir(records)).sort()).toEqual([
146
+ '.gitignore',
147
+ `producer-receipt-${name}.json`,
148
+ `producer-refusal-${name}.json`,
149
+ ]);
150
+ // The records directory ignores itself, so no checkout tracks or hashes a record.
151
+ expect(await readFile(join(records, '.gitignore'), 'utf8')).toBe('*\n');
147
152
  expect(readProducerReceipt(root, task.id)).toEqual({
148
153
  ok: false,
149
- detail:
150
- "Missing/corrupt producer completion contract; the producer's latest run refused: No bound producer pre-execution frame",
154
+ detail: `Corrupt producer completion contract at ${receiptPath}; the producer's latest run refused: No bound producer pre-execution frame`,
151
155
  });
152
- // With no receipt at all, the miss still says why the latest run published none.
156
+ // With no receipt at all, the miss names where the receipt would be and why the latest run published none.
153
157
  await rm(receiptPath);
154
- const missing = readProducerReceipt(root, task.id);
155
- expect(missing.ok ? 'hit' : missing.detail).toEndWith(
156
- "; the producer's latest run refused: No bound producer pre-execution frame",
157
- );
158
+ expect(readProducerReceipt(root, task.id)).toEqual({
159
+ ok: false,
160
+ detail: `No producer completion receipt at ${receiptPath}; the producer's latest run refused: No bound producer pre-execution frame`,
161
+ });
162
+ } finally {
163
+ await rm(root, { recursive: true, force: true });
164
+ }
165
+ });
166
+ it('tells a receipt it cannot read from a missing one, naming the path either way', async () => {
167
+ const root = await realpath(await mkdtemp(join(tmpdir(), 'producer-unreadable-')));
168
+ try {
169
+ const records = join(root, PRODUCER_RECORDS);
170
+ await mkdir(records, { recursive: true });
171
+ const name = createHash('sha256').update(JSON.stringify(task.id)).digest('hex');
172
+ const receiptPath = join(records, `producer-receipt-${name}.json`);
173
+ expect(readProducerReceipt(root, task.id)).toEqual({
174
+ ok: false,
175
+ detail: `No producer completion receipt at ${receiptPath}`,
176
+ });
177
+ // A sandbox that may not read the receipt answers EPERM; an unreadable file answers EACCES the same way.
178
+ await writeFile(receiptPath, '{}', { mode: 0 });
179
+ const denied = readProducerReceipt(root, task.id);
180
+ expect(denied.ok ? 'hit' : denied.detail).toStartWith('Cannot read producer completion receipt: EACCES');
181
+ expect(denied.ok ? 'hit' : denied.detail).toContain(receiptPath);
158
182
  } finally {
159
- if (inherited === undefined) delete process.env.NX_WORKSPACE_DATA_DIRECTORY;
160
- else process.env.NX_WORKSPACE_DATA_DIRECTORY = inherited;
161
183
  await rm(root, { recursive: true, force: true });
162
184
  }
163
185
  });
@@ -46,6 +46,16 @@ import { graphInputContractIdentity } from './graph-input-contract.js';
46
46
  export interface ProducerReceiptsOptions {
47
47
  readonly producerReceipts?: { readonly targets: readonly string[] };
48
48
  }
49
+ /**
50
+ * Where a checkout keeps its producer records, relative to its root: in its own source tree, never in Nx's
51
+ * workspace-data. Under cowshed that directory is build state on the checkout's build volume
52
+ * (specs/cowshed/16_build_volumes.md), and a consumer's read grant of the provider checkout does not reach a volume
53
+ * the checkout only links to (specs/cowshed/04_sandbox.md, "Read grants have one narrow meaning"), so a consumer
54
+ * could never read the receipt it is asked to validate. The directory ignores itself (a `.gitignore` of `*` written
55
+ * with its first record), so in any checkout git never tracks a record and Nx's file walk never hashes one: a record
56
+ * is no source or input of the run that publishes it.
57
+ */
58
+ export const PRODUCER_RECORDS = join('.cache', 'producer-receipts');
49
59
  interface ToolResolution {
50
60
  readonly name: string;
51
61
  readonly from: string;
@@ -95,16 +105,18 @@ function configured(options: ProducerReceiptsOptions | undefined): readonly stri
95
105
  * its products never replaces the receipt an earlier run published: readers validate that receipt on its own evidence.
96
106
  */
97
107
  function recordPath(root: string, target: string, disposition: ProducerRecord['disposition']): string {
98
- const load = createWorkspaceNxRequire(root);
99
108
  return join(
100
- load('nx/src/utils/cache-directory').workspaceDataDirectoryForWorkspace(root),
109
+ root,
110
+ PRODUCER_RECORDS,
101
111
  `producer-${disposition === 'published' ? 'receipt' : 'refusal'}-${sha(target)}.json`,
102
112
  );
103
113
  }
104
114
  function publish(root: string, target: string, record: ProducerRecord): ReceiptEvidence<true> {
105
115
  try {
106
116
  const path = recordPath(root, target, record.disposition);
107
- mkdirSync(dirname(path), { recursive: true });
117
+ const records = dirname(path);
118
+ mkdirSync(records, { recursive: true });
119
+ if (!existsSync(join(records, '.gitignore'))) writeFileSync(join(records, '.gitignore'), '*\n');
108
120
  const temporary = `${path}.${randomUUID()}`;
109
121
  try {
110
122
  writeFileSync(temporary, JSON.stringify(record), { flag: 'wx', mode: 0o600 });
@@ -550,10 +562,22 @@ function latestRefusal(root: string, target: string): string | null {
550
562
  }
551
563
  }
552
564
  function validatedReceipt(root: string, target: string): ReceiptEvidence<EnsureBuiltReceipt> {
565
+ const path = recordPath(root, target, 'published');
566
+ let text: string;
567
+ try {
568
+ text = readFileSync(path, 'utf8');
569
+ } catch (error) {
570
+ // No receipt is a producer that never published one; any other failure is a receipt this reader cannot reach.
571
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT')
572
+ return { ok: false, detail: `No producer completion receipt at ${path}` };
573
+ if (error instanceof Error)
574
+ return { ok: false, detail: `Cannot read producer completion receipt: ${error.message}` };
575
+ throw error;
576
+ }
553
577
  try {
554
- const record = typia.json.isParse<PublishedReceipt>(readFileSync(recordPath(root, target, 'published'), 'utf8'));
578
+ const record = typia.json.isParse<PublishedReceipt>(text);
555
579
  if (record === null || record.version !== 1)
556
- return { ok: false, detail: 'Missing/corrupt producer completion contract' };
580
+ return { ok: false, detail: `Corrupt producer completion contract at ${path}` };
557
581
  const receipt = record.receipt;
558
582
  if (
559
583
  receipt.workspaceRoot !== realpathSync(root) ||
package/src/testing.ts CHANGED
@@ -138,9 +138,10 @@ export async function awaitExit(
138
138
  owner: string,
139
139
  timeoutMs = EXIT_TIMEOUT_MS,
140
140
  ): Promise<void> {
141
- const deadline = Date.now() + timeoutMs;
141
+ // The monotonic clock: a wall-clock step (NTP, sleep and wake) must not move the deadline.
142
+ const deadline = performance.now() + timeoutMs;
142
143
  for (let waiting = processes.filter((entry) => isRunning(entry.pid)); waiting.length > 0; ) {
143
- if (Date.now() > deadline) {
144
+ if (performance.now() > deadline) {
144
145
  // A signal probe also answers for a zombie, which has already exited.
145
146
  const live = new Set(
146
147
  (await processTable()).filter((entry) => !entry.stat.startsWith('Z')).map((entry) => entry.pid),