diff --git a/packages/cargo/package.json b/packages/cargo/package.json index 2b1e688..15d8be2 100644 --- a/packages/cargo/package.json +++ b/packages/cargo/package.json @@ -1,6 +1,6 @@ { "name": "@nxrs/cargo", - "version": "0.3.2", + "version": "0.3.3", "license": "MIT", "main": "src/index.js", "generators": "./generators.json", diff --git a/packages/cargo/src/common/index.spec.ts b/packages/cargo/src/common/index.spec.ts new file mode 100644 index 0000000..ca32824 --- /dev/null +++ b/packages/cargo/src/common/index.spec.ts @@ -0,0 +1,45 @@ +import { ExecutorContext } from "@nrwl/devkit"; +import { CargoOptions, parseCargoArgs } from "."; + +describe("common utils", () => { + describe("parseCargoArgs", () => { + it("should support --target argument", () => { + let ctx = mockExecutorContext("test-app:build"); + let opts: CargoOptions = { + target: "86_64-pc-windows-gnu", + }; + let args = parseCargoArgs(opts, ctx); + args.unshift("cargo"); + + expect(args.join(" ")).toEqual( + "cargo build --bin test-app --target 86_64-pc-windows-gnu" + ); + }); + }); +}); + +function mockExecutorContext(command: string): ExecutorContext { + let [projectName, targetName] = command.split(":"); + + return { + cwd: "C:/test", + root: "C:/test", + isVerbose: false, + workspace: { + npmScope: "@test", + projects: { + "test-app": { + root: "apps/test-app", + projectType: "application", + }, + "test-lib": { + root: "libs/test-lib", + projectType: "library", + }, + }, + version: 2, + }, + projectName, + targetName, + }; +} diff --git a/packages/cargo/src/common/index.ts b/packages/cargo/src/common/index.ts index c85a63a..7e0f5a3 100644 --- a/packages/cargo/src/common/index.ts +++ b/packages/cargo/src/common/index.ts @@ -20,7 +20,7 @@ export interface GeneratorOptions { } // prettier-ignore -type CargoOptions = Partial< +export type CargoOptions = Partial< & FeatureSelection & CompilationOptions & OutputOptions @@ -160,6 +160,7 @@ export function parseCargoArgs(opts: CargoOptions, ctx: ExecutorContext): string } if (opts.noDefaultFeatures) args.push("--no-default-features"); + if (opts.target) args.push("--target", opts.target); if (opts.release) args.push("--release"); if (opts.targetDir) args.push("--target-dir", opts.targetDir); if (opts.outDir) { diff --git a/packages/cargo/src/generators/binary/generator.spec.ts b/packages/cargo/src/generators/binary/generator.spec.ts index 0f8d131..2478839 100644 --- a/packages/cargo/src/generators/binary/generator.spec.ts +++ b/packages/cargo/src/generators/binary/generator.spec.ts @@ -26,7 +26,7 @@ describe("binary generator", () => { .content!.toString(); expect(cargoContent).toContain(`name = "my_app"`); - expect(cargoContent).toContain(`edition = "2018"`); + expect(cargoContent).toContain(`edition = "2021"`); }); it("should add project to workspace members", () => { diff --git a/packages/cargo/src/generators/library/generator.spec.ts b/packages/cargo/src/generators/library/generator.spec.ts index 39c03ba..3c58860 100644 --- a/packages/cargo/src/generators/library/generator.spec.ts +++ b/packages/cargo/src/generators/library/generator.spec.ts @@ -26,7 +26,7 @@ describe("library generator", () => { .content!.toString(); expect(cargoContent).toContain(`name = "my_library"`); - expect(cargoContent).toContain(`edition = "2018"`); + expect(cargoContent).toContain(`edition = "2021"`); let libRsContent = changes .find(c => c.path === "libs/my-library/src/lib.rs")!