From c5fe49f146b981cc41686cf4f91a5b4d4aabd1e7 Mon Sep 17 00:00:00 2001 From: Fernando Daciuk Date: Sat, 25 Jun 2022 19:09:50 -0300 Subject: [PATCH] fix: use `tags` instead of a custom invalid `runtime` option Serverless 3 will throw an error if we use a `provider.runtime` option different from the allowed values. This PR removes the need to use the new runtime option (`rust`) and uses `tags.rust: true` inside the function configuration. This PR resolves #107 --- index.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 58f330b..d04ba67 100644 --- a/index.js +++ b/index.js @@ -12,8 +12,6 @@ const { mkdirSync, writeFileSync, readFileSync } = require("fs"); const DEFAULT_DOCKER_TAG = "latest"; const DEFAULT_DOCKER_IMAGE = "softprops/lambda-rust"; -const RUST_RUNTIME = "rust"; -const BASE_RUNTIME = "provided.al2"; const NO_OUTPUT_CAPTURE = { stdio: ["ignore", process.stdout, process.stderr] }; const MUSL_PLATFORMS = ["darwin", "win32", "linux"]; @@ -77,7 +75,7 @@ class RustPlugin { let target = (funcArgs || {}).target || this.custom.target - const targetArgs = + const targetArgs = target ? ['--target', target] : MUSL_PLATFORMS.includes(platform) @@ -288,8 +286,8 @@ class RustPlugin { let rustFunctionsFound = false; this.functions().forEach((funcName) => { const func = service.getFunction(funcName); - const runtime = func.runtime || service.provider.runtime; - if (runtime != RUST_RUNTIME) { + const isRustFunction = !!func.tags?.rust + if (!isRustFunction) { // skip functions which don't apply to rust return; } @@ -324,19 +322,11 @@ class RustPlugin { ); func.package = func.package || {}; func.package.artifact = artifactPath; - - // Ensure the runtime is set to a sane value for other plugins - if (func.runtime == RUST_RUNTIME) { - func.runtime = BASE_RUNTIME; - } }); - if (service.provider.runtime === RUST_RUNTIME) { - service.provider.runtime = BASE_RUNTIME; - } if (!rustFunctionsFound) { throw new Error( `Error: no Rust functions found. ` + - `Use 'runtime: ${RUST_RUNTIME}' in global or ` + + `Use 'tags.rust: true' in ` + `function configuration to use this plugin.` ); }