@smoothbricks/nx-plugin 0.4.31 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +15 -11
  2. package/dist/cargo-toolchain-policy.d.ts +6 -6
  3. package/dist/cargo-toolchain-policy.js +6 -6
  4. package/dist/cross-check-policy.d.ts +31 -14
  5. package/dist/cross-check-policy.d.ts.map +1 -1
  6. package/dist/cross-check-policy.js +43 -15
  7. package/dist/executors/cargo-zigbuild/executor.d.ts +60 -0
  8. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -0
  9. package/dist/executors/cargo-zigbuild/executor.js +266 -0
  10. package/dist/executors/cargo-zigbuild/schema.d.ts +15 -0
  11. package/dist/executors/cargo-zigbuild/schema.d.ts.map +1 -0
  12. package/dist/index.d.ts +0 -15
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +56 -89
  15. package/dist/testing.d.ts.map +1 -1
  16. package/dist/testing.js +3 -2
  17. package/executors.json +4 -4
  18. package/managed/raw/patches/nx@23.2.1.patch +177 -9
  19. package/managed/raw/tooling/direnv/devenv.smoo.nix +46 -46
  20. package/managed/raw/tooling/git-hooks/pre-push.sh +41 -23
  21. package/package.json +1 -1
  22. package/src/cargo-toolchain-policy.ts +6 -6
  23. package/src/cross-check-policy.test.ts +90 -11
  24. package/src/cross-check-policy.ts +47 -17
  25. package/src/executors/cargo-zigbuild/executor.test.ts +129 -0
  26. package/src/executors/cargo-zigbuild/executor.ts +176 -0
  27. package/src/executors/cargo-zigbuild/schema.json +35 -0
  28. package/src/executors/cargo-zigbuild/schema.ts +14 -0
  29. package/src/index.test.ts +29 -61
  30. package/src/index.ts +60 -98
  31. package/src/nx-daemon-validity.test.ts +65 -0
  32. package/src/testing.ts +3 -2
  33. package/test-timings.json +1 -1
  34. package/dist/executors/napi-cross-toolchain/executor.d.ts +0 -42
  35. package/dist/executors/napi-cross-toolchain/executor.d.ts.map +0 -1
  36. package/dist/executors/napi-cross-toolchain/executor.js +0 -126
  37. package/dist/executors/napi-cross-toolchain/schema.d.ts +0 -4
  38. package/dist/executors/napi-cross-toolchain/schema.d.ts.map +0 -1
  39. package/src/executors/napi-cross-toolchain/executor.test.ts +0 -112
  40. package/src/executors/napi-cross-toolchain/executor.ts +0 -165
  41. package/src/executors/napi-cross-toolchain/schema.json +0 -15
  42. package/src/executors/napi-cross-toolchain/schema.ts +0 -3
  43. /package/dist/executors/{napi-cross-toolchain → cargo-zigbuild}/schema.js +0 -0
package/README.md CHANGED
@@ -757,17 +757,21 @@ Concrete targets come from concrete files:
757
757
  one has finished. Explicit target declarations are not platform-conditional: dependency-only target nodes and their
758
758
  ordering edges remain off macOS even though no executable group runner is inferred. The ordinary `test` and
759
759
  `cargo-test` aggregates must still reach neither group.
760
- - Canonical `napi` package metadata provides a host `cargo-napi` target and named release targets for each configured
761
- triple. Linux `--use-napi-cross` targets compile C/C++ dependencies with Clang; the NAPI CLI supplies its downloaded
762
- GNU sysroot and toolchain flags. This avoids the bundled GCC's unsupported diagnostics-color flag without disabling
763
- the workspace's sccache wrapper.
764
- - Each `--use-napi-cross` triple also gets a `napi-toolchain-<arch>-linux` prerequisite that extracts the pinned
765
- `@napi-rs/cross-toolchain-<host>-target-<arch>` archive into `~/.napi-rs`, where the NAPI CLI probes for it. Every
766
- cross build of that triple — the inferred `napi-<arch>-linux` and any package-local `cli-<arch>-linux` — depends on
767
- it, so the CLI's own downloader never runs. That downloader `npm pack`s into its own package directory, which under
768
- Bun's isolated global store is a shared (in CI host-wide) cache: two concurrent cross builds of one triple would
769
- otherwise pack the same file into the same directory and one would die on the other's cleanup. The prerequisite
770
- produces no artifact, so it stays out of the aggregate `build` and out of collected platform outputs.
760
+ - Canonical `napi` package metadata provides a host `cargo-napi` target (only when no configured triple is the host's
761
+ own platform) and named release targets for each configured triple. macOS triples run `napi build` with the host's
762
+ toolchain, because a macOS addon needs Apple's SDK, which zig does not carry; the napi CLI also writes the platform
763
+ `.d.ts`.
764
+ - Linux artifacts reference no build-host path. N-API addons link glibc 2.17 symbol versions and carry no RUNPATH;
765
+ binaries a package builds for Linux, such as a CLI, build the same way. Both are built by devenv's zig through
766
+ cargo-zigbuild, with the same command on every host. Each Linux triple's `napi-<arch>-linux` target runs the
767
+ `@smoothbricks/nx-plugin:cargo-zigbuild` executor with `--target <triple>.2.17`, and the executor copies the cdylib to
768
+ `dist/native/linux-<arch>-gnu/<binaryName>.linux-<arch>-gnu.node` itself: the napi CLI cannot carry the glibc suffix,
769
+ since it looks for the artifact under `target/<triple>.2.17/`. A package-local `cli-<arch>-linux` uses the same
770
+ executor with `bin` set; a static CLI targets `<arch>-unknown-linux-musl`. The executor runs `cargo-zigbuild`
771
+ directly, removes any compiler or linker the shell names for its triple (a Linux shell pins its host compiler for
772
+ `x86_64-unknown-linux-gnu`), and reads the artifact path from cargo's JSON messages. zig and cargo-zigbuild come from
773
+ the managed devenv module: a Linux shell carries them, a macOS shell only inside the `linux-cross` profile
774
+ (`tooling/devenv -P linux-cross shell -- …`).
771
775
  - `build` is inferred only when the project has at least one concrete build target to run, such as inferred `tsc-js`, a
772
776
  package-local target like `tsdown-js`, or `cargo-wasm` from this plugin. It depends on output-family wildcard targets:
773
777
  `*-js`, `*-web`, `*-html`, `*-css`, `*-ios`, `*-android`, `*-native`, `*-napi`, `*-bun`, and `*-wasm`.
@@ -18,12 +18,12 @@
18
18
  * two machines ever agree and no cargo target can share a cache entry with a
19
19
  * peer or with CI — a remote cache for Rust was dead on arrival. And the dump
20
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.
21
+ * the `linux-cross` profile `CARGO_INSTALL_ROOT` moves under
22
+ * `profiles/linux-cross/`, and every variable the profile's tools set appears,
23
+ * so the entry `check:linux` writes inside the profile could never be hit by
24
+ * the pre-push probe, which runs bare. Measured on one repository-root archive
25
+ * target with the dump still in place: bare 18197306115812424011, in-profile
26
+ * 12567954759860890767.
27
27
  *
28
28
  * A file input has neither defect. The lock's bytes are identical bare and
29
29
  * in-profile and on every machine holding the checkout, while the toolchain
@@ -19,12 +19,12 @@ import { runtimeInput, shellWord } from './runtime-input.js';
19
19
  * two machines ever agree and no cargo target can share a cache entry with a
20
20
  * peer or with CI — a remote cache for Rust was dead on arrival. And the dump
21
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.
22
+ * the `linux-cross` profile `CARGO_INSTALL_ROOT` moves under
23
+ * `profiles/linux-cross/`, and every variable the profile's tools set appears,
24
+ * so the entry `check:linux` writes inside the profile could never be hit by
25
+ * the pre-push probe, which runs bare. Measured on one repository-root archive
26
+ * target with the dump still in place: bare 18197306115812424011, in-profile
27
+ * 12567954759860890767.
28
28
  *
29
29
  * A file input has neither defect. The lock's bytes are identical bare and
30
30
  * in-profile and on every machine holding the checkout, while the toolchain
@@ -5,11 +5,12 @@
5
5
  * compiles is invisible to every check a macOS host can run: a full local lint
6
6
  * passes and CI still goes red on unused imports, unresolved names and dead code
7
7
  * inside the `not(target_os = "macos")` branch. Closing that needs three pieces
8
- * to agree — a devenv profile carrying the cross C toolchain, an Nx target per
9
- * Cargo workspace that asks for the triple, and a root script that runs the
10
- * second inside the first. They live here together because the plugin infers the
11
- * target while the CLI installs the script and reports a project missing it; kept
12
- * apart, the three spellings drift and the gate silently stops gating.
8
+ * to agree — a devenv profile carrying the Linux toolchain (zig, cargo-zigbuild
9
+ * and the Linux rust-std set), an Nx target per Cargo workspace that asks for
10
+ * the triple, and a root script that runs the second inside the first. They
11
+ * live here together because the plugin infers the target while the CLI
12
+ * installs the script and reports a project missing it; kept apart, the three
13
+ * spellings drift and the gate silently stops gating.
13
14
  */
14
15
  /**
15
16
  * The triple CI's Linux job compiles, and the one a macOS host can cross-check.
@@ -17,9 +18,10 @@
17
18
  */
18
19
  export declare const CARGO_LINUX_TRIPLE = "x86_64-unknown-linux-gnu";
19
20
  /**
20
- * The devenv profile carrying the cross C compiler, defined in the managed
21
- * `tooling/direnv/devenv.smoo.nix`. Opt-in because its closure is 0.4 GiB and
22
- * nothing on Darwin links a Linux object.
21
+ * The devenv profile carrying the Linux toolchain — zig, cargo-zigbuild and the
22
+ * Linux rust-std set — defined in the managed `tooling/direnv/devenv.smoo.nix`.
23
+ * Opt-in on macOS because zig alone is a 380 MiB closure that nothing but a
24
+ * Linux artifact or this check uses.
23
25
  */
24
26
  export declare const DEVENV_CROSS_PROFILE = "linux-cross";
25
27
  /**
@@ -34,12 +36,21 @@ export declare const DEVENV_CROSS_PROFILE = "linux-cross";
34
36
  * build-output families, so no aggregate `build` picks it up either.
35
37
  */
36
38
  export declare const CARGO_CROSS_LINT_TARGET = "cargo-lint-cross";
39
+ /**
40
+ * What the cross lint prints when it refuses to compile without cargo-zigbuild
41
+ * on PATH: on a Darwin cache miss this line, and only this line, means the
42
+ * key missed. The managed pre-push hook reads its output for exactly this text
43
+ * to tell a miss from any other Nx failure.
44
+ */
45
+ export declare const CARGO_CROSS_LINT_REFUSAL = "cargo-lint-cross needs cargo-zigbuild from the linux-cross toolchain; run: bun run check:linux";
37
46
  /**
38
47
  * The prefix `cargoFrozen` writes. Exported so target inference can recognize
39
48
  * the commands whose precondition `CARGO_FETCH_TARGET` supplies without
40
49
  * re-spelling the flag; a second copy would silently stop matching.
41
50
  */
42
51
  export declare const CARGO_FROZEN_PREFIX = "cargo --frozen ";
52
+ /** Does this command text run frozen cargo, directly or through cargo-zigbuild? */
53
+ export declare function runsFrozenCargo(text: string): boolean;
43
54
  /**
44
55
  * `--frozen` is cargo's `--locked` + `--offline`. Cargo.lock and the registry
45
56
  * cache are inputs: inferred cargo must not rewrite the lockfile or fetch.
@@ -109,8 +120,13 @@ export declare const CARGO_DENY_WARNINGS = "--config 'build.warnings=\"deny\"'";
109
120
  * must then refuse to launch.
110
121
  *
111
122
  * `--target` is explicit rather than inherited from a CARGO_BUILD_TARGET exported
112
- * by the profile, so running this outside the cross shell fails loudly on a
113
- * missing tool instead of quietly linting the host and reporting green.
123
+ * by the profile, so running this outside the cross shell fails loudly on the
124
+ * missing cargo-zigbuild instead of quietly linting the host and reporting green.
125
+ *
126
+ * cargo-zigbuild rather than plain cargo because ring compiles C for the target
127
+ * from its build script, and build scripts run even under clippy: zig is the
128
+ * C compiler for every Linux triple on every host, the same one the Linux
129
+ * artifacts build with, so the check needs no per-triple cross gcc.
114
130
  *
115
131
  * `cargo fmt` is absent on purpose: formatting is target-independent and already
116
132
  * covered by `cargo-lint`, so repeating it here would only cost time.
@@ -126,7 +142,7 @@ export declare const CARGO_DENY_WARNINGS = "--config 'build.warnings=\"deny\"'";
126
142
  * are distinct anyway, and its own lock keeps the cross check from queueing
127
143
  * behind host builds.
128
144
  */
129
- export declare const CARGO_CROSS_LINT_COMMAND: string;
145
+ export declare const CARGO_CROSS_LINT_COMMAND = "command -v cargo-zigbuild >/dev/null || { echo 'cargo-lint-cross needs cargo-zigbuild from the linux-cross toolchain; run: bun run check:linux' >&2; exit 2; }; cargo-zigbuild clippy --frozen --workspace --all-targets --target x86_64-unknown-linux-gnu --target-dir target/cargo-lint-cross --config 'build.warnings=\"deny\"'";
130
146
  /**
131
147
  * No `--target-dir`: clippy writes the workspace's own `target/`, beside every
132
148
  * dev build. Check units carry their mode in the unit hash, so they never
@@ -150,9 +166,10 @@ export declare const CROSS_CHECK_SCRIPT_NAME = "check:linux";
150
166
  * cache and refuses a push that has no hit, never entering a profile or starting
151
167
  * a compile of its own. That makes this script the only place the gate ever
152
168
  * runs, and a human watching it needs devenv's progress too — the cross profile
153
- * is a 0.4 GiB closure and the clippy behind it is unbounded, so a silent
154
- * terminal is indistinguishable from a hang. Suppressing that output only paid
155
- * while a hook ran this for you and nobody read it.
169
+ * adds about 0.9 GiB (zig plus three rust-std targets) and the clippy behind it
170
+ * is unbounded, so a silent terminal is indistinguishable from a hang.
171
+ * Suppressing that output only paid while a hook ran this for you and nobody
172
+ * read it.
156
173
  */
157
174
  export declare const CROSS_CHECK_SCRIPT_COMMAND = "tooling/devenv -P linux-cross shell -- nx run-many -t cargo-lint-cross";
158
175
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"cross-check-policy.d.ts","sourceRoot":"","sources":["../src/cross-check-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;GAGG;AACH,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAE7D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAElD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAI1D;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,uCAAqC,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,wBAAwB,QAElC,CAAC;AAEJ;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,QAAyE,CAAC;AAEhH,6EAA6E;AAC7E,eAAO,MAAM,uBAAuB,gBAAgB,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,0BAA0B,2EAAiG,CAAC;AAEzI;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,6DAA6D;AAC7D,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhE;AAID,iFAAiF;AACjF,wBAAgB,qCAAqC,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKvF"}
1
+ {"version":3,"file":"cross-check-policy.d.ts","sourceRoot":"","sources":["../src/cross-check-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;GAGG;AACH,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAE7D;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAElD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,mGAC6D,CAAC;AAInG;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAYrD,mFAAmF;AACnF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,uCAAqC,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,wBAAwB,uUAA0L,CAAC;AAEhO;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,QAAyE,CAAC;AAEhH,6EAA6E;AAC7E,eAAO,MAAM,uBAAuB,gBAAgB,CAAC;AAErD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,0BAA0B,2EAAiG,CAAC;AAEzI;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,6DAA6D;AAC7D,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhE;AAID,iFAAiF;AACjF,wBAAgB,qCAAqC,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKvF"}
@@ -5,11 +5,12 @@
5
5
  * compiles is invisible to every check a macOS host can run: a full local lint
6
6
  * passes and CI still goes red on unused imports, unresolved names and dead code
7
7
  * inside the `not(target_os = "macos")` branch. Closing that needs three pieces
8
- * to agree — a devenv profile carrying the cross C toolchain, an Nx target per
9
- * Cargo workspace that asks for the triple, and a root script that runs the
10
- * second inside the first. They live here together because the plugin infers the
11
- * target while the CLI installs the script and reports a project missing it; kept
12
- * apart, the three spellings drift and the gate silently stops gating.
8
+ * to agree — a devenv profile carrying the Linux toolchain (zig, cargo-zigbuild
9
+ * and the Linux rust-std set), an Nx target per Cargo workspace that asks for
10
+ * the triple, and a root script that runs the second inside the first. They
11
+ * live here together because the plugin infers the target while the CLI
12
+ * installs the script and reports a project missing it; kept apart, the three
13
+ * spellings drift and the gate silently stops gating.
13
14
  */
14
15
  /**
15
16
  * The triple CI's Linux job compiles, and the one a macOS host can cross-check.
@@ -17,9 +18,10 @@
17
18
  */
18
19
  export const CARGO_LINUX_TRIPLE = 'x86_64-unknown-linux-gnu';
19
20
  /**
20
- * The devenv profile carrying the cross C compiler, defined in the managed
21
- * `tooling/direnv/devenv.smoo.nix`. Opt-in because its closure is 0.4 GiB and
22
- * nothing on Darwin links a Linux object.
21
+ * The devenv profile carrying the Linux toolchain — zig, cargo-zigbuild and the
22
+ * Linux rust-std set — defined in the managed `tooling/direnv/devenv.smoo.nix`.
23
+ * Opt-in on macOS because zig alone is a 380 MiB closure that nothing but a
24
+ * Linux artifact or this check uses.
23
25
  */
24
26
  export const DEVENV_CROSS_PROFILE = 'linux-cross';
25
27
  /**
@@ -34,13 +36,33 @@ export const DEVENV_CROSS_PROFILE = 'linux-cross';
34
36
  * build-output families, so no aggregate `build` picks it up either.
35
37
  */
36
38
  export const CARGO_CROSS_LINT_TARGET = 'cargo-lint-cross';
37
- const CARGO_CROSS_LINT_GUARD = `[ -n "\${CC_x86_64_unknown_linux_gnu:-}" ] || [ "$(uname -s)" = Linux ] || { echo 'cargo-lint-cross needs the linux-cross C toolchain; run: bun run check:linux' >&2; exit 2; }`;
39
+ /**
40
+ * What the cross lint prints when it refuses to compile without cargo-zigbuild
41
+ * on PATH: on a Darwin cache miss this line, and only this line, means the
42
+ * key missed. The managed pre-push hook reads its output for exactly this text
43
+ * to tell a miss from any other Nx failure.
44
+ */
45
+ export const CARGO_CROSS_LINT_REFUSAL = 'cargo-lint-cross needs cargo-zigbuild from the linux-cross toolchain; run: bun run check:linux';
46
+ const CARGO_CROSS_LINT_GUARD = `command -v cargo-zigbuild >/dev/null || { echo '${CARGO_CROSS_LINT_REFUSAL}' >&2; exit 2; }`;
38
47
  /**
39
48
  * The prefix `cargoFrozen` writes. Exported so target inference can recognize
40
49
  * the commands whose precondition `CARGO_FETCH_TARGET` supplies without
41
50
  * re-spelling the flag; a second copy would silently stop matching.
42
51
  */
43
52
  export const CARGO_FROZEN_PREFIX = 'cargo --frozen ';
53
+ /**
54
+ * cargo-zigbuild's spelling of frozen clippy. The flag sits on the subcommand
55
+ * because cargo does not forward a global `--frozen` to an external one:
56
+ * `cargo --frozen zigbuild` resolves and writes Cargo.lock as if unflagged
57
+ * (measured). And `cargo-zigbuild` is run directly rather than as
58
+ * `cargo zigbuild`, so its inner `cargo` is the one on PATH rather than the
59
+ * real binary cargo would hand it through `CARGO`.
60
+ */
61
+ const CARGO_ZIGBUILD_CLIPPY_FROZEN_PREFIX = 'cargo-zigbuild clippy --frozen ';
62
+ /** Does this command text run frozen cargo, directly or through cargo-zigbuild? */
63
+ export function runsFrozenCargo(text) {
64
+ return text.includes(CARGO_FROZEN_PREFIX) || text.includes(CARGO_ZIGBUILD_CLIPPY_FROZEN_PREFIX);
65
+ }
44
66
  /**
45
67
  * `--frozen` is cargo's `--locked` + `--offline`. Cargo.lock and the registry
46
68
  * cache are inputs: inferred cargo must not rewrite the lockfile or fetch.
@@ -112,8 +134,13 @@ export const CARGO_DENY_WARNINGS = `--config 'build.warnings="deny"'`;
112
134
  * must then refuse to launch.
113
135
  *
114
136
  * `--target` is explicit rather than inherited from a CARGO_BUILD_TARGET exported
115
- * by the profile, so running this outside the cross shell fails loudly on a
116
- * missing tool instead of quietly linting the host and reporting green.
137
+ * by the profile, so running this outside the cross shell fails loudly on the
138
+ * missing cargo-zigbuild instead of quietly linting the host and reporting green.
139
+ *
140
+ * cargo-zigbuild rather than plain cargo because ring compiles C for the target
141
+ * from its build script, and build scripts run even under clippy: zig is the
142
+ * C compiler for every Linux triple on every host, the same one the Linux
143
+ * artifacts build with, so the check needs no per-triple cross gcc.
117
144
  *
118
145
  * `cargo fmt` is absent on purpose: formatting is target-independent and already
119
146
  * covered by `cargo-lint`, so repeating it here would only cost time.
@@ -129,7 +156,7 @@ export const CARGO_DENY_WARNINGS = `--config 'build.warnings="deny"'`;
129
156
  * are distinct anyway, and its own lock keeps the cross check from queueing
130
157
  * behind host builds.
131
158
  */
132
- export const CARGO_CROSS_LINT_COMMAND = `${CARGO_CROSS_LINT_GUARD}; ${cargoFrozen(`clippy --workspace --all-targets --target ${CARGO_LINUX_TRIPLE} --target-dir target/cargo-lint-cross ${CARGO_DENY_WARNINGS}`)}`;
159
+ export const CARGO_CROSS_LINT_COMMAND = `${CARGO_CROSS_LINT_GUARD}; ${CARGO_ZIGBUILD_CLIPPY_FROZEN_PREFIX}--workspace --all-targets --target ${CARGO_LINUX_TRIPLE} --target-dir target/cargo-lint-cross ${CARGO_DENY_WARNINGS}`;
133
160
  /**
134
161
  * No `--target-dir`: clippy writes the workspace's own `target/`, beside every
135
162
  * dev build. Check units carry their mode in the unit hash, so they never
@@ -153,9 +180,10 @@ export const CROSS_CHECK_SCRIPT_NAME = 'check:linux';
153
180
  * cache and refuses a push that has no hit, never entering a profile or starting
154
181
  * a compile of its own. That makes this script the only place the gate ever
155
182
  * runs, and a human watching it needs devenv's progress too — the cross profile
156
- * is a 0.4 GiB closure and the clippy behind it is unbounded, so a silent
157
- * terminal is indistinguishable from a hang. Suppressing that output only paid
158
- * while a hook ran this for you and nobody read it.
183
+ * adds about 0.9 GiB (zig plus three rust-std targets) and the clippy behind it
184
+ * is unbounded, so a silent terminal is indistinguishable from a hang.
185
+ * Suppressing that output only paid while a hook ran this for you and nobody
186
+ * read it.
159
187
  */
160
188
  export const CROSS_CHECK_SCRIPT_COMMAND = `tooling/devenv -P ${DEVENV_CROSS_PROFILE} shell -- nx run-many -t ${CARGO_CROSS_LINT_TARGET}`;
161
189
  /**
@@ -0,0 +1,60 @@
1
+ import type { CargoZigbuildOptions } from './schema.js';
2
+ interface CargoZigbuildContext {
3
+ root: string;
4
+ }
5
+ /**
6
+ * The fields of cargo's `compiler-artifact` JSON message this executor reads.
7
+ * https://doc.rust-lang.org/cargo/reference/external-tools.html#artifact-messages
8
+ */
9
+ export interface CargoArtifactMessage {
10
+ reason: 'compiler-artifact';
11
+ manifest_path: string;
12
+ target: {
13
+ kind: string[];
14
+ name: string;
15
+ };
16
+ filenames: string[];
17
+ executable: string | null;
18
+ }
19
+ /** What one build produces: a named binary, or the package's cdylib. */
20
+ export type ZigbuildArtifact = {
21
+ kind: 'bin';
22
+ name: string;
23
+ } | {
24
+ kind: 'cdylib';
25
+ };
26
+ export declare function zigbuildArtifact(options: Pick<CargoZigbuildOptions, 'bin'>): ZigbuildArtifact;
27
+ /**
28
+ * `cargo-zigbuild zigbuild`, not `cargo zigbuild`. Run through cargo, the
29
+ * subcommand inherits `CARGO` naming the real cargo binary and calls it
30
+ * directly, bypassing the `cargo` on PATH; run directly, its inner `cargo` is
31
+ * the PATH one every other cargo target runs. `--locked` keeps Cargo.lock
32
+ * exactly as committed. The glibc suffix stays on `--target`: it is how
33
+ * cargo-zigbuild pins the symbol versions, and cargo itself sees the bare
34
+ * triple.
35
+ */
36
+ export declare function zigbuildArgs(options: CargoZigbuildOptions, manifestPath: string): string[];
37
+ /** `x86_64-unknown-linux-gnu.2.17` → `x86_64-unknown-linux-gnu`. */
38
+ export declare function cargoTriple(target: string): string;
39
+ /**
40
+ * The environment without any compiler or linker named for this triple.
41
+ *
42
+ * cargo-zigbuild supplies the triple's `CC_`/`CXX_`/`AR_`/`RANLIB_` and
43
+ * linker only where none is set, and cc-rs reads the hyphenated spelling
44
+ * before cargo-zigbuild's underscored one. A shell that pins its host
45
+ * compiler for the same triple — a Linux devenv shell pins
46
+ * `CC_x86_64_unknown_linux_gnu` to Nix's cc wrapper for host builds — would
47
+ * otherwise compile the artifact's C against the build host's glibc headers,
48
+ * which is exactly the build-host leak the zig toolchain exists to remove.
49
+ */
50
+ export declare function zigbuildEnv(env: NodeJS.ProcessEnv, target: string): NodeJS.ProcessEnv;
51
+ /**
52
+ * The artifact file one cargo JSON message names, or null when the message is
53
+ * about anything else. `manifestPath` must be canonical, as cargo reports it.
54
+ */
55
+ export declare function artifactFile(line: string, manifestPath: string, artifact: ZigbuildArtifact): string | null;
56
+ export default function cargoZigbuildExecutor(options: CargoZigbuildOptions, context: CargoZigbuildContext): Promise<{
57
+ success: boolean;
58
+ }>;
59
+ export {};
60
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/cargo-zigbuild/executor.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD,UAAU,oBAAoB;IAC5B,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAKD,wEAAwE;AACxE,MAAM,MAAM,gBAAgB,GAAG;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAElF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,oBAAoB,EAAE,KAAK,CAAC,GAAG,gBAAgB,CAE7F;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,CAe1F;AAED,oEAAoE;AACpE,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAGlD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,UAAU,CAQrF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,MAAM,GAAG,IAAI,CAqB1G;AAED,wBAA8B,qBAAqB,CACjD,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAyD/B"}
@@ -0,0 +1,266 @@
1
+ import * as _validateReport_1 from "typia/lib/internal/_validateReport";
2
+ import * as _createStandardSchema_1 from "typia/lib/internal/_createStandardSchema";
3
+ import { spawn } from 'node:child_process';
4
+ import { realpathSync } from 'node:fs';
5
+ import { chmod, copyFile, mkdir, rename } from 'node:fs/promises';
6
+ import path from 'node:path';
7
+ import { createInterface } from 'node:readline';
8
+ import typia from 'typia';
9
+ const validateReason = (() => {
10
+ const _io0 = input => "string" === typeof input.reason;
11
+ const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.reason || _report(_exceptionable, {
12
+ path: _path + ".reason",
13
+ expected: "string",
14
+ value: input.reason
15
+ })].every(flag => flag);
16
+ const __is = input => "object" === typeof input && null !== input && _io0(input);
17
+ let errors;
18
+ let _report;
19
+ return _createStandardSchema_1._createStandardSchema(input => {
20
+ if (false === __is(input)) {
21
+ errors = [];
22
+ _report = _validateReport_1._validateReport(errors);
23
+ ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
24
+ path: _path + "",
25
+ expected: "{ reason: string; }",
26
+ value: input
27
+ })) && _vo0(input, _path + "", true) || _report(true, {
28
+ path: _path + "",
29
+ expected: "{ reason: string; }",
30
+ value: input
31
+ }))(input, "$input", true);
32
+ const success = 0 === errors.length;
33
+ return success ? {
34
+ success,
35
+ data: input
36
+ } : {
37
+ success,
38
+ errors,
39
+ data: input
40
+ };
41
+ }
42
+ return {
43
+ success: true,
44
+ data: input
45
+ };
46
+ });
47
+ })();
48
+ const validateArtifact = (() => {
49
+ const _io0 = input => "compiler-artifact" === input.reason && "string" === typeof input.manifest_path && ("object" === typeof input.target && null !== input.target && _io1(input.target)) && (Array.isArray(input.filenames) && input.filenames.every(elem => "string" === typeof elem)) && (null === input.executable || "string" === typeof input.executable);
50
+ const _io1 = input => Array.isArray(input.kind) && input.kind.every(elem => "string" === typeof elem) && "string" === typeof input.name;
51
+ const _vo0 = (input, _path, _exceptionable = true) => ["compiler-artifact" === input.reason || _report(_exceptionable, {
52
+ path: _path + ".reason",
53
+ expected: "\"compiler-artifact\"",
54
+ value: input.reason
55
+ }), "string" === typeof input.manifest_path || _report(_exceptionable, {
56
+ path: _path + ".manifest_path",
57
+ expected: "string",
58
+ value: input.manifest_path
59
+ }), ("object" === typeof input.target && null !== input.target || _report(_exceptionable, {
60
+ path: _path + ".target",
61
+ expected: "{ kind: string[]; name: string; }",
62
+ value: input.target
63
+ })) && _vo1(input.target, _path + ".target", true && _exceptionable) || _report(_exceptionable, {
64
+ path: _path + ".target",
65
+ expected: "{ kind: string[]; name: string; }",
66
+ value: input.target
67
+ }), (Array.isArray(input.filenames) || _report(_exceptionable, {
68
+ path: _path + ".filenames",
69
+ expected: "Array<string>",
70
+ value: input.filenames
71
+ })) && input.filenames.map((elem, _index3) => "string" === typeof elem || _report(_exceptionable, {
72
+ path: _path + ".filenames[" + _index3 + "]",
73
+ expected: "string",
74
+ value: elem
75
+ })).every(flag => flag) || _report(_exceptionable, {
76
+ path: _path + ".filenames",
77
+ expected: "Array<string>",
78
+ value: input.filenames
79
+ }), null === input.executable || "string" === typeof input.executable || _report(_exceptionable, {
80
+ path: _path + ".executable",
81
+ expected: "(null | string)",
82
+ value: input.executable
83
+ })].every(flag => flag);
84
+ const _vo1 = (input, _path, _exceptionable = true) => [(Array.isArray(input.kind) || _report(_exceptionable, {
85
+ path: _path + ".kind",
86
+ expected: "Array<string>",
87
+ value: input.kind
88
+ })) && input.kind.map((elem, _index4) => "string" === typeof elem || _report(_exceptionable, {
89
+ path: _path + ".kind[" + _index4 + "]",
90
+ expected: "string",
91
+ value: elem
92
+ })).every(flag => flag) || _report(_exceptionable, {
93
+ path: _path + ".kind",
94
+ expected: "Array<string>",
95
+ value: input.kind
96
+ }), "string" === typeof input.name || _report(_exceptionable, {
97
+ path: _path + ".name",
98
+ expected: "string",
99
+ value: input.name
100
+ })].every(flag => flag);
101
+ const __is = input => "object" === typeof input && null !== input && _io0(input);
102
+ let errors;
103
+ let _report;
104
+ return _createStandardSchema_1._createStandardSchema(input => {
105
+ if (false === __is(input)) {
106
+ errors = [];
107
+ _report = _validateReport_1._validateReport(errors);
108
+ ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
109
+ path: _path + "",
110
+ expected: "CargoArtifactMessage",
111
+ value: input
112
+ })) && _vo0(input, _path + "", true) || _report(true, {
113
+ path: _path + "",
114
+ expected: "CargoArtifactMessage",
115
+ value: input
116
+ }))(input, "$input", true);
117
+ const success = 0 === errors.length;
118
+ return success ? {
119
+ success,
120
+ data: input
121
+ } : {
122
+ success,
123
+ errors,
124
+ data: input
125
+ };
126
+ }
127
+ return {
128
+ success: true,
129
+ data: input
130
+ };
131
+ });
132
+ })();
133
+ export function zigbuildArtifact(options) {
134
+ return options.bin === undefined ? { kind: 'cdylib' } : { kind: 'bin', name: options.bin };
135
+ }
136
+ /**
137
+ * `cargo-zigbuild zigbuild`, not `cargo zigbuild`. Run through cargo, the
138
+ * subcommand inherits `CARGO` naming the real cargo binary and calls it
139
+ * directly, bypassing the `cargo` on PATH; run directly, its inner `cargo` is
140
+ * the PATH one every other cargo target runs. `--locked` keeps Cargo.lock
141
+ * exactly as committed. The glibc suffix stays on `--target`: it is how
142
+ * cargo-zigbuild pins the symbol versions, and cargo itself sees the bare
143
+ * triple.
144
+ */
145
+ export function zigbuildArgs(options, manifestPath) {
146
+ const artifact = zigbuildArtifact(options);
147
+ return [
148
+ 'zigbuild',
149
+ '--locked',
150
+ '--message-format=json-render-diagnostics',
151
+ '--target',
152
+ options.target,
153
+ '--manifest-path',
154
+ manifestPath,
155
+ '--package',
156
+ options.package,
157
+ ...(options.release === true ? ['--release'] : []),
158
+ ...(artifact.kind === 'bin' ? ['--bin', artifact.name] : ['--lib']),
159
+ ];
160
+ }
161
+ /** `x86_64-unknown-linux-gnu.2.17` → `x86_64-unknown-linux-gnu`. */
162
+ export function cargoTriple(target) {
163
+ const glibcSuffix = /\.\d+\.\d+$/.exec(target);
164
+ return glibcSuffix === null ? target : target.slice(0, glibcSuffix.index);
165
+ }
166
+ /**
167
+ * The environment without any compiler or linker named for this triple.
168
+ *
169
+ * cargo-zigbuild supplies the triple's `CC_`/`CXX_`/`AR_`/`RANLIB_` and
170
+ * linker only where none is set, and cc-rs reads the hyphenated spelling
171
+ * before cargo-zigbuild's underscored one. A shell that pins its host
172
+ * compiler for the same triple — a Linux devenv shell pins
173
+ * `CC_x86_64_unknown_linux_gnu` to Nix's cc wrapper for host builds — would
174
+ * otherwise compile the artifact's C against the build host's glibc headers,
175
+ * which is exactly the build-host leak the zig toolchain exists to remove.
176
+ */
177
+ export function zigbuildEnv(env, target) {
178
+ const triple = cargoTriple(target);
179
+ const underscored = triple.replaceAll('-', '_');
180
+ const owned = new Set([
181
+ ...['CC', 'CXX', 'AR', 'RANLIB'].flatMap((tool) => [`${tool}_${triple}`, `${tool}_${underscored}`]),
182
+ `CARGO_TARGET_${underscored.toUpperCase()}_LINKER`,
183
+ ]);
184
+ return Object.fromEntries(Object.entries(env).filter(([name]) => !owned.has(name)));
185
+ }
186
+ /**
187
+ * The artifact file one cargo JSON message names, or null when the message is
188
+ * about anything else. `manifestPath` must be canonical, as cargo reports it.
189
+ */
190
+ export function artifactFile(line, manifestPath, artifact) {
191
+ if (!line.startsWith('{'))
192
+ return null;
193
+ const parsed = JSON.parse(line);
194
+ const header = validateReason(parsed);
195
+ if (!header.success) {
196
+ throw new Error(`cargo emitted a JSON message without a reason: ${line}`);
197
+ }
198
+ if (header.data.reason !== 'compiler-artifact')
199
+ return null;
200
+ const message = validateArtifact(parsed);
201
+ if (!message.success) {
202
+ throw new Error(`cargo compiler-artifact message does not match the artifact contract: ${JSON.stringify(message.errors)}`);
203
+ }
204
+ const { data } = message;
205
+ if (data.manifest_path !== manifestPath)
206
+ return null;
207
+ if (artifact.kind === 'bin') {
208
+ return data.target.kind.includes('bin') && data.target.name === artifact.name ? data.executable : null;
209
+ }
210
+ if (!data.target.kind.includes('cdylib'))
211
+ return null;
212
+ return data.filenames.find((file) => file.endsWith('.so')) ?? null;
213
+ }
214
+ export default async function cargoZigbuildExecutor(options, context) {
215
+ const manifestPath = realpathSync(path.resolve(context.root, options.manifestPath));
216
+ const output = path.resolve(context.root, options.output);
217
+ const artifact = zigbuildArtifact(options);
218
+ const args = zigbuildArgs(options, manifestPath);
219
+ const command = `cargo-zigbuild ${args.join(' ')}`;
220
+ // Cargo discovers `.cargo/config.toml` from its working directory upward,
221
+ // so the crate's own directory sees every config a build of it would.
222
+ const child = spawn('cargo-zigbuild', args, {
223
+ cwd: path.dirname(manifestPath),
224
+ env: zigbuildEnv(process.env, options.target),
225
+ stdio: ['ignore', 'pipe', 'inherit'],
226
+ });
227
+ const exited = new Promise((resolve, reject) => {
228
+ child.once('error', reject);
229
+ child.once('close', (code, signal) => resolve({ code, signal }));
230
+ });
231
+ let built = null;
232
+ for await (const line of createInterface({ input: child.stdout })) {
233
+ built = artifactFile(line, manifestPath, artifact) ?? built;
234
+ }
235
+ let status;
236
+ try {
237
+ status = await exited;
238
+ }
239
+ catch (error) {
240
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
241
+ console.error(`${command}: cargo-zigbuild is not on PATH. Linux artifacts build with the linux-cross toolchain; ` +
242
+ 'on macOS run the target inside it: tooling/devenv -P linux-cross shell -- nx run <project>:<target>');
243
+ return { success: false };
244
+ }
245
+ throw error;
246
+ }
247
+ if (status.code !== 0) {
248
+ console.error(`${command}: exited with ${status.signal ?? `status ${status.code}`}`);
249
+ return { success: false };
250
+ }
251
+ if (built === null) {
252
+ const wanted = artifact.kind === 'bin' ? `binary ${artifact.name}` : 'cdylib';
253
+ console.error(`${command}: cargo reported no ${wanted} artifact for ${options.package} at ${manifestPath}`);
254
+ return { success: false };
255
+ }
256
+ // Copy then rename, so the output path never holds a partial file.
257
+ await mkdir(path.dirname(output), { recursive: true });
258
+ const staging = `${output}.partial`;
259
+ await copyFile(built, staging);
260
+ if (artifact.kind === 'bin') {
261
+ await chmod(staging, 0o755);
262
+ }
263
+ await rename(staging, output);
264
+ console.log(`${path.relative(context.root, built)} -> ${path.relative(context.root, output)}`);
265
+ return { success: true };
266
+ }
@@ -0,0 +1,15 @@
1
+ export interface CargoZigbuildOptions {
2
+ /** Rust target triple, with cargo-zigbuild's glibc suffix where it pins one: `x86_64-unknown-linux-gnu.2.17`. */
3
+ target: string;
4
+ /** The crate's Cargo.toml, relative to the workspace root. */
5
+ manifestPath: string;
6
+ /** Cargo package to build. */
7
+ package: string;
8
+ /** Build this binary and copy its executable; absent, build the package's cdylib. */
9
+ bin?: string;
10
+ /** Destination file for the artifact, relative to the workspace root. */
11
+ output: string;
12
+ /** Compile cargo's `release` profile instead of `dev`. */
13
+ release?: boolean;
14
+ }
15
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/executors/cargo-zigbuild/schema.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,iHAAiH;IACjH,MAAM,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,YAAY,EAAE,MAAM,CAAC;IACrB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}