From c0cb5d6b0a6768d1aa11a7fdf0b1fd833f5e0d53 Mon Sep 17 00:00:00 2001 From: Danny McGee Date: Tue, 24 May 2022 22:31:55 -0400 Subject: [PATCH 1/3] Add support for `target` option --- packages/cargo/src/common/index.spec.ts | 45 +++++++++++++++++++++++++ packages/cargo/src/common/index.ts | 3 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 packages/cargo/src/common/index.spec.ts 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) { From fcfff666c939dfa8f58c7fea0e76a1542a8512b3 Mon Sep 17 00:00:00 2001 From: Danny McGee Date: Tue, 24 May 2022 22:32:10 -0400 Subject: [PATCH 2/3] Update edition in generator tests --- packages/cargo/src/generators/binary/generator.spec.ts | 2 +- packages/cargo/src/generators/library/generator.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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")! From baad7dc78f7736cbfbee65d6568c5d2a7264b49a Mon Sep 17 00:00:00 2001 From: Danny McGee Date: Tue, 24 May 2022 22:51:41 -0400 Subject: [PATCH 3/3] v0.3.3 --- packages/cargo/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",