@@ -73,9 +73,16 @@ class RustPlugin {
73
73
this . custom . cargoFlags ||
74
74
""
75
75
) . split ( / \s + / ) ;
76
- const targetArgs = MUSL_PLATFORMS . includes ( platform )
77
- ? [ "--target" , "x86_64-unknown-linux-musl" ]
78
- : [ ] ;
76
+
77
+
78
+ let target = ( funcArgs || { } ) . target || this . custom . target
79
+
80
+ const targetArgs =
81
+ target ?
82
+ [ '--target' , target ]
83
+ : MUSL_PLATFORMS . includes ( platform )
84
+ ? [ "--target" , "x86_64-unknown-linux-musl" ]
85
+ : [ ] ;
79
86
return [
80
87
...defaultArgs ,
81
88
...profileArgs ,
@@ -84,33 +91,44 @@ class RustPlugin {
84
91
] . filter ( ( i ) => i ) ;
85
92
}
86
93
87
- localBuildEnv ( env , platform ) {
94
+ localBuildEnv ( funcArgs , env , platform ) {
88
95
const defaultEnv = { ...env } ;
96
+
97
+ let target = ( funcArgs || { } ) . target || this . custom . target
98
+ let linker = ( funcArgs || { } ) . linker || this . custom . linker
99
+
89
100
const platformEnv =
90
- "win32" === platform
91
- ? {
92
- RUSTFLAGS : ( env [ "RUSTFLAGS" ] || "" ) + " -Clinker=rust-lld" ,
93
- TARGET_CC : "rust-lld" ,
94
- CC_x86_64_unknown_linux_musl : "rust-lld" ,
95
- }
96
- : "darwin" === platform
97
- ? {
98
- RUSTFLAGS :
99
- ( env [ "RUSTFLAGS" ] || "" ) + " -Clinker=x86_64-linux-musl-gcc" ,
100
- TARGET_CC : "x86_64-linux-musl-gcc" ,
101
- CC_x86_64_unknown_linux_musl : "x86_64-linux-musl-gcc" ,
102
- }
103
- : { } ;
101
+ linker ?
102
+ {
103
+ RUSTFLAGS : ( env [ "RUSTFLAGS" ] || "" ) + ` -Clinker=${ linker } ` ,
104
+ TARGET_CC : linker ,
105
+ [ `CC_${ target || 'x86_64_unknown_linux_musl' } ` ] : linker ,
106
+ }
107
+ : "win32" === platform
108
+ ? {
109
+ RUSTFLAGS : ( env [ "RUSTFLAGS" ] || "" ) + " -Clinker=rust-lld" ,
110
+ TARGET_CC : "rust-lld" ,
111
+ CC_x86_64_unknown_linux_musl : "rust-lld" ,
112
+ }
113
+ : "darwin" === platform
114
+ ? {
115
+ RUSTFLAGS :
116
+ ( env [ "RUSTFLAGS" ] || "" ) + " -Clinker=x86_64-linux-musl-gcc" ,
117
+ TARGET_CC : "x86_64-linux-musl-gcc" ,
118
+ CC_x86_64_unknown_linux_musl : "x86_64-linux-musl-gcc" ,
119
+ }
120
+ : { } ;
104
121
return {
105
122
...defaultEnv ,
106
123
...platformEnv ,
107
124
} ;
108
125
}
109
126
110
- localSourceDir ( profile , platform ) {
127
+ localSourceDir ( funcArgs , profile , platform ) {
111
128
let executable = "target" ;
112
129
if ( MUSL_PLATFORMS . includes ( platform ) ) {
113
- executable = path . join ( executable , "x86_64-unknown-linux-musl" ) ;
130
+ let target = ( funcArgs || { } ) . target || this . custom . target
131
+ executable = path . join ( executable , target ? target : "x86_64-unknown-linux-musl" ) ;
114
132
}
115
133
return path . join ( executable , profile !== "dev" ? "release" : "debug" ) ;
116
134
}
@@ -132,7 +150,7 @@ class RustPlugin {
132
150
platform ( )
133
151
) ;
134
152
135
- const env = this . localBuildEnv ( process . env , platform ( ) ) ;
153
+ const env = this . localBuildEnv ( funcArgs , process . env , platform ( ) ) ;
136
154
this . serverless . cli . log ( `Running local cargo build on ${ platform ( ) } ` ) ;
137
155
138
156
const buildResult = spawnSync ( "cargo" , args , {
@@ -145,7 +163,7 @@ class RustPlugin {
145
163
return buildResult ;
146
164
}
147
165
// now rename binary and zip
148
- const sourceDir = this . localSourceDir ( profile , platform ( ) ) ;
166
+ const sourceDir = this . localSourceDir ( funcArgs , profile , platform ( ) ) ;
149
167
const zip = new AdmZip ( ) ;
150
168
zip . addFile (
151
169
"bootstrap" ,
0 commit comments