Skip to content

Commit

Permalink
Merge pull request #15 from nxrs/missing-target-support
Browse files Browse the repository at this point in the history
Add support for `target` option
  • Loading branch information
dannymcgee authored May 25, 2022
2 parents 248bfda + baad7dc commit dc7fcf4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/cargo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nxrs/cargo",
"version": "0.3.2",
"version": "0.3.3",
"license": "MIT",
"main": "src/index.js",
"generators": "./generators.json",
Expand Down
45 changes: 45 additions & 0 deletions packages/cargo/src/common/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}
3 changes: 2 additions & 1 deletion packages/cargo/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface GeneratorOptions {
}

// prettier-ignore
type CargoOptions = Partial<
export type CargoOptions = Partial<
& FeatureSelection
& CompilationOptions
& OutputOptions
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cargo/src/generators/binary/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cargo/src/generators/library/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")!
Expand Down

0 comments on commit dc7fcf4

Please sign in to comment.