@smoothbricks/nx-plugin 0.4.22 → 0.4.24
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 +93 -33
- package/dist/bin/smoo-nx-exec.js +35 -11
- package/dist/bin/smoo-nx-nextest-extract.d.ts +3 -0
- package/dist/bin/smoo-nx-nextest-extract.d.ts.map +1 -0
- package/dist/bin/smoo-nx-nextest-extract.js +41 -0
- package/dist/cargo-closure-input.d.ts +63 -0
- package/dist/cargo-closure-input.d.ts.map +1 -0
- package/dist/cargo-closure-input.js +197 -0
- package/dist/cargo-source-hash.d.ts +37 -0
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +108 -190
- package/dist/cross-check-policy.d.ts +14 -0
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +15 -1
- package/dist/ensure-built.d.ts +3 -2
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +33 -56
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +152 -91
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +12 -15
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +10 -0
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/managed-files/publish-workflow.js +12 -6
- package/dist/manifest-hash.d.ts.map +1 -1
- package/dist/manifest-hash.js +24 -30
- package/dist/nextest-extraction.d.ts +101 -0
- package/dist/nextest-extraction.d.ts.map +1 -0
- package/dist/nextest-extraction.js +268 -0
- package/dist/package-target-policy.js +1 -1
- package/dist/platform-targets.d.ts +7 -0
- package/dist/platform-targets.d.ts.map +1 -1
- package/dist/platform-targets.js +7 -0
- package/dist/workspace-config-policy.d.ts +1 -1
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +1 -1
- package/managed/raw/envrc +38 -1
- package/managed/raw/tooling/direnv/developer-links.ts +201 -0
- package/managed/raw/tooling/direnv/devenv.smoo.nix +75 -51
- package/managed/raw/tooling/direnv/secret-references.ts +3 -1
- package/managed/raw/tooling/direnv/setup-environment.ts +562 -78
- package/managed/raw/tooling/direnv/shared-caches.sh +53 -0
- package/managed/raw/tooling/git-hooks/pre-push.sh +22 -1
- package/managed/templates/github/workflows/managed-files.yml +4 -3
- package/nextest.toml +5 -5
- package/package.json +4 -3
- package/src/__tests__/fixture-nx-env.ts +31 -0
- package/src/__tests__/in-process-nx-index.ts +9 -0
- package/src/bin/smoo-nx-exec.ts +40 -11
- package/src/bin/smoo-nx-nextest-extract.ts +43 -0
- package/src/bounded-test-policy.test.ts +4 -1
- package/src/cargo-closure-input.test.ts +184 -0
- package/src/cargo-closure-input.ts +247 -0
- package/src/cargo-source-hash.test.ts +8 -9
- package/src/cargo-source-hash.ts +146 -47
- package/src/cross-check-policy.ts +15 -3
- package/src/ensure-built.test.ts +65 -5
- package/src/ensure-built.ts +40 -85
- package/src/index.test.ts +222 -75
- package/src/index.ts +213 -101
- package/src/managed-files/ci-workflow.ts +12 -15
- package/src/managed-files/files.ts +10 -0
- package/src/managed-files/generator.test.ts +29 -0
- package/src/managed-files/publish-workflow.ts +17 -6
- package/src/manifest-hash.test.ts +21 -1
- package/src/manifest-hash.ts +26 -29
- package/src/nextest-extraction.test.ts +74 -0
- package/src/nextest-extraction.ts +329 -0
- package/src/package-target-policy.ts +1 -1
- package/src/platform-targets.ts +8 -0
- package/src/workspace-config-policy.ts +6 -1
package/src/index.ts
CHANGED
|
@@ -15,6 +15,13 @@ import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
|
15
15
|
import { parse as parseToml } from 'smol-toml';
|
|
16
16
|
|
|
17
17
|
import { BOUNDED_TEST_KILL_AFTER_MS, BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
|
|
18
|
+
import {
|
|
19
|
+
CARGO_CLOSURE_INPUT,
|
|
20
|
+
type CargoClosureSource,
|
|
21
|
+
cargoClosureInputs,
|
|
22
|
+
indexedCargoManifests,
|
|
23
|
+
resolveCargoClosureSource,
|
|
24
|
+
} from './cargo-closure-input.js';
|
|
18
25
|
import { CARGO_TOOLCHAIN_NAMED_INPUT, CARGO_TOOLCHAIN_PIN_INPUTS } from './cargo-toolchain-policy.js';
|
|
19
26
|
import {
|
|
20
27
|
type AttributedCargoWorkspacePackage,
|
|
@@ -48,8 +55,19 @@ import {
|
|
|
48
55
|
cargoFrozen,
|
|
49
56
|
} from './cross-check-policy.js';
|
|
50
57
|
import { hashVersionlessCrateManifests } from './manifest-hash.js';
|
|
58
|
+
import {
|
|
59
|
+
EXTRACTED_BINARIES_METADATA,
|
|
60
|
+
EXTRACTED_CARGO_METADATA,
|
|
61
|
+
EXTRACTED_TARGET_DIR,
|
|
62
|
+
NEXTEST_EXTRACT_BIN,
|
|
63
|
+
} from './nextest-extraction.js';
|
|
51
64
|
import { isNonSourceDirectory } from './source-directories.js';
|
|
52
|
-
import {
|
|
65
|
+
import {
|
|
66
|
+
isBuildOutputTargetName,
|
|
67
|
+
isTestRunnerTargetName,
|
|
68
|
+
PLATFORM_TARGET_GLOBS,
|
|
69
|
+
RELEASE_CONFIGURATION,
|
|
70
|
+
} from './workspace-config-policy.js';
|
|
53
71
|
|
|
54
72
|
export { CARGO_TEST_COMPILE_TARGET };
|
|
55
73
|
|
|
@@ -507,17 +525,56 @@ export function napiToolchainTargetName(convention: NapiTargetConvention): strin
|
|
|
507
525
|
return `${NAPI_TOOLCHAIN_TARGET_PREFIX}${convention.architecture}-${convention.targetFamily}`;
|
|
508
526
|
}
|
|
509
527
|
|
|
528
|
+
/**
|
|
529
|
+
* Cargo's two profiles. A build target's default options compile `dev`, the
|
|
530
|
+
* profile every local build, test and gate shares, so one `target/` holds one
|
|
531
|
+
* set of units; RELEASE_CONFIGURATION compiles `release` for what ships.
|
|
532
|
+
*/
|
|
533
|
+
type CargoProfile = 'dev' | 'release';
|
|
534
|
+
|
|
535
|
+
const CARGO_PROFILE_FLAG: Readonly<Record<CargoProfile, string>> = { dev: '', release: ' --release' };
|
|
536
|
+
/** The directory under `target/<triple>/` each profile writes. */
|
|
537
|
+
const CARGO_PROFILE_OUTPUT_DIR: Readonly<Record<CargoProfile, string>> = { dev: 'debug', release: 'release' };
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Cargo's default target directory for a crate, relative to the command's cwd:
|
|
541
|
+
* `target/` beside the workspace root that owns the crate, or beside the
|
|
542
|
+
* crate's own manifest when no workspace claims it. Naming it rather than
|
|
543
|
+
* passing `--target-dir` keeps the wasm build in the directory every other
|
|
544
|
+
* build of the same workspace writes.
|
|
545
|
+
*/
|
|
546
|
+
function cargoWasmTargetDirectory(
|
|
547
|
+
projectRoot: string,
|
|
548
|
+
config: ResolvedCargoWasmConfig,
|
|
549
|
+
repoRooted: boolean,
|
|
550
|
+
cargoWorkspace: CargoWorkspace | undefined,
|
|
551
|
+
): string {
|
|
552
|
+
const cwd = repoRooted ? '.' : projectRoot;
|
|
553
|
+
const crateDir = posix.join(cwd, posix.dirname(config.manifestPath));
|
|
554
|
+
const owner =
|
|
555
|
+
cargoWorkspace !== undefined &&
|
|
556
|
+
cargoWorkspace.packages.some((plan) => posix.join(cargoWorkspace.projectRoot, plan.package.dir) === crateDir)
|
|
557
|
+
? cargoWorkspace.projectRoot
|
|
558
|
+
: crateDir;
|
|
559
|
+
return posix.relative(cwd, posix.join(owner, 'target'));
|
|
560
|
+
}
|
|
561
|
+
|
|
510
562
|
function createCargoWasmTarget(
|
|
511
563
|
projectRoot: string,
|
|
512
564
|
config: ResolvedCargoWasmConfig,
|
|
513
565
|
repoRooted: boolean,
|
|
566
|
+
cargoTargetDirectory: string,
|
|
514
567
|
): TargetConfiguration {
|
|
515
|
-
const cargoTargetDirectory = repoRooted
|
|
516
|
-
? 'target/cargo-wasm'
|
|
517
|
-
: posix.join(posix.dirname(config.manifestPath), 'target/cargo-wasm');
|
|
518
|
-
const wasmInput = `${cargoTargetDirectory}/wasm32-unknown-unknown/release/${config.libraryName}.wasm`;
|
|
519
568
|
const outputDirectory = repoRooted ? posix.join(projectRoot, config.outputDirectory) : config.outputDirectory;
|
|
520
569
|
const cargoSelection = repoRooted ? `-p ${config.cargoPackage}` : `--manifest-path ${config.manifestPath}`;
|
|
570
|
+
const commands = (profile: CargoProfile): string[] => [
|
|
571
|
+
cargoFrozen(`build${CARGO_PROFILE_FLAG[profile]} --target wasm32-unknown-unknown ${cargoSelection}`),
|
|
572
|
+
...config.targets.map(
|
|
573
|
+
({ bindgenTarget, outputName }) =>
|
|
574
|
+
`wasm-bindgen --target ${bindgenTarget} --out-dir ${outputDirectory}/${outputName} ` +
|
|
575
|
+
`${cargoTargetDirectory}/wasm32-unknown-unknown/${CARGO_PROFILE_OUTPUT_DIR[profile]}/${config.libraryName}.wasm`,
|
|
576
|
+
),
|
|
577
|
+
];
|
|
521
578
|
return {
|
|
522
579
|
executor: 'nx:run-commands',
|
|
523
580
|
cache: true,
|
|
@@ -525,18 +582,11 @@ function createCargoWasmTarget(
|
|
|
525
582
|
inputs: repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : CARGO_OUTPUT_INPUTS,
|
|
526
583
|
outputs: [`{projectRoot}/${config.outputDirectory}`],
|
|
527
584
|
options: {
|
|
528
|
-
commands:
|
|
529
|
-
cargoFrozen(
|
|
530
|
-
`build --release --target wasm32-unknown-unknown --target-dir ${cargoTargetDirectory} ${cargoSelection}`,
|
|
531
|
-
),
|
|
532
|
-
...config.targets.map(
|
|
533
|
-
({ bindgenTarget, outputName }) =>
|
|
534
|
-
`wasm-bindgen --target ${bindgenTarget} --out-dir ${outputDirectory}/${outputName} ${wasmInput}`,
|
|
535
|
-
),
|
|
536
|
-
],
|
|
585
|
+
commands: commands('dev'),
|
|
537
586
|
cwd: repoRooted ? '.' : projectRoot,
|
|
538
587
|
parallel: false,
|
|
539
588
|
},
|
|
589
|
+
configurations: { [RELEASE_CONFIGURATION]: { commands: commands('release') } },
|
|
540
590
|
};
|
|
541
591
|
}
|
|
542
592
|
|
|
@@ -553,13 +603,19 @@ function createCargoWasmTarget(
|
|
|
553
603
|
* timeout. Inference serializes writers that share the default target dir
|
|
554
604
|
* (`napi-debug` after compile).
|
|
555
605
|
*
|
|
556
|
-
* Clippy
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
606
|
+
* Clippy runs ONCE over the whole workspace, in that same `target/`, rather
|
|
607
|
+
* than once per crate. Clippy of a crate is a check build of its whole
|
|
608
|
+
* closure, so 49 crates meant 49 closure rebuilds and 11 GiB of target
|
|
609
|
+
* directories on one repository, and no per-crate cache hit ever repaid that.
|
|
610
|
+
* Sharing the build's directory costs nothing: cargo's own lock serializes
|
|
611
|
+
* the invocations that use it, and the host units a dev build compiled are
|
|
612
|
+
* reused instead of compiled again.
|
|
613
|
+
*
|
|
614
|
+
* Tests compile the dev profile only, so no test target carries a
|
|
615
|
+
* RELEASE_CONFIGURATION: Nx forwards a run's configuration down every
|
|
616
|
+
* `dependsOn` edge to each target that has it, and a release `build` must
|
|
617
|
+
* warm the dev test binaries the test run will use, not release ones nobody
|
|
618
|
+
* runs.
|
|
563
619
|
*/
|
|
564
620
|
function createCargoTestCompileTarget(projectRoot: string): TargetConfiguration {
|
|
565
621
|
return {
|
|
@@ -571,9 +627,6 @@ function createCargoTestCompileTarget(projectRoot: string): TargetConfiguration
|
|
|
571
627
|
command: cargoFrozen('test --workspace --no-run'),
|
|
572
628
|
cwd: projectRoot,
|
|
573
629
|
},
|
|
574
|
-
configurations: {
|
|
575
|
-
production: { command: cargoFrozen('test --workspace --release --no-run') },
|
|
576
|
-
},
|
|
577
630
|
};
|
|
578
631
|
}
|
|
579
632
|
|
|
@@ -586,33 +639,29 @@ function createCargoTestCompileTarget(projectRoot: string): TargetConfiguration
|
|
|
586
639
|
* build with a filter: 32 such tasks on one repository each re-entered cargo,
|
|
587
640
|
* re-resolved features and chained behind one another so the flocked `target/`
|
|
588
641
|
* had a single writer. Reading from an archive removes the build from the run
|
|
589
|
-
* entirely — the
|
|
590
|
-
*
|
|
642
|
+
* entirely — the runners execute one extraction of it and never write cargo's
|
|
643
|
+
* `target/` build tree — which is what lets the runners fan out.
|
|
591
644
|
*
|
|
592
645
|
* Cached, unlike `cargo-test-compile`, because it produces a VALUE: one file,
|
|
593
646
|
* not a mutable build tree Nx would have to restore. `--workspace` matches the
|
|
594
647
|
* clippy selection exactly, so both gates unify features the same way.
|
|
595
648
|
*/
|
|
596
649
|
function createCargoTestArchiveTarget(projectRoot: string, toolConfig: string): TargetConfiguration {
|
|
597
|
-
const archiveCommand = (profile: string): string =>
|
|
598
|
-
cargoFrozen(
|
|
599
|
-
`nextest archive --workspace${profile} --archive-file ${CARGO_TEST_ARCHIVE_FILE} --user-config-file none ${toolConfig}`,
|
|
600
|
-
);
|
|
601
650
|
return {
|
|
602
651
|
executor: 'nx:run-commands',
|
|
603
652
|
cache: true,
|
|
604
653
|
inputs: CARGO_INPUTS,
|
|
605
654
|
outputs: [`{projectRoot}/${CARGO_TEST_ARCHIVE_FILE}`],
|
|
606
655
|
options: {
|
|
607
|
-
commands: [
|
|
656
|
+
commands: [
|
|
657
|
+
`mkdir -p ${posix.dirname(CARGO_TEST_ARCHIVE_FILE)}`,
|
|
658
|
+
cargoFrozen(
|
|
659
|
+
`nextest archive --workspace --archive-file ${CARGO_TEST_ARCHIVE_FILE} --user-config-file none ${toolConfig}`,
|
|
660
|
+
),
|
|
661
|
+
],
|
|
608
662
|
cwd: projectRoot,
|
|
609
663
|
parallel: false,
|
|
610
664
|
},
|
|
611
|
-
configurations: {
|
|
612
|
-
production: {
|
|
613
|
-
commands: [`mkdir -p ${posix.dirname(CARGO_TEST_ARCHIVE_FILE)}`, archiveCommand(' --release')],
|
|
614
|
-
},
|
|
615
|
-
},
|
|
616
665
|
};
|
|
617
666
|
}
|
|
618
667
|
|
|
@@ -654,9 +703,6 @@ function createCargoCrossTestTargets(
|
|
|
654
703
|
): Record<string, TargetConfiguration> {
|
|
655
704
|
const { target: triple, cargo } = crossTarget;
|
|
656
705
|
const archiveFile = cargoCrossTestArchiveFile(triple);
|
|
657
|
-
const archiveCommand = (profile: string): string =>
|
|
658
|
-
`cargo-nextest nextest archive --workspace${profile} --target ${triple} --frozen ` +
|
|
659
|
-
`--archive-file ${archiveFile} --user-config-file none ${toolConfig}`;
|
|
660
706
|
return {
|
|
661
707
|
[cargoCrossTestArchiveTargetName(triple)]: {
|
|
662
708
|
executor: 'nx:run-commands',
|
|
@@ -681,7 +727,11 @@ function createCargoCrossTestTargets(
|
|
|
681
727
|
outputs: [`{projectRoot}/${archiveFile}`],
|
|
682
728
|
dependsOn: [CARGO_FETCH_TARGET],
|
|
683
729
|
options: {
|
|
684
|
-
commands: [
|
|
730
|
+
commands: [
|
|
731
|
+
`mkdir -p ${posix.dirname(archiveFile)}`,
|
|
732
|
+
`cargo-nextest nextest archive --workspace --target ${triple} --frozen ` +
|
|
733
|
+
`--archive-file ${archiveFile} --user-config-file none ${toolConfig}`,
|
|
734
|
+
],
|
|
685
735
|
cwd: projectRoot,
|
|
686
736
|
parallel: false,
|
|
687
737
|
// `CARGO` is cargo's own driver variable and the only seam nextest
|
|
@@ -692,11 +742,6 @@ function createCargoCrossTestTargets(
|
|
|
692
742
|
// it applies to this archive and to nothing else cargo runs.
|
|
693
743
|
...(cargo === undefined ? {} : { env: { CARGO: cargo } }),
|
|
694
744
|
},
|
|
695
|
-
configurations: {
|
|
696
|
-
production: {
|
|
697
|
-
commands: [`mkdir -p ${posix.dirname(archiveFile)}`, archiveCommand(' --release')],
|
|
698
|
-
},
|
|
699
|
-
},
|
|
700
745
|
},
|
|
701
746
|
[cargoCrossTestTargetName(triple)]: {
|
|
702
747
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
@@ -712,9 +757,6 @@ function createCargoCrossTestTargets(
|
|
|
712
757
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
713
758
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
714
759
|
},
|
|
715
|
-
// The archive already holds the profile it was built with, and nextest
|
|
716
|
-
// rejects `--release` beside `--archive-file`.
|
|
717
|
-
configurations: { production: {} },
|
|
718
760
|
},
|
|
719
761
|
};
|
|
720
762
|
}
|
|
@@ -731,9 +773,6 @@ function createCargoTestTarget(projectRoot: string): TargetConfiguration {
|
|
|
731
773
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
732
774
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
733
775
|
},
|
|
734
|
-
configurations: {
|
|
735
|
-
production: { command: cargoFrozen('test --workspace --release') },
|
|
736
|
-
},
|
|
737
776
|
};
|
|
738
777
|
}
|
|
739
778
|
|
|
@@ -855,6 +894,9 @@ function createNodesHandler(hostPlatform: NapiPlatform | null): CreateNodesHandl
|
|
|
855
894
|
}
|
|
856
895
|
}),
|
|
857
896
|
);
|
|
897
|
+
// A project that failed before reaching its closure never awaited Cargo;
|
|
898
|
+
// no process this call started may outlive it.
|
|
899
|
+
await Promise.all(cargoWorkspaces.map((workspace) => workspace.closureSource));
|
|
858
900
|
|
|
859
901
|
if (errors.length > 0) {
|
|
860
902
|
throw new AggregateCreateNodesError(errors, results);
|
|
@@ -1114,7 +1156,12 @@ async function createProjectTargets(
|
|
|
1114
1156
|
}
|
|
1115
1157
|
|
|
1116
1158
|
if (inferCargoWasm && cargoWasmConfig) {
|
|
1117
|
-
targets['cargo-wasm'] = createCargoWasmTarget(
|
|
1159
|
+
targets['cargo-wasm'] = createCargoWasmTarget(
|
|
1160
|
+
projectRoot,
|
|
1161
|
+
cargoWasmConfig,
|
|
1162
|
+
isRepoRootedCargoProject,
|
|
1163
|
+
cargoWasmTargetDirectory(projectRoot, cargoWasmConfig, isRepoRootedCargoProject, cargoWorkspace),
|
|
1164
|
+
);
|
|
1118
1165
|
}
|
|
1119
1166
|
|
|
1120
1167
|
if (napiConfig) {
|
|
@@ -1245,12 +1292,13 @@ async function createProjectTargets(
|
|
|
1245
1292
|
aggregateDependencies.length > 0
|
|
1246
1293
|
? { executor: 'nx:noop', cache: true, outputs: [], dependsOn: aggregateDependencies }
|
|
1247
1294
|
: createCargoTestTarget(cargoWorkspaceRoot);
|
|
1248
|
-
// One clippy over the whole workspace, in
|
|
1249
|
-
// is a check build of its closure; a target dir per crate
|
|
1250
|
-
// shared dependency once per crate (49 closures, 11 GiB on
|
|
1251
|
-
// and no per-crate cache hit ever repaid that. The
|
|
1252
|
-
// exactly the union of every crate's, so the verdict
|
|
1253
|
-
// key set the compile does. Non-root packages depend on
|
|
1295
|
+
// One clippy over the whole workspace, in the build's target dir. Clippy
|
|
1296
|
+
// of a crate is a check build of its closure; a target dir per crate
|
|
1297
|
+
// compiled every shared dependency once per crate (49 closures, 11 GiB on
|
|
1298
|
+
// one repository) and no per-crate cache hit ever repaid that. The
|
|
1299
|
+
// workspace inputs are exactly the union of every crate's, so the verdict
|
|
1300
|
+
// caches on the same key set the compile does. Non-root packages depend on
|
|
1301
|
+
// this target.
|
|
1254
1302
|
targets['cargo-lint'] = {
|
|
1255
1303
|
executor: 'nx:run-commands',
|
|
1256
1304
|
cache: true,
|
|
@@ -1374,7 +1422,6 @@ async function createProjectTargets(
|
|
|
1374
1422
|
const target = targets[name];
|
|
1375
1423
|
if (target?.executor === 'nx:noop') {
|
|
1376
1424
|
target.outputs = [];
|
|
1377
|
-
target.configurations = { production: {} };
|
|
1378
1425
|
}
|
|
1379
1426
|
}
|
|
1380
1427
|
}
|
|
@@ -1551,7 +1598,7 @@ async function createProjectTargets(
|
|
|
1551
1598
|
// The platform binaries therefore stay Nx siblings of cargo-test-compile and
|
|
1552
1599
|
// serialize on cargo's flock instead of on a graph edge. That is the same
|
|
1553
1600
|
// arrangement `cli-<arch>-<os>` and `napi-<arch>-<os>` already have with each
|
|
1554
|
-
// other — both `napi build
|
|
1601
|
+
// other — both `napi build` on one target dir — so this adds a third
|
|
1555
1602
|
// participant to an existing wait, not a new hazard. The flock makes them wait;
|
|
1556
1603
|
// it does not corrupt anything, and these are unbounded `nx:run-commands`
|
|
1557
1604
|
// targets, so the wait is not charged against a test budget.
|
|
@@ -1664,11 +1711,11 @@ async function createProjectTargets(
|
|
|
1664
1711
|
}
|
|
1665
1712
|
// Every cargo build directory this project's own commands write. `clean`
|
|
1666
1713
|
// cannot learn them from `outputs`: a clippy or nextest target dir is a
|
|
1667
|
-
// multi-GB build tree that must never enter the Nx cache
|
|
1668
|
-
// alone was 11 GiB when each of 49 crates had its own), so the targets
|
|
1714
|
+
// multi-GB build tree that must never enter the Nx cache, so the targets
|
|
1669
1715
|
// deliberately declare `outputs: []`. Reading `--target-dir` back off the
|
|
1670
1716
|
// commands means the list cannot drift from what actually gets written, and a
|
|
1671
1717
|
// directory is named relative to the command's own cwd, not the project root.
|
|
1718
|
+
// The workspace's default `target/` is not listed: every dev build shares it.
|
|
1672
1719
|
const cargoBuildDirs = [
|
|
1673
1720
|
...new Set(
|
|
1674
1721
|
Object.entries(targets).flatMap(([name, target]) => {
|
|
@@ -1756,6 +1803,23 @@ async function createProjectTargets(
|
|
|
1756
1803
|
? { [CARGO_TOOLCHAIN_NAMED_INPUT]: [...CARGO_TOOLCHAIN_PIN_INPUTS] }
|
|
1757
1804
|
: {}),
|
|
1758
1805
|
};
|
|
1806
|
+
// A custom Cargo target names this instead of a hand-kept crate list or a
|
|
1807
|
+
// per-project runtime command: Cargo decides the closure once per graph
|
|
1808
|
+
// computation and Nx hashes its files from its own index. Defined for a
|
|
1809
|
+
// project with a workspace crate under its root — the same projects the
|
|
1810
|
+
// `--closure <projectRoot>` command could describe.
|
|
1811
|
+
const closureSources = cargoWorkspaces.filter((workspace) =>
|
|
1812
|
+
workspace.packages.some(({ package: pkg }) => {
|
|
1813
|
+
const crate = posix.join(workspace.projectRoot, pkg.dir);
|
|
1814
|
+
return projectRoot === '.' || crate === projectRoot || crate.startsWith(`${projectRoot}/`);
|
|
1815
|
+
}),
|
|
1816
|
+
);
|
|
1817
|
+
if (closureSources.length > 0) {
|
|
1818
|
+
namedInputs[CARGO_CLOSURE_INPUT] = await cargoClosureInputs(
|
|
1819
|
+
projectRoot,
|
|
1820
|
+
await Promise.all(closureSources.map((workspace) => workspace.closureSource)),
|
|
1821
|
+
);
|
|
1822
|
+
}
|
|
1759
1823
|
return {
|
|
1760
1824
|
projects: {
|
|
1761
1825
|
[projectRoot]: {
|
|
@@ -2002,13 +2066,14 @@ function createNapiTargets(
|
|
|
2002
2066
|
const targets: Record<string, TargetConfiguration> = {};
|
|
2003
2067
|
const hostCompilerEnv = napiCompilerEnv(hostPlatform, hostPlatform);
|
|
2004
2068
|
|
|
2005
|
-
// The addon the test suite loads. A dev
|
|
2006
|
-
//
|
|
2007
|
-
//
|
|
2008
|
-
//
|
|
2009
|
-
//
|
|
2010
|
-
// dist/ would ship. native.ts resolves this
|
|
2011
|
-
// napi-test target sets NAPI_DEBUG_ADDON=1, so
|
|
2069
|
+
// The addon the test suite loads. A plain dev build shares target/debug with
|
|
2070
|
+
// cargo-test's dependency graph, so after the tests compile this is nearly
|
|
2071
|
+
// free, where a `--target <triple>` platform build compiles the graph again
|
|
2072
|
+
// under target/<triple>/. The output lives OUTSIDE dist/ because packages
|
|
2073
|
+
// publish `files: ["dist"]` wholesale: an addon the test run wrote under
|
|
2074
|
+
// dist/ would ship in place of the release build. native.ts resolves this
|
|
2075
|
+
// directory only when the napi-test target sets NAPI_DEBUG_ADDON=1, so
|
|
2076
|
+
// production loads never see it.
|
|
2012
2077
|
targets['napi-debug'] = {
|
|
2013
2078
|
executor: 'nx:run-commands',
|
|
2014
2079
|
cache: true,
|
|
@@ -2024,9 +2089,13 @@ function createNapiTargets(
|
|
|
2024
2089
|
|
|
2025
2090
|
if (nativeHostTargetName === null) {
|
|
2026
2091
|
// The platform target for this host triple is the same compilation, so a
|
|
2027
|
-
// second cargo-napi invocation only buys a duplicate dependency graph
|
|
2028
|
-
//
|
|
2029
|
-
//
|
|
2092
|
+
// second cargo-napi invocation only buys a duplicate dependency graph
|
|
2093
|
+
// (a plain build and a `--target` build write different target/
|
|
2094
|
+
// subdirectories); native.ts already resolves the identical
|
|
2095
|
+
// platform-suffixed filename from dist/native/<platform-dir> after
|
|
2096
|
+
// dist/native/host.
|
|
2097
|
+
const hostBuild = (profile: CargoProfile): string =>
|
|
2098
|
+
`${napiCommand} build${CARGO_PROFILE_FLAG[profile]} --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputPath('dist/native/host')}`;
|
|
2030
2099
|
targets['cargo-napi'] = {
|
|
2031
2100
|
executor: 'nx:run-commands',
|
|
2032
2101
|
cache: true,
|
|
@@ -2035,9 +2104,10 @@ function createNapiTargets(
|
|
|
2035
2104
|
outputs: ['{projectRoot}/dist/native/host'],
|
|
2036
2105
|
options: {
|
|
2037
2106
|
cwd: cargoCwd,
|
|
2038
|
-
command:
|
|
2107
|
+
command: hostBuild('dev'),
|
|
2039
2108
|
...(hostCompilerEnv ? { env: hostCompilerEnv } : {}),
|
|
2040
2109
|
},
|
|
2110
|
+
configurations: { [RELEASE_CONFIGURATION]: { command: hostBuild('release') } },
|
|
2041
2111
|
};
|
|
2042
2112
|
}
|
|
2043
2113
|
|
|
@@ -2071,6 +2141,8 @@ function createNapiTargets(
|
|
|
2071
2141
|
const useNapiCross = usesNapiCross(convention, hostPlatform);
|
|
2072
2142
|
const crossFlag = useNapiCross ? ' --use-napi-cross' : '';
|
|
2073
2143
|
const compilerEnv = napiCompilerEnv(convention, hostPlatform);
|
|
2144
|
+
const platformBuild = (profile: CargoProfile): string =>
|
|
2145
|
+
`${napiCommand} build${CARGO_PROFILE_FLAG[profile]} --platform --no-js --dts ${config.binaryName}.${convention.outputName}.d.ts --target ${triple}${crossFlag} ${commonCommand} --output-dir ${outputPath(outputDirectory)}`;
|
|
2074
2146
|
targets[targetName] = {
|
|
2075
2147
|
executor: 'nx:run-commands',
|
|
2076
2148
|
cache: true,
|
|
@@ -2079,12 +2151,13 @@ function createNapiTargets(
|
|
|
2079
2151
|
outputs: [`{projectRoot}/${outputDirectory}`],
|
|
2080
2152
|
options: {
|
|
2081
2153
|
cwd: cargoCwd,
|
|
2082
|
-
command:
|
|
2154
|
+
command: platformBuild('dev'),
|
|
2083
2155
|
// Genuine Linux cross-compiles use Clang plus napi-rs's downloaded
|
|
2084
2156
|
// GNU sysroot. A native Linux target uses Nix's cc wrapper so C build
|
|
2085
2157
|
// scripts resolve the host libc headers instead.
|
|
2086
2158
|
...(compilerEnv ? { env: compilerEnv } : {}),
|
|
2087
2159
|
},
|
|
2160
|
+
configurations: { [RELEASE_CONFIGURATION]: { command: platformBuild('release') } },
|
|
2088
2161
|
};
|
|
2089
2162
|
}
|
|
2090
2163
|
return targets;
|
|
@@ -2095,10 +2168,11 @@ function createNapiTestTarget(projectRoot: string, hasDedicatedBunfig: boolean):
|
|
|
2095
2168
|
return {
|
|
2096
2169
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
2097
2170
|
cache: true,
|
|
2098
|
-
// Deliberately NOT `build`: the aggregate drags the host-platform
|
|
2099
|
-
//
|
|
2100
|
-
//
|
|
2101
|
-
// napi-debug supplies the addon
|
|
2171
|
+
// Deliberately NOT `build`: the aggregate drags the host-platform binaries
|
|
2172
|
+
// onto the test critical path, and a `--target <triple>` platform build
|
|
2173
|
+
// compiles the whole graph again. tsc-js supplies dist/ts for the suite's
|
|
2174
|
+
// own imports; napi-debug supplies the addon from the graph cargo-test
|
|
2175
|
+
// already built.
|
|
2102
2176
|
dependsOn: ['cargo-test', 'napi-debug', 'tsc-js', '^build'],
|
|
2103
2177
|
options: {
|
|
2104
2178
|
// cwd is src/, not the package root: `bun test <arg>` treats the arg as a
|
|
@@ -2224,6 +2298,12 @@ interface CargoWorkspace {
|
|
|
2224
2298
|
projectRoot: string;
|
|
2225
2299
|
/** One derivation memo for the whole graph computation (see cargoPackageTestInputs). */
|
|
2226
2300
|
inputsCache: CargoInputsCache;
|
|
2301
|
+
/**
|
|
2302
|
+
* Cargo's own resolve, started once per graph computation and awaited only
|
|
2303
|
+
* where a project's `cargoClosure` is built, so the `cargo metadata` process
|
|
2304
|
+
* overlaps the rest of inference.
|
|
2305
|
+
*/
|
|
2306
|
+
closureSource: Promise<CargoClosureSource>;
|
|
2227
2307
|
}
|
|
2228
2308
|
|
|
2229
2309
|
type CargoTargetDependency = NonNullable<TargetConfiguration['dependsOn']>[number];
|
|
@@ -2253,7 +2333,7 @@ async function resolveCargoWorkspaces(
|
|
|
2253
2333
|
// createProjectTargets records the path-specific parse failure below.
|
|
2254
2334
|
}
|
|
2255
2335
|
}
|
|
2256
|
-
const
|
|
2336
|
+
const found: Omit<CargoWorkspace, 'closureSource'>[] = [];
|
|
2257
2337
|
for (const rootProject of projects) {
|
|
2258
2338
|
const absoluteRoot = join(workspaceRoot, rootProject.root);
|
|
2259
2339
|
const manifest = join(absoluteRoot, 'Cargo.toml');
|
|
@@ -2292,30 +2372,59 @@ async function resolveCargoWorkspaces(
|
|
|
2292
2372
|
}
|
|
2293
2373
|
packages.push({ package: pkg, pieces });
|
|
2294
2374
|
}
|
|
2295
|
-
|
|
2375
|
+
found.push({
|
|
2296
2376
|
packages,
|
|
2297
2377
|
rootProjectName: rootProject.name,
|
|
2298
2378
|
projectRoot: rootProject.root,
|
|
2299
2379
|
inputsCache: createCargoInputsCache(),
|
|
2300
2380
|
});
|
|
2301
2381
|
}
|
|
2302
|
-
return
|
|
2382
|
+
if (found.length === 0) return [];
|
|
2383
|
+
// Started only once every workspace listed cleanly, so a listing that throws
|
|
2384
|
+
// leaves no Cargo process behind.
|
|
2385
|
+
const indexedManifests = indexedCargoManifests(workspaceRoot);
|
|
2386
|
+
return found.map((workspace) => ({
|
|
2387
|
+
...workspace,
|
|
2388
|
+
closureSource: resolveCargoClosureSource(
|
|
2389
|
+
posix.join(workspace.projectRoot, 'Cargo.toml'),
|
|
2390
|
+
workspaceRoot,
|
|
2391
|
+
indexedManifests,
|
|
2392
|
+
),
|
|
2393
|
+
}));
|
|
2303
2394
|
}
|
|
2304
2395
|
|
|
2305
2396
|
/**
|
|
2306
2397
|
* One bounded target per crate; a crate that declares `smoothbricks.test.shards`
|
|
2307
2398
|
* gets one per shard plus one for the tests nextest.toml singles out.
|
|
2308
2399
|
*
|
|
2309
|
-
* Every piece EXECUTES, it never builds:
|
|
2310
|
-
* `cargo-test-archive` compiled once for the whole workspace
|
|
2311
|
-
* the
|
|
2312
|
-
*
|
|
2313
|
-
*
|
|
2314
|
-
*
|
|
2315
|
-
*
|
|
2316
|
-
*
|
|
2317
|
-
*
|
|
2318
|
-
*
|
|
2400
|
+
* Every piece EXECUTES, it never builds: it runs the binaries
|
|
2401
|
+
* `cargo-test-archive` compiled once for the whole workspace. That is what
|
|
2402
|
+
* removed the two costs the old shape could not avoid. `nextest run --workspace
|
|
2403
|
+
* -E 'package(X)'` re-entered cargo once per crate, and the `-p X` form
|
|
2404
|
+
* re-resolved that crate's features so cargo rebuilt the divergent half inside
|
|
2405
|
+
* the bounded window — measured at 57.9s of a 120s budget on a hosted 3-core
|
|
2406
|
+
* macOS runner, killing the run with 264 tests still to go. Neither form is
|
|
2407
|
+
* reachable from a reused build: nextest rejects `--workspace` and `-p` beside
|
|
2408
|
+
* it, so the filterset is the only selector left, and it selects the same tests
|
|
2409
|
+
* it always did.
|
|
2410
|
+
*
|
|
2411
|
+
* The archive is unpacked ONCE per content, not once per piece. `nextest run
|
|
2412
|
+
* --archive-file` extracts the whole archive into a temporary directory of its
|
|
2413
|
+
* own on every run, so N pieces paid N extractions of every binary in the
|
|
2414
|
+
* workspace to run 1/N of the tests each: on a workspace with ~200 test
|
|
2415
|
+
* binaries, ~25 runners extracting side by side on a loaded host all hit the
|
|
2416
|
+
* 120s bound still "Extracting". `smoo-nx-nextest-extract` hashes the archive,
|
|
2417
|
+
* unpacks it under that hash unless a previous runner already did — one
|
|
2418
|
+
* extracts while the rest wait — and prints the directory; the run then reuses
|
|
2419
|
+
* it through nextest's own reuse-build flags, which is what `--archive-file`
|
|
2420
|
+
* does after unpacking. Keyed by the archive's bytes, so a rebuilt or restored
|
|
2421
|
+
* archive can never run an older extraction's binaries. The one difference
|
|
2422
|
+
* from `--archive-file` is the Rust standard library directory: nextest has no
|
|
2423
|
+
* flag to remap it, so a run uses the producing toolchain's own sysroot rather
|
|
2424
|
+
* than the archived copy of it — the same toolchain, because the archive's hash
|
|
2425
|
+
* covers the toolchain pin. The extraction lives under `target/nextest`, never
|
|
2426
|
+
* in an Nx output: it is a multi-GB tree for a cached verdict that has no
|
|
2427
|
+
* outputs.
|
|
2319
2428
|
*
|
|
2320
2429
|
* `--workspace-remap .` is not cosmetic. An archive records the ABSOLUTE paths
|
|
2321
2430
|
* of the tree that produced it; without the remap, a restored archive hands
|
|
@@ -2348,8 +2457,8 @@ async function resolveCargoWorkspaces(
|
|
|
2348
2457
|
* making valid empty crates and shards fail execution.
|
|
2349
2458
|
*
|
|
2350
2459
|
* Pieces fan out rather than chain. The chain existed because every runner was
|
|
2351
|
-
* a cargo writer on one flocked `target/`;
|
|
2352
|
-
* so the only serialization left is the one
|
|
2460
|
+
* a cargo writer on one flocked `target/`; a reused-build run writes nothing
|
|
2461
|
+
* there, so the only serialization left is the one extraction per archive.
|
|
2353
2462
|
*/
|
|
2354
2463
|
async function addCargoTestTargets(
|
|
2355
2464
|
targets: Record<string, TargetConfiguration>,
|
|
@@ -2360,6 +2469,12 @@ async function addCargoTestTargets(
|
|
|
2360
2469
|
): Promise<string[]> {
|
|
2361
2470
|
const targetNames: string[] = [];
|
|
2362
2471
|
const toolConfig = nextestToolConfigArg(workspaceRoot, workspace.projectRoot, PLUGIN_NEXTEST_CONFIG);
|
|
2472
|
+
// Relative to the runner's cwd, so the hashed command is the same in every checkout.
|
|
2473
|
+
const extractBin = posix.join(posix.relative(workspace.projectRoot, '.'), NEXTEST_EXTRACT_BIN);
|
|
2474
|
+
const reuseExtraction =
|
|
2475
|
+
`--binaries-metadata "$extracted/${EXTRACTED_BINARIES_METADATA}" ` +
|
|
2476
|
+
`--cargo-metadata "$extracted/${EXTRACTED_CARGO_METADATA}" ` +
|
|
2477
|
+
`--target-dir-remap "$extracted/${EXTRACTED_TARGET_DIR}"`;
|
|
2363
2478
|
for (const plan of workspace.packages) {
|
|
2364
2479
|
if (plan.package.projectRoot !== projectRoot) {
|
|
2365
2480
|
continue;
|
|
@@ -2402,18 +2517,15 @@ async function addCargoTestTargets(
|
|
|
2402
2517
|
inputs,
|
|
2403
2518
|
dependsOn: [archive],
|
|
2404
2519
|
options: {
|
|
2405
|
-
command:
|
|
2406
|
-
`
|
|
2407
|
-
|
|
2520
|
+
command:
|
|
2521
|
+
`extracted="$(node ${extractBin} ${CARGO_TEST_ARCHIVE_FILE})" && ` +
|
|
2522
|
+
cargoFrozen(
|
|
2523
|
+
`nextest run ${reuseExtraction} --workspace-remap . -E '${piece.selector}'${piece.extra} --no-tests=pass --user-config-file none ${toolConfig}`,
|
|
2524
|
+
),
|
|
2408
2525
|
cwd: workspace.projectRoot,
|
|
2409
2526
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
2410
2527
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
2411
2528
|
},
|
|
2412
|
-
// The archive already holds the profile it was built with, and nextest
|
|
2413
|
-
// rejects `--release` beside `--archive-file`. Nx propagates the
|
|
2414
|
-
// configuration to this target's dependencies, so `:production` builds
|
|
2415
|
-
// the release archive and this command runs exactly what it finds.
|
|
2416
|
-
configurations: { production: {} },
|
|
2417
2529
|
};
|
|
2418
2530
|
}
|
|
2419
2531
|
}
|
|
@@ -202,7 +202,7 @@ export function defineCiWorkflow(options: CiWorkflowDefinitionOptions): CiWorkfl
|
|
|
202
202
|
steps.push({ kind: CiWorkflowStepKind.BrowserTests, name: '🌐 Browser Tests' });
|
|
203
203
|
}
|
|
204
204
|
steps.push(
|
|
205
|
-
{ kind: CiWorkflowStepKind.ManagedFilesCheck, name: '🩺 Check managed-file drift' },
|
|
205
|
+
{ kind: CiWorkflowStepKind.ManagedFilesCheck, name: '🩺 Check monorepo policies and managed-file drift' },
|
|
206
206
|
{ kind: CiWorkflowStepKind.ManagedFilesDispatch, name: '🔁 Dispatch managed-file drift healing' },
|
|
207
207
|
{ kind: CiWorkflowStepKind.SaveNxCache, name: '💾 Save Nx cache' },
|
|
208
208
|
{ kind: CiWorkflowStepKind.UploadTraceDbs, name: '📎 Upload trace DBs' },
|
|
@@ -477,24 +477,21 @@ function yamlLinesForStep(step: CiWorkflowStep, options: CiWorkflowDefinitionOpt
|
|
|
477
477
|
` run: smoo github-ci nx-run-many --targets "${darwinCrossTestTargetNames(options).join(',')}"`,
|
|
478
478
|
];
|
|
479
479
|
case CiWorkflowStepKind.ManagedFilesCheck:
|
|
480
|
-
//
|
|
481
|
-
//
|
|
482
|
-
// `drifted=<count>` for the dispatch step below.
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
' id: managed-drift',
|
|
486
|
-
' if:',
|
|
487
|
-
" ${{ github.event_name == 'push' && github.ref == format('refs/heads/{0}',",
|
|
488
|
-
' github.event.repository.default_branch) }}',
|
|
489
|
-
' run: smoo monorepo check --warn',
|
|
490
|
-
];
|
|
480
|
+
// Runs on every event, pull requests included: the package policies fail the job, since
|
|
481
|
+
// nothing heals them, while --warn keeps managed-file drift non-blocking and publishes the
|
|
482
|
+
// step output `drifted=<count>` for the dispatch step below. The check is nearly free here
|
|
483
|
+
// (devenv is already up).
|
|
484
|
+
return [` - name: ${step.name}`, ' id: managed-drift', ' run: smoo monorepo check --warn'];
|
|
491
485
|
case CiWorkflowStepKind.ManagedFilesDispatch:
|
|
492
486
|
// Dispatches the managed-files workflow, which maintains the persistent
|
|
493
|
-
// review PR. workflow_dispatch is exempt from
|
|
494
|
-
// recursion guard, so the default token suffices.
|
|
487
|
+
// review PR, from the default branch only. workflow_dispatch is exempt from
|
|
488
|
+
// GitHub's GITHUB_TOKEN recursion guard, so the default token suffices.
|
|
495
489
|
return [
|
|
496
490
|
` - name: ${step.name}`,
|
|
497
|
-
|
|
491
|
+
' if: >-',
|
|
492
|
+
" ${{ github.event_name == 'push' && github.ref == format('refs/heads/{0}',",
|
|
493
|
+
" github.event.repository.default_branch) && steps.managed-drift.outputs.drifted != '' &&",
|
|
494
|
+
" steps.managed-drift.outputs.drifted != '0' }}",
|
|
498
495
|
' run: smoo github-ci dispatch-workflow --workflow managed-files.yml --ref "$GITHUB_REF_NAME"',
|
|
499
496
|
];
|
|
500
497
|
case CiWorkflowStepKind.Deploy:
|
|
@@ -109,6 +109,11 @@ const managedFiles: ManagedFileDescriptor[] = [
|
|
|
109
109
|
target: 'tooling/direnv/setup-environment.ts',
|
|
110
110
|
executable: true,
|
|
111
111
|
},
|
|
112
|
+
{
|
|
113
|
+
kind: 'raw',
|
|
114
|
+
source: 'tooling/direnv/developer-links.ts',
|
|
115
|
+
target: 'tooling/direnv/developer-links.ts',
|
|
116
|
+
},
|
|
112
117
|
{
|
|
113
118
|
kind: 'raw',
|
|
114
119
|
source: 'tooling/direnv/secret-references.ts',
|
|
@@ -125,6 +130,11 @@ const managedFiles: ManagedFileDescriptor[] = [
|
|
|
125
130
|
source: 'tooling/direnv/devenv.smoo.nix',
|
|
126
131
|
target: 'tooling/direnv/devenv.smoo.nix',
|
|
127
132
|
},
|
|
133
|
+
{
|
|
134
|
+
kind: 'raw',
|
|
135
|
+
source: 'tooling/direnv/shared-caches.sh',
|
|
136
|
+
target: 'tooling/direnv/shared-caches.sh',
|
|
137
|
+
},
|
|
128
138
|
{
|
|
129
139
|
kind: 'raw',
|
|
130
140
|
source: 'tooling/git-hooks/pre-commit.sh',
|