@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
@@ -678,7 +678,7 @@ index c2a2f8f70fe71940e47c97931c5925bac1fbd480..39582a8fc342ae59decd3d4ca25179f2
678
678
  // Bump generation synchronously so any in-flight compute fails its
679
679
  diff --git a/dist/src/daemon/server/restart-checks.d.ts b/dist/src/daemon/server/restart-checks.d.ts
680
680
  new file mode 100644
681
- index 0000000000000000000000000000000000000000..2a76dce933112854e34d61a44aa90b7c4e1d34e9
681
+ index 0000000000000000000000000000000000000000..28f263f82b7b698ec1bf88943924696b3d9a91e7
682
682
  --- /dev/null
683
683
  +++ b/dist/src/daemon/server/restart-checks.d.ts
684
684
  @@ -0,0 +1,10 @@
@@ -687,22 +687,22 @@ index 0000000000000000000000000000000000000000..2a76dce933112854e34d61a44aa90b7c
687
687
  +export declare const DAEMON_VALIDITY_SAFETY_INTERVAL_MS = 5000;
688
688
  +export declare const relativeServerProcess: string;
689
689
  +export declare function registerDaemonForRestartChecks(server: Server, sockets: Iterable<Socket>, socketPath: string): void;
690
- +export declare function recordLockFileHash(): void;
690
+ +export declare function recordInstallationBaseline(): void;
691
691
  +export declare function restartDaemonIfLockFilesChanged(paths: string[]): boolean;
692
692
  +export declare function stopDaemonIfReplaced(events: WatchEvent[]): boolean;
693
693
  +export declare function stopDaemonIfOutdated(): boolean;
694
694
  +export declare function stopDaemonIfWorkspaceGone(): boolean;
695
695
  diff --git a/dist/src/daemon/server/restart-checks.js b/dist/src/daemon/server/restart-checks.js
696
696
  new file mode 100644
697
- index 0000000000000000000000000000000000000000..6adb712340b154dcabb7570bc1b4c586f3416cdf
697
+ index 0000000000000000000000000000000000000000..5f7aa0aa874dfe389388169c8acb0c0ab45f5180
698
698
  --- /dev/null
699
699
  +++ b/dist/src/daemon/server/restart-checks.js
700
- @@ -0,0 +1,127 @@
700
+ @@ -0,0 +1,295 @@
701
701
  +"use strict";
702
702
  +Object.defineProperty(exports, "__esModule", { value: true });
703
703
  +exports.relativeServerProcess = exports.DAEMON_VALIDITY_SAFETY_INTERVAL_MS = void 0;
704
704
  +exports.registerDaemonForRestartChecks = registerDaemonForRestartChecks;
705
- +exports.recordLockFileHash = recordLockFileHash;
705
+ +exports.recordInstallationBaseline = recordInstallationBaseline;
706
706
  +exports.restartDaemonIfLockFilesChanged = restartDaemonIfLockFilesChanged;
707
707
  +exports.stopDaemonIfReplaced = stopDaemonIfReplaced;
708
708
  +exports.stopDaemonIfOutdated = stopDaemonIfOutdated;
@@ -740,8 +740,14 @@ index 0000000000000000000000000000000000000000..6adb712340b154dcabb7570bc1b4c586
740
740
  + }
741
741
  + return (0, file_hasher_1.hashArray)(hashes);
742
742
  +}
743
- +function recordLockFileHash() {
743
+ +// The startup baseline of everything a restart judges by bytes: the root
744
+ +// lockfiles and the linked plugins below.
745
+ +function recordInstallationBaseline() {
744
746
  + lockFileHash = hashLockFiles();
747
+ + const roots = linkedPluginRoots() ?? [];
748
+ + linkedPluginRootKey = JSON.stringify(roots);
749
+ + linkedPluginFiles = hashCensus(linkedPluginCensus(roots), new Map());
750
+ + linkedPluginCensusAt = Date.now();
745
751
  +}
746
752
  +function lockFileHashChanged() {
747
753
  + const newHash = hashLockFiles();
@@ -753,6 +759,164 @@ index 0000000000000000000000000000000000000000..6adb712340b154dcabb7570bc1b4c586
753
759
  + lockFileHash = newHash;
754
760
  + return false;
755
761
  +}
762
+ +// A plugin nx.json names whose package resolves outside the workspace (a
763
+ +// developer link into another checkout) changes behind that link with no
764
+ +// lockfile change here. The daemon kept serving the graph the old plugin code
765
+ +// inferred, so every task hashed after the change was keyed on a configuration
766
+ +// no fresh process computes. Its published files and the lockfiles of the
767
+ +// checkout it lives in are judged like the root lockfiles: a file whose stat
768
+ +// moved is hashed again, and only changed bytes restart the daemon. Files are
769
+ +// keyed by plugin and package-relative path, so a link moved to a copy with the
770
+ +// same bytes keeps the daemon. A request resolves each link and stats the files
771
+ +// already known; a moved link, and at most once per safety interval anyway, takes
772
+ +// the full census, which finds a file added beside them. A package inside the
773
+ +// workspace changes only with its lockfile.
774
+ +let linkedPluginRootKey;
775
+ +let linkedPluginFiles;
776
+ +let linkedPluginCensusAt = 0;
777
+ +const PACKAGE_GLOB = /[*?[{]/;
778
+ +function pluginSpecifiers() {
779
+ + let plugins;
780
+ + try {
781
+ + plugins = JSON.parse((0, fs_1.readFileSync)(nxJson, 'utf8')).plugins;
782
+ + }
783
+ + catch (error) {
784
+ + logger_1.serverLogger.log(`[Server] linked plugins not judged: nx.json unreadable: ${error.message}`);
785
+ + return null;
786
+ + }
787
+ + return (Array.isArray(plugins) ? plugins : [])
788
+ + .map((entry) => (typeof entry === 'string' ? entry : entry?.plugin))
789
+ + .filter((name) => typeof name === 'string' && !name.startsWith('.') && !(0, path_1.isAbsolute)(name));
790
+ +}
791
+ +// Each nx.json plugin whose package resolves outside the workspace, as
792
+ +// [specifier, real package root]; null when nx.json cannot say which plugins there are.
793
+ +function linkedPluginRoots() {
794
+ + const specifiers = pluginSpecifiers();
795
+ + if (specifiers === null) return null;
796
+ + const workspace = (0, fs_1.realpathSync)(workspace_root_1.workspaceRoot);
797
+ + const roots = [];
798
+ + for (const name of specifiers) {
799
+ + let root;
800
+ + try {
801
+ + root = (0, fs_1.realpathSync)((0, path_1.join)(workspace_root_1.workspaceRoot, 'node_modules', name));
802
+ + }
803
+ + catch (error) {
804
+ + if (error.code === 'ENOENT') continue;
805
+ + throw error;
806
+ + }
807
+ + if (root !== workspace && !root.startsWith(workspace + path_1.sep)) roots.push([name, root]);
808
+ + }
809
+ + return roots;
810
+ +}
811
+ +function statKey(stat) {
812
+ + return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
813
+ +}
814
+ +// Adds every file under `path` (following links, each directory once) to
815
+ +// `census`, keyed by `prefix` and its path relative to `base`, with its stat.
816
+ +function addFiles(census, prefix, base, path, seen = new Set()) {
817
+ + let stat;
818
+ + try {
819
+ + stat = (0, fs_1.statSync)(path, { bigint: true });
820
+ + }
821
+ + catch (error) {
822
+ + if (error.code === 'ENOENT') return;
823
+ + throw error;
824
+ + }
825
+ + if (stat.isDirectory()) {
826
+ + const directory = `${stat.dev}:${stat.ino}`;
827
+ + if (seen.has(directory)) return;
828
+ + seen.add(directory);
829
+ + for (const entry of (0, fs_1.readdirSync)(path)) {
830
+ + if (entry !== 'node_modules') addFiles(census, prefix, base, (0, path_1.join)(path, entry), seen);
831
+ + }
832
+ + }
833
+ + else if (stat.isFile()) {
834
+ + census.set(`${prefix}${(0, path_1.relative)(base, path)}`, { path, stat: statKey(stat) });
835
+ + }
836
+ +}
837
+ +// Every file each linked plugin publishes and its checkout's lockfiles.
838
+ +function linkedPluginCensus(roots) {
839
+ + const census = new Map();
840
+ + for (const [name, root] of roots) {
841
+ + const manifest = (0, path_1.join)(root, 'package.json');
842
+ + addFiles(census, `${name}\0`, root, manifest);
843
+ + // A manifest with no plain `files` list (absent, a glob, or bytes that do
844
+ + // not parse, which the census holds too) publishes the whole package.
845
+ + let files;
846
+ + try {
847
+ + files = JSON.parse((0, fs_1.readFileSync)(manifest, 'utf8')).files;
848
+ + }
849
+ + catch {
850
+ + files = undefined;
851
+ + }
852
+ + const listed = Array.isArray(files) ? files.filter((file) => typeof file !== 'string' || !file.startsWith('!')) : [];
853
+ + const published = listed.length > 0 && listed.every((file) => typeof file === 'string' && !PACKAGE_GLOB.test(file));
854
+ + for (const file of published ? listed : ['.']) addFiles(census, `${name}\0`, root, (0, path_1.join)(root, file));
855
+ + for (let directory = root; ; directory = (0, path_1.dirname)(directory)) {
856
+ + const locks = LOCK_FILE_NAMES.map((lock) => (0, path_1.join)(directory, lock)).filter((lock) => (0, fs_1.existsSync)(lock));
857
+ + if (locks.length > 0 || (0, path_1.dirname)(directory) === directory) {
858
+ + for (const lock of locks) addFiles(census, `${name}\0lock\0`, directory, lock);
859
+ + break;
860
+ + }
861
+ + }
862
+ + }
863
+ + return census;
864
+ +}
865
+ +// The census with each file's hash, reusing `recorded`'s for a file whose path
866
+ +// and stat have not moved.
867
+ +function hashCensus(census, recorded) {
868
+ + const files = new Map();
869
+ + for (const [key, { path, stat }] of census) {
870
+ + const previous = recorded.get(key);
871
+ + files.set(key, previous !== undefined && previous.path === path && previous.stat === stat
872
+ + ? previous
873
+ + : { path, stat, hash: (0, native_1.hashFile)(path) });
874
+ + }
875
+ + return files;
876
+ +}
877
+ +// The known files' stats, a vanished one left out.
878
+ +function knownFileStats() {
879
+ + const census = new Map();
880
+ + for (const [key, { path }] of linkedPluginFiles) {
881
+ + let stat;
882
+ + try {
883
+ + stat = (0, fs_1.statSync)(path, { bigint: true });
884
+ + }
885
+ + catch (error) {
886
+ + if (error.code === 'ENOENT') continue;
887
+ + throw error;
888
+ + }
889
+ + census.set(key, { path, stat: statKey(stat) });
890
+ + }
891
+ + return census;
892
+ +}
893
+ +function linkedPluginsChanged() {
894
+ + if (linkedPluginFiles === undefined) return false;
895
+ + const roots = linkedPluginRoots();
896
+ + if (roots === null) return false;
897
+ + const rootKey = JSON.stringify(roots);
898
+ + const now = Date.now();
899
+ + const full = rootKey !== linkedPluginRootKey || now - linkedPluginCensusAt >= exports.DAEMON_VALIDITY_SAFETY_INTERVAL_MS;
900
+ + const census = full ? linkedPluginCensus(roots) : knownFileStats();
901
+ + if (full) {
902
+ + linkedPluginRootKey = rootKey;
903
+ + linkedPluginCensusAt = now;
904
+ + }
905
+ + const files = hashCensus(census, linkedPluginFiles);
906
+ + let change = null;
907
+ + for (const [key, { path, hash }] of files) {
908
+ + const previous = linkedPluginFiles.get(key);
909
+ + if (previous === undefined) change ??= `${path} appeared`;
910
+ + else if (previous.hash !== hash) change ??= `${path} changed`;
911
+ + }
912
+ + for (const [key, { path }] of linkedPluginFiles) {
913
+ + if (!files.has(key)) change ??= `${path} disappeared`;
914
+ + }
915
+ + linkedPluginFiles = files;
916
+ + if (change === null) return false;
917
+ + logger_1.serverLogger.log(`[Server] linked plugin file ${change}`);
918
+ + return true;
919
+ +}
756
920
  +// Applied paths have been hashed by the native workspace context; same-byte
757
921
  +// rewrites were dropped already. No lockfile is read on this watcher path.
758
922
  +function restartDaemonIfLockFilesChanged(paths) {
@@ -806,6 +970,10 @@ index 0000000000000000000000000000000000000000..6adb712340b154dcabb7570bc1b4c586
806
970
  + restartDaemon('LOCK_FILES_CHANGED');
807
971
  + return true;
808
972
  + }
973
+ + if (linkedPluginsChanged()) {
974
+ + restartDaemon('LINKED_PLUGIN_CHANGED');
975
+ + return true;
976
+ + }
809
977
  + return false;
810
978
  +}
811
979
  +function isReplaced() {
@@ -826,7 +994,7 @@ index 0000000000000000000000000000000000000000..6adb712340b154dcabb7570bc1b4c586
826
994
  + (0, shutdown_utils_1.handleServerProcessTerminationWithRestart)({ server: daemon.server, reason, sockets: daemon.sockets });
827
995
  +}
828
996
  diff --git a/dist/src/daemon/server/server.js b/dist/src/daemon/server/server.js
829
- index b1c143e244efd435b28642ed86e999d6c86f7d94..5f1157fd3e37afc8ef739a8adce78a2b472e08af 100644
997
+ index b1c143e244efd435b28642ed86e999d6c86f7d94..c68bcacb9bc46babaa86ea0ac212e79de1b47244 100644
830
998
  --- a/dist/src/daemon/server/server.js
831
999
  +++ b/dist/src/daemon/server/server.js
832
1000
  @@ -7,17 +7,13 @@ const fs_1 = require("fs");
@@ -1011,8 +1179,8 @@ index b1c143e244efd435b28642ed86e999d6c86f7d94..5f1157fd3e37afc8ef739a8adce78a2b
1011
1179
  + process.exit(0);
1012
1180
  + }
1013
1181
  + (0, restart_checks_1.registerDaemonForRestartChecks)(server, exports.openSockets, socketPath);
1014
- + // Record before watch/scan so a lockfile changed during boot is not lost.
1015
- + (0, restart_checks_1.recordLockFileHash)();
1182
+ + // Record before watch/scan so a lockfile or linked plugin changed during boot is not lost.
1183
+ + (0, restart_checks_1.recordInstallationBaseline)();
1016
1184
  // Watch before scan: a file written during boot must be visible to the
1017
1185
  // watcher or the scan below. Scan-first left a blind window where such
1018
1186
  // files stayed invisible to both until an unrelated change arrived.
@@ -98,6 +98,19 @@
98
98
  mkdir -p "$out/bin"
99
99
  ln -s ${pkgs.python3Packages.pyflakes}/bin/pyflakes "$out/bin/pyflakes"
100
100
  '';
101
+
102
+ # Builds every Linux artifact and the cross clippy; see `profiles.linux-cross`
103
+ # below for where it applies and why. The rust-std set is every Linux triple
104
+ # an artifact ships for except x86_64-unknown-linux-gnu, which the base shell
105
+ # already carries.
106
+ linuxToolchain = {
107
+ packages = [pkgs.zig pkgs.cargo-zigbuild];
108
+ languages.rust.targets = [
109
+ "aarch64-unknown-linux-gnu"
110
+ "x86_64-unknown-linux-musl"
111
+ "aarch64-unknown-linux-musl"
112
+ ];
113
+ };
101
114
  in {
102
115
  # nixpkgs carries actionlint, not the jdx fork. Supply the immutable upstream
103
116
  # release as a normal package, with the same pin in developer shells and CI.
@@ -233,62 +246,49 @@ in {
233
246
  # CI validates on Linux, so a macOS shell carries Linux's std and can
234
247
  # type-check the arm CI compiles. rust-std alone reaches every crate whose
235
248
  # dependency graph is pure Rust; a dependency that compiles C for the target
236
- # — ring, openssl-sys, libgit2-sys, libz-sys — additionally needs a cross C
237
- # compiler, which is 0.4 GiB and so lives in the opt-in `linux-cross` profile
238
- # below rather than here, keeping it off every macOS shell and macOS runner.
249
+ # — ring, openssl-sys, libgit2-sys, libz-sys — additionally needs a C
250
+ # compiler for the target, which is zig in the `linux-cross` toolchain
251
+ # below, kept off every macOS shell and macOS runner.
239
252
  #
240
253
  # The reverse direction is not available at any price: type-checking an Apple
241
254
  # target from Linux needs an Apple SDK for those same C-building
242
255
  # dependencies, which is a licensing boundary rather than a missing package.
243
- targets = [
244
- "wasm32-unknown-unknown"
245
- "x86_64-unknown-linux-gnu"
246
- ];
256
+ targets =
257
+ [
258
+ "wasm32-unknown-unknown"
259
+ "x86_64-unknown-linux-gnu"
260
+ ]
261
+ ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux linuxToolchain.languages.rust.targets;
247
262
  };
248
263
 
249
- # Opt-in Linux cross toolchain, activated by `devenv -P linux-cross` and driven
250
- # by the root `check:linux` script. devenv 2.2.3 has first-class profiles, so
251
- # this is one gated module in the shared file rather than a second config
252
- # directory that would have to re-import and re-pin everything here.
253
- #
254
- # It is a profile and NOT a default package because pkgsCross.gnu64's cc
255
- # closure is 0.4 GiB against a default shell closure of ~5.4 GiB — a 7% tax on
256
- # every shell entry and every CI cache restore, to serve one command that a
257
- # macOS laptop runs deliberately. Nothing on Darwin links a Linux object.
264
+ # The Linux toolchain: zig, driven through cargo-zigbuild, plus the Linux
265
+ # rust-std set. It builds every published Linux artifact — static musl CLIs,
266
+ # glibc 2.17 N-API addons — and `check:linux`'s cross clippy, with the same
267
+ # command on every host. zig carries glibc symbol-version stubs for every
268
+ # glibc and the musl sources inside its own store path, so nothing on the
269
+ # build machine reaches the artifact: no loader path, no RUNPATH, no build
270
+ # host's glibc floor. cargo-zigbuild supplies the `zig cc` shims and per-triple
271
+ # compiler variables itself, so this module sets no environment.
258
272
  #
259
- # Why a C compiler is needed at all, when rust-std above is already installed:
260
- # ring, openssl-sys, libgit2-sys and libz-sys compile C for the target from
261
- # their build scripts, and build scripts are compiled and run even under
262
- # `cargo check`, so std alone stops at `ToolNotFound: failed to find tool
263
- # "x86_64-linux-gnu-gcc"`. The `cc` crate probes triple-prefixed tool names,
264
- # which is precisely what this wrapper's bin/ exports.
273
+ # A Linux host carries it in the base shell, because its ordinary `build`
274
+ # includes its own platform's artifacts. A macOS host opts in through the
275
+ # `linux-cross` profile, activated by `devenv -P linux-cross` and driven by
276
+ # the root `check:linux` script: zig is a 380 MiB closure, about 0.9 GiB with
277
+ # the three rust-std targets, and nothing else on Darwin needs it. devenv 2.2.3
278
+ # has first-class profiles, so this is one gated module in the shared file
279
+ # rather than a second config directory that would re-import and re-pin
280
+ # everything here.
265
281
  #
266
- # Each tool path is derived from the wrapper's own `targetPrefix` instead of
267
- # being written out, so a nixpkgs bump that renames the prefix carries these
268
- # with it rather than leaving four stale strings that fail at build-script time.
269
- #
270
- # This profile supplies the toolchain and nothing else. CARGO_BUILD_TARGET is
282
+ # The profile supplies the toolchain and nothing else. CARGO_BUILD_TARGET is
271
283
  # deliberately NOT set: the triple belongs to the Nx target that asks for it
272
- # (`cargo-lint-x64-linux` passes `--target` explicitly), not to the ambient
284
+ # (`cargo-lint-cross` passes `--target` explicitly), not to the ambient
273
285
  # environment. An ambient triple would make the check silently host-local
274
- # whenever the profile was forgotten — reporting green having compiled macOS —
275
- # and that false green is the precise failure this whole profile exists to end.
286
+ # whenever the profile was forgotten — reporting green having compiled macOS.
276
287
  # With the flag on the target instead, running it outside this profile fails
277
- # loudly at `ToolNotFound` and a host lint can never be mistaken for a cross one.
278
- profiles.linux-cross.module = let
279
- crossCC = pkgs.pkgsCross.gnu64.stdenv.cc;
280
- crossLibc = lib.getDev crossCC.libc;
281
- tool = name: "${crossCC}/bin/${crossCC.targetPrefix}${name}";
282
- in {
283
- packages = [crossCC];
284
- env = {
285
- CC_x86_64_unknown_linux_gnu = tool "cc";
286
- CXX_x86_64_unknown_linux_gnu = tool "c++";
287
- AR_x86_64_unknown_linux_gnu = tool "ar";
288
- CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER = tool "cc";
289
- # bindgen runs host libclang, which cannot infer the cross compiler's headers.
290
- BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu = "--target=x86_64-unknown-linux-gnu -isystem ${crossLibc}/include -isystem ${pkgs.pkgsCross.gnu64.linuxHeaders}/include";
291
- };
288
+ # loudly on the missing cargo-zigbuild, and a host lint can never be mistaken
289
+ # for a cross one.
290
+ profiles.linux-cross.module = {
291
+ config = lib.mkIf (!pkgs.stdenv.hostPlatform.isLinux) linuxToolchain;
292
292
  };
293
293
 
294
294
  # linux-cross is the only profile here, and the shape of the publish job is
@@ -404,7 +404,7 @@ in {
404
404
  # `cargo hakari verify` for a workspace that took that route.
405
405
  pkgs.cargo-hakari
406
406
  ]
407
- ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [pkgs.chromium];
407
+ ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux ([pkgs.chromium] ++ linuxToolchain.packages);
408
408
 
409
409
  # devenv wraps the Python interpreter to find native libraries in
410
410
  # `languages.python.libraries`, whose default is this checkout's
@@ -537,9 +537,7 @@ in {
537
537
  # use, so a hook and a shell resolve one binary the same way. The Rust
538
538
  # toolchain's store bin then goes ahead of all of it (rustToolchainBin
539
539
  # above): the same files the profile links, named by a path no checkout
540
- # owns. Ahead of even that goes the installed cowshed's bin, whose
541
- # `cargo` link is the jobserver launcher, so the budget reaches builds
542
- # no Nx executor started.
540
+ # owns.
543
541
  # 3. ttsc drives the native TypeScript 7 binary while Nx imports the TypeScript
544
542
  # 6 API, so the two must be named separately.
545
543
  # 4. ttsc caches in the checkout's .cache/ttsc (the path the CI ttsc-plugin
@@ -23,7 +23,8 @@
23
23
  * names: the checkout's own build, never a consumer override;
24
24
  * - each such package's `node_modules` links. A link into the provider's own
25
25
  * `node_modules/.bun` store copies that store entry whole; a link into Bun's
26
- * global cache stays an absolute link to it. Any other target refuses.
26
+ * global cache, as `bun pm cache` names it in the consumer checkout, stays an
27
+ * absolute link to it. Any other target refuses.
27
28
  *
28
29
  * Provenance is the provider's own Nx producer receipt. Every declared target
29
30
  * must be a probe hit (the read-only `probeBuilt`, which runs and
@@ -156,6 +157,8 @@ type PlanNode =
156
157
  interface SnapshotPlan {
157
158
  readonly name: string;
158
159
  readonly root: string;
160
+ /** Bun's immutable install cache the plan's links were classified against (`bunCacheRoot`). */
161
+ readonly cache: string;
159
162
  readonly packagePath: string;
160
163
  readonly nodes: ReadonlyMap<string, PlanNode>;
161
164
  }
@@ -184,7 +187,7 @@ export async function snapshotBinding(
184
187
  ): Promise<SnapshotBinding> {
185
188
  try {
186
189
  const store = snapshotStore(root);
187
- const plan = planSnapshot(source, name, declaration);
190
+ const plan = planSnapshot(source, name, declaration, bunCacheRoot(root));
188
191
  const id = await capture(store, plan, declaration, probe, fingerprintOf(plan));
189
192
  return { kind: 'snapshot', id, directory: path.join(store, id, plan.packagePath) };
190
193
  } catch (error) {
@@ -236,11 +239,10 @@ export function pluginProbe(from: string): ProducerProbe {
236
239
  };
237
240
  }
238
241
 
239
- /** What a snapshot of `source` would hold, read from the provider as it is now. */
240
- function planSnapshot(source: string, name: string, declaration: SnapshotDeclaration): SnapshotPlan {
242
+ /** What a snapshot of `source` would hold, read from the provider as it is now, with `cache` as Bun's cache. */
243
+ function planSnapshot(source: string, name: string, declaration: SnapshotDeclaration, cache: string): SnapshotPlan {
241
244
  const directory = realpathSync(source);
242
245
  const root = providerRoot(directory);
243
- const cache = bunCacheRoot(root);
244
246
  const nodes = new Map<string, PlanNode>();
245
247
  const pending = [directory];
246
248
  const packages = new Map<string, Record<string, unknown>>();
@@ -307,7 +309,7 @@ function planSnapshot(source: string, name: string, declaration: SnapshotDeclara
307
309
  addFile(path.join(root, 'package.json'), 'provider');
308
310
  for (const specifier of declaration.artifactModules) addFile(nativeArtifact(specifier, directory), 'provider');
309
311
  for (const [at, manifest] of packages) assertExportsPublished(at, manifest, root, nodes);
310
- return { name, root, packagePath: path.relative(root, directory), nodes };
312
+ return { name, root, cache, packagePath: path.relative(root, directory), nodes };
311
313
  }
312
314
 
313
315
  /**
@@ -356,7 +358,12 @@ function providerRoot(directory: string): string {
356
358
  }
357
359
  }
358
360
 
359
- /** Bun's immutable install cache as the provider's Bun names it. */
361
+ /**
362
+ * Bun's immutable install cache as Bun names it in the consumer checkout `root`. Never in the provider: `bun pm`
363
+ * opens its root manifest for writing just to print a path, and a sandboxed consumer may only read its provider (a
364
+ * cowshed workspace's sibling grant). Every checkout reaches the cache through one literal path (smoothbricks
365
+ * specs/cowshed/03_caches.md, "Link-target caches"), so a provider link into another cache refuses as outside it.
366
+ */
360
367
  function bunCacheRoot(root: string): string {
361
368
  const run = spawnSync('bun', ['pm', 'cache'], { cwd: root, encoding: 'utf8' });
362
369
  if (run.error !== undefined || run.status !== 0) {
@@ -560,7 +567,10 @@ async function capture(
560
567
  attest(relative, bytes, digest, executable, tracked, outputs, plan, provenance);
561
568
  census.push({ path: relative, type: 'file', executable, sha256: digest });
562
569
  }
563
- if (fingerprintOf(planSnapshot(path.join(plan.root, plan.packagePath), plan.name, declaration)) !== fingerprint) {
570
+ if (
571
+ fingerprintOf(planSnapshot(path.join(plan.root, plan.packagePath), plan.name, declaration, plan.cache)) !==
572
+ fingerprint
573
+ ) {
564
574
  throw new SnapshotRefusal(
565
575
  `${plan.root} changed while it was copied; nothing was published, so retry once it is quiet`,
566
576
  );
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bash
2
- # Single source of truth for repo-local PATH and installed Cargo launcher precedence.
2
+ # Single source of truth for repo-local PATH and the installed cowshed's place in it.
3
3
  # All tooling that sets up PATH must call this instead of hardcoding paths.
4
4
  #
5
5
  # Usage:
@@ -8,24 +8,27 @@
8
8
  # repository so the guard never publishes what it guards; with none
9
9
  # configured the check passes silently.
10
10
  #
11
- # 2. The macOS-only Linux cross-compile gate. It is a cache PROBE and nothing
12
- # else: it reads the nx cache and never compiles. A hit means a real
13
- # `cargo clippy --target x86_64-unknown-linux-gnu` already passed for exactly
14
- # this tree, so the push is safe with no toolchain present. Anything else
15
- # refuses the push and names the one command that fixes it.
11
+ # 2. The macOS-only Linux cross-compile gate. It asks Nx for cargo-lint-cross,
12
+ # whose hit means a real `cargo-zigbuild clippy --target x86_64-unknown-linux-gnu`
13
+ # already passed for exactly this tree, so the push is safe with no toolchain
14
+ # present. From a plain shell the cross target itself never compiles here: on
15
+ # a miss its guard refuses. Its dependencies are ordinary Nx tasks whose outputs
16
+ # the cross key reads, so Nx restores them from the cache or, for a tree no gate
17
+ # ran, builds them. A refusal names the one command that fixes it; any other Nx
18
+ # failure is said as that, never as a cache miss.
16
19
  #
17
- # Why probe-only. The cross-clippy needs the linux-cross C toolchain, which
18
- # lives in a devenv profile. A hook that entered that profile spent minutes
19
- # compiling on a push the user expected to take a second, and it did so in an
20
- # environment they never asked for. Pushing is not the place to discover that
21
- # the tree has not been compiled for Linux; `bun run check:linux` is.
20
+ # Why the cross target never compiles here. The cross-clippy needs zig and
21
+ # cargo-zigbuild, which a macOS host carries only in the linux-cross devenv
22
+ # profile. A hook that entered that profile spent minutes compiling on a push
23
+ # the user expected to take a second, and it did so in an environment they
24
+ # never asked for. Pushing is not the place to discover that the tree has not
25
+ # been compiled for Linux: the land gate, or `bun run check:linux`, is.
22
26
  #
23
- # CC_x86_64_unknown_linux_gnu is unset for the probe deliberately. The target's
24
- # own guard reads it to decide whether the toolchain is present, so leaving it
25
- # set would let a push made from inside an already-entered linux-cross shell
26
- # fall through into a real multi-minute compile. It is not a declared input of
27
- # the target, so unsetting it cannot change the task hash — a warm entry still
28
- # hits.
27
+ # The target's own guard refuses to start when cargo-zigbuild is not on PATH,
28
+ # which is what turns a miss into a refusal here. A push made from a shell that
29
+ # already carries cargo-zigbuild — an entered linux-cross shell — passes that
30
+ # guard, so there a miss runs the check itself: the same clippy `check:linux`
31
+ # runs, in the toolchain the user entered for it.
29
32
  #
30
33
  # Everything in tooling depends only on devenv.nix packages, so this hook also
31
34
  # works with no devenv on PATH. It must never pretend a check ran that did not.
@@ -63,18 +66,33 @@ case "$(uname -s)" in
63
66
  *) exit 0 ;;
64
67
  esac
65
68
 
66
- if env -u CC_x86_64_unknown_linux_gnu nx run-many -t cargo-lint-cross --output-style=static; then
67
- exit 0
68
- fi
69
+ # The guard's refusal (nx-plugin cross-check-policy.ts CARGO_CROSS_LINT_REFUSAL)
70
+ # is the one line that means the key missed. Nx exits 1 for every task failure,
71
+ # so the hook reads the output for it rather than guessing from the status.
72
+ output=$(mktemp "${TMPDIR:-/tmp}/pre-push-cross.XXXXXX") || exit 1
73
+ trap 'rm -f "$output"' EXIT
74
+ set -o pipefail
75
+ nx run-many -t cargo-lint-cross --output-style=static 2>&1 | tee "$output"
76
+ status=$?
77
+ [ "$status" -eq 0 ] && exit 0
69
78
 
70
- cat >&2 <<'EOF'
79
+ if grep -qF 'cargo-lint-cross needs cargo-zigbuild from the linux-cross toolchain; run: bun run check:linux' "$output"; then
80
+ cat >&2 <<'EOF'
71
81
 
72
82
  pre-push: the Linux cross-compile check is NOT cached for this tree, so this
73
- push would ship code that has never been compiled for Linux. This hook only
74
- reads the cache; it does not build. The "needs the linux-cross C toolchain"
75
- line above is the probe refusing to compile, not a broken toolchain.
83
+ push would ship code that has never been compiled for Linux. The "needs
84
+ cargo-zigbuild" line above is the cross target refusing to compile here, not a
85
+ broken toolchain.
76
86
 
77
87
  Run: bun run check:linux
78
88
  Wait for it to pass, then push again.
79
89
  EOF
90
+ else
91
+ cat >&2 <<EOF
92
+
93
+ pre-push: Nx failed (exit $status) before the Linux cross-compile check reached
94
+ a cache verdict; the output above names why. This is not a cache miss, and
95
+ bun run check:linux will not fix it.
96
+ EOF
97
+ fi
80
98
  exit 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.4.31",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -558,7 +558,7 @@ async function shim(
558
558
  join(bin, 'cargo'),
559
559
  [
560
560
  '#!/bin/sh',
561
- // Delegate with the caller's original search path: a launcher must not resolve this shim again.
561
+ // Delegate with the caller's original search path: nothing the real Cargo starts may resolve this shim again.
562
562
  `export PATH=${quote(path)}`,
563
563
  `real=${quote(real)}`,
564
564
  `if [ "$1" != metadata ]; then ${forward}; fi`,
@@ -254,7 +254,7 @@ function leafControls(workspace: string, edit: (path: string, text: string) => P
254
254
  };
255
255
  }
256
256
 
257
- it('delegates counted Cargo through the caller launcher without re-entering its broker', async () => {
257
+ it("delegates counted Cargo to the caller's own cargo without re-entering its broker", async () => {
258
258
  const root = await realpath(await mkdtemp(join(tmpdir(), 'cargo-counted-delegate-')));
259
259
  let fixtureCargo: CountedCargo | undefined;
260
260
  try {
@@ -20,12 +20,12 @@ import { runtimeInput, shellWord } from './runtime-input.js';
20
20
  * two machines ever agree and no cargo target can share a cache entry with a
21
21
  * peer or with CI — a remote cache for Rust was dead on arrival. And the dump
22
22
  * differs between a bare shell and a devenv profile for the SAME sources: in
23
- * the `linux-cross` profile `AR` becomes `x86_64-unknown-linux-gnu-ar`,
24
- * `CARGO_INSTALL_ROOT` moves under `profiles/linux-cross/`, and
25
- * `CC_x86_64_unknown_linux_gnu` appears, so the entry `check:linux` writes
26
- * inside the profile could never be hit by the pre-push probe, which runs
27
- * bare. Measured on one repository-root archive target with the dump still in
28
- * place: bare 18197306115812424011, in-profile 12567954759860890767.
23
+ * the `linux-cross` profile `CARGO_INSTALL_ROOT` moves under
24
+ * `profiles/linux-cross/`, and every variable the profile's tools set appears,
25
+ * so the entry `check:linux` writes inside the profile could never be hit by
26
+ * the pre-push probe, which runs bare. Measured on one repository-root archive
27
+ * target with the dump still in place: bare 18197306115812424011, in-profile
28
+ * 12567954759860890767.
29
29
  *
30
30
  * A file input has neither defect. The lock's bytes are identical bare and
31
31
  * in-profile and on every machine holding the checkout, while the toolchain