@@ -47,6 +47,7 @@ class RustPlugin {
47
47
dockerTag : DEFAULT_DOCKER_TAG ,
48
48
dockerImage : DEFAULT_DOCKER_IMAGE ,
49
49
dockerless : false ,
50
+ strictMode : true ,
50
51
} ,
51
52
( this . serverless . service . custom && this . serverless . service . custom . rust ) ||
52
53
{ }
@@ -281,6 +282,7 @@ class RustPlugin {
281
282
282
283
/** the entry point for building functions */
283
284
build ( ) {
285
+ const strictMode = this . custom . strictMode !== false ;
284
286
const service = this . serverless . service ;
285
287
if ( service . provider . name != "aws" ) {
286
288
return ;
@@ -289,51 +291,59 @@ class RustPlugin {
289
291
this . functions ( ) . forEach ( ( funcName ) => {
290
292
const func = service . getFunction ( funcName ) ;
291
293
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" ) ) {
293
297
// skip functions which don't apply to rust
294
298
return ;
295
299
}
296
300
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 ;
301
301
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
- ) ;
325
302
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 ;
327
336
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
+ }
331
341
}
332
342
} ) ;
333
343
if ( service . provider . runtime === RUST_RUNTIME ) {
334
344
service . provider . runtime = BASE_RUNTIME ;
335
345
}
336
- if ( ! rustFunctionsFound ) {
346
+ if ( ! rustFunctionsFound && strictMode ) {
337
347
throw new Error (
338
348
`Error: no Rust functions found. ` +
339
349
`Use 'runtime: ${ RUST_RUNTIME } ' in global or ` +
0 commit comments