Skip to content

Commit

Permalink
allow for explicitly turning on debuginfo for docker builds
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcountryman committed Aug 26, 2020
1 parent d7d12a6 commit cdbdbfb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class RustPlugin {
cargoPackage,
binary,
profile,
debugInfo,
srcPath,
cargoRegistry,
cargoDownloads,
Expand All @@ -198,6 +199,9 @@ class RustPlugin {
// release or dev
customArgs.push("-e", `PROFILE=${profile}`);
}
if (debugInfo) {
customArgs.push("-e", `DEBUGINFO=${debugInfo}`);
}
if (cargoPackage != undefined) {
if (cargoFlags) {
cargoFlags = `${cargoFlags} -p ${cargoPackage}`;
Expand All @@ -219,7 +223,7 @@ class RustPlugin {
].filter((i) => i);
}

dockerBuild(funcArgs, cargoPackage, binary, profile) {
dockerBuild(funcArgs, cargoPackage, binary, profile, debugInfo) {
const cargoHome = process.env.CARGO_HOME || path.join(homedir(), ".cargo");
const cargoRegistry = path.join(cargoHome, "registry");
const cargoDownloads = path.join(cargoHome, "git");
Expand All @@ -230,6 +234,7 @@ class RustPlugin {
cargoPackage,
binary,
profile,
debugInfo,
this.srcPath,
cargoRegistry,
cargoDownloads,
Expand Down Expand Up @@ -280,10 +285,11 @@ class RustPlugin {

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

const res = this.buildLocally(func)
? this.localBuild(func.rust, cargoPackage, binary, profile)
: this.dockerBuild(func.rust, cargoPackage, binary, profile);
: this.dockerBuild(func.rust, cargoPackage, binary, profile, debugInfo);
if (res.error || res.status > 0) {
this.serverless.cli.log(
`Rust build encountered an error: ${res.error} ${res.status}.`
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ describe("RustPlugin", () => {
"foo",
"bar",
"release",
false,
"source_path",
"cargo_registry",
"cargo_downloads",
Expand All @@ -252,4 +253,40 @@ describe("RustPlugin", () => {
]
);
});

it("configures expected dockerBuildArgs with debugInfo", () => {
assert.deepEqual(
plugin.dockerBuildArgs(
{},
"foo",
"bar",
"release",
true,
"source_path",
"cargo_registry",
"cargo_downloads",
{}
),
[
"run",
"--rm",
"-t",
"-e",
"BIN=bar",
"-v",
"source_path:/code",
"-v",
"cargo_registry:/root/.cargo/registry",
"-v",
"cargo_downloads:/root/.cargo/git",
"-e",
"PROFILE=release",
"-e",
"DEBUGINFO=true",
"-e",
"CARGO_FLAGS=--features foo -p foo",
"notsoftprops/lambda-rust:latest",
]
);
});
});

0 comments on commit cdbdbfb

Please sign in to comment.