@convesoft/nx-rust 0.0.0 → 1.0.0-rc.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/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +47 -1
- package/executors.json +35 -0
- package/generators.json +19 -0
- package/package.json +17 -4
- package/src/cargo/build-settings.d.ts +54 -0
- package/src/cargo/build-settings.js +93 -0
- package/src/cargo/build-settings.js.map +1 -0
- package/src/cargo/configured-runner.d.ts +36 -0
- package/src/cargo/configured-runner.js +99 -0
- package/src/cargo/configured-runner.js.map +1 -0
- package/src/cargo/configured-tools.d.ts +35 -0
- package/src/cargo/configured-tools.js +46 -0
- package/src/cargo/configured-tools.js.map +1 -0
- package/src/cargo/dep-info-basedir.d.ts +18 -0
- package/src/cargo/dep-info-basedir.js +38 -0
- package/src/cargo/dep-info-basedir.js.map +1 -0
- package/src/cargo/directories.d.ts +40 -0
- package/src/cargo/directories.js +89 -0
- package/src/cargo/directories.js.map +1 -0
- package/src/cargo/host-triple.d.ts +7 -0
- package/src/cargo/host-triple.js +21 -0
- package/src/cargo/host-triple.js.map +1 -0
- package/src/cargo/lockfile.d.ts +63 -0
- package/src/cargo/lockfile.js +157 -0
- package/src/cargo/lockfile.js.map +1 -0
- package/src/cargo/metadata.d.ts +112 -0
- package/src/cargo/metadata.js +37 -0
- package/src/cargo/metadata.js.map +1 -0
- package/src/cargo/package-specs.d.ts +54 -0
- package/src/cargo/package-specs.js +109 -0
- package/src/cargo/package-specs.js.map +1 -0
- package/src/cargo/paths-crates.d.ts +27 -0
- package/src/cargo/paths-crates.js +69 -0
- package/src/cargo/paths-crates.js.map +1 -0
- package/src/cargo/print-artifact-folders.d.ts +1 -0
- package/src/cargo/print-artifact-folders.js +58 -0
- package/src/cargo/print-artifact-folders.js.map +1 -0
- package/src/cargo/redirections.d.ts +87 -0
- package/src/cargo/redirections.js +195 -0
- package/src/cargo/redirections.js.map +1 -0
- package/src/cargo/run-cargo.d.ts +31 -0
- package/src/cargo/run-cargo.js +75 -0
- package/src/cargo/run-cargo.js.map +1 -0
- package/src/cargo/target-triples.d.ts +98 -0
- package/src/cargo/target-triples.js +265 -0
- package/src/cargo/target-triples.js.map +1 -0
- package/src/cargo/version-req.d.ts +12 -0
- package/src/cargo/version-req.js +122 -0
- package/src/cargo/version-req.js.map +1 -0
- package/src/compatibility/cargo-version.d.ts +43 -0
- package/src/compatibility/cargo-version.js +83 -0
- package/src/compatibility/cargo-version.js.map +1 -0
- package/src/compatibility/nx-bridge.d.ts +312 -0
- package/src/compatibility/nx-bridge.js +407 -0
- package/src/compatibility/nx-bridge.js.map +1 -0
- package/src/compatibility/nx-version.d.ts +104 -0
- package/src/compatibility/nx-version.js +272 -0
- package/src/compatibility/nx-version.js.map +1 -0
- package/src/executors/affected-inputs.d.ts +29 -0
- package/src/executors/affected-inputs.js +259 -0
- package/src/executors/affected-inputs.js.map +1 -0
- package/src/executors/affected-run.d.ts +54 -0
- package/src/executors/affected-run.js +394 -0
- package/src/executors/affected-run.js.map +1 -0
- package/src/executors/affected.d.ts +239 -0
- package/src/executors/affected.js +589 -0
- package/src/executors/affected.js.map +1 -0
- package/src/executors/baseline-context.d.ts +85 -0
- package/src/executors/baseline-context.js +227 -0
- package/src/executors/baseline-context.js.map +1 -0
- package/src/executors/baseline.d.ts +123 -0
- package/src/executors/baseline.js +356 -0
- package/src/executors/baseline.js.map +1 -0
- package/src/executors/batch.d.ts +75 -0
- package/src/executors/batch.js +434 -0
- package/src/executors/batch.js.map +1 -0
- package/src/executors/build-records.d.ts +110 -0
- package/src/executors/build-records.js +267 -0
- package/src/executors/build-records.js.map +1 -0
- package/src/executors/cargo/executor.d.ts +28 -0
- package/src/executors/cargo/executor.js +58 -0
- package/src/executors/cargo/executor.js.map +1 -0
- package/src/executors/cargo/schema.json +54 -0
- package/src/executors/cargo-invocation.d.ts +81 -0
- package/src/executors/cargo-invocation.js +109 -0
- package/src/executors/cargo-invocation.js.map +1 -0
- package/src/executors/cargo-output.d.ts +212 -0
- package/src/executors/cargo-output.js +646 -0
- package/src/executors/cargo-output.js.map +1 -0
- package/src/executors/command.d.ts +318 -0
- package/src/executors/command.js +517 -0
- package/src/executors/command.js.map +1 -0
- package/src/executors/coverage-baseline.d.ts +23 -0
- package/src/executors/coverage-baseline.js +284 -0
- package/src/executors/coverage-baseline.js.map +1 -0
- package/src/executors/declared-options.d.ts +21 -0
- package/src/executors/declared-options.js +58 -0
- package/src/executors/declared-options.js.map +1 -0
- package/src/executors/digests.d.ts +94 -0
- package/src/executors/digests.js +190 -0
- package/src/executors/digests.js.map +1 -0
- package/src/executors/dotenv-check.d.ts +79 -0
- package/src/executors/dotenv-check.js +553 -0
- package/src/executors/dotenv-check.js.map +1 -0
- package/src/executors/group-invocations.d.ts +80 -0
- package/src/executors/group-invocations.js +253 -0
- package/src/executors/group-invocations.js.map +1 -0
- package/src/executors/group-run.d.ts +114 -0
- package/src/executors/group-run.js +591 -0
- package/src/executors/group-run.js.map +1 -0
- package/src/executors/groups.d.ts +113 -0
- package/src/executors/groups.js +285 -0
- package/src/executors/groups.js.map +1 -0
- package/src/executors/input-check.d.ts +52 -0
- package/src/executors/input-check.js +271 -0
- package/src/executors/input-check.js.map +1 -0
- package/src/executors/kept-files.d.ts +98 -0
- package/src/executors/kept-files.js +341 -0
- package/src/executors/kept-files.js.map +1 -0
- package/src/executors/lockfile/executor.d.ts +16 -0
- package/src/executors/lockfile/executor.js +37 -0
- package/src/executors/lockfile/executor.js.map +1 -0
- package/src/executors/lockfile/schema.json +50 -0
- package/src/executors/napi-build.d.ts +73 -0
- package/src/executors/napi-build.js +420 -0
- package/src/executors/napi-build.js.map +1 -0
- package/src/executors/nextest.d.ts +185 -0
- package/src/executors/nextest.js +498 -0
- package/src/executors/nextest.js.map +1 -0
- package/src/executors/nx-command.d.ts +95 -0
- package/src/executors/nx-command.js +205 -0
- package/src/executors/nx-command.js.map +1 -0
- package/src/executors/nx-task-files.d.ts +82 -0
- package/src/executors/nx-task-files.js +156 -0
- package/src/executors/nx-task-files.js.map +1 -0
- package/src/executors/print-test-mode.d.ts +1 -0
- package/src/executors/print-test-mode.js +25 -0
- package/src/executors/print-test-mode.js.map +1 -0
- package/src/executors/release-publish/executor.d.ts +24 -0
- package/src/executors/release-publish/executor.js +165 -0
- package/src/executors/release-publish/executor.js.map +1 -0
- package/src/executors/release-publish/schema.json +30 -0
- package/src/executors/run/executor.d.ts +12 -0
- package/src/executors/run/executor.js +27 -0
- package/src/executors/run/executor.js.map +1 -0
- package/src/executors/run/schema.json +45 -0
- package/src/executors/runner-script.d.ts +12 -0
- package/src/executors/runner-script.js +22 -0
- package/src/executors/runner-script.js.map +1 -0
- package/src/executors/runtime-input-check.d.ts +24 -0
- package/src/executors/runtime-input-check.js +87 -0
- package/src/executors/runtime-input-check.js.map +1 -0
- package/src/executors/shared-artifacts.d.ts +44 -0
- package/src/executors/shared-artifacts.js +132 -0
- package/src/executors/shared-artifacts.js.map +1 -0
- package/src/executors/split-words.d.ts +24 -0
- package/src/executors/split-words.js +111 -0
- package/src/executors/split-words.js.map +1 -0
- package/src/executors/stage.d.ts +163 -0
- package/src/executors/stage.js +526 -0
- package/src/executors/stage.js.map +1 -0
- package/src/executors/staged-run.d.ts +24 -0
- package/src/executors/staged-run.js +110 -0
- package/src/executors/staged-run.js.map +1 -0
- package/src/executors/task-env.d.ts +271 -0
- package/src/executors/task-env.js +494 -0
- package/src/executors/task-env.js.map +1 -0
- package/src/executors/task-execution.d.ts +61 -0
- package/src/executors/task-execution.js +122 -0
- package/src/executors/task-execution.js.map +1 -0
- package/src/executors/task-guards.d.ts +112 -0
- package/src/executors/task-guards.js +430 -0
- package/src/executors/task-guards.js.map +1 -0
- package/src/executors/task-options.d.ts +114 -0
- package/src/executors/task-options.js +258 -0
- package/src/executors/task-options.js.map +1 -0
- package/src/executors/task.d.ts +166 -0
- package/src/executors/task.js +520 -0
- package/src/executors/task.js.map +1 -0
- package/src/executors/test-mode.d.ts +182 -0
- package/src/executors/test-mode.js +391 -0
- package/src/executors/test-mode.js.map +1 -0
- package/src/executors/test-runner.d.ts +44 -0
- package/src/executors/test-runner.js +159 -0
- package/src/executors/test-runner.js.map +1 -0
- package/src/executors/test-steps.d.ts +109 -0
- package/src/executors/test-steps.js +535 -0
- package/src/executors/test-steps.js.map +1 -0
- package/src/executors/wasm-build.d.ts +56 -0
- package/src/executors/wasm-build.js +216 -0
- package/src/executors/wasm-build.js.map +1 -0
- package/src/generators/crate/binary.schema.json +28 -0
- package/src/generators/crate/crate.d.ts +24 -0
- package/src/generators/crate/crate.js +108 -0
- package/src/generators/crate/crate.js.map +1 -0
- package/src/generators/crate/enclosing-workspace.d.ts +25 -0
- package/src/generators/crate/enclosing-workspace.js +58 -0
- package/src/generators/crate/enclosing-workspace.js.map +1 -0
- package/src/generators/crate/library.schema.json +28 -0
- package/src/generators/init/graph-check.d.ts +81 -0
- package/src/generators/init/graph-check.js +299 -0
- package/src/generators/init/graph-check.js.map +1 -0
- package/src/generators/init/init.d.ts +23 -0
- package/src/generators/init/init.js +113 -0
- package/src/generators/init/init.js.map +1 -0
- package/src/generators/init/report.d.ts +19 -0
- package/src/generators/init/report.js +93 -0
- package/src/generators/init/report.js.map +1 -0
- package/src/generators/init/schema.json +9 -0
- package/src/graph/artifact-kinds.d.ts +29 -0
- package/src/graph/artifact-kinds.js +50 -0
- package/src/graph/artifact-kinds.js.map +1 -0
- package/src/graph/artifact-names.d.ts +97 -0
- package/src/graph/artifact-names.js +276 -0
- package/src/graph/artifact-names.js.map +1 -0
- package/src/graph/build-records.d.ts +74 -0
- package/src/graph/build-records.js +104 -0
- package/src/graph/build-records.js.map +1 -0
- package/src/graph/caching.d.ts +148 -0
- package/src/graph/caching.js +676 -0
- package/src/graph/caching.js.map +1 -0
- package/src/graph/collisions.d.ts +106 -0
- package/src/graph/collisions.js +156 -0
- package/src/graph/collisions.js.map +1 -0
- package/src/graph/computation-reports.d.ts +89 -0
- package/src/graph/computation-reports.js +216 -0
- package/src/graph/computation-reports.js.map +1 -0
- package/src/graph/declared-files.d.ts +190 -0
- package/src/graph/declared-files.js +600 -0
- package/src/graph/declared-files.js.map +1 -0
- package/src/graph/discovery.d.ts +175 -0
- package/src/graph/discovery.js +656 -0
- package/src/graph/discovery.js.map +1 -0
- package/src/graph/edges.d.ts +25 -0
- package/src/graph/edges.js +94 -0
- package/src/graph/edges.js.map +1 -0
- package/src/graph/entries.d.ts +83 -0
- package/src/graph/entries.js +259 -0
- package/src/graph/entries.js.map +1 -0
- package/src/graph/inputs.d.ts +420 -0
- package/src/graph/inputs.js +746 -0
- package/src/graph/inputs.js.map +1 -0
- package/src/graph/lockfile-task.d.ts +74 -0
- package/src/graph/lockfile-task.js +105 -0
- package/src/graph/lockfile-task.js.map +1 -0
- package/src/graph/names.d.ts +41 -0
- package/src/graph/names.js +34 -0
- package/src/graph/names.js.map +1 -0
- package/src/graph/napi.d.ts +107 -0
- package/src/graph/napi.js +206 -0
- package/src/graph/napi.js.map +1 -0
- package/src/graph/nx-glob.d.ts +36 -0
- package/src/graph/nx-glob.js +152 -0
- package/src/graph/nx-glob.js.map +1 -0
- package/src/graph/nx-internals.d.ts +57 -0
- package/src/graph/nx-internals.js +128 -0
- package/src/graph/nx-internals.js.map +1 -0
- package/src/graph/options.d.ts +32 -0
- package/src/graph/options.js +80 -0
- package/src/graph/options.js.map +1 -0
- package/src/graph/outputs.d.ts +75 -0
- package/src/graph/outputs.js +140 -0
- package/src/graph/outputs.js.map +1 -0
- package/src/graph/path-dependencies.d.ts +122 -0
- package/src/graph/path-dependencies.js +459 -0
- package/src/graph/path-dependencies.js.map +1 -0
- package/src/graph/plugin-package.d.ts +36 -0
- package/src/graph/plugin-package.js +132 -0
- package/src/graph/plugin-package.js.map +1 -0
- package/src/graph/plugin-version.d.ts +20 -0
- package/src/graph/plugin-version.js +153 -0
- package/src/graph/plugin-version.js.map +1 -0
- package/src/graph/projects.d.ts +141 -0
- package/src/graph/projects.js +182 -0
- package/src/graph/projects.js.map +1 -0
- package/src/graph/reached-projects.d.ts +46 -0
- package/src/graph/reached-projects.js +102 -0
- package/src/graph/reached-projects.js.map +1 -0
- package/src/graph/real-path.d.ts +47 -0
- package/src/graph/real-path.js +113 -0
- package/src/graph/real-path.js.map +1 -0
- package/src/graph/redirected-uses.d.ts +98 -0
- package/src/graph/redirected-uses.js +434 -0
- package/src/graph/redirected-uses.js.map +1 -0
- package/src/graph/registration.d.ts +121 -0
- package/src/graph/registration.js +233 -0
- package/src/graph/registration.js.map +1 -0
- package/src/graph/script-input.d.ts +46 -0
- package/src/graph/script-input.js +65 -0
- package/src/graph/script-input.js.map +1 -0
- package/src/graph/settings.d.ts +178 -0
- package/src/graph/settings.js +479 -0
- package/src/graph/settings.js.map +1 -0
- package/src/graph/target-defaults-causes.d.ts +33 -0
- package/src/graph/target-defaults-causes.js +202 -0
- package/src/graph/target-defaults-causes.js.map +1 -0
- package/src/graph/target-defaults-layers.d.ts +186 -0
- package/src/graph/target-defaults-layers.js +420 -0
- package/src/graph/target-defaults-layers.js.map +1 -0
- package/src/graph/target-defaults-meaning.d.ts +95 -0
- package/src/graph/target-defaults-meaning.js +292 -0
- package/src/graph/target-defaults-meaning.js.map +1 -0
- package/src/graph/target-defaults-report.d.ts +77 -0
- package/src/graph/target-defaults-report.js +242 -0
- package/src/graph/target-defaults-report.js.map +1 -0
- package/src/graph/target-defaults.d.ts +79 -0
- package/src/graph/target-defaults.js +425 -0
- package/src/graph/target-defaults.js.map +1 -0
- package/src/graph/target-fields.d.ts +16 -0
- package/src/graph/target-fields.js +134 -0
- package/src/graph/target-fields.js.map +1 -0
- package/src/graph/target-tables.d.ts +45 -0
- package/src/graph/target-tables.js +299 -0
- package/src/graph/target-tables.js.map +1 -0
- package/src/graph/targets.d.ts +367 -0
- package/src/graph/targets.js +404 -0
- package/src/graph/targets.js.map +1 -0
- package/src/graph/unification.d.ts +141 -0
- package/src/graph/unification.js +459 -0
- package/src/graph/unification.js.map +1 -0
- package/src/graph/unignored-directories.d.ts +25 -0
- package/src/graph/unignored-directories.js +89 -0
- package/src/graph/unignored-directories.js.map +1 -0
- package/src/graph/visibility.d.ts +17 -0
- package/src/graph/visibility.js +67 -0
- package/src/graph/visibility.js.map +1 -0
- package/src/graph/warnings.d.ts +38 -0
- package/src/graph/warnings.js +77 -0
- package/src/graph/warnings.js.map +1 -0
- package/src/graph/wasm.d.ts +56 -0
- package/src/graph/wasm.js +77 -0
- package/src/graph/wasm.js.map +1 -0
- package/src/index.d.ts +68 -0
- package/src/index.js +109 -0
- package/src/index.js.map +1 -0
- package/src/release/manifests.d.ts +95 -0
- package/src/release/manifests.js +164 -0
- package/src/release/manifests.js.map +1 -0
- package/src/release/places.d.ts +127 -0
- package/src/release/places.js +368 -0
- package/src/release/places.js.map +1 -0
- package/src/release/publish-cargo.d.ts +177 -0
- package/src/release/publish-cargo.js +351 -0
- package/src/release/publish-cargo.js.map +1 -0
- package/src/release/publish-crates.d.ts +124 -0
- package/src/release/publish-crates.js +242 -0
- package/src/release/publish-crates.js.map +1 -0
- package/src/release/publish-environments.d.ts +50 -0
- package/src/release/publish-environments.js +284 -0
- package/src/release/publish-environments.js.map +1 -0
- package/src/release/publish-messages.d.ts +66 -0
- package/src/release/publish-messages.js +273 -0
- package/src/release/publish-messages.js.map +1 -0
- package/src/release/publish-registry.d.ts +27 -0
- package/src/release/publish-registry.js +135 -0
- package/src/release/publish-registry.js.map +1 -0
- package/src/release/publish-settings.d.ts +26 -0
- package/src/release/publish-settings.js +56 -0
- package/src/release/publish-settings.js.map +1 -0
- package/src/release/publish.d.ts +59 -0
- package/src/release/publish.js +620 -0
- package/src/release/publish.js.map +1 -0
- package/src/release/repository.d.ts +73 -0
- package/src/release/repository.js +219 -0
- package/src/release/repository.js.map +1 -0
- package/src/release/requirements.d.ts +34 -0
- package/src/release/requirements.js +30 -0
- package/src/release/requirements.js.map +1 -0
- package/src/release/toml-edit.d.ts +67 -0
- package/src/release/toml-edit.js +453 -0
- package/src/release/toml-edit.js.map +1 -0
- package/src/release/version-actions.d.ts +133 -0
- package/src/release/version-actions.js +474 -0
- package/src/release/version-actions.js.map +1 -0
- package/src/release/version-checks.d.ts +21 -0
- package/src/release/version-checks.js +151 -0
- package/src/release/version-checks.js.map +1 -0
- package/src/release/version-lockfiles.d.ts +61 -0
- package/src/release/version-lockfiles.js +222 -0
- package/src/release/version-lockfiles.js.map +1 -0
- package/src/tools/napi-cli.d.ts +70 -0
- package/src/tools/napi-cli.js +63 -0
- package/src/tools/napi-cli.js.map +1 -0
- package/src/tools/optional-tools.d.ts +121 -0
- package/src/tools/optional-tools.js +303 -0
- package/src/tools/optional-tools.js.map +1 -0
- package/src/tools/print-napi-cli.d.ts +1 -0
- package/src/tools/print-napi-cli.js +24 -0
- package/src/tools/print-napi-cli.js.map +1 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WasmTaskError = void 0;
|
|
4
|
+
exports.prepareWasmTask = prepareWasmTask;
|
|
5
|
+
exports.runWasmGroup = runWasmGroup;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const node_child_process_1 = require("node:child_process");
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const node_path_1 = require("node:path");
|
|
10
|
+
const lockfile_1 = require("../cargo/lockfile");
|
|
11
|
+
const wasm_1 = require("../graph/wasm");
|
|
12
|
+
const optional_tools_1 = require("../tools/optional-tools");
|
|
13
|
+
const cargo_invocation_1 = require("./cargo-invocation");
|
|
14
|
+
const cargo_output_1 = require("./cargo-output");
|
|
15
|
+
const group_run_1 = require("./group-run");
|
|
16
|
+
/** Thrown by {@link prepareWasmTask} with the message with which the task fails before cargo. */
|
|
17
|
+
class WasmTaskError extends Error {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "WasmTaskError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.WasmTaskError = WasmTaskError;
|
|
24
|
+
/**
|
|
25
|
+
* The checks of a `wasm-build` task before cargo runs (`DES-WASM`, "What
|
|
26
|
+
* the step needs"; `DES-DIAGNOSTICS`), in this order:
|
|
27
|
+
*
|
|
28
|
+
* - the crate's library has the file name of another crate's file, which
|
|
29
|
+
* graph creation records ({@link TargetCargoMetadata.sharedLibrary}), so
|
|
30
|
+
* that cargo builds one `.wasm` file for both;
|
|
31
|
+
* - the `wasmTarget` option is none of `bundler`, `web` and `nodejs`;
|
|
32
|
+
* - the toolchain that the workspace root selects has no standard library
|
|
33
|
+
* for the wasm triple;
|
|
34
|
+
* - the `wasm-bindgen` CLI is not on the task's `PATH`, as cargo looks it
|
|
35
|
+
* up in the workspace root, or does not say its version;
|
|
36
|
+
* - the lockfile, which the lockfile task has brought up to date, reaches
|
|
37
|
+
* no `wasm-bindgen` crate from the crate's entry, or several versions, or
|
|
38
|
+
* one of another version than the CLI.
|
|
39
|
+
*
|
|
40
|
+
* The plugin installs nothing (`ADR-V1-SCOPE`).
|
|
41
|
+
*
|
|
42
|
+
* @param crateFolder The absolute path of the crate's folder.
|
|
43
|
+
* @param cwd The absolute path of the workspace root, where cargo runs.
|
|
44
|
+
* @param version The crate's version where graph creation recorded it.
|
|
45
|
+
* @throws {WasmTaskError} With the message of the first check that fails.
|
|
46
|
+
*/
|
|
47
|
+
// @mara implements DES-WASM
|
|
48
|
+
// @mara implements DES-DIAGNOSTICS
|
|
49
|
+
function prepareWasmTask(task, crate, metadata, crateFolder, cwd, env, options, repositoryRoot, version) {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
if (metadata.sharedLibrary !== undefined) {
|
|
52
|
+
throw new WasmTaskError(`${task}: the library of ${crate} has the file name of another crate's library: ${metadata.sharedLibrary}. Cargo builds one file for crates whose libraries share a file name, so that the wasm package could hold the other crate's functions. The task does not run, so that Nx stores no result for it. Give the crates different [lib] names in their Cargo.toml.`);
|
|
53
|
+
}
|
|
54
|
+
const wasmTarget = options.wasmTarget;
|
|
55
|
+
if (typeof wasmTarget !== "string" || !wasm_1.wasmTargets.includes(wasmTarget)) {
|
|
56
|
+
throw new WasmTaskError(`${task}: the option wasmTarget is ${JSON.stringify(wasmTarget)}, but wasm-build writes the wasm targets ${(0, cargo_output_1.describeList)(wasm_1.wasmTargets.map((name) => `"${name}"`))} of the wasm-bindgen CLI. Set wasmTarget to one of them.`);
|
|
57
|
+
}
|
|
58
|
+
const workspace = (0, optional_tools_1.describeFolder)((0, node_path_1.relative)(repositoryRoot, cwd) || ".");
|
|
59
|
+
const neededBy = `the wasm-build target of the crate ${crate} in the Cargo workspace in ${workspace}`;
|
|
60
|
+
const context = { workspaceRoot: repositoryRoot, workspaces: [], env, folder: cwd };
|
|
61
|
+
try {
|
|
62
|
+
(0, optional_tools_1.requireTool)("wasm-target", neededBy, context);
|
|
63
|
+
(0, optional_tools_1.requireTool)("wasm-bindgen", neededBy, context);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
throw error instanceof optional_tools_1.MissingToolError
|
|
67
|
+
? new WasmTaskError(`${task}: ${error.message}`)
|
|
68
|
+
: error;
|
|
69
|
+
}
|
|
70
|
+
const cli = (0, optional_tools_1.findExecutable)("wasm-bindgen", (0, optional_tools_1.searchPath)(env, cwd));
|
|
71
|
+
const run = (0, node_child_process_1.spawnSync)(cli, ["--version"], { cwd, env, encoding: "utf8" });
|
|
72
|
+
const cliVersion = (_b = /^wasm-bindgen (\S+)/m.exec((_a = run.stdout) !== null && _a !== void 0 ? _a : "")) === null || _b === void 0 ? void 0 : _b[1];
|
|
73
|
+
if (run.status !== 0 || cliVersion === undefined) {
|
|
74
|
+
throw new WasmTaskError(`${task}: the wasm-bindgen CLI at ${cli} did not print its version with --version, so wasm-build cannot tell whether it matches the wasm-bindgen crate in Cargo.lock. The task does not run, so that Nx stores no result for it.${run.stderr ? `\n${run.stderr.trim()}` : ""}`);
|
|
75
|
+
}
|
|
76
|
+
const locked = lockedVersions((0, node_path_1.join)(cwd, "Cargo.lock"), crate, version);
|
|
77
|
+
if (typeof locked === "string") {
|
|
78
|
+
throw new WasmTaskError(`${task}: ${locked} The task does not run, so that Nx stores no result for it.`);
|
|
79
|
+
}
|
|
80
|
+
if (locked.length === 0) {
|
|
81
|
+
throw new WasmTaskError(`${task}: ${crate} reaches no wasm-bindgen crate in Cargo.lock, so the wasm-bindgen CLI cannot post-process its library. The task does not run, so that Nx stores no result for it. Add wasm-bindgen to the crate's dependencies, or remove "wasm" from the artifacts of its [package.metadata.nx].`);
|
|
82
|
+
}
|
|
83
|
+
if (locked.length > 1) {
|
|
84
|
+
throw new WasmTaskError(`${task}: ${crate} reaches the wasm-bindgen crate in the versions ${(0, cargo_output_1.describeList)(locked)} in Cargo.lock, and one wasm-bindgen CLI can post-process only one of them. The task does not run, so that Nx stores no result for it. Make the crates of the workspace use one version of wasm-bindgen.`);
|
|
85
|
+
}
|
|
86
|
+
if (locked[0] !== cliVersion) {
|
|
87
|
+
throw new WasmTaskError(`${task}: the wasm-bindgen CLI is ${cliVersion}, but Cargo.lock locks the wasm-bindgen crate of ${crate} at ${locked[0]}, and the CLI post-processes only the version it was released with. The task does not run, so that Nx stores no result for it. Install the matching CLI with \`cargo install --locked wasm-bindgen-cli --version ${locked[0]}\`.`);
|
|
88
|
+
}
|
|
89
|
+
return { crateFolder, cli, version: cliVersion, wasmTarget: wasmTarget };
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The versions of `wasm-bindgen` that the crate's entry reaches in the
|
|
93
|
+
* lockfile ({@link reachedEntries}), sorted, or why the lockfile cannot
|
|
94
|
+
* tell. The entry is the one without a source of the crate's name and
|
|
95
|
+
* `version`, or the only one of its name where the version is unknown.
|
|
96
|
+
*/
|
|
97
|
+
function lockedVersions(path, crate, version) {
|
|
98
|
+
let lockfile;
|
|
99
|
+
try {
|
|
100
|
+
lockfile = (0, lockfile_1.parseLockfile)((0, node_fs_1.readFileSync)(path, "utf8"));
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
return `wasm-build cannot read the version of the wasm-bindgen crate from ${path}: ${error instanceof Error ? error.message : String(error)}.`;
|
|
104
|
+
}
|
|
105
|
+
const own = lockfile.entries.filter((entry) => entry.name === crate &&
|
|
106
|
+
entry.source === undefined &&
|
|
107
|
+
(version === undefined || entry.version === version));
|
|
108
|
+
if (own.length !== 1) {
|
|
109
|
+
return `wasm-build cannot tell the entry of ${crate} in ${path}, which has ${own.length} entries of that name, so it cannot read the version of the wasm-bindgen crate.`;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
return [
|
|
113
|
+
...new Set((0, lockfile_1.reachedEntries)(lockfile, own[0])
|
|
114
|
+
.filter((entry) => entry.name === "wasm-bindgen")
|
|
115
|
+
.map((entry) => entry.version)),
|
|
116
|
+
].sort();
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (error instanceof lockfile_1.LockfileError) {
|
|
120
|
+
return `wasm-build cannot read the version of the wasm-bindgen crate from ${path}: ${error.message}.`;
|
|
121
|
+
}
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Runs a group of `wasm-build` tasks (`DES-WASM`): the group's compile for
|
|
127
|
+
* the wasm triple, as a group of `build` runs it, with the checks after
|
|
128
|
+
* cargo of `build` ({@link runGroup}); then, for each task whose crate
|
|
129
|
+
* passed, the `wasm-bindgen` CLI on the `.wasm` file that cargo reported for
|
|
130
|
+
* the crate's `cdylib` in this compile, into the crate's package folder,
|
|
131
|
+
* which it empties first. A task fails where cargo reported no such file
|
|
132
|
+
* for its crate, or more than one, and where the CLI fails.
|
|
133
|
+
*
|
|
134
|
+
* @returns One result per member, in order.
|
|
135
|
+
*/
|
|
136
|
+
// @mara implements DES-WASM
|
|
137
|
+
// @mara implements DES-ARTIFACT-STEPS
|
|
138
|
+
function runWasmGroup(members_1) {
|
|
139
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (members, verbose = false, live = "none") {
|
|
140
|
+
// The compile's output, whose JSON messages report the `.wasm` files.
|
|
141
|
+
let compileOutput = "";
|
|
142
|
+
const compiled = yield (0, group_run_1.runGroup)(members, verbose, live, (_step, output) => {
|
|
143
|
+
compileOutput = output;
|
|
144
|
+
});
|
|
145
|
+
const libraries = (0, cargo_output_1.reportedCdylibFiles)(compileOutput, /\.wasm$/);
|
|
146
|
+
return members.map((member, index) => {
|
|
147
|
+
var _a, _b, _c;
|
|
148
|
+
const result = compiled[index];
|
|
149
|
+
if (!result.success) {
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
const written = postProcess(member, (_c = libraries.get((_b = (_a = member.invocation.package) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : "")) !== null && _c !== void 0 ? _c : []);
|
|
153
|
+
return {
|
|
154
|
+
success: written.success,
|
|
155
|
+
output: [...(result.output === "" ? [] : [result.output]), written.output].join("\n"),
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Writes a task's package (`DES-WASM`, "Post-processing"): removes the
|
|
162
|
+
* package folder of an earlier run, then runs the `wasm-bindgen` CLI with
|
|
163
|
+
* the task's wasm target on the file that cargo reported in this compile,
|
|
164
|
+
* with the environment that cargo had, so that it writes the package
|
|
165
|
+
* folder anew.
|
|
166
|
+
*/
|
|
167
|
+
// @mara implements DES-WASM
|
|
168
|
+
function postProcess(member, reported) {
|
|
169
|
+
var _a, _b, _c, _d;
|
|
170
|
+
const { prepared, invocation } = member;
|
|
171
|
+
const wasm = prepared.wasm;
|
|
172
|
+
const task = prepared.task;
|
|
173
|
+
const fail = (message) => ({
|
|
174
|
+
success: false,
|
|
175
|
+
output: `${task}: ${message} The task does not run, so that Nx stores no result for it.`,
|
|
176
|
+
});
|
|
177
|
+
if (reported.length !== 1) {
|
|
178
|
+
return fail(reported.length === 0
|
|
179
|
+
? `cargo reported no .wasm file of the cdylib of ${(_a = prepared.crate) !== null && _a !== void 0 ? _a : "the crate"} in this compile for ${wasm_1.wasmTriple}, so wasm-build has no file to give the wasm-bindgen CLI. Give the crate's [lib] table crate-type = ["cdylib"].`
|
|
180
|
+
: `cargo reported ${reported.length} .wasm files of the cdylib of ${(_b = prepared.crate) !== null && _b !== void 0 ? _b : "the crate"} in this compile, ${reported.map((file) => (0, node_path_1.relative)(invocation.cwd, file)).join(" and ")}, so wasm-build cannot tell which one is the package's.`);
|
|
181
|
+
}
|
|
182
|
+
const folder = (0, node_path_1.join)(wasm.crateFolder, wasm_1.wasmPackageFolder);
|
|
183
|
+
(0, node_fs_1.rmSync)(folder, { recursive: true, force: true });
|
|
184
|
+
const run = (0, node_child_process_1.spawnSync)(wasm.cli, ["--target", wasm.wasmTarget, "--out-dir", folder, reported[0]], {
|
|
185
|
+
cwd: invocation.cwd,
|
|
186
|
+
env: (0, cargo_invocation_1.cargoEnvironment)(invocation, prepared.env),
|
|
187
|
+
encoding: "utf8",
|
|
188
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
189
|
+
});
|
|
190
|
+
const said = `${(_c = run.stdout) !== null && _c !== void 0 ? _c : ""}${(_d = run.stderr) !== null && _d !== void 0 ? _d : ""}`.trim();
|
|
191
|
+
if (run.status !== 0) {
|
|
192
|
+
(0, node_fs_1.rmSync)(folder, { recursive: true, force: true });
|
|
193
|
+
return fail(`the wasm-bindgen CLI ${wasm.version} failed on ${(0, node_path_1.relative)(invocation.cwd, reported[0])}${run.error === undefined ? ` with status ${run.status}` : `: ${run.error.message}`}.${said === "" ? "" : `\n${said}`}`);
|
|
194
|
+
}
|
|
195
|
+
let files;
|
|
196
|
+
try {
|
|
197
|
+
files = (0, node_fs_1.readdirSync)(folder).sort();
|
|
198
|
+
}
|
|
199
|
+
catch (_e) {
|
|
200
|
+
files = [];
|
|
201
|
+
}
|
|
202
|
+
// The CLI names the module after the file it reads (`EVD-WASM-POSTPROCESS`).
|
|
203
|
+
const module = `${(0, node_path_1.basename)(reported[0], ".wasm")}_bg.wasm`;
|
|
204
|
+
if (!files.includes(module)) {
|
|
205
|
+
(0, node_fs_1.rmSync)(folder, { recursive: true, force: true });
|
|
206
|
+
return fail(`the wasm-bindgen CLI ${wasm.version} ended without error but wrote no ${module} into ${wasm_1.wasmPackageFolder}/.${said === "" ? "" : `\n${said}`}`);
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
success: true,
|
|
210
|
+
output: [
|
|
211
|
+
...(said === "" ? [] : [said]),
|
|
212
|
+
`${task}: wrote ${wasm_1.wasmPackageFolder}/ with ${(0, cargo_output_1.describeList)(files)}.`,
|
|
213
|
+
].join("\n"),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=wasm-build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-build.js","sourceRoot":"","sources":["../../../../nx-rust/src/executors/wasm-build.ts"],"names":[],"mappings":";;;AA8DA,0CA+DC;AAyDD,oCAsBC;;AA5MD,2DAA+C;AAC/C,qCAA4D;AAC5D,yCAAqD;AACrD,gDAAgG;AAEhG,wCAA4F;AAC5F,4DAMiC;AACjC,yDAAsD;AACtD,iDAAmE;AACnE,2CAA6F;AAc7F,iGAAiG;AACjG,MAAa,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AALD,sCAKC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,4BAA4B;AAC5B,mCAAmC;AACnC,SAAgB,eAAe,CAC7B,IAAY,EACZ,KAAa,EACb,QAA6B,EAC7B,WAAmB,EACnB,GAAW,EACX,GAAsB,EACtB,OAAiC,EACjC,cAAsB,EACtB,OAAgB;;IAEhB,IAAI,QAAQ,CAAC,aAAa,KAAK,SAAS,E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AI,EAAE,CAAC;IACrC,CAAC;IAAC,WAAM,CAAC;QACP,KAAK,GAAG,EAAE,CAAC;IACb,CAAC;IACD,6EAA6E;IAC7E,MAAM,MAAM,GAAG,GAAG,IAAA,oBAAQ,EAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC;IAC3D,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,IAAA,gBAAM,EAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACjD,OAAO,IAAI,CACT,wBAAwB,IAAI,CAAC,OAAO,qCAAqC,MAAM,SAAS,wBAAiB,KAAK,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,EAAE,CAC/I,CAAC;IACJ,CAAC;IACD,OAAO;QACL,OAAO,EAAE,IAAI;QACb,MAAM,EAAE;YACN,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAC9B,GAAG,IAAI,WAAW,wBAAiB,UAAU,IAAA,2BAAY,EAAC,KAAK,CAAC,GAAG;SACpE,CAAC,IAAI,CAAC,IAAI,CAAC;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "NxRustBinary",
|
|
4
|
+
"title": "Create a binary crate",
|
|
5
|
+
"description": "Create a binary crate with `cargo new --vcs none --bin`. Cargo adds it to the members of the Cargo workspace around the folder.",
|
|
6
|
+
"cli": "nx",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"directory": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "The crate's folder, relative to the folder you run nx in.",
|
|
12
|
+
"$default": {
|
|
13
|
+
"$source": "argv",
|
|
14
|
+
"index": 0
|
|
15
|
+
},
|
|
16
|
+
"x-prompt": "Which folder should the binary crate be created in?"
|
|
17
|
+
},
|
|
18
|
+
"name": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "The package name. Without it, the crate is named after its folder."
|
|
21
|
+
},
|
|
22
|
+
"edition": {
|
|
23
|
+
"type": ["string", "number"],
|
|
24
|
+
"description": "The Rust edition, such as 2024. Without it, the crate takes the workspace's edition, or Cargo's default."
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"required": ["directory"]
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { GeneratorCallback, Tree } from "@nx/devkit";
|
|
2
|
+
/** The options of `library` and `binary`. */
|
|
3
|
+
export interface CrateGeneratorSchema {
|
|
4
|
+
/** The crate's folder, relative to the folder `nx` runs in. */
|
|
5
|
+
directory: string;
|
|
6
|
+
/** The package name; cargo takes the folder's name without it. */
|
|
7
|
+
name?: string;
|
|
8
|
+
/**
|
|
9
|
+
* The Rust edition; cargo chooses without it. A number when the command
|
|
10
|
+
* line gives it, as in `--edition 2024`, which Nx does not turn into text.
|
|
11
|
+
*/
|
|
12
|
+
edition?: string | number;
|
|
13
|
+
}
|
|
14
|
+
/** Creates a library crate with `cargo new --lib`. */
|
|
15
|
+
export declare function libraryGenerator(tree: Tree, options: CrateGeneratorSchema): Promise<GeneratorCallback>;
|
|
16
|
+
/** Creates a binary crate with `cargo new --bin`. */
|
|
17
|
+
export declare function binaryGenerator(tree: Tree, options: CrateGeneratorSchema): Promise<GeneratorCallback>;
|
|
18
|
+
/**
|
|
19
|
+
* Resolves `directory` as Nx's own generators resolve it: against the
|
|
20
|
+
* folder `nx` runs in, unless it already starts with that folder.
|
|
21
|
+
*
|
|
22
|
+
* @returns The path relative to the repository root, with `/` separators.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveDirectory(workspaceRoot: string, directory: string): string;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.libraryGenerator = libraryGenerator;
|
|
4
|
+
exports.binaryGenerator = binaryGenerator;
|
|
5
|
+
exports.resolveDirectory = resolveDirectory;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const node_child_process_1 = require("node:child_process");
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const devkit_1 = require("@nx/devkit");
|
|
10
|
+
const enclosing_workspace_1 = require("./enclosing-workspace");
|
|
11
|
+
/** Creates a library crate with `cargo new --lib`. */
|
|
12
|
+
// @mara implements DES-GENERATORS
|
|
13
|
+
function libraryGenerator(tree, options) {
|
|
14
|
+
return crateGenerator(tree, options, "lib");
|
|
15
|
+
}
|
|
16
|
+
/** Creates a binary crate with `cargo new --bin`. */
|
|
17
|
+
// @mara implements DES-GENERATORS
|
|
18
|
+
function binaryGenerator(tree, options) {
|
|
19
|
+
return crateGenerator(tree, options, "bin");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates one crate with `cargo new --vcs none`, which cargo adds to the
|
|
23
|
+
* members of the enclosing workspace. The generator writes nothing through
|
|
24
|
+
* Nx's file tree: the callback it returns runs cargo, and Nx runs that
|
|
25
|
+
* callback only without `--dry-run`.
|
|
26
|
+
*
|
|
27
|
+
* @throws {Error} When the enclosing workspace's `exclude` leaves the folder
|
|
28
|
+
* out, before cargo runs.
|
|
29
|
+
*/
|
|
30
|
+
function crateGenerator(tree, options, kind) {
|
|
31
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const directory = resolveDirectory(tree.root, options.directory);
|
|
33
|
+
const folder = (0, node_path_1.join)(tree.root, directory);
|
|
34
|
+
const workspace = (0, enclosing_workspace_1.enclosingWorkspace)(folder);
|
|
35
|
+
if (workspace === undefined) {
|
|
36
|
+
devkit_1.logger.info(`${directory} lies outside every Cargo workspace, so the crate will be a standalone crate, with its own Cargo.lock and build directory.`);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const entry = (0, enclosing_workspace_1.excludingEntry)(workspace, folder);
|
|
40
|
+
if (entry !== undefined) {
|
|
41
|
+
const manifest = displayPath(tree.root, workspace.manifest);
|
|
42
|
+
throw new Error([
|
|
43
|
+
`nx-rust did not create a crate in ${directory}: ${manifest} lists "${entry}" under [workspace] exclude, which leaves the folder out of that workspace.`,
|
|
44
|
+
"cargo new would add the folder to the workspace's members, which overrides exclude.",
|
|
45
|
+
`Choose a folder that "${entry}" does not cover, or remove "${entry}" from exclude in ${manifest} first.`,
|
|
46
|
+
].join("\n"));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const args = [
|
|
50
|
+
"new",
|
|
51
|
+
"--vcs",
|
|
52
|
+
"none",
|
|
53
|
+
`--${kind}`,
|
|
54
|
+
...(options.name ? ["--name", options.name] : []),
|
|
55
|
+
...(options.edition ? ["--edition", String(options.edition)] : []),
|
|
56
|
+
directory,
|
|
57
|
+
];
|
|
58
|
+
const command = ["cargo", ...args].map(shellWord).join(" ");
|
|
59
|
+
if (process.env.NX_DRY_RUN === "true") {
|
|
60
|
+
devkit_1.logger.info(`Without --dry-run, nx-rust would run \`${command}\` in the repository root.`);
|
|
61
|
+
}
|
|
62
|
+
return () => runCargoNew(args, command, tree.root);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Resolves `directory` as Nx's own generators resolve it: against the
|
|
67
|
+
* folder `nx` runs in, unless it already starts with that folder.
|
|
68
|
+
*
|
|
69
|
+
* @returns The path relative to the repository root, with `/` separators.
|
|
70
|
+
*/
|
|
71
|
+
function resolveDirectory(workspaceRoot, directory) {
|
|
72
|
+
const initCwd = process.env.INIT_CWD;
|
|
73
|
+
const cwd = (initCwd === null || initCwd === void 0 ? void 0 : initCwd.startsWith(workspaceRoot)) ? initCwd : process.cwd();
|
|
74
|
+
const relativeCwd = (0, devkit_1.normalizePath)((0, node_path_1.relative)(workspaceRoot, cwd));
|
|
75
|
+
const path = (0, devkit_1.normalizePath)(directory);
|
|
76
|
+
return path === relativeCwd || path.startsWith(`${relativeCwd}/`) || relativeCwd === ""
|
|
77
|
+
? (0, devkit_1.joinPathFragments)(path)
|
|
78
|
+
: (0, devkit_1.joinPathFragments)(relativeCwd, path);
|
|
79
|
+
}
|
|
80
|
+
function runCargoNew(args, command, workspaceRoot) {
|
|
81
|
+
const result = (0, node_child_process_1.spawnSync)("cargo", args, {
|
|
82
|
+
cwd: workspaceRoot,
|
|
83
|
+
env: process.env,
|
|
84
|
+
encoding: "utf8",
|
|
85
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
86
|
+
});
|
|
87
|
+
if (result.error) {
|
|
88
|
+
throw new Error([
|
|
89
|
+
`nx-rust could not run \`${command}\`: ${result.error.message}.`,
|
|
90
|
+
"Install a Rust toolchain or put cargo on PATH, then run the generator again.",
|
|
91
|
+
].join("\n"));
|
|
92
|
+
}
|
|
93
|
+
if (result.status !== 0) {
|
|
94
|
+
const reason = result.signal
|
|
95
|
+
? `was stopped by ${result.signal}`
|
|
96
|
+
: `failed with status ${result.status}`;
|
|
97
|
+
throw new Error([`\`${command}\` ${reason}:`, result.stderr.trimEnd()].join("\n"));
|
|
98
|
+
}
|
|
99
|
+
process.stderr.write(result.stderr);
|
|
100
|
+
}
|
|
101
|
+
function displayPath(workspaceRoot, path) {
|
|
102
|
+
const inside = (0, node_path_1.relative)(workspaceRoot, path);
|
|
103
|
+
return inside.startsWith("..") ? path : inside;
|
|
104
|
+
}
|
|
105
|
+
function shellWord(word) {
|
|
106
|
+
return /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.split("'").join(`'"'"'`)}'`;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=crate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crate.js","sourceRoot":"","sources":["../../../../../nx-rust/src/generators/crate/crate.ts"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AAC;AACtC,CAAC;AAED,SAAS,WAAW,CAAC,aAAqB,EAAE,IAAY;IACtD,MAAM,MAAM,GAAG,IAAA,oBAAQ,EAAC,aAAa,EAAE,IAAI,CAAC,CAAC;IAC7C,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;AACjD,CAAC;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,OAAO,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;AACrF,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** The Cargo workspace that a new crate's folder lies in. */
|
|
2
|
+
export interface EnclosingWorkspace {
|
|
3
|
+
/** The absolute path of the workspace's root manifest. */
|
|
4
|
+
manifest: string;
|
|
5
|
+
/** The entries of `[workspace] exclude`, as written. */
|
|
6
|
+
exclude: string[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The workspace that will enclose a crate created in `folder`, found as
|
|
10
|
+
* cargo finds it: the nearest `Cargo.toml` above the folder that has a
|
|
11
|
+
* `[workspace]` table. `undefined` when there is none, so that the crate is
|
|
12
|
+
* a standalone crate. A manifest that is not valid TOML is passed over.
|
|
13
|
+
*
|
|
14
|
+
* @param folder The absolute path of the crate's folder.
|
|
15
|
+
*/
|
|
16
|
+
export declare function enclosingWorkspace(folder: string): EnclosingWorkspace | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* The entry of the workspace's `exclude` that leaves `folder` out of the
|
|
19
|
+
* workspace, or `undefined`. Cargo reads an entry as a path relative to the
|
|
20
|
+
* workspace root, not as a glob, and leaves out every folder at or below
|
|
21
|
+
* it.
|
|
22
|
+
*
|
|
23
|
+
* @param folder The absolute path of the crate's folder.
|
|
24
|
+
*/
|
|
25
|
+
export declare function excludingEntry(workspace: EnclosingWorkspace, folder: string): string | undefined;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enclosingWorkspace = enclosingWorkspace;
|
|
4
|
+
exports.excludingEntry = excludingEntry;
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const smol_toml_1 = require("smol-toml");
|
|
8
|
+
/**
|
|
9
|
+
* The workspace that will enclose a crate created in `folder`, found as
|
|
10
|
+
* cargo finds it: the nearest `Cargo.toml` above the folder that has a
|
|
11
|
+
* `[workspace]` table. `undefined` when there is none, so that the crate is
|
|
12
|
+
* a standalone crate. A manifest that is not valid TOML is passed over.
|
|
13
|
+
*
|
|
14
|
+
* @param folder The absolute path of the crate's folder.
|
|
15
|
+
*/
|
|
16
|
+
// @mara implements DES-GENERATORS
|
|
17
|
+
function enclosingWorkspace(folder) {
|
|
18
|
+
for (let above = (0, node_path_1.dirname)(folder);; above = (0, node_path_1.dirname)(above)) {
|
|
19
|
+
const manifest = (0, node_path_1.join)(above, "Cargo.toml");
|
|
20
|
+
const workspace = (0, node_fs_1.existsSync)(manifest) ? readWorkspaceTable(manifest) : undefined;
|
|
21
|
+
if (workspace !== undefined) {
|
|
22
|
+
const exclude = Array.isArray(workspace.exclude)
|
|
23
|
+
? workspace.exclude.filter((entry) => typeof entry === "string")
|
|
24
|
+
: [];
|
|
25
|
+
return { manifest, exclude };
|
|
26
|
+
}
|
|
27
|
+
if ((0, node_path_1.dirname)(above) === above) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The entry of the workspace's `exclude` that leaves `folder` out of the
|
|
34
|
+
* workspace, or `undefined`. Cargo reads an entry as a path relative to the
|
|
35
|
+
* workspace root, not as a glob, and leaves out every folder at or below
|
|
36
|
+
* it.
|
|
37
|
+
*
|
|
38
|
+
* @param folder The absolute path of the crate's folder.
|
|
39
|
+
*/
|
|
40
|
+
function excludingEntry(workspace, folder) {
|
|
41
|
+
const root = (0, node_path_1.dirname)(workspace.manifest);
|
|
42
|
+
return workspace.exclude.find((entry) => {
|
|
43
|
+
const path = (0, node_path_1.relative)((0, node_path_1.join)(root, entry), folder);
|
|
44
|
+
return path === "" || (path !== ".." && !path.startsWith(`..${node_path_1.sep}`) && !(0, node_path_1.isAbsolute)(path));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function readWorkspaceTable(manifest) {
|
|
48
|
+
try {
|
|
49
|
+
const workspace = (0, smol_toml_1.parse)((0, node_fs_1.readFileSync)(manifest, "utf8")).workspace;
|
|
50
|
+
return typeof workspace === "object" && workspace !== null && !Array.isArray(workspace)
|
|
51
|
+
? workspace
|
|
52
|
+
: undefined;
|
|
53
|
+
}
|
|
54
|
+
catch (_a) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=enclosing-workspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enclosing-workspace.js","sourceRoot":"","sources":["../../../../../nx-rust/src/generators/crate/enclosing-workspace.ts"],"names":[],"mappings":";;AAqBA,gDAcC;AAUD,wCAMC;AAnDD,qCAAmD;AACnD,yCAAqE;AACrE,yCAAkC;AAUlC;;;;;;;GAOG;AACH,kCAAkC;AAClC,SAAgB,kBAAkB,CAAC,MAAc;IAC/C,KAAK,IAAI,KAAK,GAAG,IAAA,mBAAO,EAAC,MAAM,CAAC,GAAI,KAAK,GAAG,IAAA,mBAAO,EAAC,KAAK,CAAC,EAAE,CAAC;QAC3D,MAAM,QAAQ,GAAG,IAAA,gBAAI,EAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QAC3C,MAAM,SAAS,GAAG,IAAA,oBAAU,EAAC,QAAQ,CAAC,CAAC,CAAC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AAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;YACrF,CAAC,CAAE,SAAqC;YACxC,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "NxRustLibrary",
|
|
4
|
+
"title": "Create a library crate",
|
|
5
|
+
"description": "Create a library crate with `cargo new --vcs none --lib`. Cargo adds it to the members of the Cargo workspace around the folder.",
|
|
6
|
+
"cli": "nx",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"directory": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "The crate's folder, relative to the folder you run nx in.",
|
|
12
|
+
"$default": {
|
|
13
|
+
"$source": "argv",
|
|
14
|
+
"index": 0
|
|
15
|
+
},
|
|
16
|
+
"x-prompt": "Which folder should the library crate be created in?"
|
|
17
|
+
},
|
|
18
|
+
"name": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "The package name. Without it, the crate is named after its folder."
|
|
21
|
+
},
|
|
22
|
+
"edition": {
|
|
23
|
+
"type": ["string", "number"],
|
|
24
|
+
"description": "The Rust edition, such as 2024. Without it, the crate takes the workspace's edition, or Cargo's default."
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"required": ["directory"]
|
|
28
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { NxJsonConfiguration, PluginConfiguration } from "@nx/devkit";
|
|
2
|
+
import type { CargoWorkspace } from "../../graph/discovery";
|
|
3
|
+
import type { FeatureUnification } from "../../graph/settings";
|
|
4
|
+
/** The name under which `nx.json` lists the plugin. */
|
|
5
|
+
export declare const pluginName = "@convesoft/nx-rust";
|
|
6
|
+
/** What graph creation found with the plugin's entries in `nx.json`. */
|
|
7
|
+
export interface GraphCheck {
|
|
8
|
+
/**
|
|
9
|
+
* The `Cargo.toml` files that Nx sees in the repository, relative to its
|
|
10
|
+
* root, before the entries' `include` and `exclude` apply.
|
|
11
|
+
*/
|
|
12
|
+
manifests: string[];
|
|
13
|
+
/** The Cargo workspaces the entries found, each once, in the order they were found. */
|
|
14
|
+
workspaces: CargoWorkspace[];
|
|
15
|
+
/**
|
|
16
|
+
* The roots of the workspaces whose settings choose the nextest runner
|
|
17
|
+
* (`testRunner`), relative to the repository root.
|
|
18
|
+
*/
|
|
19
|
+
nextestWorkspaces?: string[];
|
|
20
|
+
/**
|
|
21
|
+
* The roots of the workspaces whose settings turn on the selection of
|
|
22
|
+
* affected tests (`affectedTests`), relative to the repository root.
|
|
23
|
+
*/
|
|
24
|
+
affectedTestsWorkspaces?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* The feature-unification strategy that graph creation chose for each of
|
|
27
|
+
* them, by the workspace's root folder (`DES-UNIFICATION`).
|
|
28
|
+
*/
|
|
29
|
+
strategies?: ReadonlyMap<string, FeatureUnification>;
|
|
30
|
+
}
|
|
31
|
+
/** Graph creation would fail with the plugin's entries in `nx.json`. */
|
|
32
|
+
export declare class GraphCheckError extends Error {
|
|
33
|
+
/** The errors that Nx reports for graph creation, each as Nx words it. */
|
|
34
|
+
readonly errors: string[];
|
|
35
|
+
constructor(
|
|
36
|
+
/** The errors that Nx reports for graph creation, each as Nx words it. */
|
|
37
|
+
errors: string[]);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The installed Nx lacks the internal parts of Nx through which the check
|
|
41
|
+
* runs graph creation, or they work differently from what the check expects.
|
|
42
|
+
*/
|
|
43
|
+
export declare class UnsupportedNxError extends Error {
|
|
44
|
+
/** The version of the installed Nx, if it could be read. */
|
|
45
|
+
readonly nxVersion: string | undefined;
|
|
46
|
+
/** What is missing or different. */
|
|
47
|
+
readonly detail: string;
|
|
48
|
+
constructor(
|
|
49
|
+
/** The version of the installed Nx, if it could be read. */
|
|
50
|
+
nxVersion: string | undefined,
|
|
51
|
+
/** What is missing or different. */
|
|
52
|
+
detail: string);
|
|
53
|
+
}
|
|
54
|
+
/** Whether a `plugins` entry of `nx.json` is one of this plugin. */
|
|
55
|
+
export declare function isPluginEntry(entry: PluginConfiguration): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Creates the project graph as Nx would with `nxJson`, as far as the
|
|
58
|
+
* plugin's checks need it, without writing anything, and returns what the
|
|
59
|
+
* plugin found.
|
|
60
|
+
*
|
|
61
|
+
* First it checks the installed Nx as the plugin does when it loads. Then
|
|
62
|
+
* each entry of the plugin in `nxJson.plugins` runs the plugin's own
|
|
63
|
+
* `createNodes` through Nx's project-configuration step, together with the
|
|
64
|
+
* other plugins that `nxJson` lists and Nx's default plugins, in the order
|
|
65
|
+
* graph creation runs them. Nx hands each entry the `Cargo.toml` files of
|
|
66
|
+
* its workspace context that the entry's `include` and `exclude` let
|
|
67
|
+
* through, and merges the projects of all plugins, as graph creation does.
|
|
68
|
+
* Each entry's `createDependencies` then runs on the merged projects and
|
|
69
|
+
* the repository's files. Every check that graph creation makes in the
|
|
70
|
+
* plugin therefore runs here too, and the warnings it prints are printed
|
|
71
|
+
* again. Nx's project-configuration step and plugin loader are not part of
|
|
72
|
+
* its public API: the end-to-end suite checks them on each supported Nx
|
|
73
|
+
* major (`REQ-COMPATIBILITY`).
|
|
74
|
+
*
|
|
75
|
+
* @param nxJson `nx.json` as it would be, with the plugin's entries.
|
|
76
|
+
* @param workspaceRoot The absolute path of the repository root.
|
|
77
|
+
* @throws {GraphCheckError} When graph creation would fail.
|
|
78
|
+
* @throws {UnsupportedNxError} When the installed Nx lacks those internal
|
|
79
|
+
* parts, or they return something the check cannot read.
|
|
80
|
+
*/
|
|
81
|
+
export declare function checkGraphCreation(nxJson: NxJsonConfiguration, workspaceRoot: string): Promise<GraphCheck>;
|