@smoothbricks/nx-plugin 0.4.13 → 0.4.14

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.
package/README.md CHANGED
@@ -68,11 +68,22 @@ Cargo's shared mutable build directory before the bounded runner, even if that d
68
68
  successful run. Cargo's own incremental cache avoids recompiling unchanged code. Nx never restores or collects shared
69
69
  Cargo build directories; lint and test **results**, and dedicated Wasm/N-API **outputs**, remain cacheable.
70
70
 
71
- Validation inputs include the crate's files, local dependency closure, governing manifests and configuration, toolchain
72
- versions, Cargo/Rust/native-build environment, target/profile overrides, and global Cargo configuration. Workspace test
73
- runners additionally hash all workspace member manifests because those affect unified features, and the nextest
74
- executable/configuration. Production test configurations use release compilation and release runners together. Keep
75
- explicit inputs for arbitrary build-script reads or custom environment variables that Cargo metadata cannot name.
71
+ Validation inputs include the crate's files, local dependency closure, governing manifests and configuration, the
72
+ declared toolchain pin, and the toolchain's own reported versions. The pin is `devenv.lock`, hashed as an ordinary file
73
+ input at both `{workspaceRoot}/devenv.lock` and `{workspaceRoot}/tooling/direnv/devenv.lock` — devenv resolves it into
74
+ the rustc, cargo, linker, C toolchain and SDK every cargo command inherits, so bumping it invalidates every cached cargo
75
+ target. Workspace test runners additionally hash all workspace member manifests because those affect unified features,
76
+ and the nextest executable/configuration. Production test configurations use release compilation and release runners
77
+ together.
78
+
79
+ Nothing machine-local takes part. The ambient cargo environment and the global `$CARGO_HOME/config.toml` are
80
+ deliberately not hashed: their values carry absolute store paths and per-checkout state directories, which would make
81
+ every cache entry private to the machine that wrote it and make one target hash differently inside a devenv profile than
82
+ outside it — enough to make a pre-push cross-compile probe unsatisfiable. Keep explicit inputs for arbitrary
83
+ build-script reads or custom environment variables that Cargo metadata cannot name.
84
+
85
+ A target whose inputs a repository DECLARES replaces the inferred list, pin included. Name the two `devenv.lock` entries
86
+ in that declaration, or in the named input it uses, or a toolchain bump will not invalidate it.
76
87
 
77
88
  Cargo keeps the caller's `CARGO_HOME`. Moving configuration into an isolated home can change relative paths or lose
78
89
  source replacement, credentials, and toolchain settings; forwarding it with `--config` changes precedence. Registry
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The toolchain half of a cargo task's identity, shared by the two things that
3
+ * must agree about it: target inference, which attaches it, and the monorepo
4
+ * policy, which refuses a repository's own declaration that drops it.
5
+ */
6
+ /**
7
+ * The DECLARED pin, hashed as an ordinary file. devenv resolves this lock into
8
+ * the rustc, cargo, linker, C toolchain and SDK that every cargo command
9
+ * inherits, so a bump here is exactly the event that must invalidate a cached
10
+ * artifact — and it is the only such event the workspace can state portably.
11
+ *
12
+ * This replaces a runtime input that dumped the ambient cargo environment
13
+ * (every `CARGO_`, `RUST`, `CC`, `CXX`, `AR`, `SDKROOT`, `LIBCLANG_PATH`,
14
+ * `CMAKE_` and `ZIG` prefixed variable, plus the contents of
15
+ * `$CARGO_HOME/config{,.toml}`). That bought the same
16
+ * invalidation at the price of two defects. Its values are absolute
17
+ * `/nix/store/<hash>-…` paths and per-checkout devenv state directories, so no
18
+ * two machines ever agree and no cargo target can share a cache entry with a
19
+ * peer or with CI — a remote cache for Rust was dead on arrival. And the dump
20
+ * differs between a bare shell and a devenv profile for the SAME sources: in
21
+ * the `linux-cross` profile `AR` becomes `x86_64-unknown-linux-gnu-ar`,
22
+ * `CARGO_INSTALL_ROOT` moves under `profiles/linux-cross/`, and
23
+ * `CC_x86_64_unknown_linux_gnu` appears, so the entry `check:linux` writes
24
+ * inside the profile could never be hit by the pre-push probe, which runs
25
+ * bare. Measured on one repository-root archive target with the dump still in
26
+ * place: bare 18197306115812424011, in-profile 12567954759860890767.
27
+ *
28
+ * A file input has neither defect. The lock's bytes are identical bare and
29
+ * in-profile and on every machine holding the checkout, while the toolchain
30
+ * VERSIONS the dump was really guarding stay covered twice over — by the pin
31
+ * itself, and by the `rustc -vV && cargo -V` runtime input attached beside it,
32
+ * whose stdout is byte-identical in both shells (measured). Nothing
33
+ * machine-local survives. A NARROWED dump was rejected rather than kept: a
34
+ * subset re-acquires a store path the moment anyone widens it.
35
+ *
36
+ * Both fleet locations are stated: the pin lives under `tooling/direnv/` in
37
+ * every repository and additionally at the root in some. A fileset that
38
+ * matches nothing contributes nothing — the same property the inert
39
+ * `rust-toolchain*` entries already rely on.
40
+ */
41
+ export declare const CARGO_TOOLCHAIN_PIN_INPUTS: readonly string[];
42
+ /**
43
+ * The name a repository's own `inputs` declaration uses to reach the pin
44
+ * without restating its paths.
45
+ *
46
+ * A declared target REPLACES the inferred input list, pin included, so a
47
+ * hand-written `inputs` array silently drops the toolchain identity and the
48
+ * target stops seeing a toolchain bump at all. Inference defines this named
49
+ * input on every project that has cargo targets so a declaration can name one
50
+ * token that cannot drift from what the plugin attaches.
51
+ */
52
+ export declare const CARGO_TOOLCHAIN_NAMED_INPUT = "cargoToolchain";
53
+ /**
54
+ * Does one resolved input string carry the toolchain identity?
55
+ *
56
+ * Resolved: named inputs already expanded. The check is by suffix rather than
57
+ * by exact path because a repository may keep its lock at a location this list
58
+ * does not name; what matters is that a devenv lock is hashed, not which one.
59
+ */
60
+ export declare function isCargoToolchainInput(input: string): boolean;
61
+ //# sourceMappingURL=cargo-toolchain-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cargo-toolchain-policy.d.ts","sourceRoot":"","sources":["../src/cargo-toolchain-policy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,0BAA0B,EAAE,SAAS,MAAM,EAGvD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,mBAAmB,CAAC;AAE5D;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE5D"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The toolchain half of a cargo task's identity, shared by the two things that
3
+ * must agree about it: target inference, which attaches it, and the monorepo
4
+ * policy, which refuses a repository's own declaration that drops it.
5
+ */
6
+ /**
7
+ * The DECLARED pin, hashed as an ordinary file. devenv resolves this lock into
8
+ * the rustc, cargo, linker, C toolchain and SDK that every cargo command
9
+ * inherits, so a bump here is exactly the event that must invalidate a cached
10
+ * artifact — and it is the only such event the workspace can state portably.
11
+ *
12
+ * This replaces a runtime input that dumped the ambient cargo environment
13
+ * (every `CARGO_`, `RUST`, `CC`, `CXX`, `AR`, `SDKROOT`, `LIBCLANG_PATH`,
14
+ * `CMAKE_` and `ZIG` prefixed variable, plus the contents of
15
+ * `$CARGO_HOME/config{,.toml}`). That bought the same
16
+ * invalidation at the price of two defects. Its values are absolute
17
+ * `/nix/store/<hash>-…` paths and per-checkout devenv state directories, so no
18
+ * two machines ever agree and no cargo target can share a cache entry with a
19
+ * peer or with CI — a remote cache for Rust was dead on arrival. And the dump
20
+ * differs between a bare shell and a devenv profile for the SAME sources: in
21
+ * the `linux-cross` profile `AR` becomes `x86_64-unknown-linux-gnu-ar`,
22
+ * `CARGO_INSTALL_ROOT` moves under `profiles/linux-cross/`, and
23
+ * `CC_x86_64_unknown_linux_gnu` appears, so the entry `check:linux` writes
24
+ * inside the profile could never be hit by the pre-push probe, which runs
25
+ * bare. Measured on one repository-root archive target with the dump still in
26
+ * place: bare 18197306115812424011, in-profile 12567954759860890767.
27
+ *
28
+ * A file input has neither defect. The lock's bytes are identical bare and
29
+ * in-profile and on every machine holding the checkout, while the toolchain
30
+ * VERSIONS the dump was really guarding stay covered twice over — by the pin
31
+ * itself, and by the `rustc -vV && cargo -V` runtime input attached beside it,
32
+ * whose stdout is byte-identical in both shells (measured). Nothing
33
+ * machine-local survives. A NARROWED dump was rejected rather than kept: a
34
+ * subset re-acquires a store path the moment anyone widens it.
35
+ *
36
+ * Both fleet locations are stated: the pin lives under `tooling/direnv/` in
37
+ * every repository and additionally at the root in some. A fileset that
38
+ * matches nothing contributes nothing — the same property the inert
39
+ * `rust-toolchain*` entries already rely on.
40
+ */
41
+ export const CARGO_TOOLCHAIN_PIN_INPUTS = [
42
+ '{workspaceRoot}/devenv.lock',
43
+ '{workspaceRoot}/tooling/direnv/devenv.lock',
44
+ ];
45
+ /**
46
+ * The name a repository's own `inputs` declaration uses to reach the pin
47
+ * without restating its paths.
48
+ *
49
+ * A declared target REPLACES the inferred input list, pin included, so a
50
+ * hand-written `inputs` array silently drops the toolchain identity and the
51
+ * target stops seeing a toolchain bump at all. Inference defines this named
52
+ * input on every project that has cargo targets so a declaration can name one
53
+ * token that cannot drift from what the plugin attaches.
54
+ */
55
+ export const CARGO_TOOLCHAIN_NAMED_INPUT = 'cargoToolchain';
56
+ /**
57
+ * Does one resolved input string carry the toolchain identity?
58
+ *
59
+ * Resolved: named inputs already expanded. The check is by suffix rather than
60
+ * by exact path because a repository may keep its lock at a location this list
61
+ * does not name; what matters is that a devenv lock is hashed, not which one.
62
+ */
63
+ export function isCargoToolchainInput(input) {
64
+ return !input.startsWith('!') && input.endsWith('/devenv.lock');
65
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAKL,yBAAyB,EAa1B,MAAM,sBAAsB,CAAC;AAiB9B,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,gEAAgE;AAChE,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AA4GlD,KAAK,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AACxC,KAAK,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C,UAAU,YAAY;IACpB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,gBAAgB,CAAC;CAChC;AAkJD,UAAU,oBAAqB,SAAQ,YAAY;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AA0CD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,oBAAoB,GAAG,MAAM,CAEhF;AAoWD,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAEvG;AAED,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAKL,yBAAyB,EAa1B,MAAM,sBAAsB,CAAC;AAiB9B,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,gEAAgE;AAChE,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AA4GlD,KAAK,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AACxC,KAAK,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C,UAAU,YAAY;IACpB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,gBAAgB,CAAC;CAChC;AAqJD,UAAU,oBAAqB,SAAQ,YAAY;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AA0CD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,oBAAoB,GAAG,MAAM,CAEhF;AAuWD,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAEvG;AAED,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC"}
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ import { readJsonFile, } from 'nx/src/devkit-exports.js';
7
7
  import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
8
8
  import { parse as parseToml } from 'smol-toml';
9
9
  import { BOUNDED_TEST_KILL_AFTER_MS, BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
10
+ import { CARGO_TOOLCHAIN_NAMED_INPUT, CARGO_TOOLCHAIN_PIN_INPUTS } from './cargo-toolchain-policy.js';
10
11
  import { attributeCargoWorkspacePackages, CARGO_TEST_ARCHIVE_FILE, CARGO_TEST_ARCHIVE_TARGET, CARGO_TEST_COMPILE_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestPackageTargetName, createCargoInputsCache, exceptionalTestFilter, listCargoCrossTestTargets, listCargoWorkspacePackages, NEXTEST_REPO_CONFIG_PATH, nextestToolConfigArg, } from './cargo-workspace.js';
11
12
  import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND, CARGO_FETCH_TARGET, CARGO_FROZEN_PREFIX, CARGO_LINT_CLIPPY_COMMAND, cargoCrossTestArchiveFile, cargoCrossTestArchiveTargetName, cargoCrossTestTargetName, cargoFrozen, } from './cross-check-policy.js';
12
13
  import { hashVersionlessCrateManifests } from './manifest-hash.js';
@@ -209,15 +210,10 @@ const REPO_ROOT_CARGO_OUTPUT_INPUTS = [
209
210
  '{workspaceRoot}/scripts/*.sh',
210
211
  '!{workspaceRoot}/**/target/**',
211
212
  ];
212
- // The environment half of a cargo task's identity. Beyond cargo/rustc's own
213
- // variables, every build script that compiles C/C++ reads the Apple SDK
214
- // (SDKROOT, DEVELOPER_DIR, the deployment targets), bindgen reads its libclang
215
- // and extra clang args, cmake-rs forwards CMAKE_*, and zig-based cross links
216
- // read ZIG*. An output linked against one sysroot must never hash equal to
217
- // the same sources linked against another.
218
- const CARGO_ENVIRONMENT_INPUT = {
219
- runtime: `bun -e 'const fs = require("node:fs"); const path = require("node:path"); const home = process.env.CARGO_HOME || path.join(require("node:os").homedir(), ".cargo"); console.log(JSON.stringify({env: Object.entries(process.env).filter(([name]) => /^(?:CARGO_|RUST|NEXTEST_|CLIPPY_|CC(?:_|$)|CXX(?:_|$)|AR(?:_|$)|CFLAGS|CXXFLAGS|CPPFLAGS|LDFLAGS|PKG_CONFIG|TARGET_|HOST_|SDKROOT$|DEVELOPER_DIR$|MACOSX_DEPLOYMENT_TARGET$|IPHONEOS_DEPLOYMENT_TARGET$|LIBCLANG_PATH$|BINDGEN_EXTRA_CLANG_ARGS|CMAKE_|ZIG)/.test(name)).sort(([a], [b]) => a.localeCompare(b)), config: ["config", "config.toml"].map(name => { const file = path.join(home, name); return fs.existsSync(file) ? fs.readFileSync(file, "utf8") : null; })}));'`,
220
- };
213
+ // The toolchain half of a cargo task's identity lives in its own module
214
+ // because `smoo monorepo validate` reads the same two constants to refuse a
215
+ // declaration that drops it. See cargo-toolchain-policy.ts for why it is the
216
+ // declared pin and not the ambient environment.
221
217
  function cargoRuntimeInput(projectRoot, command) {
222
218
  const quotedRoot = `'${projectRoot.replaceAll("'", "'\"'\"'")}'`;
223
219
  return { runtime: `cd ${quotedRoot} && ${command}` };
@@ -237,10 +233,17 @@ function targetCommandText(target) {
237
233
  ].join('\n');
238
234
  }
239
235
  /**
240
- * The N-API build's inputs beyond the Cargo sources: the package's `napi`
241
- * block, which names the binary and the targets, and the napi CLI's resolved
242
- * version from the lockfile. Neither the package version nor any other
243
- * lockfile entry is part of the artifact.
236
+ * The N-API build's inputs beyond the Cargo sources: the toolchain pin, the
237
+ * package's `napi` block, which names the binary and the targets, and the napi
238
+ * CLI's resolved version from the lockfile. Neither the package version nor
239
+ * any other lockfile entry is part of the artifact.
240
+ *
241
+ * The pin is stated here rather than inherited: `napi build` compiles with the
242
+ * same rustc and links against the same SDK as any other cargo target, but its
243
+ * command does not spell `cargo --frozen`, which is how every other cached
244
+ * cargo target acquires its toolchain identity. Without it a `.node` linked
245
+ * against one toolchain hashed equal to the same sources linked against the
246
+ * next one.
244
247
  */
245
248
  function napiInputs(projectRoot, repoRooted) {
246
249
  // Runtime inputs execute from the workspace root, so the manifest is named
@@ -248,6 +251,7 @@ function napiInputs(projectRoot, repoRooted) {
248
251
  const packageJson = `./${posix.join(projectRoot, 'package.json')}`;
249
252
  return [
250
253
  ...(repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : CARGO_OUTPUT_INPUTS),
254
+ ...CARGO_TOOLCHAIN_PIN_INPUTS,
251
255
  { runtime: `bun -e 'console.log(JSON.stringify(require(${JSON.stringify(packageJson)}).napi ?? null))'` },
252
256
  { externalDependencies: ['@napi-rs/cli'] },
253
257
  ];
@@ -406,7 +410,7 @@ function createCargoTestArchiveTarget(projectRoot, toolConfig) {
406
410
  * (measured: `metadata … --frozen` and `test --no-run … --frozen`).
407
411
  *
408
412
  * The archive target therefore states `CARGO_FETCH_TARGET` and the toolchain
409
- * runtime inputs itself: both are otherwise attached by matching the
413
+ * inputs itself: both are otherwise attached by matching the
410
414
  * `cargo --frozen` prefix in a command, and this command does not carry it.
411
415
  *
412
416
  * The RUNNER declares no dependency on the archive and is not cached. That is
@@ -426,18 +430,21 @@ function createCargoCrossTestTargets(projectRoot, toolConfig, crossTarget, archi
426
430
  [cargoCrossTestArchiveTargetName(triple)]: {
427
431
  executor: 'nx:run-commands',
428
432
  cache: true,
429
- // The two runtime inputs every cached cargo target carries, plus the
430
- // declared driver's own bytes. They are attached elsewhere by matching
431
- // the `cargo --frozen` prefix in a command, which this one does not
432
- // spell — and they matter MORE here than anywhere else: the cross
433
- // environment (SDKROOT, CC_<triple>, ZIG*, and CARGO itself) is what
434
- // decides whether these bytes are Mach-O at all, so an archive linked
435
- // against one sysroot must never hash equal to the same sources linked
436
- // against another.
433
+ // The toolchain inputs every cached cargo target carries, plus the
434
+ // declared driver's own bytes. Those toolchain inputs are attached
435
+ // elsewhere by matching the `cargo --frozen` prefix in a command,
436
+ // which this one does not spell — and the pin matters MORE here than
437
+ // anywhere else: the cross regime this archive links under (the C
438
+ // toolchain for the triple, its sysroot, and the `CARGO` driver below)
439
+ // comes out of the same devenv lock, so an archive built under one pin
440
+ // must never hash equal to the same sources built under another. The
441
+ // declared driver is hashed by its own bytes; nothing samples the shell
442
+ // that supplies it, which is why this hash is the same bare and inside
443
+ // the cross profile.
437
444
  inputs: [
438
445
  ...archiveInputs,
446
+ ...CARGO_TOOLCHAIN_PIN_INPUTS,
439
447
  ...(cargo === undefined ? [] : [`{projectRoot}/${cargo}`]),
440
- cargoRuntimeInput(projectRoot, CARGO_ENVIRONMENT_INPUT.runtime),
441
448
  cargoRuntimeInput(projectRoot, 'rustc -vV && cargo -V && cargo nextest --version'),
442
449
  ],
443
450
  outputs: [`{projectRoot}/${archiveFile}`],
@@ -1088,7 +1095,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1088
1095
  : '';
1089
1096
  target.inputs = [
1090
1097
  ...(target.inputs ?? CARGO_INPUTS),
1091
- cargoRuntimeInput(typeof cwd === 'string' ? cwd : projectRoot, CARGO_ENVIRONMENT_INPUT.runtime),
1098
+ ...CARGO_TOOLCHAIN_PIN_INPUTS,
1092
1099
  cargoRuntimeInput(typeof cwd === 'string' ? cwd : projectRoot, `rustc -vV && cargo -V${versions}`),
1093
1100
  ];
1094
1101
  }
@@ -1325,6 +1332,26 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1325
1332
  : {}),
1326
1333
  };
1327
1334
  }
1335
+ // A declared target REPLACES the inferred input list, pin included, so a
1336
+ // repository that hand-writes `inputs` for a cargo target silently loses its
1337
+ // toolchain identity. Name the pin once here so such a declaration can
1338
+ // reference it as `cargoToolchain` instead of restating two paths that could
1339
+ // drift from the plugin; `smoo monorepo validate` refuses a cached cargo
1340
+ // target whose resolved inputs reach neither. Defined only for projects that
1341
+ // HAVE cargo targets: a project's namedInputs definitions are hashed into
1342
+ // its configuration hash, so defining it everywhere would invalidate every
1343
+ // task in the repository to serve projects that can never reference it.
1344
+ const namedInputs = {
1345
+ ...(versionless === null
1346
+ ? {}
1347
+ : {
1348
+ [VERSIONLESS_PRODUCTION_INPUT]: ['production', ...versionlessProjectInputs],
1349
+ [VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
1350
+ }),
1351
+ ...(Object.keys(targets).some((name) => name.startsWith('cargo-') || name.startsWith('napi-'))
1352
+ ? { [CARGO_TOOLCHAIN_NAMED_INPUT]: [...CARGO_TOOLCHAIN_PIN_INPUTS] }
1353
+ : {}),
1354
+ };
1328
1355
  return {
1329
1356
  projects: {
1330
1357
  [projectRoot]: {
@@ -1338,14 +1365,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1338
1365
  // Nx resolves a named input from the project first and nx.json second,
1339
1366
  // so a workspace-wide definition still covers projects this plugin
1340
1367
  // never inferred.
1341
- ...(versionless === null
1342
- ? {}
1343
- : {
1344
- namedInputs: {
1345
- [VERSIONLESS_PRODUCTION_INPUT]: ['production', ...versionlessProjectInputs],
1346
- [VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
1347
- },
1348
- }),
1368
+ ...(Object.keys(namedInputs).length === 0 ? {} : { namedInputs }),
1349
1369
  },
1350
1370
  },
1351
1371
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.4.13",
3
+ "version": "0.4.14",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -52,6 +52,11 @@
52
52
  "types": "./dist/cross-check-policy.d.ts",
53
53
  "import": "./dist/cross-check-policy.js",
54
54
  "default": "./dist/cross-check-policy.js"
55
+ },
56
+ "./cargo-toolchain-policy": {
57
+ "types": "./dist/cargo-toolchain-policy.d.ts",
58
+ "import": "./dist/cargo-toolchain-policy.js",
59
+ "default": "./dist/cargo-toolchain-policy.js"
55
60
  }
56
61
  },
57
62
  "bin": {
@@ -108,7 +113,7 @@
108
113
  "typia": "14.0.2"
109
114
  },
110
115
  "devDependencies": {
111
- "@smoothbricks/lmao": "0.3.12",
116
+ "@smoothbricks/lmao": "0.3.13",
112
117
  "@smoothbricks/validation": "0.1.8"
113
118
  }
114
119
  }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The toolchain half of a cargo task's identity, shared by the two things that
3
+ * must agree about it: target inference, which attaches it, and the monorepo
4
+ * policy, which refuses a repository's own declaration that drops it.
5
+ */
6
+
7
+ /**
8
+ * The DECLARED pin, hashed as an ordinary file. devenv resolves this lock into
9
+ * the rustc, cargo, linker, C toolchain and SDK that every cargo command
10
+ * inherits, so a bump here is exactly the event that must invalidate a cached
11
+ * artifact — and it is the only such event the workspace can state portably.
12
+ *
13
+ * This replaces a runtime input that dumped the ambient cargo environment
14
+ * (every `CARGO_`, `RUST`, `CC`, `CXX`, `AR`, `SDKROOT`, `LIBCLANG_PATH`,
15
+ * `CMAKE_` and `ZIG` prefixed variable, plus the contents of
16
+ * `$CARGO_HOME/config{,.toml}`). That bought the same
17
+ * invalidation at the price of two defects. Its values are absolute
18
+ * `/nix/store/<hash>-…` paths and per-checkout devenv state directories, so no
19
+ * two machines ever agree and no cargo target can share a cache entry with a
20
+ * peer or with CI — a remote cache for Rust was dead on arrival. And the dump
21
+ * differs between a bare shell and a devenv profile for the SAME sources: in
22
+ * the `linux-cross` profile `AR` becomes `x86_64-unknown-linux-gnu-ar`,
23
+ * `CARGO_INSTALL_ROOT` moves under `profiles/linux-cross/`, and
24
+ * `CC_x86_64_unknown_linux_gnu` appears, so the entry `check:linux` writes
25
+ * inside the profile could never be hit by the pre-push probe, which runs
26
+ * bare. Measured on one repository-root archive target with the dump still in
27
+ * place: bare 18197306115812424011, in-profile 12567954759860890767.
28
+ *
29
+ * A file input has neither defect. The lock's bytes are identical bare and
30
+ * in-profile and on every machine holding the checkout, while the toolchain
31
+ * VERSIONS the dump was really guarding stay covered twice over — by the pin
32
+ * itself, and by the `rustc -vV && cargo -V` runtime input attached beside it,
33
+ * whose stdout is byte-identical in both shells (measured). Nothing
34
+ * machine-local survives. A NARROWED dump was rejected rather than kept: a
35
+ * subset re-acquires a store path the moment anyone widens it.
36
+ *
37
+ * Both fleet locations are stated: the pin lives under `tooling/direnv/` in
38
+ * every repository and additionally at the root in some. A fileset that
39
+ * matches nothing contributes nothing — the same property the inert
40
+ * `rust-toolchain*` entries already rely on.
41
+ */
42
+ export const CARGO_TOOLCHAIN_PIN_INPUTS: readonly string[] = [
43
+ '{workspaceRoot}/devenv.lock',
44
+ '{workspaceRoot}/tooling/direnv/devenv.lock',
45
+ ];
46
+
47
+ /**
48
+ * The name a repository's own `inputs` declaration uses to reach the pin
49
+ * without restating its paths.
50
+ *
51
+ * A declared target REPLACES the inferred input list, pin included, so a
52
+ * hand-written `inputs` array silently drops the toolchain identity and the
53
+ * target stops seeing a toolchain bump at all. Inference defines this named
54
+ * input on every project that has cargo targets so a declaration can name one
55
+ * token that cannot drift from what the plugin attaches.
56
+ */
57
+ export const CARGO_TOOLCHAIN_NAMED_INPUT = 'cargoToolchain';
58
+
59
+ /**
60
+ * Does one resolved input string carry the toolchain identity?
61
+ *
62
+ * Resolved: named inputs already expanded. The check is by suffix rather than
63
+ * by exact path because a repository may keep its lock at a location this list
64
+ * does not name; what matters is that a devenv lock is hashed, not which one.
65
+ */
66
+ export function isCargoToolchainInput(input: string): boolean {
67
+ return !input.startsWith('!') && input.endsWith('/devenv.lock');
68
+ }
package/src/index.test.ts CHANGED
@@ -882,6 +882,11 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
882
882
  ).toBe(true);
883
883
  expect(napiInputs).not.toContain('{workspaceRoot}/bun.lock');
884
884
  expect(napiInputs.some((input) => typeof input === 'string' && input.endsWith('/package.json'))).toBe(false);
885
+ // ... and on the toolchain pin, which it must state itself: `napi build`
886
+ // compiles with the pinned rustc but never spells `cargo --frozen`, so
887
+ // the sweep that gives every other cargo target its identity skips it.
888
+ expect(napiInputs).toContain('{workspaceRoot}/devenv.lock');
889
+ expect(napiInputs).toContain('{workspaceRoot}/tooling/direnv/devenv.lock');
885
890
  expect(native['napi-debug']?.options).toMatchObject({
886
891
  cwd: '.',
887
892
  command:
@@ -984,45 +989,74 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
984
989
  }
985
990
  });
986
991
 
987
- it('invalidates cached lint verdicts for Cargo target, profile and global configuration changes', async () => {
992
+ it('keys every cached cargo target on the declared toolchain pin', async () => {
988
993
  const workspace = await createWorkspace();
989
994
  try {
990
- await workspace.write('package.json', '{"name":"cache-fixture"}\n');
991
- await workspace.write('Cargo.toml', '[workspace]\nmembers = ["crate"]\n');
992
- await workspace.write('crate/Cargo.toml', '[package]\nname = "cache-crate"\n');
993
- await workspace.write('cargo-home/config.toml', '[build]\njobs = 1\n');
994
- const targets = await inferProjectTargets(workspace, 'package.json');
995
- const runtimeCommands = (targets['cargo-lint']?.inputs ?? []).flatMap((input) =>
996
- typeof input !== 'string' && 'runtime' in input ? [input.runtime] : [],
997
- );
998
- const capture = async (extraEnv: Record<string, string>) =>
999
- Promise.all(
1000
- runtimeCommands.map(async (command) => {
1001
- const child = Bun.spawn(['sh', '-c', command], {
1002
- cwd: workspace.context.workspaceRoot,
1003
- env: { ...process.env, CARGO_HOME: join(workspace.context.workspaceRoot, 'cargo-home'), ...extraEnv },
1004
- stdout: 'pipe',
1005
- stderr: 'pipe',
1006
- });
1007
- const [exitCode, stdout, stderr] = await Promise.all([
1008
- child.exited,
1009
- new Response(child.stdout).text(),
1010
- new Response(child.stderr).text(),
1011
- ]);
1012
- expect({ exitCode, stderr }).toMatchObject({ exitCode: 0 });
1013
- return stdout;
1014
- }),
995
+ await writeCargoIdentityFixture(workspace);
996
+ const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
997
+ const cached = cachedCargoTargets(targets);
998
+
999
+ // Named, so a family that stops being cached — or a new one that starts —
1000
+ // shows up here rather than silently leaving the sweep below empty.
1001
+ expect(cached.map(([name]) => name).sort()).toEqual([
1002
+ 'cargo-cross-test-archive-aarch64-apple-darwin',
1003
+ 'cargo-lint',
1004
+ 'cargo-lint-cross',
1005
+ 'cargo-test-archive',
1006
+ 'cargo-test-ferris-core',
1007
+ ]);
1008
+ // An SDK or toolchain change must invalidate every one of them. The pin
1009
+ // is the only thing in the identity that can see one, and it is declared
1010
+ // at both fleet locations because a fileset matching nothing is free.
1011
+ for (const [name, target] of cached) {
1012
+ const declared = (target.inputs ?? []).filter(
1013
+ (input) => typeof input === 'string' && input.endsWith('devenv.lock'),
1015
1014
  );
1016
- const baseline = await capture({});
1017
- expect(await capture({ CARGO_BUILD_TARGET: 'wasm32-unknown-unknown' })).not.toEqual(baseline);
1018
- expect(await capture({ CARGO_PROFILE_DEV_OPT_LEVEL: '2' })).not.toEqual(baseline);
1019
- expect(await capture({ UNRELATED_FIXTURE_VARIABLE: 'changed' })).toEqual(baseline);
1020
- await workspace.write('cargo-home/config.toml', '[build]\njobs = 2\n');
1021
- expect(await capture({})).not.toEqual(baseline);
1015
+ expect([name, declared]).toEqual([
1016
+ name,
1017
+ ['{workspaceRoot}/devenv.lock', '{workspaceRoot}/tooling/direnv/devenv.lock'],
1018
+ ]);
1019
+ }
1020
+ } finally {
1021
+ await workspace.cleanup();
1022
+ }
1023
+ });
1024
+
1025
+ // The property that decides whether Rust can ever use a shared cache. A cargo
1026
+ // target's identity used to include a dump of the ambient cargo environment,
1027
+ // whose values are absolute `/nix/store/…` and per-checkout devenv state
1028
+ // paths: no two machines agreed, and the same target hashed differently in a
1029
+ // bare shell and inside a devenv profile, which made the pre-push
1030
+ // cross-compile probe unsatisfiable by construction.
1031
+ //
1032
+ // Runtime inputs are checked by their OUTPUT, not their command text, because
1033
+ // that is what Nx hashes: measured, two workspaces at different absolute
1034
+ // paths whose only difference is the spelling of a runtime command producing
1035
+ // identical stdout hash identically.
1036
+ it('hashes no machine-local value into a cached cargo target', async () => {
1037
+ const workspace = await createWorkspace();
1038
+ try {
1039
+ await writeCargoIdentityFixture(workspace);
1040
+ const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
1041
+ const offenders: string[] = [];
1042
+ for (const [name, target] of cachedCargoTargets(targets)) {
1043
+ for (const input of target.inputs ?? []) {
1044
+ if (typeof input === 'string') {
1045
+ if (!WORKSPACE_ANCHORED_INPUT.test(input)) offenders.push(`${name}: fileset ${input}`);
1046
+ continue;
1047
+ }
1048
+ if ('env' in input) offenders.push(`${name}: environment input ${String(input.env)}`);
1049
+ if (!('runtime' in input)) continue;
1050
+ const value = await runtimeInputValue(input.runtime, workspace.context.workspaceRoot);
1051
+ const rooted = PATH_OUTSIDE_WORKSPACE.exec(value);
1052
+ if (rooted) offenders.push(`${name}: runtime input yields ${rooted[0].trim()} — from ${input.runtime}`);
1053
+ }
1054
+ }
1055
+ expect(offenders).toEqual([]);
1022
1056
  } finally {
1023
1057
  await workspace.cleanup();
1024
1058
  }
1025
- }, 30_000);
1059
+ }, 60_000);
1026
1060
 
1027
1061
  it('scopes each per-crate cargo-test command to exactly one package', async () => {
1028
1062
  const workspace = await createWorkspace();
@@ -1983,6 +2017,62 @@ interface WorkspaceFixture {
1983
2017
  cleanup(): Promise<void>;
1984
2018
  }
1985
2019
 
2020
+ /**
2021
+ * A fileset Nx resolves against the workspace, or a named input nx.json
2022
+ * declares. Anything else is a path this machine happens to have.
2023
+ */
2024
+ const WORKSPACE_ANCHORED_INPUT = /^!?(?:\{(?:projectRoot|workspaceRoot)\}\/|\^?[A-Za-z][\w-]*$)/;
2025
+
2026
+ /** A path rooted outside the workspace, wherever it appears in a hashed value. */
2027
+ const PATH_OUTSIDE_WORKSPACE = /(?:^|[^\w.\-~])(\/[\w.-]+\/[\w.-]+)/;
2028
+
2029
+ /**
2030
+ * One Cargo workspace producing every cached cargo target family inference can
2031
+ * make: the host archive, a per-crate run, both lint verdicts, and — through
2032
+ * the `cross-targets` declaration — the foreign-triple archive, which states
2033
+ * its own inputs instead of receiving them from the `cargo --frozen` sweep.
2034
+ */
2035
+ async function writeCargoIdentityFixture(workspace: WorkspaceFixture): Promise<void> {
2036
+ await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
2037
+ await workspace.write(
2038
+ 'packages/ferris/Cargo.toml',
2039
+ '[workspace]\nmembers = ["crates/ferris-core"]\n\n' +
2040
+ '[workspace.metadata.smoothbricks.test]\n' +
2041
+ 'cross-targets = [{ target = "aarch64-apple-darwin", cargo = "scripts/cargo-for-nextest.sh" }]\n',
2042
+ );
2043
+ await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
2044
+ await workspace.write('packages/ferris/scripts/cargo-for-nextest.sh', '#!/bin/sh\nexec cargo "$@"\n');
2045
+ }
2046
+
2047
+ /**
2048
+ * The targets a cache verdict can be wrong about: cached, and running cargo.
2049
+ * Derived rather than listed, so a new cargo family joins these assertions the
2050
+ * day it is inferred instead of the day someone remembers to add it.
2051
+ */
2052
+ function cachedCargoTargets(targets: Record<string, TargetConfiguration>): [string, TargetConfiguration][] {
2053
+ return Object.entries(targets).filter(([, target]) => {
2054
+ const command: unknown = target.options?.command;
2055
+ const commands: unknown = target.options?.commands;
2056
+ const text = [
2057
+ typeof command === 'string' ? command : '',
2058
+ ...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
2059
+ ].join('\n');
2060
+ return target.cache === true && /\bcargo/.test(text);
2061
+ });
2062
+ }
2063
+
2064
+ /** What Nx actually hashes for a `runtime` input: the command's stdout. */
2065
+ async function runtimeInputValue(command: string, cwd: string): Promise<string> {
2066
+ const child = Bun.spawn(['sh', '-c', command], { cwd, stdout: 'pipe', stderr: 'pipe' });
2067
+ const [exitCode, stdout, stderr] = await Promise.all([
2068
+ child.exited,
2069
+ new Response(child.stdout).text(),
2070
+ new Response(child.stderr).text(),
2071
+ ]);
2072
+ expect({ command, exitCode, stderr }).toMatchObject({ command, exitCode: 0 });
2073
+ return stdout;
2074
+ }
2075
+
1986
2076
  async function inferProject(
1987
2077
  workspace: WorkspaceFixture,
1988
2078
  packageJsonPath: string,
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
15
15
  import { parse as parseToml } from 'smol-toml';
16
16
 
17
17
  import { BOUNDED_TEST_KILL_AFTER_MS, BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
18
+ import { CARGO_TOOLCHAIN_NAMED_INPUT, CARGO_TOOLCHAIN_PIN_INPUTS } from './cargo-toolchain-policy.js';
18
19
  import {
19
20
  type AttributedCargoWorkspacePackage,
20
21
  attributeCargoWorkspacePackages,
@@ -269,15 +270,10 @@ const REPO_ROOT_CARGO_OUTPUT_INPUTS = [
269
270
  '{workspaceRoot}/scripts/*.sh',
270
271
  '!{workspaceRoot}/**/target/**',
271
272
  ];
272
- // The environment half of a cargo task's identity. Beyond cargo/rustc's own
273
- // variables, every build script that compiles C/C++ reads the Apple SDK
274
- // (SDKROOT, DEVELOPER_DIR, the deployment targets), bindgen reads its libclang
275
- // and extra clang args, cmake-rs forwards CMAKE_*, and zig-based cross links
276
- // read ZIG*. An output linked against one sysroot must never hash equal to
277
- // the same sources linked against another.
278
- const CARGO_ENVIRONMENT_INPUT = {
279
- runtime: `bun -e 'const fs = require("node:fs"); const path = require("node:path"); const home = process.env.CARGO_HOME || path.join(require("node:os").homedir(), ".cargo"); console.log(JSON.stringify({env: Object.entries(process.env).filter(([name]) => /^(?:CARGO_|RUST|NEXTEST_|CLIPPY_|CC(?:_|$)|CXX(?:_|$)|AR(?:_|$)|CFLAGS|CXXFLAGS|CPPFLAGS|LDFLAGS|PKG_CONFIG|TARGET_|HOST_|SDKROOT$|DEVELOPER_DIR$|MACOSX_DEPLOYMENT_TARGET$|IPHONEOS_DEPLOYMENT_TARGET$|LIBCLANG_PATH$|BINDGEN_EXTRA_CLANG_ARGS|CMAKE_|ZIG)/.test(name)).sort(([a], [b]) => a.localeCompare(b)), config: ["config", "config.toml"].map(name => { const file = path.join(home, name); return fs.existsSync(file) ? fs.readFileSync(file, "utf8") : null; })}));'`,
280
- };
273
+ // The toolchain half of a cargo task's identity lives in its own module
274
+ // because `smoo monorepo validate` reads the same two constants to refuse a
275
+ // declaration that drops it. See cargo-toolchain-policy.ts for why it is the
276
+ // declared pin and not the ambient environment.
281
277
 
282
278
  function cargoRuntimeInput(projectRoot: string, command: string): { runtime: string } {
283
279
  const quotedRoot = `'${projectRoot.replaceAll("'", "'\"'\"'")}'`;
@@ -299,10 +295,17 @@ function targetCommandText(target: TargetConfiguration): string {
299
295
  ].join('\n');
300
296
  }
301
297
  /**
302
- * The N-API build's inputs beyond the Cargo sources: the package's `napi`
303
- * block, which names the binary and the targets, and the napi CLI's resolved
304
- * version from the lockfile. Neither the package version nor any other
305
- * lockfile entry is part of the artifact.
298
+ * The N-API build's inputs beyond the Cargo sources: the toolchain pin, the
299
+ * package's `napi` block, which names the binary and the targets, and the napi
300
+ * CLI's resolved version from the lockfile. Neither the package version nor
301
+ * any other lockfile entry is part of the artifact.
302
+ *
303
+ * The pin is stated here rather than inherited: `napi build` compiles with the
304
+ * same rustc and links against the same SDK as any other cargo target, but its
305
+ * command does not spell `cargo --frozen`, which is how every other cached
306
+ * cargo target acquires its toolchain identity. Without it a `.node` linked
307
+ * against one toolchain hashed equal to the same sources linked against the
308
+ * next one.
306
309
  */
307
310
  function napiInputs(projectRoot: string, repoRooted: boolean): TargetConfiguration['inputs'] {
308
311
  // Runtime inputs execute from the workspace root, so the manifest is named
@@ -310,6 +313,7 @@ function napiInputs(projectRoot: string, repoRooted: boolean): TargetConfigurati
310
313
  const packageJson = `./${posix.join(projectRoot, 'package.json')}`;
311
314
  return [
312
315
  ...(repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : CARGO_OUTPUT_INPUTS),
316
+ ...CARGO_TOOLCHAIN_PIN_INPUTS,
313
317
  { runtime: `bun -e 'console.log(JSON.stringify(require(${JSON.stringify(packageJson)}).napi ?? null))'` },
314
318
  { externalDependencies: ['@napi-rs/cli'] },
315
319
  ];
@@ -496,7 +500,7 @@ function createCargoTestArchiveTarget(projectRoot: string, toolConfig: string):
496
500
  * (measured: `metadata … --frozen` and `test --no-run … --frozen`).
497
501
  *
498
502
  * The archive target therefore states `CARGO_FETCH_TARGET` and the toolchain
499
- * runtime inputs itself: both are otherwise attached by matching the
503
+ * inputs itself: both are otherwise attached by matching the
500
504
  * `cargo --frozen` prefix in a command, and this command does not carry it.
501
505
  *
502
506
  * The RUNNER declares no dependency on the archive and is not cached. That is
@@ -522,18 +526,21 @@ function createCargoCrossTestTargets(
522
526
  [cargoCrossTestArchiveTargetName(triple)]: {
523
527
  executor: 'nx:run-commands',
524
528
  cache: true,
525
- // The two runtime inputs every cached cargo target carries, plus the
526
- // declared driver's own bytes. They are attached elsewhere by matching
527
- // the `cargo --frozen` prefix in a command, which this one does not
528
- // spell — and they matter MORE here than anywhere else: the cross
529
- // environment (SDKROOT, CC_<triple>, ZIG*, and CARGO itself) is what
530
- // decides whether these bytes are Mach-O at all, so an archive linked
531
- // against one sysroot must never hash equal to the same sources linked
532
- // against another.
529
+ // The toolchain inputs every cached cargo target carries, plus the
530
+ // declared driver's own bytes. Those toolchain inputs are attached
531
+ // elsewhere by matching the `cargo --frozen` prefix in a command,
532
+ // which this one does not spell — and the pin matters MORE here than
533
+ // anywhere else: the cross regime this archive links under (the C
534
+ // toolchain for the triple, its sysroot, and the `CARGO` driver below)
535
+ // comes out of the same devenv lock, so an archive built under one pin
536
+ // must never hash equal to the same sources built under another. The
537
+ // declared driver is hashed by its own bytes; nothing samples the shell
538
+ // that supplies it, which is why this hash is the same bare and inside
539
+ // the cross profile.
533
540
  inputs: [
534
541
  ...archiveInputs,
542
+ ...CARGO_TOOLCHAIN_PIN_INPUTS,
535
543
  ...(cargo === undefined ? [] : [`{projectRoot}/${cargo}`]),
536
- cargoRuntimeInput(projectRoot, CARGO_ENVIRONMENT_INPUT.runtime),
537
544
  cargoRuntimeInput(projectRoot, 'rustc -vV && cargo -V && cargo nextest --version'),
538
545
  ],
539
546
  outputs: [`{projectRoot}/${archiveFile}`],
@@ -1320,7 +1327,7 @@ async function createProjectTargets(
1320
1327
  : '';
1321
1328
  target.inputs = [
1322
1329
  ...(target.inputs ?? CARGO_INPUTS),
1323
- cargoRuntimeInput(typeof cwd === 'string' ? cwd : projectRoot, CARGO_ENVIRONMENT_INPUT.runtime),
1330
+ ...CARGO_TOOLCHAIN_PIN_INPUTS,
1324
1331
  cargoRuntimeInput(typeof cwd === 'string' ? cwd : projectRoot, `rustc -vV && cargo -V${versions}`),
1325
1332
  ];
1326
1333
  }
@@ -1575,6 +1582,26 @@ async function createProjectTargets(
1575
1582
  };
1576
1583
  }
1577
1584
 
1585
+ // A declared target REPLACES the inferred input list, pin included, so a
1586
+ // repository that hand-writes `inputs` for a cargo target silently loses its
1587
+ // toolchain identity. Name the pin once here so such a declaration can
1588
+ // reference it as `cargoToolchain` instead of restating two paths that could
1589
+ // drift from the plugin; `smoo monorepo validate` refuses a cached cargo
1590
+ // target whose resolved inputs reach neither. Defined only for projects that
1591
+ // HAVE cargo targets: a project's namedInputs definitions are hashed into
1592
+ // its configuration hash, so defining it everywhere would invalidate every
1593
+ // task in the repository to serve projects that can never reference it.
1594
+ const namedInputs: Record<string, NonNullable<TargetConfiguration['inputs']>> = {
1595
+ ...(versionless === null
1596
+ ? {}
1597
+ : {
1598
+ [VERSIONLESS_PRODUCTION_INPUT]: ['production', ...versionlessProjectInputs],
1599
+ [VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
1600
+ }),
1601
+ ...(Object.keys(targets).some((name) => name.startsWith('cargo-') || name.startsWith('napi-'))
1602
+ ? { [CARGO_TOOLCHAIN_NAMED_INPUT]: [...CARGO_TOOLCHAIN_PIN_INPUTS] }
1603
+ : {}),
1604
+ };
1578
1605
  return {
1579
1606
  projects: {
1580
1607
  [projectRoot]: {
@@ -1588,14 +1615,7 @@ async function createProjectTargets(
1588
1615
  // Nx resolves a named input from the project first and nx.json second,
1589
1616
  // so a workspace-wide definition still covers projects this plugin
1590
1617
  // never inferred.
1591
- ...(versionless === null
1592
- ? {}
1593
- : {
1594
- namedInputs: {
1595
- [VERSIONLESS_PRODUCTION_INPUT]: ['production', ...versionlessProjectInputs],
1596
- [VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
1597
- },
1598
- }),
1618
+ ...(Object.keys(namedInputs).length === 0 ? {} : { namedInputs }),
1599
1619
  },
1600
1620
  },
1601
1621
  };