@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.
- package/README.md +15 -11
- package/dist/cargo-toolchain-policy.d.ts +6 -6
- package/dist/cargo-toolchain-policy.js +6 -6
- package/dist/cross-check-policy.d.ts +31 -14
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +43 -15
- package/dist/executors/cargo-zigbuild/executor.d.ts +60 -0
- package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -0
- package/dist/executors/cargo-zigbuild/executor.js +266 -0
- package/dist/executors/cargo-zigbuild/schema.d.ts +15 -0
- package/dist/executors/cargo-zigbuild/schema.d.ts.map +1 -0
- package/dist/index.d.ts +0 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +56 -89
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +3 -2
- package/executors.json +4 -4
- package/managed/raw/patches/nx@23.2.1.patch +177 -9
- package/managed/raw/tooling/direnv/devenv.smoo.nix +46 -46
- package/managed/raw/tooling/git-hooks/pre-push.sh +41 -23
- package/package.json +1 -1
- package/src/cargo-toolchain-policy.ts +6 -6
- package/src/cross-check-policy.test.ts +90 -11
- package/src/cross-check-policy.ts +47 -17
- package/src/executors/cargo-zigbuild/executor.test.ts +129 -0
- package/src/executors/cargo-zigbuild/executor.ts +176 -0
- package/src/executors/cargo-zigbuild/schema.json +35 -0
- package/src/executors/cargo-zigbuild/schema.ts +14 -0
- package/src/index.test.ts +29 -61
- package/src/index.ts +60 -98
- package/src/nx-daemon-validity.test.ts +65 -0
- package/src/testing.ts +3 -2
- package/test-timings.json +1 -1
- package/dist/executors/napi-cross-toolchain/executor.d.ts +0 -42
- package/dist/executors/napi-cross-toolchain/executor.d.ts.map +0 -1
- package/dist/executors/napi-cross-toolchain/executor.js +0 -126
- package/dist/executors/napi-cross-toolchain/schema.d.ts +0 -4
- package/dist/executors/napi-cross-toolchain/schema.d.ts.map +0 -1
- package/src/executors/napi-cross-toolchain/executor.test.ts +0 -112
- package/src/executors/napi-cross-toolchain/executor.ts +0 -165
- package/src/executors/napi-cross-toolchain/schema.json +0 -15
- package/src/executors/napi-cross-toolchain/schema.ts +0 -3
- /package/dist/executors/{napi-cross-toolchain → cargo-zigbuild}/schema.js +0 -0
|
@@ -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
|
|
237
|
-
# compiler, which is
|
|
238
|
-
# below
|
|
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
|
-
|
|
245
|
-
|
|
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
|
-
#
|
|
250
|
-
#
|
|
251
|
-
#
|
|
252
|
-
#
|
|
253
|
-
#
|
|
254
|
-
#
|
|
255
|
-
#
|
|
256
|
-
#
|
|
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
|
-
#
|
|
260
|
-
#
|
|
261
|
-
#
|
|
262
|
-
# `
|
|
263
|
-
#
|
|
264
|
-
#
|
|
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
|
-
#
|
|
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-
|
|
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
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
|
@@ -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
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
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
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
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
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
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.
|
|
74
|
-
|
|
75
|
-
|
|
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
|
@@ -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 `
|
|
24
|
-
* `
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
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
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { describe, expect, it } from 'bun:test';
|
|
2
|
-
import {
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { chmod, mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
3
4
|
import { tmpdir } from 'node:os';
|
|
4
5
|
import { join } from 'node:path';
|
|
5
6
|
|
|
6
7
|
import {
|
|
7
8
|
CARGO_CROSS_LINT_COMMAND,
|
|
9
|
+
CARGO_CROSS_LINT_REFUSAL,
|
|
8
10
|
CARGO_CROSS_LINT_TARGET,
|
|
9
11
|
CARGO_DENY_WARNINGS,
|
|
10
12
|
CARGO_LINT_CLIPPY_COMMAND,
|
|
@@ -13,6 +15,7 @@ import {
|
|
|
13
15
|
CROSS_CHECK_SCRIPT_NAME,
|
|
14
16
|
cargoFrozen,
|
|
15
17
|
DEVENV_CROSS_PROFILE,
|
|
18
|
+
runsFrozenCargo,
|
|
16
19
|
} from './cross-check-policy.js';
|
|
17
20
|
import { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
18
21
|
|
|
@@ -119,12 +122,24 @@ describe('Linux cross-check policy', () => {
|
|
|
119
122
|
}
|
|
120
123
|
});
|
|
121
124
|
|
|
122
|
-
it('
|
|
123
|
-
// Without this guard a
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
it('refuses to start without cargo-zigbuild instead of compiling', async () => {
|
|
126
|
+
// Without this guard a cache miss outside the linux-cross toolchain would
|
|
127
|
+
// start a compile that cannot finish. Run for real against a PATH with no
|
|
128
|
+
// cargo-zigbuild: it must refuse, name the fix, and never reach cargo.
|
|
129
|
+
const child = Bun.spawn(['/bin/sh', '-c', CARGO_CROSS_LINT_COMMAND], {
|
|
130
|
+
cwd: tmpdir(),
|
|
131
|
+
env: { PATH: '/usr/bin:/bin' },
|
|
132
|
+
stdout: 'pipe',
|
|
133
|
+
stderr: 'pipe',
|
|
134
|
+
});
|
|
135
|
+
const [exitCode, stderr] = await Promise.all([child.exited, new Response(child.stderr).text()]);
|
|
136
|
+
expect(exitCode).toBe(2);
|
|
137
|
+
expect(stderr).toContain('needs cargo-zigbuild');
|
|
138
|
+
expect(stderr).toContain('bun run check:linux');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('prints the refusal the managed pre-push hook reads as a cache miss', () => {
|
|
142
|
+
expect(CARGO_CROSS_LINT_COMMAND).toContain(`echo '${CARGO_CROSS_LINT_REFUSAL}' >&2; exit 2`);
|
|
128
143
|
});
|
|
129
144
|
|
|
130
145
|
it('carries the triple explicitly so a host lint cannot pass for a cross one', () => {
|
|
@@ -171,8 +186,16 @@ describe('Linux cross-check policy', () => {
|
|
|
171
186
|
|
|
172
187
|
it('pins clippy to the committed lockfile and local cache', () => {
|
|
173
188
|
expect(cargoFrozen('clippy --workspace')).toBe('cargo --frozen clippy --workspace');
|
|
174
|
-
|
|
189
|
+
// cargo drops a global --frozen in front of an external subcommand, so the
|
|
190
|
+
// flag sits on cargo-zigbuild's own subcommand.
|
|
191
|
+
expect(CARGO_CROSS_LINT_COMMAND).toContain('cargo-zigbuild clippy --frozen ');
|
|
192
|
+
expect(CARGO_CROSS_LINT_COMMAND).not.toContain('cargo --frozen zigbuild');
|
|
175
193
|
expect(CARGO_LINT_CLIPPY_COMMAND).toContain('cargo --frozen clippy');
|
|
194
|
+
// Inference recognizes both spellings, so both get the fetch prerequisite
|
|
195
|
+
// and the toolchain identity.
|
|
196
|
+
expect(runsFrozenCargo(CARGO_CROSS_LINT_COMMAND)).toBe(true);
|
|
197
|
+
expect(runsFrozenCargo(CARGO_LINT_CLIPPY_COMMAND)).toBe(true);
|
|
198
|
+
expect(runsFrozenCargo('cargo clippy --workspace')).toBe(false);
|
|
176
199
|
});
|
|
177
200
|
|
|
178
201
|
it('drives the Nx target through the cross profile from the root script', () => {
|
|
@@ -184,9 +207,9 @@ describe('Linux cross-check policy', () => {
|
|
|
184
207
|
// ...and runs Nx rather than cargo directly, so caching and project
|
|
185
208
|
// discovery stay Nx's job.
|
|
186
209
|
expect(CROSS_CHECK_SCRIPT_COMMAND).toContain(`nx run-many -t ${CARGO_CROSS_LINT_TARGET}`);
|
|
187
|
-
// The
|
|
188
|
-
// devenv's own progress has to reach them, or a 0.
|
|
189
|
-
// unbounded clippy are indistinguishable from a hang.
|
|
210
|
+
// The pre-push gate never enters the cross profile, so a human does — and
|
|
211
|
+
// devenv's own progress has to reach them, or a 0.9 GiB toolchain closure
|
|
212
|
+
// and an unbounded clippy are indistinguishable from a hang.
|
|
190
213
|
expect(CROSS_CHECK_SCRIPT_COMMAND).not.toContain('--quiet');
|
|
191
214
|
});
|
|
192
215
|
|
|
@@ -194,3 +217,59 @@ describe('Linux cross-check policy', () => {
|
|
|
194
217
|
expect(CROSS_CHECK_SCRIPT_NAME).toMatch(/^[a-z]+:[a-z-]+$/);
|
|
195
218
|
});
|
|
196
219
|
});
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* The managed pre-push hook, run for real in a fixture repository whose `tooling/direnv/repo-path` puts stand-ins
|
|
223
|
+
* first on PATH: `uname` says Darwin, `smoo` passes the denylist, and `nx` prints what a cross run printed and exits
|
|
224
|
+
* with its status. The hook must call a miss a miss and every other Nx failure what it is.
|
|
225
|
+
*/
|
|
226
|
+
describe('managed pre-push cross probe', () => {
|
|
227
|
+
const hook = join(import.meta.dir, '../managed/raw/tooling/git-hooks/pre-push.sh');
|
|
228
|
+
|
|
229
|
+
async function push(nxOutput: string, nxStatus: number): Promise<{ status: number | null; stderr: string }> {
|
|
230
|
+
const root = await mkdtemp(join(tmpdir(), 'pre-push-cross-'));
|
|
231
|
+
try {
|
|
232
|
+
const bin = join(root, 'bin');
|
|
233
|
+
await mkdir(bin);
|
|
234
|
+
await mkdir(join(root, 'repo', 'tooling', 'direnv'), { recursive: true });
|
|
235
|
+
const stub = async (name: string, body: string) => {
|
|
236
|
+
await writeFile(join(bin, name), `#!/bin/sh\n${body}\n`);
|
|
237
|
+
await chmod(join(bin, name), 0o755);
|
|
238
|
+
};
|
|
239
|
+
await stub('uname', 'echo Darwin');
|
|
240
|
+
await stub('smoo', 'exit 0');
|
|
241
|
+
await stub('nx', `printf '%s\\n' "$NX_STUB_OUTPUT"; exit ${nxStatus}`);
|
|
242
|
+
await writeFile(join(root, 'repo', 'tooling', 'direnv', 'repo-path'), `#!/bin/sh\necho "${bin}:$PATH"\n`);
|
|
243
|
+
await chmod(join(root, 'repo', 'tooling', 'direnv', 'repo-path'), 0o755);
|
|
244
|
+
await writeFile(join(root, 'repo', 'tooling', 'direnv', 'ttsc-env.sh'), '');
|
|
245
|
+
expect(spawnSync('git', ['init', '-q', join(root, 'repo')]).status).toBe(0);
|
|
246
|
+
const run = spawnSync('bash', [hook, 'origin'], {
|
|
247
|
+
cwd: join(root, 'repo'),
|
|
248
|
+
env: { ...process.env, NX_STUB_OUTPUT: nxOutput },
|
|
249
|
+
input: '',
|
|
250
|
+
encoding: 'utf8',
|
|
251
|
+
});
|
|
252
|
+
return { status: run.status, stderr: run.stderr };
|
|
253
|
+
} finally {
|
|
254
|
+
await rm(root, { recursive: true, force: true });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
it('passes a hit', async () => {
|
|
259
|
+
expect((await push('Successfully ran target cargo-lint-cross', 0)).status).toBe(0);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('names a miss when the cross target refused to compile', async () => {
|
|
263
|
+
const { status, stderr } = await push(CARGO_CROSS_LINT_REFUSAL, 1);
|
|
264
|
+
expect(status).toBe(1);
|
|
265
|
+
expect(stderr).toContain('NOT cached for this tree');
|
|
266
|
+
expect(stderr).toContain('bun run check:linux');
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('names any other Nx failure as that, never as a cache miss', async () => {
|
|
270
|
+
const { status, stderr } = await push('NX NX_WORKSPACE_ROOT_PATH names another workspace', 1);
|
|
271
|
+
expect(status).toBe(1);
|
|
272
|
+
expect(stderr).toContain('Nx failed (exit 1) before the Linux cross-compile check reached');
|
|
273
|
+
expect(stderr).not.toContain('NOT cached');
|
|
274
|
+
});
|
|
275
|
+
});
|
|
@@ -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
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
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
|
/**
|
|
@@ -19,9 +20,10 @@
|
|
|
19
20
|
export const CARGO_LINUX_TRIPLE = 'x86_64-unknown-linux-gnu';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
|
-
* The devenv profile carrying the
|
|
23
|
-
* `tooling/direnv/devenv.smoo.nix`.
|
|
24
|
-
*
|
|
23
|
+
* The devenv profile carrying the Linux toolchain — zig, cargo-zigbuild and the
|
|
24
|
+
* Linux rust-std set — defined in the managed `tooling/direnv/devenv.smoo.nix`.
|
|
25
|
+
* Opt-in on macOS because zig alone is a 380 MiB closure that nothing but a
|
|
26
|
+
* Linux artifact or this check uses.
|
|
25
27
|
*/
|
|
26
28
|
export const DEVENV_CROSS_PROFILE = 'linux-cross';
|
|
27
29
|
|
|
@@ -38,7 +40,16 @@ export const DEVENV_CROSS_PROFILE = 'linux-cross';
|
|
|
38
40
|
*/
|
|
39
41
|
export const CARGO_CROSS_LINT_TARGET = 'cargo-lint-cross';
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
/**
|
|
44
|
+
* What the cross lint prints when it refuses to compile without cargo-zigbuild
|
|
45
|
+
* on PATH: on a Darwin cache miss this line, and only this line, means the
|
|
46
|
+
* key missed. The managed pre-push hook reads its output for exactly this text
|
|
47
|
+
* to tell a miss from any other Nx failure.
|
|
48
|
+
*/
|
|
49
|
+
export const CARGO_CROSS_LINT_REFUSAL =
|
|
50
|
+
'cargo-lint-cross needs cargo-zigbuild from the linux-cross toolchain; run: bun run check:linux';
|
|
51
|
+
|
|
52
|
+
const CARGO_CROSS_LINT_GUARD = `command -v cargo-zigbuild >/dev/null || { echo '${CARGO_CROSS_LINT_REFUSAL}' >&2; exit 2; }`;
|
|
42
53
|
|
|
43
54
|
/**
|
|
44
55
|
* The prefix `cargoFrozen` writes. Exported so target inference can recognize
|
|
@@ -47,6 +58,21 @@ const CARGO_CROSS_LINT_GUARD = `[ -n "\${CC_x86_64_unknown_linux_gnu:-}" ] || [
|
|
|
47
58
|
*/
|
|
48
59
|
export const CARGO_FROZEN_PREFIX = 'cargo --frozen ';
|
|
49
60
|
|
|
61
|
+
/**
|
|
62
|
+
* cargo-zigbuild's spelling of frozen clippy. The flag sits on the subcommand
|
|
63
|
+
* because cargo does not forward a global `--frozen` to an external one:
|
|
64
|
+
* `cargo --frozen zigbuild` resolves and writes Cargo.lock as if unflagged
|
|
65
|
+
* (measured). And `cargo-zigbuild` is run directly rather than as
|
|
66
|
+
* `cargo zigbuild`, so its inner `cargo` is the one on PATH rather than the
|
|
67
|
+
* real binary cargo would hand it through `CARGO`.
|
|
68
|
+
*/
|
|
69
|
+
const CARGO_ZIGBUILD_CLIPPY_FROZEN_PREFIX = 'cargo-zigbuild clippy --frozen ';
|
|
70
|
+
|
|
71
|
+
/** Does this command text run frozen cargo, directly or through cargo-zigbuild? */
|
|
72
|
+
export function runsFrozenCargo(text: string): boolean {
|
|
73
|
+
return text.includes(CARGO_FROZEN_PREFIX) || text.includes(CARGO_ZIGBUILD_CLIPPY_FROZEN_PREFIX);
|
|
74
|
+
}
|
|
75
|
+
|
|
50
76
|
/**
|
|
51
77
|
* `--frozen` is cargo's `--locked` + `--offline`. Cargo.lock and the registry
|
|
52
78
|
* cache are inputs: inferred cargo must not rewrite the lockfile or fetch.
|
|
@@ -122,8 +148,13 @@ export const CARGO_DENY_WARNINGS = `--config 'build.warnings="deny"'`;
|
|
|
122
148
|
* must then refuse to launch.
|
|
123
149
|
*
|
|
124
150
|
* `--target` is explicit rather than inherited from a CARGO_BUILD_TARGET exported
|
|
125
|
-
* by the profile, so running this outside the cross shell fails loudly on
|
|
126
|
-
* missing
|
|
151
|
+
* by the profile, so running this outside the cross shell fails loudly on the
|
|
152
|
+
* missing cargo-zigbuild instead of quietly linting the host and reporting green.
|
|
153
|
+
*
|
|
154
|
+
* cargo-zigbuild rather than plain cargo because ring compiles C for the target
|
|
155
|
+
* from its build script, and build scripts run even under clippy: zig is the
|
|
156
|
+
* C compiler for every Linux triple on every host, the same one the Linux
|
|
157
|
+
* artifacts build with, so the check needs no per-triple cross gcc.
|
|
127
158
|
*
|
|
128
159
|
* `cargo fmt` is absent on purpose: formatting is target-independent and already
|
|
129
160
|
* covered by `cargo-lint`, so repeating it here would only cost time.
|
|
@@ -139,9 +170,7 @@ export const CARGO_DENY_WARNINGS = `--config 'build.warnings="deny"'`;
|
|
|
139
170
|
* are distinct anyway, and its own lock keeps the cross check from queueing
|
|
140
171
|
* behind host builds.
|
|
141
172
|
*/
|
|
142
|
-
export const CARGO_CROSS_LINT_COMMAND = `${CARGO_CROSS_LINT_GUARD}; ${
|
|
143
|
-
`clippy --workspace --all-targets --target ${CARGO_LINUX_TRIPLE} --target-dir target/cargo-lint-cross ${CARGO_DENY_WARNINGS}`,
|
|
144
|
-
)}`;
|
|
173
|
+
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}`;
|
|
145
174
|
|
|
146
175
|
/**
|
|
147
176
|
* No `--target-dir`: clippy writes the workspace's own `target/`, beside every
|
|
@@ -168,9 +197,10 @@ export const CROSS_CHECK_SCRIPT_NAME = 'check:linux';
|
|
|
168
197
|
* cache and refuses a push that has no hit, never entering a profile or starting
|
|
169
198
|
* a compile of its own. That makes this script the only place the gate ever
|
|
170
199
|
* runs, and a human watching it needs devenv's progress too — the cross profile
|
|
171
|
-
*
|
|
172
|
-
* terminal is indistinguishable from a hang.
|
|
173
|
-
* while a hook ran this for you and nobody
|
|
200
|
+
* adds about 0.9 GiB (zig plus three rust-std targets) and the clippy behind it
|
|
201
|
+
* is unbounded, so a silent terminal is indistinguishable from a hang.
|
|
202
|
+
* Suppressing that output only paid while a hook ran this for you and nobody
|
|
203
|
+
* read it.
|
|
174
204
|
*/
|
|
175
205
|
export const CROSS_CHECK_SCRIPT_COMMAND = `tooling/devenv -P ${DEVENV_CROSS_PROFILE} shell -- nx run-many -t ${CARGO_CROSS_LINT_TARGET}`;
|
|
176
206
|
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
|
|
3
|
+
import { artifactFile, cargoTriple, zigbuildArgs, zigbuildEnv } from './executor.js';
|
|
4
|
+
|
|
5
|
+
const MANIFEST = '/repo/packages/cowshed/crates/cowshed-cli/Cargo.toml';
|
|
6
|
+
|
|
7
|
+
/** One `compiler-artifact` line in the shape cargo prints it, trimmed to stable fields. */
|
|
8
|
+
function artifactLine(fields: {
|
|
9
|
+
manifest: string;
|
|
10
|
+
kind: string[];
|
|
11
|
+
name: string;
|
|
12
|
+
filenames: string[];
|
|
13
|
+
executable: string | null;
|
|
14
|
+
}): string {
|
|
15
|
+
return JSON.stringify({
|
|
16
|
+
reason: 'compiler-artifact',
|
|
17
|
+
package_id: 'path+file:///repo/packages/cowshed/crates/cowshed-cli#0.0.1',
|
|
18
|
+
manifest_path: fields.manifest,
|
|
19
|
+
target: { kind: fields.kind, crate_types: fields.kind, name: fields.name, src_path: '/repo/src/main.rs' },
|
|
20
|
+
profile: { opt_level: '3', debuginfo: 0, debug_assertions: false, overflow_checks: false, test: false },
|
|
21
|
+
features: [],
|
|
22
|
+
filenames: fields.filenames,
|
|
23
|
+
executable: fields.executable,
|
|
24
|
+
fresh: false,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('cargo-zigbuild executor', () => {
|
|
29
|
+
it('runs cargo-zigbuild directly, locked, with the pinned glibc suffix on the target', () => {
|
|
30
|
+
expect(
|
|
31
|
+
zigbuildArgs(
|
|
32
|
+
{ target: 'x86_64-unknown-linux-gnu.2.17', manifestPath: 'm', package: 'cowshed-napi', output: 'o' },
|
|
33
|
+
MANIFEST,
|
|
34
|
+
),
|
|
35
|
+
).toEqual([
|
|
36
|
+
'zigbuild',
|
|
37
|
+
'--locked',
|
|
38
|
+
'--message-format=json-render-diagnostics',
|
|
39
|
+
'--target',
|
|
40
|
+
'x86_64-unknown-linux-gnu.2.17',
|
|
41
|
+
'--manifest-path',
|
|
42
|
+
MANIFEST,
|
|
43
|
+
'--package',
|
|
44
|
+
'cowshed-napi',
|
|
45
|
+
'--lib',
|
|
46
|
+
]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('selects the named binary and the release profile when asked', () => {
|
|
50
|
+
const args = zigbuildArgs(
|
|
51
|
+
{
|
|
52
|
+
target: 'aarch64-unknown-linux-musl',
|
|
53
|
+
manifestPath: 'm',
|
|
54
|
+
package: 'cowshed-cli',
|
|
55
|
+
bin: 'cowshed',
|
|
56
|
+
output: 'o',
|
|
57
|
+
release: true,
|
|
58
|
+
},
|
|
59
|
+
MANIFEST,
|
|
60
|
+
);
|
|
61
|
+
expect(args.slice(-3)).toEqual(['--release', '--bin', 'cowshed']);
|
|
62
|
+
expect(args).not.toContain('--lib');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('names the bare triple cargo sees under a glibc suffix', () => {
|
|
66
|
+
expect(cargoTriple('x86_64-unknown-linux-gnu.2.17')).toBe('x86_64-unknown-linux-gnu');
|
|
67
|
+
expect(cargoTriple('aarch64-unknown-linux-musl')).toBe('aarch64-unknown-linux-musl');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("drops the shell's compilers for the artifact's triple and keeps everything else", () => {
|
|
71
|
+
const env = zigbuildEnv(
|
|
72
|
+
{
|
|
73
|
+
CC_x86_64_unknown_linux_gnu: '/nix/store/cc-wrapper/bin/cc',
|
|
74
|
+
'CC_x86_64-unknown-linux-gnu': '/nix/store/cc-wrapper/bin/cc',
|
|
75
|
+
CXX_x86_64_unknown_linux_gnu: '/nix/store/cc-wrapper/bin/c++',
|
|
76
|
+
AR_x86_64_unknown_linux_gnu: 'ar',
|
|
77
|
+
RANLIB_x86_64_unknown_linux_gnu: 'ranlib',
|
|
78
|
+
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: 'cc',
|
|
79
|
+
CC_aarch64_unknown_linux_gnu: 'kept-other-triple',
|
|
80
|
+
CC: 'kept-generic',
|
|
81
|
+
PATH: '/bin',
|
|
82
|
+
},
|
|
83
|
+
'x86_64-unknown-linux-gnu.2.17',
|
|
84
|
+
);
|
|
85
|
+
expect(env).toEqual({ CC_aarch64_unknown_linux_gnu: 'kept-other-triple', CC: 'kept-generic', PATH: '/bin' });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("reads the binary's executable from its artifact message", () => {
|
|
89
|
+
const line = artifactLine({
|
|
90
|
+
manifest: MANIFEST,
|
|
91
|
+
kind: ['bin'],
|
|
92
|
+
name: 'cowshed',
|
|
93
|
+
filenames: ['/repo/target/x86_64-unknown-linux-musl/release/cowshed'],
|
|
94
|
+
executable: '/repo/target/x86_64-unknown-linux-musl/release/cowshed',
|
|
95
|
+
});
|
|
96
|
+
expect(artifactFile(line, MANIFEST, { kind: 'bin', name: 'cowshed' })).toBe(
|
|
97
|
+
'/repo/target/x86_64-unknown-linux-musl/release/cowshed',
|
|
98
|
+
);
|
|
99
|
+
expect(artifactFile(line, MANIFEST, { kind: 'bin', name: 'other' })).toBeNull();
|
|
100
|
+
expect(artifactFile(line, '/repo/elsewhere/Cargo.toml', { kind: 'bin', name: 'cowshed' })).toBeNull();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("reads the cdylib's shared object, not the rlib beside it", () => {
|
|
104
|
+
const line = artifactLine({
|
|
105
|
+
manifest: MANIFEST,
|
|
106
|
+
kind: ['cdylib', 'rlib'],
|
|
107
|
+
name: 'cowshed_napi',
|
|
108
|
+
filenames: [
|
|
109
|
+
'/repo/target/x86_64-unknown-linux-gnu/debug/libcowshed_napi.rlib',
|
|
110
|
+
'/repo/target/x86_64-unknown-linux-gnu/debug/libcowshed_napi.so',
|
|
111
|
+
],
|
|
112
|
+
executable: null,
|
|
113
|
+
});
|
|
114
|
+
expect(artifactFile(line, MANIFEST, { kind: 'cdylib' })).toBe(
|
|
115
|
+
'/repo/target/x86_64-unknown-linux-gnu/debug/libcowshed_napi.so',
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('ignores the other messages cargo prints', () => {
|
|
120
|
+
expect(artifactFile('{"reason":"build-finished","success":true}', MANIFEST, { kind: 'cdylib' })).toBeNull();
|
|
121
|
+
expect(artifactFile('', MANIFEST, { kind: 'cdylib' })).toBeNull();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('refuses an artifact message that breaks the contract instead of skipping it', () => {
|
|
125
|
+
expect(() =>
|
|
126
|
+
artifactFile('{"reason":"compiler-artifact","manifest_path":7}', MANIFEST, { kind: 'cdylib' }),
|
|
127
|
+
).toThrow('does not match the artifact contract');
|
|
128
|
+
});
|
|
129
|
+
});
|