@@ -9,9 +9,9 @@ use std::collections::{BTreeSet, HashMap};
9
9
#[ derive( Debug , Deserialize , PartialEq , Eq , Default ) ]
10
10
pub struct CrossEnvConfig {
11
11
#[ serde( default ) ]
12
- volumes : Vec < String > ,
12
+ volumes : Option < Vec < String > > ,
13
13
#[ serde( default ) ]
14
- passthrough : Vec < String > ,
14
+ passthrough : Option < Vec < String > > ,
15
15
}
16
16
17
17
/// Build configuration
@@ -89,22 +89,22 @@ impl CrossToml {
89
89
90
90
/// Returns the list of environment variables to pass through for `build`,
91
91
pub fn env_passthrough_build ( & self ) -> & [ String ] {
92
- & self . build . env . passthrough
92
+ self . build . env . passthrough . as_deref ( ) . unwrap_or ( & [ ] )
93
93
}
94
94
95
95
/// Returns the list of environment variables to pass through for `target`,
96
96
pub fn env_passthrough_target ( & self , target : & Target ) -> & [ String ] {
97
- self . get_vec ( target, |e| & e. passthrough )
97
+ self . get_vec ( target, |e| e. passthrough . as_deref ( ) . unwrap_or ( & [ ] ) )
98
98
}
99
99
100
100
/// Returns the list of environment variables to pass through for `build`,
101
101
pub fn env_volumes_build ( & self ) -> & [ String ] {
102
- & self . build . env . volumes
102
+ self . build . env . volumes . as_deref ( ) . unwrap_or ( & [ ] )
103
103
}
104
104
105
105
/// Returns the list of environment variables to pass through for `target`,
106
106
pub fn env_volumes_target ( & self , target : & Target ) -> & [ String ] {
107
- self . get_vec ( target, |e| & e. volumes )
107
+ self . get_vec ( target, |e| e. volumes . as_deref ( ) . unwrap_or ( & [ ] ) )
108
108
}
109
109
110
110
/// Returns the default target to build,
@@ -169,8 +169,8 @@ mod tests {
169
169
targets : HashMap :: new ( ) ,
170
170
build : CrossBuildConfig {
171
171
env : CrossEnvConfig {
172
- volumes : vec ! [ "VOL1_ARG" . to_string( ) , "VOL2_ARG" . to_string( ) ] ,
173
- passthrough : vec ! [ "VAR1" . to_string( ) , "VAR2" . to_string( ) ] ,
172
+ volumes : Some ( vec ! [ "VOL1_ARG" . to_string( ) , "VOL2_ARG" . to_string( ) ] ) ,
173
+ passthrough : Some ( vec ! [ "VAR1" . to_string( ) , "VAR2" . to_string( ) ] ) ,
174
174
} ,
175
175
xargo : Some ( true ) ,
176
176
build_std : None ,
@@ -203,8 +203,8 @@ mod tests {
203
203
} ,
204
204
CrossTargetConfig {
205
205
env : CrossEnvConfig {
206
- passthrough : vec ! [ "VAR1" . to_string( ) , "VAR2" . to_string( ) ] ,
207
- volumes : vec ! [ "VOL1_ARG" . to_string( ) , "VOL2_ARG" . to_string( ) ] ,
206
+ passthrough : Some ( vec ! [ "VAR1" . to_string( ) , "VAR2" . to_string( ) ] ) ,
207
+ volumes : Some ( vec ! [ "VOL1_ARG" . to_string( ) , "VOL2_ARG" . to_string( ) ] ) ,
208
208
} ,
209
209
xargo : Some ( false ) ,
210
210
build_std : Some ( true ) ,
@@ -234,4 +234,57 @@ mod tests {
234
234
235
235
Ok ( ( ) )
236
236
}
237
+
238
+ #[ test]
239
+ pub fn parse_mixed_toml ( ) -> Result < ( ) > {
240
+ let mut target_map = HashMap :: new ( ) ;
241
+ target_map. insert (
242
+ Target :: BuiltIn {
243
+ triple : "aarch64-unknown-linux-gnu" . to_string ( ) ,
244
+ } ,
245
+ CrossTargetConfig {
246
+ env : CrossEnvConfig {
247
+ passthrough : None ,
248
+ volumes : Some ( vec ! [ "VOL" . to_string( ) ] ) ,
249
+ } ,
250
+ xargo : Some ( false ) ,
251
+ build_std : None ,
252
+ image : None ,
253
+ runner : None ,
254
+ } ,
255
+ ) ;
256
+
257
+ let cfg = CrossToml {
258
+ targets : target_map,
259
+ build : CrossBuildConfig {
260
+ env : CrossEnvConfig {
261
+ volumes : None ,
262
+ passthrough : Some ( vec ! [ ] ) ,
263
+ } ,
264
+ xargo : Some ( true ) ,
265
+ build_std : None ,
266
+ default_target : None ,
267
+ } ,
268
+ } ;
269
+
270
+ let test_str = r#"
271
+ [build]
272
+ xargo = true
273
+
274
+ [build.env]
275
+ passthrough = []
276
+
277
+ [target.aarch64-unknown-linux-gnu]
278
+ xargo = false
279
+
280
+ [target.aarch64-unknown-linux-gnu.env]
281
+ volumes = ["VOL"]
282
+ "# ;
283
+ let ( parsed_cfg, unused) = CrossToml :: parse ( test_str) ?;
284
+
285
+ assert_eq ! ( parsed_cfg, cfg) ;
286
+ assert ! ( unused. is_empty( ) ) ;
287
+
288
+ Ok ( ( ) )
289
+ }
237
290
}
0 commit comments