@smoothbricks/nx-plugin 0.4.31 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -46
- 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/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +14 -9
- package/dist/executors/bounded-exec/cpu-pool.d.ts +14 -7
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +297 -38
- package/dist/executors/bounded-exec/cpu-tokens.d.ts +19 -7
- package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-tokens.js +21 -7
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +12 -6
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/run-cpu-pool.js +5 -4
- 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/producer-receipts.d.ts +10 -0
- package/dist/producer-receipts.d.ts.map +1 -1
- package/dist/producer-receipts.js +30 -5
- 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 +47 -49
- package/managed/raw/tooling/direnv/linked-snapshots.ts +18 -8
- package/managed/raw/tooling/direnv/repo-path +1 -1
- package/managed/raw/tooling/git-hooks/pre-push.sh +41 -23
- package/package.json +1 -1
- package/src/__tests__/counted-cargo.ts +1 -1
- package/src/cargo-closure-input.test.ts +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/ensure-built.test.ts +39 -0
- package/src/ensure-built.ts +23 -9
- package/src/executors/bounded-exec/cpu-pool.test.ts +132 -4
- package/src/executors/bounded-exec/cpu-pool.ts +300 -46
- package/src/executors/bounded-exec/cpu-tokens.test.ts +60 -15
- package/src/executors/bounded-exec/cpu-tokens.ts +34 -11
- package/src/executors/bounded-exec/executor.test.ts +72 -4
- package/src/executors/bounded-exec/executor.ts +12 -6
- package/src/executors/bounded-exec/run-cpu-pool.test.ts +3 -0
- package/src/executors/bounded-exec/run-cpu-pool.ts +5 -4
- 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/producer-receipts.test.ts +37 -15
- package/src/producer-receipts.ts +29 -5
- 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
|
@@ -10,12 +10,13 @@ import { GATEWAY_SOCKET } from './gateway-lease.js';
|
|
|
10
10
|
* Every runner sizes itself to the whole host unless something budgets it, and without a gateway nothing did: under
|
|
11
11
|
* `NX_PARALLEL=100%` Nx starts every target side by side and each one's runner takes the whole machine. The run
|
|
12
12
|
* therefore serves its own pool of one token per core, as a gateway-granted executor serves its children, and every
|
|
13
|
-
* task inherits it: `bounded-exec`
|
|
14
|
-
*
|
|
13
|
+
* task inherits it: `bounded-exec` takes from it as from any parent pool, FIFO, the head taking `min(want, free)` once
|
|
14
|
+
* one token is free, and a Cargo that Nx's own `nx:run-commands` starts reads its jobserver fifo through the
|
|
15
|
+
* `CARGO_MAKEFLAGS` the pool exports, so the runners of one run together stay within the cores.
|
|
15
16
|
*
|
|
16
17
|
* The run serves it only when nothing else budgets it: it inherits no pool, and the gateway's control socket does
|
|
17
|
-
* not exist. Only `ENOENT` proves the gateway absent
|
|
18
|
-
*
|
|
18
|
+
* not exist. Only `ENOENT` proves the gateway absent; a socket that exists but does not answer may be a live,
|
|
19
|
+
* saturated gateway, and a run budgeting itself beside it would count the host twice.
|
|
19
20
|
*/
|
|
20
21
|
/** The pools this process serves, by Nx run id, until that run's `postTasksExecution`. */
|
|
21
22
|
const pools = new Map();
|
|
@@ -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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,21 +6,6 @@ export { CARGO_TEST_COMPILE_TARGET };
|
|
|
6
6
|
export declare const DEPLOY_TARGET = "deploy";
|
|
7
7
|
/** The purely file-derived half a deploy needs built first; cached. */
|
|
8
8
|
export declare const DEPLOY_BUILD_TARGET = "deploy-build";
|
|
9
|
-
type NapiArchitecture = 'arm64' | 'x64';
|
|
10
|
-
type NapiTargetFamily = 'linux' | 'macos';
|
|
11
|
-
interface NapiPlatform {
|
|
12
|
-
architecture: NapiArchitecture;
|
|
13
|
-
targetFamily: NapiTargetFamily;
|
|
14
|
-
}
|
|
15
|
-
interface NapiTargetConvention extends NapiPlatform {
|
|
16
|
-
outputName: string;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Prerequisite target that extracts the cross toolchain one triple needs. The
|
|
20
|
-
* platform suffix keeps it inside its own platform family, so it can be a
|
|
21
|
-
* dependency of `napi-<arch>-linux` and package-local `cli-<arch>-linux`.
|
|
22
|
-
*/
|
|
23
|
-
export declare function napiToolchainTargetName(convention: NapiTargetConvention): string;
|
|
24
9
|
/**
|
|
25
10
|
* The npm packages a cached cargo target runs, for its `externalDependencies`.
|
|
26
11
|
* Cargo runs none. A target this plugin's executor runs, or whose command reads
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAEtB,KAAK,mBAAmB,EACzB,MAAM,0BAA0B,CAAC;AAkBlC,OAAO,EAKL,yBAAyB,EAiB1B,MAAM,sBAAsB,CAAC;AAsB9B,OAAO,EACL,KAAK,uBAAuB,EAG7B,MAAM,wBAAwB,CAAC;AAahC,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,gEAAgE;AAChE,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAEtB,KAAK,mBAAmB,EACzB,MAAM,0BAA0B,CAAC;AAkBlC,OAAO,EAKL,yBAAyB,EAiB1B,MAAM,sBAAsB,CAAC;AAsB9B,OAAO,EACL,KAAK,uBAAuB,EAG7B,MAAM,wBAAwB,CAAC;AAahC,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,gEAAgE;AAChE,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAmyBlD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,mBAAmB,EAC3B,WAAW,EAAE,MAAM,EACnB,SAAS,UAAsB,GAC9B,MAAM,EAAE,CAKV;AAkID,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAEvG;AAED,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC;AAeF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,EAAE,iBAAiB,CAAC,uBAAuB,CAIxE,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,kBAAkB,CAAC,uBAAuB,CAI1E,CAAC"}
|