@@ -75,15 +75,13 @@ class RustPlugin {
75
75
""
76
76
) . split ( / \s + / ) ;
77
77
78
+ let target = ( funcArgs || { } ) . target || this . custom . target ;
78
79
79
- let target = ( funcArgs || { } ) . target || this . custom . target
80
-
81
- const targetArgs =
82
- target ?
83
- [ '--target' , target ]
84
- : MUSL_PLATFORMS . includes ( platform )
85
- ? [ "--target" , "x86_64-unknown-linux-musl" ]
86
- : [ ] ;
80
+ const targetArgs = target
81
+ ? [ "--target" , target ]
82
+ : MUSL_PLATFORMS . includes ( platform )
83
+ ? [ "--target" , "x86_64-unknown-linux-musl" ]
84
+ : [ ] ;
87
85
return [
88
86
...defaultArgs ,
89
87
...profileArgs ,
@@ -95,30 +93,29 @@ class RustPlugin {
95
93
localBuildEnv ( funcArgs , env , platform ) {
96
94
const defaultEnv = { ...env } ;
97
95
98
- let target = ( funcArgs || { } ) . target || this . custom . target
99
- let linker = ( funcArgs || { } ) . linker || this . custom . linker
96
+ let target = ( funcArgs || { } ) . target || this . custom . target ;
97
+ let linker = ( funcArgs || { } ) . linker || this . custom . linker ;
100
98
101
- const platformEnv =
102
- linker ?
103
- {
99
+ const platformEnv = linker
100
+ ? {
104
101
RUSTFLAGS : ( env [ "RUSTFLAGS" ] || "" ) + ` -Clinker=${ linker } ` ,
105
102
TARGET_CC : linker ,
106
- [ `CC_${ target || 'x86_64_unknown_linux_musl' } ` ] : linker ,
103
+ [ `CC_${ target || "x86_64_unknown_linux_musl" } ` ] : linker ,
104
+ }
105
+ : "win32" === platform
106
+ ? {
107
+ RUSTFLAGS : ( env [ "RUSTFLAGS" ] || "" ) + " -Clinker=rust-lld" ,
108
+ TARGET_CC : "rust-lld" ,
109
+ CC_x86_64_unknown_linux_musl : "rust-lld" ,
110
+ }
111
+ : "darwin" === platform
112
+ ? {
113
+ RUSTFLAGS :
114
+ ( env [ "RUSTFLAGS" ] || "" ) + " -Clinker=x86_64-linux-musl-gcc" ,
115
+ TARGET_CC : "x86_64-linux-musl-gcc" ,
116
+ CC_x86_64_unknown_linux_musl : "x86_64-linux-musl-gcc" ,
107
117
}
108
- : "win32" === platform
109
- ? {
110
- RUSTFLAGS : ( env [ "RUSTFLAGS" ] || "" ) + " -Clinker=rust-lld" ,
111
- TARGET_CC : "rust-lld" ,
112
- CC_x86_64_unknown_linux_musl : "rust-lld" ,
113
- }
114
- : "darwin" === platform
115
- ? {
116
- RUSTFLAGS :
117
- ( env [ "RUSTFLAGS" ] || "" ) + " -Clinker=x86_64-linux-musl-gcc" ,
118
- TARGET_CC : "x86_64-linux-musl-gcc" ,
119
- CC_x86_64_unknown_linux_musl : "x86_64-linux-musl-gcc" ,
120
- }
121
- : { } ;
118
+ : { } ;
122
119
return {
123
120
...defaultEnv ,
124
121
...platformEnv ,
@@ -128,8 +125,11 @@ class RustPlugin {
128
125
localSourceDir ( funcArgs , profile , platform ) {
129
126
let executable = "target" ;
130
127
if ( MUSL_PLATFORMS . includes ( platform ) ) {
131
- let target = ( funcArgs || { } ) . target || this . custom . target
132
- executable = path . join ( executable , target ? target : "x86_64-unknown-linux-musl" ) ;
128
+ let target = ( funcArgs || { } ) . target || this . custom . target ;
129
+ executable = path . join (
130
+ executable ,
131
+ target ? target : "x86_64-unknown-linux-musl"
132
+ ) ;
133
133
}
134
134
return path . join ( executable , profile !== "dev" ? "release" : "debug" ) ;
135
135
}
@@ -301,19 +301,21 @@ class RustPlugin {
301
301
302
302
func . package = func . package || { } ;
303
303
if ( func . package . artifact && func . package . artifact !== "" ) {
304
- this . serverless . cli . log ( `Artifact defined for ${ func . handler } , skipping build...` ) ;
304
+ this . serverless . cli . log (
305
+ `Artifact defined for ${ func . handler } , skipping build...`
306
+ ) ;
305
307
} else {
306
- const { cargoPackage, binary} = this . cargoBinary ( func ) ;
308
+ const { cargoPackage, binary } = this . cargoBinary ( func ) ;
307
309
308
310
this . serverless . cli . log ( `Building Rust ${ func . handler } func...` ) ;
309
311
let profile = ( func . rust || { } ) . profile || this . custom . profile ;
310
312
311
313
const res = this . buildLocally ( func )
312
- ? this . localBuild ( func . rust , cargoPackage , binary , profile )
313
- : this . dockerBuild ( func . rust , cargoPackage , binary , profile ) ;
314
+ ? this . localBuild ( func . rust , cargoPackage , binary , profile )
315
+ : this . dockerBuild ( func . rust , cargoPackage , binary , profile ) ;
314
316
if ( res . error || res . status > 0 ) {
315
317
this . serverless . cli . log (
316
- `Rust build encountered an error: ${ res . error } ${ res . status } .`
318
+ `Rust build encountered an error: ${ res . error } ${ res . status } .`
317
319
) ;
318
320
throw new Error ( res . error ) ;
319
321
}
@@ -327,9 +329,9 @@ class RustPlugin {
327
329
// see https://serverless.com/framework/docs/providers/aws/guide/packaging/
328
330
// for more information
329
331
const artifactPath = path . join (
330
- this . srcPath ,
331
- `target/lambda/${ "dev" === profile ? "debug" : "release" } ` ,
332
- `${ binary } .zip`
332
+ this . srcPath ,
333
+ `target/lambda/${ "dev" === profile ? "debug" : "release" } ` ,
334
+ `${ binary } .zip`
333
335
) ;
334
336
func . package = func . package || { } ;
335
337
func . package . artifact = artifactPath ;
0 commit comments