Skip to content

Commit cdbdbfb

Browse files
committed
allow for explicitly turning on debuginfo for docker builds
1 parent d7d12a6 commit cdbdbfb

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class RustPlugin {
174174
cargoPackage,
175175
binary,
176176
profile,
177+
debugInfo,
177178
srcPath,
178179
cargoRegistry,
179180
cargoDownloads,
@@ -198,6 +199,9 @@ class RustPlugin {
198199
// release or dev
199200
customArgs.push("-e", `PROFILE=${profile}`);
200201
}
202+
if (debugInfo) {
203+
customArgs.push("-e", `DEBUGINFO=${debugInfo}`);
204+
}
201205
if (cargoPackage != undefined) {
202206
if (cargoFlags) {
203207
cargoFlags = `${cargoFlags} -p ${cargoPackage}`;
@@ -219,7 +223,7 @@ class RustPlugin {
219223
].filter((i) => i);
220224
}
221225

222-
dockerBuild(funcArgs, cargoPackage, binary, profile) {
226+
dockerBuild(funcArgs, cargoPackage, binary, profile, debugInfo) {
223227
const cargoHome = process.env.CARGO_HOME || path.join(homedir(), ".cargo");
224228
const cargoRegistry = path.join(cargoHome, "registry");
225229
const cargoDownloads = path.join(cargoHome, "git");
@@ -230,6 +234,7 @@ class RustPlugin {
230234
cargoPackage,
231235
binary,
232236
profile,
237+
debugInfo,
233238
this.srcPath,
234239
cargoRegistry,
235240
cargoDownloads,
@@ -280,10 +285,11 @@ class RustPlugin {
280285

281286
this.serverless.cli.log(`Building Rust ${func.handler} func...`);
282287
let profile = (func.rust || {}).profile || this.custom.profile;
288+
let debugInfo = (func.rust || {}).debugInfo || this.custom.debugInfo;
283289

284290
const res = this.buildLocally(func)
285291
? this.localBuild(func.rust, cargoPackage, binary, profile)
286-
: this.dockerBuild(func.rust, cargoPackage, binary, profile);
292+
: this.dockerBuild(func.rust, cargoPackage, binary, profile, debugInfo);
287293
if (res.error || res.status > 0) {
288294
this.serverless.cli.log(
289295
`Rust build encountered an error: ${res.error} ${res.status}.`

tests/unit/index.test.js

+37
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ describe("RustPlugin", () => {
227227
"foo",
228228
"bar",
229229
"release",
230+
false,
230231
"source_path",
231232
"cargo_registry",
232233
"cargo_downloads",
@@ -252,4 +253,40 @@ describe("RustPlugin", () => {
252253
]
253254
);
254255
});
256+
257+
it("configures expected dockerBuildArgs with debugInfo", () => {
258+
assert.deepEqual(
259+
plugin.dockerBuildArgs(
260+
{},
261+
"foo",
262+
"bar",
263+
"release",
264+
true,
265+
"source_path",
266+
"cargo_registry",
267+
"cargo_downloads",
268+
{}
269+
),
270+
[
271+
"run",
272+
"--rm",
273+
"-t",
274+
"-e",
275+
"BIN=bar",
276+
"-v",
277+
"source_path:/code",
278+
"-v",
279+
"cargo_registry:/root/.cargo/registry",
280+
"-v",
281+
"cargo_downloads:/root/.cargo/git",
282+
"-e",
283+
"PROFILE=release",
284+
"-e",
285+
"DEBUGINFO=true",
286+
"-e",
287+
"CARGO_FLAGS=--features foo -p foo",
288+
"notsoftprops/lambda-rust:latest",
289+
]
290+
);
291+
});
255292
});

0 commit comments

Comments
 (0)