diff --git a/index.js b/index.js index d59a6ef..2d962c3 100644 --- a/index.js +++ b/index.js @@ -174,6 +174,7 @@ class RustPlugin { cargoPackage, binary, profile, + debugInfo, srcPath, cargoRegistry, cargoDownloads, @@ -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}`; @@ -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"); @@ -230,6 +234,7 @@ class RustPlugin { cargoPackage, binary, profile, + debugInfo, this.srcPath, cargoRegistry, cargoDownloads, @@ -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}.` diff --git a/tests/unit/index.test.js b/tests/unit/index.test.js index 02fce94..941e5b2 100644 --- a/tests/unit/index.test.js +++ b/tests/unit/index.test.js @@ -227,6 +227,7 @@ describe("RustPlugin", () => { "foo", "bar", "release", + false, "source_path", "cargo_registry", "cargo_downloads", @@ -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", + ] + ); + }); });