@convesoft/nx-rust 0.0.0 → 1.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (418) hide show
  1. package/LICENSE-APACHE +201 -0
  2. package/LICENSE-MIT +21 -0
  3. package/PLUGIN.md +106 -0
  4. package/README.md +51 -1
  5. package/docs/artifacts.mara.md +374 -0
  6. package/docs/caching.mara.md +999 -0
  7. package/docs/ci.mara.md +308 -0
  8. package/docs/configuration.mara.md +508 -0
  9. package/docs/decisions.mara.md +3267 -0
  10. package/docs/execution.mara.md +533 -0
  11. package/docs/index.mara.md +51 -0
  12. package/docs/product.mara.md +366 -0
  13. package/docs/release.mara.md +493 -0
  14. package/docs/setup.mara.md +486 -0
  15. package/docs/targets.mara.md +704 -0
  16. package/docs/testing.mara.md +431 -0
  17. package/docs/verification.mara.md +465 -0
  18. package/docs/workspaces.mara.md +445 -0
  19. package/executors.json +35 -0
  20. package/generators.json +19 -0
  21. package/package.json +17 -4
  22. package/src/cargo/build-settings.d.ts +61 -0
  23. package/src/cargo/build-settings.js +103 -0
  24. package/src/cargo/build-settings.js.map +1 -0
  25. package/src/cargo/configured-runner.d.ts +36 -0
  26. package/src/cargo/configured-runner.js +99 -0
  27. package/src/cargo/configured-runner.js.map +1 -0
  28. package/src/cargo/configured-tools.d.ts +35 -0
  29. package/src/cargo/configured-tools.js +46 -0
  30. package/src/cargo/configured-tools.js.map +1 -0
  31. package/src/cargo/dep-info-basedir.d.ts +18 -0
  32. package/src/cargo/dep-info-basedir.js +38 -0
  33. package/src/cargo/dep-info-basedir.js.map +1 -0
  34. package/src/cargo/directories.d.ts +40 -0
  35. package/src/cargo/directories.js +89 -0
  36. package/src/cargo/directories.js.map +1 -0
  37. package/src/cargo/host-triple.d.ts +7 -0
  38. package/src/cargo/host-triple.js +21 -0
  39. package/src/cargo/host-triple.js.map +1 -0
  40. package/src/cargo/lockfile.d.ts +63 -0
  41. package/src/cargo/lockfile.js +157 -0
  42. package/src/cargo/lockfile.js.map +1 -0
  43. package/src/cargo/metadata.d.ts +114 -0
  44. package/src/cargo/metadata.js +37 -0
  45. package/src/cargo/metadata.js.map +1 -0
  46. package/src/cargo/package-specs.d.ts +54 -0
  47. package/src/cargo/package-specs.js +109 -0
  48. package/src/cargo/package-specs.js.map +1 -0
  49. package/src/cargo/paths-crates.d.ts +27 -0
  50. package/src/cargo/paths-crates.js +69 -0
  51. package/src/cargo/paths-crates.js.map +1 -0
  52. package/src/cargo/print-artifact-folders.d.ts +1 -0
  53. package/src/cargo/print-artifact-folders.js +58 -0
  54. package/src/cargo/print-artifact-folders.js.map +1 -0
  55. package/src/cargo/redirections.d.ts +90 -0
  56. package/src/cargo/redirections.js +200 -0
  57. package/src/cargo/redirections.js.map +1 -0
  58. package/src/cargo/run-cargo.d.ts +31 -0
  59. package/src/cargo/run-cargo.js +75 -0
  60. package/src/cargo/run-cargo.js.map +1 -0
  61. package/src/cargo/target-triples.d.ts +98 -0
  62. package/src/cargo/target-triples.js +265 -0
  63. package/src/cargo/target-triples.js.map +1 -0
  64. package/src/cargo/version-req.d.ts +12 -0
  65. package/src/cargo/version-req.js +122 -0
  66. package/src/cargo/version-req.js.map +1 -0
  67. package/src/cargo/warnings-setting.d.ts +24 -0
  68. package/src/cargo/warnings-setting.js +81 -0
  69. package/src/cargo/warnings-setting.js.map +1 -0
  70. package/src/compatibility/cargo-version.d.ts +43 -0
  71. package/src/compatibility/cargo-version.js +83 -0
  72. package/src/compatibility/cargo-version.js.map +1 -0
  73. package/src/compatibility/nx-bridge.d.ts +312 -0
  74. package/src/compatibility/nx-bridge.js +407 -0
  75. package/src/compatibility/nx-bridge.js.map +1 -0
  76. package/src/compatibility/nx-version.d.ts +104 -0
  77. package/src/compatibility/nx-version.js +272 -0
  78. package/src/compatibility/nx-version.js.map +1 -0
  79. package/src/executors/affected-inputs.d.ts +29 -0
  80. package/src/executors/affected-inputs.js +259 -0
  81. package/src/executors/affected-inputs.js.map +1 -0
  82. package/src/executors/affected-run.d.ts +54 -0
  83. package/src/executors/affected-run.js +394 -0
  84. package/src/executors/affected-run.js.map +1 -0
  85. package/src/executors/affected.d.ts +239 -0
  86. package/src/executors/affected.js +589 -0
  87. package/src/executors/affected.js.map +1 -0
  88. package/src/executors/baseline-context.d.ts +85 -0
  89. package/src/executors/baseline-context.js +227 -0
  90. package/src/executors/baseline-context.js.map +1 -0
  91. package/src/executors/baseline.d.ts +123 -0
  92. package/src/executors/baseline.js +356 -0
  93. package/src/executors/baseline.js.map +1 -0
  94. package/src/executors/batch.d.ts +75 -0
  95. package/src/executors/batch.js +434 -0
  96. package/src/executors/batch.js.map +1 -0
  97. package/src/executors/build-records.d.ts +110 -0
  98. package/src/executors/build-records.js +267 -0
  99. package/src/executors/build-records.js.map +1 -0
  100. package/src/executors/cargo/executor.d.ts +28 -0
  101. package/src/executors/cargo/executor.js +58 -0
  102. package/src/executors/cargo/executor.js.map +1 -0
  103. package/src/executors/cargo/schema.json +58 -0
  104. package/src/executors/cargo-invocation.d.ts +81 -0
  105. package/src/executors/cargo-invocation.js +109 -0
  106. package/src/executors/cargo-invocation.js.map +1 -0
  107. package/src/executors/cargo-output.d.ts +218 -0
  108. package/src/executors/cargo-output.js +660 -0
  109. package/src/executors/cargo-output.js.map +1 -0
  110. package/src/executors/command.d.ts +331 -0
  111. package/src/executors/command.js +547 -0
  112. package/src/executors/command.js.map +1 -0
  113. package/src/executors/coverage-baseline.d.ts +23 -0
  114. package/src/executors/coverage-baseline.js +284 -0
  115. package/src/executors/coverage-baseline.js.map +1 -0
  116. package/src/executors/declared-options.d.ts +21 -0
  117. package/src/executors/declared-options.js +58 -0
  118. package/src/executors/declared-options.js.map +1 -0
  119. package/src/executors/denied-warnings.d.ts +99 -0
  120. package/src/executors/denied-warnings.js +188 -0
  121. package/src/executors/denied-warnings.js.map +1 -0
  122. package/src/executors/digests.d.ts +94 -0
  123. package/src/executors/digests.js +190 -0
  124. package/src/executors/digests.js.map +1 -0
  125. package/src/executors/dotenv-check.d.ts +79 -0
  126. package/src/executors/dotenv-check.js +553 -0
  127. package/src/executors/dotenv-check.js.map +1 -0
  128. package/src/executors/group-invocations.d.ts +80 -0
  129. package/src/executors/group-invocations.js +253 -0
  130. package/src/executors/group-invocations.js.map +1 -0
  131. package/src/executors/group-run.d.ts +114 -0
  132. package/src/executors/group-run.js +601 -0
  133. package/src/executors/group-run.js.map +1 -0
  134. package/src/executors/groups.d.ts +118 -0
  135. package/src/executors/groups.js +304 -0
  136. package/src/executors/groups.js.map +1 -0
  137. package/src/executors/input-check.d.ts +52 -0
  138. package/src/executors/input-check.js +271 -0
  139. package/src/executors/input-check.js.map +1 -0
  140. package/src/executors/kept-files.d.ts +98 -0
  141. package/src/executors/kept-files.js +341 -0
  142. package/src/executors/kept-files.js.map +1 -0
  143. package/src/executors/lockfile/executor.d.ts +16 -0
  144. package/src/executors/lockfile/executor.js +37 -0
  145. package/src/executors/lockfile/executor.js.map +1 -0
  146. package/src/executors/lockfile/schema.json +50 -0
  147. package/src/executors/napi-build.d.ts +73 -0
  148. package/src/executors/napi-build.js +420 -0
  149. package/src/executors/napi-build.js.map +1 -0
  150. package/src/executors/nextest.d.ts +189 -0
  151. package/src/executors/nextest.js +504 -0
  152. package/src/executors/nextest.js.map +1 -0
  153. package/src/executors/nx-command.d.ts +95 -0
  154. package/src/executors/nx-command.js +205 -0
  155. package/src/executors/nx-command.js.map +1 -0
  156. package/src/executors/nx-task-files.d.ts +82 -0
  157. package/src/executors/nx-task-files.js +156 -0
  158. package/src/executors/nx-task-files.js.map +1 -0
  159. package/src/executors/print-test-mode.d.ts +1 -0
  160. package/src/executors/print-test-mode.js +25 -0
  161. package/src/executors/print-test-mode.js.map +1 -0
  162. package/src/executors/release-publish/executor.d.ts +24 -0
  163. package/src/executors/release-publish/executor.js +165 -0
  164. package/src/executors/release-publish/executor.js.map +1 -0
  165. package/src/executors/release-publish/schema.json +30 -0
  166. package/src/executors/run/executor.d.ts +12 -0
  167. package/src/executors/run/executor.js +27 -0
  168. package/src/executors/run/executor.js.map +1 -0
  169. package/src/executors/run/schema.json +45 -0
  170. package/src/executors/runner-script.d.ts +12 -0
  171. package/src/executors/runner-script.js +22 -0
  172. package/src/executors/runner-script.js.map +1 -0
  173. package/src/executors/runtime-input-check.d.ts +24 -0
  174. package/src/executors/runtime-input-check.js +87 -0
  175. package/src/executors/runtime-input-check.js.map +1 -0
  176. package/src/executors/shared-artifacts.d.ts +44 -0
  177. package/src/executors/shared-artifacts.js +132 -0
  178. package/src/executors/shared-artifacts.js.map +1 -0
  179. package/src/executors/split-words.d.ts +24 -0
  180. package/src/executors/split-words.js +111 -0
  181. package/src/executors/split-words.js.map +1 -0
  182. package/src/executors/stage.d.ts +163 -0
  183. package/src/executors/stage.js +526 -0
  184. package/src/executors/stage.js.map +1 -0
  185. package/src/executors/staged-run.d.ts +24 -0
  186. package/src/executors/staged-run.js +110 -0
  187. package/src/executors/staged-run.js.map +1 -0
  188. package/src/executors/task-env.d.ts +271 -0
  189. package/src/executors/task-env.js +494 -0
  190. package/src/executors/task-env.js.map +1 -0
  191. package/src/executors/task-execution.d.ts +61 -0
  192. package/src/executors/task-execution.js +122 -0
  193. package/src/executors/task-execution.js.map +1 -0
  194. package/src/executors/task-guards.d.ts +112 -0
  195. package/src/executors/task-guards.js +435 -0
  196. package/src/executors/task-guards.js.map +1 -0
  197. package/src/executors/task-options.d.ts +114 -0
  198. package/src/executors/task-options.js +258 -0
  199. package/src/executors/task-options.js.map +1 -0
  200. package/src/executors/task.d.ts +166 -0
  201. package/src/executors/task.js +527 -0
  202. package/src/executors/task.js.map +1 -0
  203. package/src/executors/test-mode.d.ts +185 -0
  204. package/src/executors/test-mode.js +397 -0
  205. package/src/executors/test-mode.js.map +1 -0
  206. package/src/executors/test-runner.d.ts +44 -0
  207. package/src/executors/test-runner.js +159 -0
  208. package/src/executors/test-runner.js.map +1 -0
  209. package/src/executors/test-steps.d.ts +121 -0
  210. package/src/executors/test-steps.js +566 -0
  211. package/src/executors/test-steps.js.map +1 -0
  212. package/src/executors/wasm-build.d.ts +56 -0
  213. package/src/executors/wasm-build.js +216 -0
  214. package/src/executors/wasm-build.js.map +1 -0
  215. package/src/generators/crate/binary.schema.json +28 -0
  216. package/src/generators/crate/crate.d.ts +24 -0
  217. package/src/generators/crate/crate.js +108 -0
  218. package/src/generators/crate/crate.js.map +1 -0
  219. package/src/generators/crate/enclosing-workspace.d.ts +25 -0
  220. package/src/generators/crate/enclosing-workspace.js +58 -0
  221. package/src/generators/crate/enclosing-workspace.js.map +1 -0
  222. package/src/generators/crate/library.schema.json +28 -0
  223. package/src/generators/init/graph-check.d.ts +81 -0
  224. package/src/generators/init/graph-check.js +299 -0
  225. package/src/generators/init/graph-check.js.map +1 -0
  226. package/src/generators/init/init.d.ts +23 -0
  227. package/src/generators/init/init.js +113 -0
  228. package/src/generators/init/init.js.map +1 -0
  229. package/src/generators/init/report.d.ts +19 -0
  230. package/src/generators/init/report.js +93 -0
  231. package/src/generators/init/report.js.map +1 -0
  232. package/src/generators/init/schema.json +9 -0
  233. package/src/graph/artifact-kinds.d.ts +29 -0
  234. package/src/graph/artifact-kinds.js +50 -0
  235. package/src/graph/artifact-kinds.js.map +1 -0
  236. package/src/graph/artifact-names.d.ts +97 -0
  237. package/src/graph/artifact-names.js +276 -0
  238. package/src/graph/artifact-names.js.map +1 -0
  239. package/src/graph/build-records.d.ts +74 -0
  240. package/src/graph/build-records.js +104 -0
  241. package/src/graph/build-records.js.map +1 -0
  242. package/src/graph/caching.d.ts +148 -0
  243. package/src/graph/caching.js +681 -0
  244. package/src/graph/caching.js.map +1 -0
  245. package/src/graph/clippy-input.d.ts +53 -0
  246. package/src/graph/clippy-input.js +107 -0
  247. package/src/graph/clippy-input.js.map +1 -0
  248. package/src/graph/collisions.d.ts +113 -0
  249. package/src/graph/collisions.js +156 -0
  250. package/src/graph/collisions.js.map +1 -0
  251. package/src/graph/computation-reports.d.ts +89 -0
  252. package/src/graph/computation-reports.js +216 -0
  253. package/src/graph/computation-reports.js.map +1 -0
  254. package/src/graph/declared-files.d.ts +190 -0
  255. package/src/graph/declared-files.js +600 -0
  256. package/src/graph/declared-files.js.map +1 -0
  257. package/src/graph/discovery.d.ts +190 -0
  258. package/src/graph/discovery.js +661 -0
  259. package/src/graph/discovery.js.map +1 -0
  260. package/src/graph/edges.d.ts +25 -0
  261. package/src/graph/edges.js +94 -0
  262. package/src/graph/edges.js.map +1 -0
  263. package/src/graph/entries.d.ts +83 -0
  264. package/src/graph/entries.js +259 -0
  265. package/src/graph/entries.js.map +1 -0
  266. package/src/graph/inputs.d.ts +422 -0
  267. package/src/graph/inputs.js +756 -0
  268. package/src/graph/inputs.js.map +1 -0
  269. package/src/graph/lockfile-task.d.ts +74 -0
  270. package/src/graph/lockfile-task.js +105 -0
  271. package/src/graph/lockfile-task.js.map +1 -0
  272. package/src/graph/names.d.ts +41 -0
  273. package/src/graph/names.js +34 -0
  274. package/src/graph/names.js.map +1 -0
  275. package/src/graph/napi.d.ts +107 -0
  276. package/src/graph/napi.js +206 -0
  277. package/src/graph/napi.js.map +1 -0
  278. package/src/graph/nx-glob.d.ts +36 -0
  279. package/src/graph/nx-glob.js +152 -0
  280. package/src/graph/nx-glob.js.map +1 -0
  281. package/src/graph/nx-internals.d.ts +57 -0
  282. package/src/graph/nx-internals.js +128 -0
  283. package/src/graph/nx-internals.js.map +1 -0
  284. package/src/graph/options.d.ts +32 -0
  285. package/src/graph/options.js +80 -0
  286. package/src/graph/options.js.map +1 -0
  287. package/src/graph/outputs.d.ts +75 -0
  288. package/src/graph/outputs.js +140 -0
  289. package/src/graph/outputs.js.map +1 -0
  290. package/src/graph/path-dependencies.d.ts +122 -0
  291. package/src/graph/path-dependencies.js +459 -0
  292. package/src/graph/path-dependencies.js.map +1 -0
  293. package/src/graph/plugin-package.d.ts +36 -0
  294. package/src/graph/plugin-package.js +132 -0
  295. package/src/graph/plugin-package.js.map +1 -0
  296. package/src/graph/plugin-version.d.ts +20 -0
  297. package/src/graph/plugin-version.js +153 -0
  298. package/src/graph/plugin-version.js.map +1 -0
  299. package/src/graph/projects.d.ts +141 -0
  300. package/src/graph/projects.js +193 -0
  301. package/src/graph/projects.js.map +1 -0
  302. package/src/graph/reached-projects.d.ts +46 -0
  303. package/src/graph/reached-projects.js +102 -0
  304. package/src/graph/reached-projects.js.map +1 -0
  305. package/src/graph/real-path.d.ts +47 -0
  306. package/src/graph/real-path.js +113 -0
  307. package/src/graph/real-path.js.map +1 -0
  308. package/src/graph/redirected-uses.d.ts +98 -0
  309. package/src/graph/redirected-uses.js +434 -0
  310. package/src/graph/redirected-uses.js.map +1 -0
  311. package/src/graph/registration.d.ts +121 -0
  312. package/src/graph/registration.js +233 -0
  313. package/src/graph/registration.js.map +1 -0
  314. package/src/graph/rustfmt-config.d.ts +42 -0
  315. package/src/graph/rustfmt-config.js +173 -0
  316. package/src/graph/rustfmt-config.js.map +1 -0
  317. package/src/graph/script-input.d.ts +46 -0
  318. package/src/graph/script-input.js +65 -0
  319. package/src/graph/script-input.js.map +1 -0
  320. package/src/graph/settings.d.ts +178 -0
  321. package/src/graph/settings.js +479 -0
  322. package/src/graph/settings.js.map +1 -0
  323. package/src/graph/target-defaults-causes.d.ts +33 -0
  324. package/src/graph/target-defaults-causes.js +202 -0
  325. package/src/graph/target-defaults-causes.js.map +1 -0
  326. package/src/graph/target-defaults-layers.d.ts +186 -0
  327. package/src/graph/target-defaults-layers.js +420 -0
  328. package/src/graph/target-defaults-layers.js.map +1 -0
  329. package/src/graph/target-defaults-meaning.d.ts +95 -0
  330. package/src/graph/target-defaults-meaning.js +292 -0
  331. package/src/graph/target-defaults-meaning.js.map +1 -0
  332. package/src/graph/target-defaults-report.d.ts +77 -0
  333. package/src/graph/target-defaults-report.js +242 -0
  334. package/src/graph/target-defaults-report.js.map +1 -0
  335. package/src/graph/target-defaults.d.ts +79 -0
  336. package/src/graph/target-defaults.js +425 -0
  337. package/src/graph/target-defaults.js.map +1 -0
  338. package/src/graph/target-fields.d.ts +16 -0
  339. package/src/graph/target-fields.js +134 -0
  340. package/src/graph/target-fields.js.map +1 -0
  341. package/src/graph/target-tables.d.ts +45 -0
  342. package/src/graph/target-tables.js +299 -0
  343. package/src/graph/target-tables.js.map +1 -0
  344. package/src/graph/targets.d.ts +371 -0
  345. package/src/graph/targets.js +408 -0
  346. package/src/graph/targets.js.map +1 -0
  347. package/src/graph/unification.d.ts +141 -0
  348. package/src/graph/unification.js +459 -0
  349. package/src/graph/unification.js.map +1 -0
  350. package/src/graph/unignored-directories.d.ts +25 -0
  351. package/src/graph/unignored-directories.js +89 -0
  352. package/src/graph/unignored-directories.js.map +1 -0
  353. package/src/graph/visibility.d.ts +17 -0
  354. package/src/graph/visibility.js +67 -0
  355. package/src/graph/visibility.js.map +1 -0
  356. package/src/graph/warnings.d.ts +38 -0
  357. package/src/graph/warnings.js +77 -0
  358. package/src/graph/warnings.js.map +1 -0
  359. package/src/graph/wasm.d.ts +56 -0
  360. package/src/graph/wasm.js +77 -0
  361. package/src/graph/wasm.js.map +1 -0
  362. package/src/index.d.ts +68 -0
  363. package/src/index.js +109 -0
  364. package/src/index.js.map +1 -0
  365. package/src/release/manifests.d.ts +95 -0
  366. package/src/release/manifests.js +164 -0
  367. package/src/release/manifests.js.map +1 -0
  368. package/src/release/places.d.ts +127 -0
  369. package/src/release/places.js +368 -0
  370. package/src/release/places.js.map +1 -0
  371. package/src/release/publish-cargo.d.ts +177 -0
  372. package/src/release/publish-cargo.js +351 -0
  373. package/src/release/publish-cargo.js.map +1 -0
  374. package/src/release/publish-crates.d.ts +124 -0
  375. package/src/release/publish-crates.js +242 -0
  376. package/src/release/publish-crates.js.map +1 -0
  377. package/src/release/publish-environments.d.ts +50 -0
  378. package/src/release/publish-environments.js +284 -0
  379. package/src/release/publish-environments.js.map +1 -0
  380. package/src/release/publish-messages.d.ts +66 -0
  381. package/src/release/publish-messages.js +273 -0
  382. package/src/release/publish-messages.js.map +1 -0
  383. package/src/release/publish-registry.d.ts +27 -0
  384. package/src/release/publish-registry.js +135 -0
  385. package/src/release/publish-registry.js.map +1 -0
  386. package/src/release/publish-settings.d.ts +26 -0
  387. package/src/release/publish-settings.js +56 -0
  388. package/src/release/publish-settings.js.map +1 -0
  389. package/src/release/publish.d.ts +59 -0
  390. package/src/release/publish.js +620 -0
  391. package/src/release/publish.js.map +1 -0
  392. package/src/release/repository.d.ts +73 -0
  393. package/src/release/repository.js +219 -0
  394. package/src/release/repository.js.map +1 -0
  395. package/src/release/requirements.d.ts +34 -0
  396. package/src/release/requirements.js +30 -0
  397. package/src/release/requirements.js.map +1 -0
  398. package/src/release/toml-edit.d.ts +67 -0
  399. package/src/release/toml-edit.js +453 -0
  400. package/src/release/toml-edit.js.map +1 -0
  401. package/src/release/version-actions.d.ts +133 -0
  402. package/src/release/version-actions.js +474 -0
  403. package/src/release/version-actions.js.map +1 -0
  404. package/src/release/version-checks.d.ts +21 -0
  405. package/src/release/version-checks.js +151 -0
  406. package/src/release/version-checks.js.map +1 -0
  407. package/src/release/version-lockfiles.d.ts +61 -0
  408. package/src/release/version-lockfiles.js +222 -0
  409. package/src/release/version-lockfiles.js.map +1 -0
  410. package/src/tools/napi-cli.d.ts +70 -0
  411. package/src/tools/napi-cli.js +63 -0
  412. package/src/tools/napi-cli.js.map +1 -0
  413. package/src/tools/optional-tools.d.ts +121 -0
  414. package/src/tools/optional-tools.js +303 -0
  415. package/src/tools/optional-tools.js.map +1 -0
  416. package/src/tools/print-napi-cli.d.ts +1 -0
  417. package/src/tools/print-napi-cli.js +24 -0
  418. package/src/tools/print-napi-cli.js.map +1 -0
@@ -0,0 +1,56 @@
1
+ import type { TargetCargoMetadata } from "../graph/targets";
2
+ import { type WasmTarget } from "../graph/wasm";
3
+ import { type GroupMember, type LiveOutput, type MemberResult } from "./group-run";
4
+ /** What a `wasm-build` task needs beyond a `build` task, from its checks before cargo. */
5
+ export interface WasmTask {
6
+ /** The absolute path of the crate's folder, which holds the package folder. */
7
+ crateFolder: string;
8
+ /** The absolute path of the `wasm-bindgen` CLI that the task runs. */
9
+ cli: string;
10
+ /** The CLI's version, which matches the `wasm-bindgen` crate in the lockfile. */
11
+ version: string;
12
+ /** The wasm target, the CLI's `--target`. */
13
+ wasmTarget: WasmTarget;
14
+ }
15
+ /** Thrown by {@link prepareWasmTask} with the message with which the task fails before cargo. */
16
+ export declare class WasmTaskError extends Error {
17
+ constructor(message: string);
18
+ }
19
+ /**
20
+ * The checks of a `wasm-build` task before cargo runs (`DES-WASM`, "What
21
+ * the step needs"; `DES-DIAGNOSTICS`), in this order:
22
+ *
23
+ * - the crate's library has the file name of another crate's file, which
24
+ * graph creation records ({@link TargetCargoMetadata.sharedLibrary}), so
25
+ * that cargo builds one `.wasm` file for both;
26
+ * - the `wasmTarget` option is none of `bundler`, `web` and `nodejs`;
27
+ * - the toolchain that the workspace root selects has no standard library
28
+ * for the wasm triple;
29
+ * - the `wasm-bindgen` CLI is not on the task's `PATH`, as cargo looks it
30
+ * up in the workspace root, or does not say its version;
31
+ * - the lockfile, which the lockfile task has brought up to date, reaches
32
+ * no `wasm-bindgen` crate from the crate's entry, or several versions, or
33
+ * one of another version than the CLI.
34
+ *
35
+ * The plugin installs nothing (`ADR-V1-SCOPE`).
36
+ *
37
+ * @param crateFolder The absolute path of the crate's folder.
38
+ * @param cwd The absolute path of the workspace root, where cargo runs.
39
+ * @param version The crate's version where graph creation recorded it.
40
+ * @throws {WasmTaskError} With the message of the first check that fails.
41
+ */
42
+ export declare function prepareWasmTask(task: string, crate: string, metadata: TargetCargoMetadata, crateFolder: string, cwd: string, env: NodeJS.ProcessEnv, options: {
43
+ wasmTarget?: unknown;
44
+ }, repositoryRoot: string, version?: string): WasmTask;
45
+ /**
46
+ * Runs a group of `wasm-build` tasks (`DES-WASM`): the group's compile for
47
+ * the wasm triple, as a group of `build` runs it, with the checks after
48
+ * cargo of `build` ({@link runGroup}); then, for each task whose crate
49
+ * passed, the `wasm-bindgen` CLI on the `.wasm` file that cargo reported for
50
+ * the crate's `cdylib` in this compile, into the crate's package folder,
51
+ * which it empties first. A task fails where cargo reported no such file
52
+ * for its crate, or more than one, and where the CLI fails.
53
+ *
54
+ * @returns One result per member, in order.
55
+ */
56
+ export declare function runWasmGroup(members: readonly GroupMember[], verbose?: boolean, live?: LiveOutput): Promise<MemberResult[]>;
@@ -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+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E,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"],"names":[],"mappings":";;AAoBA,4CAKC;AAID,0CAKC;AA0DD,4CAQC;;AApGD,2DAA+C;AAC/C,yCAA2C;AAC3C,uCAA+F;AAC/F,+DAA2E;AAe3E,sDAAsD;AACtD,kCAAkC;AAClC,SAAgB,gBAAgB,CAC9B,IAAU,EACV,OAA6B;IAE7B,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED,qDAAqD;AACrD,kCAAkC;AAClC,SAAgB,eAAe,CAC7B,IAAU,EACV,OAA6B;IAE7B,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;;GAQG;AACH,SAAe,cAAc,CAC3B,IAAU,EACV,OAA6B,EAC7B,IAAmB;;QAEnB,MAAM,SAAS,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACjE,MAAM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AAK,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb;YACE,2BAA2B,OAAO,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG;YAChE,8EAA8E;SAC/E,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM;YAC1B,CAAC,CAAC,kBAAkB,MAAM,CAAC,MAAM,EAAE;YACnC,CAAC,CAAC,sBAAsB,MAAM,CAAC,MAAM,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,CAAC,KAAK,OAAO,MAAM,MAAM,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;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,CAAC,kB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,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
+ }