Commit 22ab4d1 1 parent 913f457 commit 22ab4d1 Copy full SHA for 22ab4d1
File tree 3 files changed +29
-2
lines changed
3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -188,7 +188,7 @@ impl Config {
188
188
if let Some ( env_value) = self . env . target ( ) {
189
189
return Ok ( Some ( Target :: from ( & env_value, target_list) ) ) ;
190
190
}
191
- Ok ( None )
191
+ self . toml . as_ref ( ) . map_or ( Ok ( None ) , |t| t . target ( target_list ) )
192
192
}
193
193
194
194
fn sum_of_env_toml_values < ' a > (
@@ -402,6 +402,20 @@ mod tests {
402
402
Ok ( ( ) )
403
403
}
404
404
405
+ #[ test]
406
+ pub fn no_env_but_toml_default_target_then_use_toml ( ) -> Result < ( ) > {
407
+ let env = Environment :: new ( None ) ;
408
+ let config = Config :: new_with ( Some ( toml ( TOML_DEFAULT_TARGET ) ?) , env) ;
409
+
410
+ let config_target = config. target ( & target_list ( ) ) ?. unwrap ( ) ;
411
+ assert ! ( matches!(
412
+ config_target. triple( ) ,
413
+ "aarch64-unknown-linux-gnu"
414
+ ) ) ;
415
+
416
+ Ok ( ( ) )
417
+ }
418
+
405
419
static TOML_BUILD_XARGO_FALSE : & str = r#"
406
420
[build]
407
421
xargo = false
@@ -421,7 +435,7 @@ mod tests {
421
435
422
436
static TOML_DEFAULT_TARGET : & str = r#"
423
437
[build]
424
- default = "aarch64-unknown-linux-gnu"
438
+ target = "aarch64-unknown-linux-gnu"
425
439
"# ;
426
440
}
427
441
}
Original file line number Diff line number Diff line change @@ -485,6 +485,18 @@ impl Toml {
485
485
self . target_env ( target, "volumes" )
486
486
}
487
487
488
+ /// Returns the default target to build,
489
+ pub fn target ( & self , target_list : & TargetList ) -> Result < Option < Target > > {
490
+ if let Some ( value) = self . table . get ( "build" ) . and_then ( |t| t. get ( "target" ) ) {
491
+ let value = value
492
+ . as_str ( )
493
+ . ok_or_else ( || "build.target must be a string" . to_string ( ) ) ?;
494
+ Ok ( Some ( Target :: from ( & value, target_list) ) )
495
+ } else {
496
+ Ok ( None )
497
+ }
498
+ }
499
+
488
500
fn target_env ( & self , target : & Target , key : & str ) -> Result < Vec < & str > > {
489
501
let triple = target. triple ( ) ;
490
502
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use crate::{Host, Target};
7
7
use crate :: errors:: * ;
8
8
use crate :: extensions:: CommandExt ;
9
9
10
+ #[ derive( Debug ) ]
10
11
pub struct TargetList {
11
12
pub triples : Vec < String > ,
12
13
}
You can’t perform that action at this time.
0 commit comments