@joshmossas/nx-cargo 0.6.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.
- package/.babelrc +3 -0
- package/.eslintrc.json +34 -0
- package/README.md +39 -0
- package/build.config.ts +10 -0
- package/dist/index.cjs +100 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +79 -0
- package/executors.json +25 -0
- package/generators.json +25 -0
- package/jest.config.ts +17 -0
- package/package.json +30 -0
- package/project.json +53 -0
- package/src/common/index.spec.ts +183 -0
- package/src/common/index.ts +358 -0
- package/src/common/schema.d.ts +111 -0
- package/src/executors/build/executor.ts +21 -0
- package/src/executors/build/schema.d.ts +39 -0
- package/src/executors/build/schema.json +77 -0
- package/src/executors/clippy/executor.ts +18 -0
- package/src/executors/clippy/schema.d.ts +34 -0
- package/src/executors/clippy/schema.json +29 -0
- package/src/executors/run/executor.ts +19 -0
- package/src/executors/run/schema.d.ts +32 -0
- package/src/executors/run/schema.json +77 -0
- package/src/executors/test/executor.ts +19 -0
- package/src/executors/test/schema.d.ts +22 -0
- package/src/executors/test/schema.json +73 -0
- package/src/generators/binary/files/Cargo.toml__template__ +8 -0
- package/src/generators/binary/files/src/main.rs__template__ +3 -0
- package/src/generators/binary/generator.spec.ts +75 -0
- package/src/generators/binary/generator.ts +76 -0
- package/src/generators/binary/schema.d.ts +6 -0
- package/src/generators/binary/schema.json +35 -0
- package/src/generators/init/files/Cargo.toml +2 -0
- package/src/generators/init/files/rust-toolchain.toml__template__ +2 -0
- package/src/generators/init/files/rustfmt.toml +0 -0
- package/src/generators/init/generator.spec.ts +49 -0
- package/src/generators/init/generator.ts +55 -0
- package/src/generators/init/schema.d.ts +7 -0
- package/src/generators/init/schema.json +14 -0
- package/src/generators/library/files/Cargo.toml__template__ +8 -0
- package/src/generators/library/files/src/lib.rs__template__ +13 -0
- package/src/generators/library/generator.spec.ts +96 -0
- package/src/generators/library/generator.ts +78 -0
- package/src/generators/library/schema.d.ts +6 -0
- package/src/generators/library/schema.json +35 -0
- package/src/graph/index.ts +189 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lib.json +12 -0
- package/tsconfig.spec.json +20 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ExecutorContext } from "@nx/devkit";
|
|
2
|
+
|
|
3
|
+
import { Target, parseCargoArgs, runCargo } from "../../common";
|
|
4
|
+
import CLIOptions from "./schema";
|
|
5
|
+
|
|
6
|
+
export default async function (opts: CLIOptions, ctx: ExecutorContext) {
|
|
7
|
+
try {
|
|
8
|
+
let [args, env] = parseCargoArgs(Target.Run, opts, ctx);
|
|
9
|
+
|
|
10
|
+
await runCargo(args, ctx, env);
|
|
11
|
+
|
|
12
|
+
return { success: true };
|
|
13
|
+
} catch (err) {
|
|
14
|
+
return {
|
|
15
|
+
success: false,
|
|
16
|
+
reason: err?.message,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CompilationOptions,
|
|
3
|
+
DisplayOptions,
|
|
4
|
+
FeatureSelection,
|
|
5
|
+
OutputOptions,
|
|
6
|
+
ManifestOptions,
|
|
7
|
+
PackageSelection,
|
|
8
|
+
EnvironmentOptions,
|
|
9
|
+
} from "../../common/schema";
|
|
10
|
+
|
|
11
|
+
// prettier-ignore
|
|
12
|
+
type Options =
|
|
13
|
+
& PackageSelection
|
|
14
|
+
& FeatureSelection
|
|
15
|
+
& CompilationOptions
|
|
16
|
+
& OutputOptions
|
|
17
|
+
& DisplayOptions
|
|
18
|
+
& ManifestOptions
|
|
19
|
+
& EnvironmentOptions
|
|
20
|
+
& { [key: string]: unknown }
|
|
21
|
+
& {
|
|
22
|
+
/**
|
|
23
|
+
* Copy final artifacts to this directory.
|
|
24
|
+
*
|
|
25
|
+
* This option is unstable and available only on the [nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
|
|
26
|
+
* and requires the `-Z unstable-options` flag to enable. See https://github.com/rust-lang/cargo/issues/6790
|
|
27
|
+
* for more information.
|
|
28
|
+
*/
|
|
29
|
+
outDir?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default Options;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 2,
|
|
3
|
+
"outputCapture": "direct-nodejs",
|
|
4
|
+
"$schema": "http://json-schema.org/schema",
|
|
5
|
+
"title": "Run executor",
|
|
6
|
+
"description": "",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"package": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "Specify the Cargo package, if different from the Nx project name."
|
|
12
|
+
},
|
|
13
|
+
"features": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "Space or comma separated list of features to activate, or \"all\"."
|
|
16
|
+
},
|
|
17
|
+
"noDefaultFeatures": {
|
|
18
|
+
"type": "boolean",
|
|
19
|
+
"description": "Do not activate the `default` feature of the package."
|
|
20
|
+
},
|
|
21
|
+
"target": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Build for the given architecture. The default is the host architecture. The general format of the triple is `<arch><sub>-<vendor>-<sys>-<abi>`. Run `rustc --print target-list` for a list of supported targets.\n\nThis may also be specified with the `build.target` [config value](https://doc.rust-lang.org/cargo/reference/config.html).\n\nNote that specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. See the [build cache](https://doc.rust-lang.org/cargo/guide/build-cache.html) documentation for more details."
|
|
24
|
+
},
|
|
25
|
+
"release": {
|
|
26
|
+
"type": "boolean",
|
|
27
|
+
"description": "Build optimized artifacts with the `release` profile. See the [PROFILES](https://doc.rust-lang.org/cargo/commands/cargo-build.html#profiles) section for details on how this affects profile selection."
|
|
28
|
+
},
|
|
29
|
+
"targetDir": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"description": "Directory for all generated artifacts and intermediate files. May also be specified with the `CARGO_TARGET_DIR` environment variable, or the `build.target-dir` [config value](https://doc.rust-lang.org/cargo/reference/config.html). Defaults to `target` in the root of the workspace."
|
|
32
|
+
},
|
|
33
|
+
"outDir": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"description": "Copy final artifacts to this directory.\n\nThis option is unstable and available only on the [nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html). See https://github.com/rust-lang/cargo/issues/6790 for more information."
|
|
36
|
+
},
|
|
37
|
+
"verbose": {
|
|
38
|
+
"type": "boolean",
|
|
39
|
+
"description": "Use verbose output. May also be specified with the term.verbose [config value](https://doc.rust-lang.org/cargo/reference/config.html).",
|
|
40
|
+
"alias": "v"
|
|
41
|
+
},
|
|
42
|
+
"veryVerbose": {
|
|
43
|
+
"type": "boolean",
|
|
44
|
+
"description": "Include extra output such as dependency warnings and build script output."
|
|
45
|
+
},
|
|
46
|
+
"quiet": {
|
|
47
|
+
"type": "boolean",
|
|
48
|
+
"description": "No output printed to stdout.",
|
|
49
|
+
"alias": "q"
|
|
50
|
+
},
|
|
51
|
+
"messageFormat": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"description": "The output format for diagnostic messages. Can be specified multiple times and consists of comma-separated values. Valid values:\n * `human` (default): Display in a human-readable text format. Conflicts with `short` and `json`.\n * `short`: Emit shorter, human-readable text messages. Conflicts with `human` and `json`.\n * `json`: Emit JSON messages to stdout. See [the reference](https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages) for more details. Conflicts with `human` and `short`.\n * `json-diagnostic-short`: Ensure the `rendered` field of JSON messages contains the \"short\" rendering from rustc. Cannot be used with `human` or `short`.\n * `json-diagnostic-rendered-ansi`: Ensure the `rendered` field of JSON messages contains embedded ANSI color codes for respecting rustc's default color scheme. Cannot be used with `human` or `short`.\n * `json-render-diagnostics`: Instruct Cargo to not include rustc diagnostics in JSON messages printed, but instead Cargo itself should render the JSON diagnostics coming from rustc. Cargo's own JSON diagnostics and others coming from rustc are still emitted. Cannot be used with `human` or `short`."
|
|
54
|
+
},
|
|
55
|
+
"locked": {
|
|
56
|
+
"type": "boolean",
|
|
57
|
+
"description": "Requires that the `Cargo.lock` file is up-to-date. If the lock file is missing, or it needs to be updated, Cargo will exit with an error."
|
|
58
|
+
},
|
|
59
|
+
"frozen": {
|
|
60
|
+
"type": "boolean",
|
|
61
|
+
"description": "Like `locked`, but prevents Cargo from attempting to access the network to determine if `Cargo.lock` is out-of-date."
|
|
62
|
+
},
|
|
63
|
+
"offline": {
|
|
64
|
+
"type": "boolean",
|
|
65
|
+
"description": "Prevents Cargo from accessing the network for any reason. Without this flag, Cargo will stop with an error if it needs to access the network and the network is not available. With this flag, Cargo will attempt to proceed without the network if possible."
|
|
66
|
+
},
|
|
67
|
+
"toolchain": {
|
|
68
|
+
"type": "string",
|
|
69
|
+
"description": "See the [rustup documentation](https://rust-lang.github.io/rustup/overrides.html) for more information about how toolchain overrides work."
|
|
70
|
+
},
|
|
71
|
+
"env": {
|
|
72
|
+
"type": "object",
|
|
73
|
+
"description": "Specify environment variables to set while running the Cargo command."
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"required": []
|
|
77
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ExecutorContext } from "@nx/devkit";
|
|
2
|
+
|
|
3
|
+
import { parseCargoArgs, runCargo, Target } from "../../common";
|
|
4
|
+
import CLIOptions from "./schema";
|
|
5
|
+
|
|
6
|
+
export default async function (opts: CLIOptions, ctx: ExecutorContext) {
|
|
7
|
+
try {
|
|
8
|
+
let [args, env] = parseCargoArgs(Target.Test, opts, ctx);
|
|
9
|
+
|
|
10
|
+
await runCargo(args, ctx, env);
|
|
11
|
+
|
|
12
|
+
return { success: true };
|
|
13
|
+
} catch (err) {
|
|
14
|
+
return {
|
|
15
|
+
success: false,
|
|
16
|
+
reason: err?.message,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CompilationOptions,
|
|
3
|
+
DisplayOptions,
|
|
4
|
+
EnvironmentOptions,
|
|
5
|
+
FeatureSelection,
|
|
6
|
+
ManifestOptions,
|
|
7
|
+
OutputOptions,
|
|
8
|
+
PackageSelection,
|
|
9
|
+
} from "../../common/schema";
|
|
10
|
+
|
|
11
|
+
// prettier-ignore
|
|
12
|
+
type Options =
|
|
13
|
+
& PackageSelection
|
|
14
|
+
& FeatureSelection
|
|
15
|
+
& CompilationOptions
|
|
16
|
+
& OutputOptions
|
|
17
|
+
& DisplayOptions
|
|
18
|
+
& ManifestOptions
|
|
19
|
+
& EnvironmentOptions
|
|
20
|
+
& { [key: string]: unknown };
|
|
21
|
+
|
|
22
|
+
export default Options;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 2,
|
|
3
|
+
"outputCapture": "direct-nodejs",
|
|
4
|
+
"$schema": "http://json-schema.org/schema",
|
|
5
|
+
"title": "Test executor",
|
|
6
|
+
"description": "",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"package": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "Specify the Cargo package, if different from the Nx project name."
|
|
12
|
+
},
|
|
13
|
+
"features": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "Space or comma separated list of features to activate, or \"all\"."
|
|
16
|
+
},
|
|
17
|
+
"noDefaultFeatures": {
|
|
18
|
+
"type": "boolean",
|
|
19
|
+
"description": "Do not activate the `default` feature of the package."
|
|
20
|
+
},
|
|
21
|
+
"target": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Build for the given architecture. The default is the host architecture. The general format of the triple is `<arch><sub>-<vendor>-<sys>-<abi>`. Run `rustc --print target-list` for a list of supported targets.\n\nThis may also be specified with the `build.target` [config value](https://doc.rust-lang.org/cargo/reference/config.html).\n\nNote that specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. See the [build cache](https://doc.rust-lang.org/cargo/guide/build-cache.html) documentation for more details."
|
|
24
|
+
},
|
|
25
|
+
"release": {
|
|
26
|
+
"type": "boolean",
|
|
27
|
+
"description": "Build optimized artifacts with the `release` profile. See the [PROFILES](https://doc.rust-lang.org/cargo/commands/cargo-build.html#profiles) section for details on how this affects profile selection."
|
|
28
|
+
},
|
|
29
|
+
"targetDir": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"description": "Directory for all generated artifacts and intermediate files. May also be specified with the `CARGO_TARGET_DIR` environment variable, or the `build.target-dir` [config value](https://doc.rust-lang.org/cargo/reference/config.html). Defaults to `target` in the root of the workspace."
|
|
32
|
+
},
|
|
33
|
+
"verbose": {
|
|
34
|
+
"type": "boolean",
|
|
35
|
+
"description": "Use verbose output. May also be specified with the term.verbose [config value](https://doc.rust-lang.org/cargo/reference/config.html).",
|
|
36
|
+
"alias": "v"
|
|
37
|
+
},
|
|
38
|
+
"veryVerbose": {
|
|
39
|
+
"type": "boolean",
|
|
40
|
+
"description": "Include extra output such as dependency warnings and build script output."
|
|
41
|
+
},
|
|
42
|
+
"quiet": {
|
|
43
|
+
"type": "boolean",
|
|
44
|
+
"description": "No output printed to stdout.",
|
|
45
|
+
"alias": "q"
|
|
46
|
+
},
|
|
47
|
+
"messageFormat": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"description": "The output format for diagnostic messages. Can be specified multiple times and consists of comma-separated values. Valid values:\n * `human` (default): Display in a human-readable text format. Conflicts with `short` and `json`.\n * `short`: Emit shorter, human-readable text messages. Conflicts with `human` and `json`.\n * `json`: Emit JSON messages to stdout. See [the reference](https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages) for more details. Conflicts with `human` and `short`.\n * `json-diagnostic-short`: Ensure the `rendered` field of JSON messages contains the \"short\" rendering from rustc. Cannot be used with `human` or `short`.\n * `json-diagnostic-rendered-ansi`: Ensure the `rendered` field of JSON messages contains embedded ANSI color codes for respecting rustc's default color scheme. Cannot be used with `human` or `short`.\n * `json-render-diagnostics`: Instruct Cargo to not include rustc diagnostics in JSON messages printed, but instead Cargo itself should render the JSON diagnostics coming from rustc. Cargo's own JSON diagnostics and others coming from rustc are still emitted. Cannot be used with `human` or `short`."
|
|
50
|
+
},
|
|
51
|
+
"locked": {
|
|
52
|
+
"type": "boolean",
|
|
53
|
+
"description": "Requires that the `Cargo.lock` file is up-to-date. If the lock file is missing, or it needs to be updated, Cargo will exit with an error."
|
|
54
|
+
},
|
|
55
|
+
"frozen": {
|
|
56
|
+
"type": "boolean",
|
|
57
|
+
"description": "Like `locked`, but prevents Cargo from attempting to access the network to determine if `Cargo.lock` is out-of-date."
|
|
58
|
+
},
|
|
59
|
+
"offline": {
|
|
60
|
+
"type": "boolean",
|
|
61
|
+
"description": "Prevents Cargo from accessing the network for any reason. Without this flag, Cargo will stop with an error if it needs to access the network and the network is not available. With this flag, Cargo will attempt to proceed without the network if possible."
|
|
62
|
+
},
|
|
63
|
+
"toolchain": {
|
|
64
|
+
"type": "string",
|
|
65
|
+
"description": "See the [rustup documentation](https://rust-lang.github.io/rustup/overrides.html) for more information about how toolchain overrides work."
|
|
66
|
+
},
|
|
67
|
+
"env": {
|
|
68
|
+
"type": "object",
|
|
69
|
+
"description": "Specify environment variables to set while running the Cargo command."
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"required": []
|
|
73
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Tree } from "@nx/devkit";
|
|
2
|
+
import { createTreeWithEmptyWorkspace } from "@nx/devkit/testing";
|
|
3
|
+
import runGenerator from "./generator";
|
|
4
|
+
|
|
5
|
+
describe("binary generator", () => {
|
|
6
|
+
let appTree: Tree;
|
|
7
|
+
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
appTree = createTreeWithEmptyWorkspace({ layout: "apps-libs" });
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe("with kebab-case project name", () => {
|
|
13
|
+
beforeAll(async () => {
|
|
14
|
+
await runGenerator(appTree, { name: "my-app" });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should create the correct file structure", () => {
|
|
18
|
+
let changes = appTree.listChanges();
|
|
19
|
+
let cargoToml = changes.find(c => c.path === "apps/my-app/Cargo.toml");
|
|
20
|
+
let libRs = changes.find(c => c.path === "apps/my-app/src/main.rs");
|
|
21
|
+
|
|
22
|
+
expect(cargoToml).toBeTruthy();
|
|
23
|
+
expect(libRs).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should populate project files with the correct content", () => {
|
|
27
|
+
let changes = appTree.listChanges();
|
|
28
|
+
let cargoContent = changes
|
|
29
|
+
.find(c => c.path === "apps/my-app/Cargo.toml")!
|
|
30
|
+
.content!.toString();
|
|
31
|
+
|
|
32
|
+
expect(cargoContent).toContain(`name = "my-app"`);
|
|
33
|
+
expect(cargoContent).toContain(`edition = "2021"`);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should add project to workspace members", () => {
|
|
37
|
+
let changes = appTree.listChanges();
|
|
38
|
+
let members = changes.find(c => c.path === "Cargo.toml")!.content!.toString();
|
|
39
|
+
|
|
40
|
+
expect(members).toContain(`"apps/my-app"`);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("with snake_case project name", () => {
|
|
45
|
+
beforeAll(async () => {
|
|
46
|
+
await runGenerator(appTree, { name: "my_app" });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should create the correct file structure", () => {
|
|
50
|
+
let changes = appTree.listChanges();
|
|
51
|
+
let cargoToml = changes.find(c => c.path === "apps/my_app/Cargo.toml");
|
|
52
|
+
let libRs = changes.find(c => c.path === "apps/my_app/src/main.rs");
|
|
53
|
+
|
|
54
|
+
expect(cargoToml).toBeTruthy();
|
|
55
|
+
expect(libRs).toBeTruthy();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should populate project files with the correct content", () => {
|
|
59
|
+
let changes = appTree.listChanges();
|
|
60
|
+
let cargoContent = changes
|
|
61
|
+
.find(c => c.path === "apps/my_app/Cargo.toml")!
|
|
62
|
+
.content!.toString();
|
|
63
|
+
|
|
64
|
+
expect(cargoContent).toContain(`name = "my_app"`);
|
|
65
|
+
expect(cargoContent).toContain(`edition = "2021"`);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should add project to workspace members", () => {
|
|
69
|
+
let changes = appTree.listChanges();
|
|
70
|
+
let members = changes.find(c => c.path === "Cargo.toml")!.content!.toString();
|
|
71
|
+
|
|
72
|
+
expect(members).toContain(`"apps/my_app"`);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Tree, addProjectConfiguration, formatFiles, generateFiles } from "@nx/devkit";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
GeneratorOptions,
|
|
6
|
+
normalizeGeneratorOptions,
|
|
7
|
+
updateWorkspaceMembers,
|
|
8
|
+
} from "../../common";
|
|
9
|
+
import cargoInit from "../init/generator";
|
|
10
|
+
import CLIOptions from "./schema";
|
|
11
|
+
|
|
12
|
+
// prettier-ignore
|
|
13
|
+
type Options = CLIOptions & GeneratorOptions;
|
|
14
|
+
|
|
15
|
+
export default async function (host: Tree, opts: CLIOptions) {
|
|
16
|
+
let options = normalizeGeneratorOptions("application", host, opts);
|
|
17
|
+
|
|
18
|
+
addProjectConfiguration(host, options.projectName, {
|
|
19
|
+
root: options.projectRoot,
|
|
20
|
+
projectType: "application",
|
|
21
|
+
sourceRoot: `${options.projectRoot}/src`,
|
|
22
|
+
targets: {
|
|
23
|
+
build: {
|
|
24
|
+
executor: "@nxrs/cargo:build",
|
|
25
|
+
options: {
|
|
26
|
+
profile: "dev",
|
|
27
|
+
},
|
|
28
|
+
configurations: {
|
|
29
|
+
production: {
|
|
30
|
+
profile: "release",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
dev: {
|
|
35
|
+
executor: "@nxrs/cargo:run",
|
|
36
|
+
options: {},
|
|
37
|
+
},
|
|
38
|
+
test: {
|
|
39
|
+
executor: "@nxrs/cargo:test",
|
|
40
|
+
options: {},
|
|
41
|
+
},
|
|
42
|
+
lint: {
|
|
43
|
+
executor: "@nxrs/cargo:clippy",
|
|
44
|
+
options: {
|
|
45
|
+
fix: false,
|
|
46
|
+
failOnWarnings: true,
|
|
47
|
+
noDeps: true,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
tags: options.parsedTags,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await addFiles(host, options);
|
|
55
|
+
updateWorkspaceMembers(host, options);
|
|
56
|
+
await formatFiles(host);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function addFiles(host: Tree, opts: Options) {
|
|
60
|
+
if (!host.exists("Cargo.toml")) {
|
|
61
|
+
await cargoInit(host, {});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let substitutions = {
|
|
65
|
+
projectName: opts.projectName,
|
|
66
|
+
edition: opts.edition,
|
|
67
|
+
template: "",
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
generateFiles(
|
|
71
|
+
host,
|
|
72
|
+
path.join(__dirname, "files"),
|
|
73
|
+
opts.projectRoot,
|
|
74
|
+
substitutions
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"id": "Binary",
|
|
4
|
+
"title": "",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"name": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "",
|
|
10
|
+
"$default": {
|
|
11
|
+
"$source": "argv",
|
|
12
|
+
"index": 0
|
|
13
|
+
},
|
|
14
|
+
"x-prompt": "What name would you like to use?"
|
|
15
|
+
},
|
|
16
|
+
"edition": {
|
|
17
|
+
"type": "number",
|
|
18
|
+
"description": "What Rust edition to use",
|
|
19
|
+
"default": 2021
|
|
20
|
+
},
|
|
21
|
+
"tags": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Add tags to the project (used for linting)",
|
|
24
|
+
"alias": "t"
|
|
25
|
+
},
|
|
26
|
+
"directory": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"description": "A directory where the project is placed",
|
|
29
|
+
"alias": "d"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"required": [
|
|
33
|
+
"name"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createTreeWithEmptyWorkspace } from "@nx/devkit/testing";
|
|
2
|
+
import { Tree } from "@nx/devkit";
|
|
3
|
+
|
|
4
|
+
import runGenerator from "./generator";
|
|
5
|
+
|
|
6
|
+
describe("init generator", () => {
|
|
7
|
+
let appTree: Tree;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
appTree = createTreeWithEmptyWorkspace();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should run successfully", async () => {
|
|
14
|
+
await runGenerator(appTree, {});
|
|
15
|
+
let changes = appTree.listChanges();
|
|
16
|
+
|
|
17
|
+
let cargoToml = changes.find(c => c.path === "Cargo.toml");
|
|
18
|
+
let toolchainToml = changes.find(c => c.path === "rust-toolchain.toml");
|
|
19
|
+
let rustfmtToml = changes.find(c => c.path === "rustfmt.toml");
|
|
20
|
+
|
|
21
|
+
expect(cargoToml).toBeTruthy();
|
|
22
|
+
expect(toolchainToml).toBeTruthy();
|
|
23
|
+
expect(rustfmtToml).toBeTruthy();
|
|
24
|
+
|
|
25
|
+
let content = toolchainToml?.content!.toString();
|
|
26
|
+
expect(content).toContain(`channel = "stable"`);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should respect the 'toolchain' CLI option", async () => {
|
|
30
|
+
await runGenerator(appTree, { toolchain: "nightly" });
|
|
31
|
+
let toolchainToml = appTree
|
|
32
|
+
.listChanges()
|
|
33
|
+
.find(c => c.path === "rust-toolchain.toml")!
|
|
34
|
+
.content!.toString();
|
|
35
|
+
|
|
36
|
+
expect(toolchainToml).toContain(`channel = "nightly"`);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should add the graph plugin to nx.json plugins", async () => {
|
|
40
|
+
await runGenerator(appTree, {});
|
|
41
|
+
let changes = appTree.listChanges();
|
|
42
|
+
|
|
43
|
+
let nxJson = changes.find(c => c.path === "nx.json");
|
|
44
|
+
expect(nxJson).toBeTruthy();
|
|
45
|
+
|
|
46
|
+
let json = JSON.parse(nxJson!.content!.toString());
|
|
47
|
+
expect(json.plugins).toContain("@nxrs/cargo");
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Tree,
|
|
3
|
+
formatFiles,
|
|
4
|
+
generateFiles,
|
|
5
|
+
readNxJson,
|
|
6
|
+
updateNxJson,
|
|
7
|
+
} from "@nx/devkit";
|
|
8
|
+
import * as path from "path";
|
|
9
|
+
|
|
10
|
+
import CLIOptions from "./schema";
|
|
11
|
+
|
|
12
|
+
// TODO: Add `buildable` option to `library` generator
|
|
13
|
+
// TODO: Add `format` executor via rustfmt
|
|
14
|
+
// TODO: Add `benchmark` generator/executor via Criterion
|
|
15
|
+
|
|
16
|
+
interface Options extends CLIOptions {
|
|
17
|
+
toolchain: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default async function (host: Tree, opts: CLIOptions) {
|
|
21
|
+
let options = normalizeOptions(host, opts);
|
|
22
|
+
addFiles(host, options);
|
|
23
|
+
addPlugin(host, options);
|
|
24
|
+
|
|
25
|
+
await formatFiles(host);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function normalizeOptions(_: Tree, options: CLIOptions): Options {
|
|
29
|
+
let toolchain = options.toolchain ?? "stable";
|
|
30
|
+
|
|
31
|
+
return { toolchain };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function addFiles(host: Tree, options: Options) {
|
|
35
|
+
let templateOptions = {
|
|
36
|
+
toolchain: options.toolchain,
|
|
37
|
+
template: "",
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
generateFiles(host, path.join(__dirname, "files"), ".", templateOptions);
|
|
41
|
+
|
|
42
|
+
let gitignore = host.read(".gitignore")?.toString() ?? "";
|
|
43
|
+
gitignore += "/target";
|
|
44
|
+
|
|
45
|
+
host.write(".gitignore", gitignore);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function addPlugin(host: Tree, _: Options) {
|
|
49
|
+
let config = readNxJson(host) ?? {};
|
|
50
|
+
let plugins = config.plugins
|
|
51
|
+
? config.plugins.concat("@nxrs/cargo")
|
|
52
|
+
: ["@nxrs/cargo"];
|
|
53
|
+
|
|
54
|
+
updateNxJson(host, { ...config, plugins });
|
|
55
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"id": "Cargo",
|
|
4
|
+
"title": "",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"toolchain": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "The rustup toolchain channel for projects in this workspace",
|
|
10
|
+
"$default": "stable"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"required": []
|
|
14
|
+
}
|