From 0179c6a00258e34bbe55b6f2db9d8d14321fe187 Mon Sep 17 00:00:00 2001 From: Zapodask Date: Fri, 7 Apr 2023 02:50:23 -0300 Subject: [PATCH 1/2] set default handler and runtime --- sls-rust.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sls-rust.js b/sls-rust.js index 043f90f..303c35b 100644 --- a/sls-rust.js +++ b/sls-rust.js @@ -96,6 +96,8 @@ class SlsRust { const artifactPath = join(targetPath, `${projectName}.zip`) fn.package = fn.package || {} fn.package.artifact = artifactPath + fn.handler = 'bootstrap' + fn.runtime = 'provided.al2' this.log(`Finished building ${projectName}!`) } From 4bfad37001c06ca13f789bfd7a7b07ef1708792c Mon Sep 17 00:00:00 2001 From: Zapodask Date: Wed, 12 Apr 2023 16:23:24 -0300 Subject: [PATCH 2/2] use workspaces --- sls-rust.js | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/sls-rust.js b/sls-rust.js index 303c35b..3c553b2 100644 --- a/sls-rust.js +++ b/sls-rust.js @@ -32,6 +32,9 @@ class SlsRust { throw new SlsRustPluginNoRustFnsError() } + this.log(`Building Rust funcs...`) + await this.runBuildCommand() + const buildPromises = rustFns.map(fnName => { const fn = this.serverless.service.getFunction(fnName) return this.build(fn) @@ -55,14 +58,14 @@ class SlsRust { } - async runBuildCommand ({ path, projectName }) { + async runBuildCommand () { try { await this.runCommand({ command: `cargo build --release --target ${this.targetRuntime}`, - cwd: path, + cwd: '.', }) } catch (error) { - throw new Error(`Error building project ${projectName}: ${error}`) + throw new Error(`Error building rust functions: ${error}`) } } @@ -86,11 +89,8 @@ class SlsRust { } async build (fn) { - const { projectPath, projectName } = this.getProjectPathAndName(fn) - this.log(`Building Rust ${fn.handler} func...`) - const path = join('.', projectPath) - const targetPath = join(path, 'target', this.targetRuntime, 'release') - await this.runBuildCommand({ path, projectName }) + const projectName = fn.handler + const targetPath = join('.', 'target', this.targetRuntime, 'release') await this.runZipArtifact({ path: targetPath, projectName }) const artifactPath = join(targetPath, `${projectName}.zip`) @@ -100,15 +100,6 @@ class SlsRust { fn.runtime = 'provided.al2' this.log(`Finished building ${projectName}!`) } - - getProjectPathAndName (fn) { - const [projectPath, projectName] = fn.handler.split('.') - if (!projectPath || !projectName) { - throw new SlsRustPluginWrongHandlerError() - } - - return { projectPath, projectName } - } } class SlsRustPluginMainError extends Error { @@ -132,7 +123,6 @@ class SlsRustPluginNoRustFnsError extends SlsRustPluginMainError { functions: rust: handler: your_rust_project_name - runtime: provided.al2 tags: rust: true `