Skip to content

Commit 995032c

Browse files
TravisCalderRyan-Gordon
authored andcommitted
- Run fmt to ensure lint passes
- Update tests to correct some pre-existing failures and test around strictMode
1 parent dce1fa4 commit 995032c

File tree

2 files changed

+57
-47
lines changed

2 files changed

+57
-47
lines changed

index.js

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,13 @@ class RustPlugin {
7575
""
7676
).split(/\s+/);
7777

78+
let target = (funcArgs || {}).target || this.custom.target;
7879

79-
let target = (funcArgs || {}).target || this.custom.target
80-
81-
const targetArgs =
82-
target ?
83-
['--target', target]
84-
: MUSL_PLATFORMS.includes(platform)
85-
? ["--target", "x86_64-unknown-linux-musl"]
86-
: [];
80+
const targetArgs = target
81+
? ["--target", target]
82+
: MUSL_PLATFORMS.includes(platform)
83+
? ["--target", "x86_64-unknown-linux-musl"]
84+
: [];
8785
return [
8886
...defaultArgs,
8987
...profileArgs,
@@ -95,30 +93,29 @@ class RustPlugin {
9593
localBuildEnv(funcArgs, env, platform) {
9694
const defaultEnv = { ...env };
9795

98-
let target = (funcArgs || {}).target || this.custom.target
99-
let linker = (funcArgs || {}).linker || this.custom.linker
96+
let target = (funcArgs || {}).target || this.custom.target;
97+
let linker = (funcArgs || {}).linker || this.custom.linker;
10098

101-
const platformEnv =
102-
linker ?
103-
{
99+
const platformEnv = linker
100+
? {
104101
RUSTFLAGS: (env["RUSTFLAGS"] || "") + ` -Clinker=${linker}`,
105102
TARGET_CC: linker,
106-
[`CC_${target || 'x86_64_unknown_linux_musl'}`]: linker,
103+
[`CC_${target || "x86_64_unknown_linux_musl"}`]: linker,
104+
}
105+
: "win32" === platform
106+
? {
107+
RUSTFLAGS: (env["RUSTFLAGS"] || "") + " -Clinker=rust-lld",
108+
TARGET_CC: "rust-lld",
109+
CC_x86_64_unknown_linux_musl: "rust-lld",
110+
}
111+
: "darwin" === platform
112+
? {
113+
RUSTFLAGS:
114+
(env["RUSTFLAGS"] || "") + " -Clinker=x86_64-linux-musl-gcc",
115+
TARGET_CC: "x86_64-linux-musl-gcc",
116+
CC_x86_64_unknown_linux_musl: "x86_64-linux-musl-gcc",
107117
}
108-
: "win32" === platform
109-
? {
110-
RUSTFLAGS: (env["RUSTFLAGS"] || "") + " -Clinker=rust-lld",
111-
TARGET_CC: "rust-lld",
112-
CC_x86_64_unknown_linux_musl: "rust-lld",
113-
}
114-
: "darwin" === platform
115-
? {
116-
RUSTFLAGS:
117-
(env["RUSTFLAGS"] || "") + " -Clinker=x86_64-linux-musl-gcc",
118-
TARGET_CC: "x86_64-linux-musl-gcc",
119-
CC_x86_64_unknown_linux_musl: "x86_64-linux-musl-gcc",
120-
}
121-
: {};
118+
: {};
122119
return {
123120
...defaultEnv,
124121
...platformEnv,
@@ -128,8 +125,11 @@ class RustPlugin {
128125
localSourceDir(funcArgs, profile, platform) {
129126
let executable = "target";
130127
if (MUSL_PLATFORMS.includes(platform)) {
131-
let target = (funcArgs || {}).target || this.custom.target
132-
executable = path.join(executable, target ? target : "x86_64-unknown-linux-musl");
128+
let target = (funcArgs || {}).target || this.custom.target;
129+
executable = path.join(
130+
executable,
131+
target ? target : "x86_64-unknown-linux-musl"
132+
);
133133
}
134134
return path.join(executable, profile !== "dev" ? "release" : "debug");
135135
}
@@ -301,19 +301,21 @@ class RustPlugin {
301301

302302
func.package = func.package || {};
303303
if (func.package.artifact && func.package.artifact !== "") {
304-
this.serverless.cli.log(`Artifact defined for ${func.handler}, skipping build...`);
304+
this.serverless.cli.log(
305+
`Artifact defined for ${func.handler}, skipping build...`
306+
);
305307
} else {
306-
const {cargoPackage, binary} = this.cargoBinary(func);
308+
const { cargoPackage, binary } = this.cargoBinary(func);
307309

308310
this.serverless.cli.log(`Building Rust ${func.handler} func...`);
309311
let profile = (func.rust || {}).profile || this.custom.profile;
310312

311313
const res = this.buildLocally(func)
312-
? this.localBuild(func.rust, cargoPackage, binary, profile)
313-
: this.dockerBuild(func.rust, cargoPackage, binary, profile);
314+
? this.localBuild(func.rust, cargoPackage, binary, profile)
315+
: this.dockerBuild(func.rust, cargoPackage, binary, profile);
314316
if (res.error || res.status > 0) {
315317
this.serverless.cli.log(
316-
`Rust build encountered an error: ${res.error} ${res.status}.`
318+
`Rust build encountered an error: ${res.error} ${res.status}.`
317319
);
318320
throw new Error(res.error);
319321
}
@@ -327,9 +329,9 @@ class RustPlugin {
327329
// see https://serverless.com/framework/docs/providers/aws/guide/packaging/
328330
// for more information
329331
const artifactPath = path.join(
330-
this.srcPath,
331-
`target/lambda/${"dev" === profile ? "debug" : "release"}`,
332-
`${binary}.zip`
332+
this.srcPath,
333+
`target/lambda/${"dev" === profile ? "debug" : "release"}`,
334+
`${binary}.zip`
333335
);
334336
func.package = func.package || {};
335337
func.package.artifact = artifactPath;

tests/unit/index.test.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe("RustPlugin", () => {
1313
dockerImage: "notsoftprops/lambda-rust",
1414
dockerTag: "latest",
1515
dockerless: true,
16+
strictMode: true,
1617
},
1718
},
1819
package: {},
@@ -40,6 +41,7 @@ describe("RustPlugin", () => {
4041
dockerImage: "softprops/lambda-rust",
4142
dockerTag: "latest",
4243
dockerless: false,
44+
strictMode: true,
4345
});
4446
});
4547

@@ -54,6 +56,7 @@ describe("RustPlugin", () => {
5456
dockerImage: "notsoftprops/lambda-rust",
5557
dockerTag: "custom-tag",
5658
dockerless: true,
59+
strictMode: false,
5760
},
5861
},
5962
package: {},
@@ -67,6 +70,7 @@ describe("RustPlugin", () => {
6770
dockerImage: "notsoftprops/lambda-rust",
6871
dockerTag: "custom-tag",
6972
dockerless: true,
73+
strictMode: false,
7074
});
7175
});
7276

@@ -128,9 +132,13 @@ describe("RustPlugin", () => {
128132
});
129133

130134
it("configures expected localBuildEnv", () => {
131-
assert.deepEqual(plugin.localBuildEnv({}, "linux"), {}, "failed on linux");
132135
assert.deepEqual(
133-
plugin.localBuildEnv({}, "darwin"),
136+
plugin.localBuildEnv({}, {}, "linux"),
137+
{},
138+
"failed on linux"
139+
);
140+
assert.deepEqual(
141+
plugin.localBuildEnv({}, {}, "darwin"),
134142

135143
{
136144
CC_x86_64_unknown_linux_musl: "x86_64-linux-musl-gcc",
@@ -140,7 +148,7 @@ describe("RustPlugin", () => {
140148
"failed on osx"
141149
);
142150
assert.deepEqual(
143-
plugin.localBuildEnv({}, "win32"),
151+
plugin.localBuildEnv({}, {}, "win32"),
144152
{
145153
CC_x86_64_unknown_linux_musl: "rust-lld",
146154
RUSTFLAGS: " -Clinker=rust-lld",
@@ -152,32 +160,32 @@ describe("RustPlugin", () => {
152160

153161
it("configures expected localSourceDir", () => {
154162
assert.equal(
155-
plugin.localSourceDir("dev", "linux"),
163+
plugin.localSourceDir({}, "dev", "linux"),
156164
path.join("target", "x86_64-unknown-linux-musl", "debug"),
157165
"failed on linux"
158166
);
159167
assert.equal(
160-
plugin.localSourceDir("release", "linux"),
168+
plugin.localSourceDir({}, "release", "linux"),
161169
path.join("target", "x86_64-unknown-linux-musl", "release"),
162170
"failed on linux"
163171
);
164172
assert.equal(
165-
plugin.localSourceDir("dev", "darwin"),
173+
plugin.localSourceDir({}, "dev", "darwin"),
166174
path.join("target", "x86_64-unknown-linux-musl", "debug"),
167175
"failed on osx"
168176
);
169177
assert.equal(
170-
plugin.localSourceDir("release", "darwin"),
178+
plugin.localSourceDir({}, "release", "darwin"),
171179
path.join("target", "x86_64-unknown-linux-musl", "release"),
172180
"failed on osx"
173181
);
174182
assert.equal(
175-
plugin.localSourceDir("dev", "win32"),
183+
plugin.localSourceDir({}, "dev", "win32"),
176184
path.join("target", "x86_64-unknown-linux-musl", "debug"),
177185
"failed on windows"
178186
);
179187
assert.equal(
180-
plugin.localSourceDir("release", "win32"),
188+
plugin.localSourceDir({}, "release", "win32"),
181189
path.join("target", "x86_64-unknown-linux-musl", "release"),
182190
"failed on windows"
183191
);

0 commit comments

Comments
 (0)