@@ -75,15 +75,13 @@ class RustPlugin {
7575 ""
7676 ) . split ( / \s + / ) ;
7777
78+ let target = ( funcArgs || { } ) . target || this . custom . target ;
7879
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+ : [ ] ;
8785 return [
8886 ...defaultArgs ,
8987 ...profileArgs ,
@@ -95,30 +93,29 @@ class RustPlugin {
9593 localBuildEnv ( funcArgs , env , platform ) {
9694 const defaultEnv = { ...env } ;
9795
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 ;
10098
101- const platformEnv =
102- linker ?
103- {
99+ const platformEnv = linker
100+ ? {
104101 RUSTFLAGS : ( env [ "RUSTFLAGS" ] || "" ) + ` -Clinker=${ linker } ` ,
105102 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" ,
107117 }
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+ : { } ;
122119 return {
123120 ...defaultEnv ,
124121 ...platformEnv ,
@@ -128,8 +125,11 @@ class RustPlugin {
128125 localSourceDir ( funcArgs , profile , platform ) {
129126 let executable = "target" ;
130127 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+ ) ;
133133 }
134134 return path . join ( executable , profile !== "dev" ? "release" : "debug" ) ;
135135 }
@@ -301,19 +301,21 @@ class RustPlugin {
301301
302302 func . package = func . package || { } ;
303303 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+ ) ;
305307 } else {
306- const { cargoPackage, binary} = this . cargoBinary ( func ) ;
308+ const { cargoPackage, binary } = this . cargoBinary ( func ) ;
307309
308310 this . serverless . cli . log ( `Building Rust ${ func . handler } func...` ) ;
309311 let profile = ( func . rust || { } ) . profile || this . custom . profile ;
310312
311313 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 ) ;
314316 if ( res . error || res . status > 0 ) {
315317 this . serverless . cli . log (
316- `Rust build encountered an error: ${ res . error } ${ res . status } .`
318+ `Rust build encountered an error: ${ res . error } ${ res . status } .`
317319 ) ;
318320 throw new Error ( res . error ) ;
319321 }
@@ -327,9 +329,9 @@ class RustPlugin {
327329 // see https://serverless.com/framework/docs/providers/aws/guide/packaging/
328330 // for more information
329331 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`
333335 ) ;
334336 func . package = func . package || { } ;
335337 func . package . artifact = artifactPath ;
0 commit comments