@@ -17,6 +17,9 @@ use serde::{Deserialize, Deserializer, Serialize};
17
17
#[ derive( Debug , Serialize , Deserialize , PartialEq , Eq , Default ) ]
18
18
#[ serde( rename_all = "kebab-case" ) ]
19
19
pub struct CrossEnvConfig {
20
+ // TODO(ahuszagh) Change to an enum
21
+ cargo_config : Option < CargoConfigBehavior > ,
22
+ complete_cargo_config : Option < bool > ,
20
23
ignore_cargo_config : Option < bool > ,
21
24
volumes : Option < Vec < String > > ,
22
25
passthrough : Option < Vec < String > > ,
@@ -84,6 +87,34 @@ pub struct CrossToml {
84
87
pub build : CrossBuildConfig ,
85
88
}
86
89
90
+ #[ derive( Debug , Serialize , Deserialize , PartialEq , Eq , Clone , Copy ) ]
91
+ #[ serde( rename_all = "kebab-case" ) ]
92
+ pub enum CargoConfigBehavior {
93
+ Ignore ,
94
+ #[ serde( rename = "default" ) ]
95
+ Normal ,
96
+ Complete ,
97
+ }
98
+
99
+ impl Default for CargoConfigBehavior {
100
+ fn default ( ) -> CargoConfigBehavior {
101
+ CargoConfigBehavior :: Normal
102
+ }
103
+ }
104
+
105
+ impl FromStr for CargoConfigBehavior {
106
+ type Err = eyre:: Error ;
107
+
108
+ fn from_str ( s : & str ) -> Result < CargoConfigBehavior > {
109
+ match s {
110
+ "ignore" => Ok ( CargoConfigBehavior :: Ignore ) ,
111
+ "default" => Ok ( CargoConfigBehavior :: Normal ) ,
112
+ "complete" => Ok ( CargoConfigBehavior :: Complete ) ,
113
+ _ => eyre:: bail!( "invalid cargo config behavior, got {s}" ) ,
114
+ }
115
+ }
116
+ }
117
+
87
118
impl CrossToml {
88
119
/// Obtains the [`CrossToml`] from one of the possible locations
89
120
///
@@ -324,6 +355,24 @@ impl CrossToml {
324
355
self . get_value ( target, |b| b. build_std , |t| t. build_std )
325
356
}
326
357
358
+ /// Returns the cargo config behavior.
359
+ pub fn env_cargo_config ( & self , target : & Target ) -> ( Option < CargoConfigBehavior > , Option < CargoConfigBehavior > ) {
360
+ self . get_value (
361
+ target,
362
+ |b| b. env . cargo_config ,
363
+ |t| t. env . cargo_config ,
364
+ )
365
+ }
366
+
367
+ /// Returns the whether to use the complete cargo config settings.
368
+ pub fn env_complete_cargo_config ( & self , target : & Target ) -> ( Option < bool > , Option < bool > ) {
369
+ self . get_value (
370
+ target,
371
+ |b| b. env . complete_cargo_config ,
372
+ |t| t. env . complete_cargo_config ,
373
+ )
374
+ }
375
+
327
376
/// Returns the whether to ignore cargo config files.
328
377
pub fn env_ignore_cargo_config ( & self , target : & Target ) -> ( Option < bool > , Option < bool > ) {
329
378
self . get_value (
@@ -529,6 +578,18 @@ mod tests {
529
578
} ;
530
579
}
531
580
581
+ #[ test]
582
+ pub fn test_toml_cargo_config_behavior ( ) -> Result < ( ) > {
583
+ assert_eq ! ( CargoConfigBehavior :: Normal , toml:: from_str( "\" default\" " ) ?) ;
584
+ assert_eq ! ( CargoConfigBehavior :: Ignore , toml:: from_str( "\" ignore\" " ) ?) ;
585
+ assert_eq ! ( CargoConfigBehavior :: Complete , toml:: from_str( "\" complete\" " ) ?) ;
586
+ assert ! ( toml:: from_str:: <CargoConfigBehavior >( "\" other\" " ) . is_err( ) ) ;
587
+ assert ! ( toml:: from_str:: <CargoConfigBehavior >( "true" ) . is_err( ) ) ;
588
+ assert ! ( toml:: from_str:: <CargoConfigBehavior >( "0" ) . is_err( ) ) ;
589
+
590
+ Ok ( ( ) )
591
+ }
592
+
532
593
#[ test]
533
594
pub fn parse_empty_toml ( ) -> Result < ( ) > {
534
595
let cfg = CrossToml {
@@ -549,6 +610,9 @@ mod tests {
549
610
targets : HashMap :: new ( ) ,
550
611
build : CrossBuildConfig {
551
612
env : CrossEnvConfig {
613
+ // TODO(ahuszagh) Remove
614
+ cargo_config : None ,
615
+ complete_cargo_config : None ,
552
616
ignore_cargo_config : Some ( false ) ,
553
617
volumes : Some ( vec ! [ s!( "VOL1_ARG" ) , s!( "VOL2_ARG" ) ] ) ,
554
618
passthrough : Some ( vec ! [ s!( "VAR1" ) , s!( "VAR2" ) ] ) ,
@@ -588,6 +652,9 @@ mod tests {
588
652
} ,
589
653
CrossTargetConfig {
590
654
env : CrossEnvConfig {
655
+ // TODO(ahuszagh) Remove
656
+ cargo_config : None ,
657
+ complete_cargo_config : None ,
591
658
ignore_cargo_config : None ,
592
659
passthrough : Some ( vec ! [ s!( "VAR1" ) , s!( "VAR2" ) ] ) ,
593
660
volumes : Some ( vec ! [ s!( "VOL1_ARG" ) , s!( "VOL2_ARG" ) ] ) ,
@@ -643,6 +710,9 @@ mod tests {
643
710
pre_build : Some ( PreBuild :: Lines ( vec ! [ s!( "echo 'Hello'" ) ] ) ) ,
644
711
runner : None ,
645
712
env : CrossEnvConfig {
713
+ // TODO(ahuszagh) Remove
714
+ cargo_config : None ,
715
+ complete_cargo_config : None ,
646
716
ignore_cargo_config : None ,
647
717
passthrough : None ,
648
718
volumes : Some ( vec ! [ s!( "VOL" ) ] ) ,
@@ -654,6 +724,9 @@ mod tests {
654
724
targets : target_map,
655
725
build : CrossBuildConfig {
656
726
env : CrossEnvConfig {
727
+ // TODO(ahuszagh) Remove
728
+ cargo_config : None ,
729
+ complete_cargo_config : None ,
657
730
ignore_cargo_config : Some ( true ) ,
658
731
volumes : None ,
659
732
passthrough : Some ( vec ! [ ] ) ,
@@ -714,6 +787,9 @@ mod tests {
714
787
targets : HashMap :: new ( ) ,
715
788
build : CrossBuildConfig {
716
789
env : CrossEnvConfig {
790
+ // TODO(ahuszagh) Remove
791
+ cargo_config : None ,
792
+ complete_cargo_config : None ,
717
793
ignore_cargo_config : None ,
718
794
passthrough : None ,
719
795
volumes : None ,
0 commit comments