@@ -47,6 +47,7 @@ class RustPlugin {
4747 dockerTag : DEFAULT_DOCKER_TAG ,
4848 dockerImage : DEFAULT_DOCKER_IMAGE ,
4949 dockerless : false ,
50+ strictMode : true ,
5051 } ,
5152 ( this . serverless . service . custom && this . serverless . service . custom . rust ) ||
5253 { }
@@ -281,6 +282,7 @@ class RustPlugin {
281282
282283 /** the entry point for building functions */
283284 build ( ) {
285+ const strictMode = this . custom . strictMode !== false ;
284286 const service = this . serverless . service ;
285287 if ( service . provider . name != "aws" ) {
286288 return ;
@@ -289,51 +291,59 @@ class RustPlugin {
289291 this . functions ( ) . forEach ( ( funcName ) => {
290292 const func = service . getFunction ( funcName ) ;
291293 const runtime = func . runtime || service . provider . runtime ;
292- if ( runtime != RUST_RUNTIME ) {
294+
295+ func . tags = func . tags || { } ;
296+ if ( ! ( runtime === RUST_RUNTIME || func . tags . language === "rust" ) ) {
293297 // skip functions which don't apply to rust
294298 return ;
295299 }
296300 rustFunctionsFound = true ;
297- const { cargoPackage, binary } = this . cargoBinary ( func ) ;
298-
299- this . serverless . cli . log ( `Building Rust ${ func . handler } func...` ) ;
300- let profile = ( func . rust || { } ) . profile || this . custom . profile ;
301301
302- const res = this . buildLocally ( func )
303- ? this . localBuild ( func . rust , cargoPackage , binary , profile )
304- : this . dockerBuild ( func . rust , cargoPackage , binary , profile ) ;
305- if ( res . error || res . status > 0 ) {
306- this . serverless . cli . log (
307- `Rust build encountered an error: ${ res . error } ${ res . status } .`
308- ) ;
309- throw new Error ( res . error ) ;
310- }
311- // If all went well, we should now have find a packaged compiled binary under `target/lambda/release`.
312- //
313- // The AWS "provided" lambda runtime requires executables to be named
314- // "bootstrap" -- https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html
315- //
316- // To avoid artifact naming conflicts when we potentially have more than one function
317- // we leverage the ability to declare a package artifact directly
318- // see https://serverless.com/framework/docs/providers/aws/guide/packaging/
319- // for more information
320- const artifactPath = path . join (
321- this . srcPath ,
322- `target/lambda/${ "dev" === profile ? "debug" : "release" } ` ,
323- `${ binary } .zip`
324- ) ;
325302 func . package = func . package || { } ;
326- func . package . artifact = artifactPath ;
303+ if ( func . package . artifact && func . package . artifact !== "" ) {
304+ this . serverless . cli . log ( `Artifact defined for ${ func . handler } , skipping build...` ) ;
305+ } else {
306+ const { cargoPackage, binary} = this . cargoBinary ( func ) ;
307+
308+ this . serverless . cli . log ( `Building Rust ${ func . handler } func...` ) ;
309+ let profile = ( func . rust || { } ) . profile || this . custom . profile ;
310+
311+ const res = this . buildLocally ( func )
312+ ? this . localBuild ( func . rust , cargoPackage , binary , profile )
313+ : this . dockerBuild ( func . rust , cargoPackage , binary , profile ) ;
314+ if ( res . error || res . status > 0 ) {
315+ this . serverless . cli . log (
316+ `Rust build encountered an error: ${ res . error } ${ res . status } .`
317+ ) ;
318+ throw new Error ( res . error ) ;
319+ }
320+ // If all went well, we should now have find a packaged compiled binary under `target/lambda/release`.
321+ //
322+ // The AWS "provided" lambda runtime requires executables to be named
323+ // "bootstrap" -- https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html
324+ //
325+ // To avoid artifact naming conflicts when we potentially have more than one function
326+ // we leverage the ability to declare a package artifact directly
327+ // see https://serverless.com/framework/docs/providers/aws/guide/packaging/
328+ // for more information
329+ const artifactPath = path . join (
330+ this . srcPath ,
331+ `target/lambda/${ "dev" === profile ? "debug" : "release" } ` ,
332+ `${ binary } .zip`
333+ ) ;
334+ func . package = func . package || { } ;
335+ func . package . artifact = artifactPath ;
327336
328- // Ensure the runtime is set to a sane value for other plugins
329- if ( func . runtime == RUST_RUNTIME ) {
330- func . runtime = BASE_RUNTIME ;
337+ // Ensure the runtime is set to a sane value for other plugins
338+ if ( func . runtime == RUST_RUNTIME ) {
339+ func . runtime = BASE_RUNTIME ;
340+ }
331341 }
332342 } ) ;
333343 if ( service . provider . runtime === RUST_RUNTIME ) {
334344 service . provider . runtime = BASE_RUNTIME ;
335345 }
336- if ( ! rustFunctionsFound ) {
346+ if ( ! rustFunctionsFound && strictMode ) {
337347 throw new Error (
338348 `Error: no Rust functions found. ` +
339349 `Use 'runtime: ${ RUST_RUNTIME } ' in global or ` +
0 commit comments