@@ -17,6 +17,9 @@ use serde::{Deserialize, Deserializer, Serialize};
1717#[ derive( Debug , Serialize , Deserialize , PartialEq , Eq , Default ) ]
1818#[ serde( rename_all = "kebab-case" ) ]
1919pub struct CrossEnvConfig {
20+ // TODO(ahuszagh) Change to an enum
21+ cargo_config : Option < CargoConfigBehavior > ,
22+ complete_cargo_config : Option < bool > ,
2023 ignore_cargo_config : Option < bool > ,
2124 volumes : Option < Vec < String > > ,
2225 passthrough : Option < Vec < String > > ,
@@ -84,6 +87,34 @@ pub struct CrossToml {
8487 pub build : CrossBuildConfig ,
8588}
8689
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+
87118impl CrossToml {
88119 /// Obtains the [`CrossToml`] from one of the possible locations
89120 ///
@@ -324,6 +355,24 @@ impl CrossToml {
324355 self . get_value ( target, |b| b. build_std , |t| t. build_std )
325356 }
326357
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+
327376 /// Returns the whether to ignore cargo config files.
328377 pub fn env_ignore_cargo_config ( & self , target : & Target ) -> ( Option < bool > , Option < bool > ) {
329378 self . get_value (
@@ -529,6 +578,18 @@ mod tests {
529578 } ;
530579 }
531580
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+
532593 #[ test]
533594 pub fn parse_empty_toml ( ) -> Result < ( ) > {
534595 let cfg = CrossToml {
@@ -549,6 +610,9 @@ mod tests {
549610 targets : HashMap :: new ( ) ,
550611 build : CrossBuildConfig {
551612 env : CrossEnvConfig {
613+ // TODO(ahuszagh) Remove
614+ cargo_config : None ,
615+ complete_cargo_config : None ,
552616 ignore_cargo_config : Some ( false ) ,
553617 volumes : Some ( vec ! [ s!( "VOL1_ARG" ) , s!( "VOL2_ARG" ) ] ) ,
554618 passthrough : Some ( vec ! [ s!( "VAR1" ) , s!( "VAR2" ) ] ) ,
@@ -588,6 +652,9 @@ mod tests {
588652 } ,
589653 CrossTargetConfig {
590654 env : CrossEnvConfig {
655+ // TODO(ahuszagh) Remove
656+ cargo_config : None ,
657+ complete_cargo_config : None ,
591658 ignore_cargo_config : None ,
592659 passthrough : Some ( vec ! [ s!( "VAR1" ) , s!( "VAR2" ) ] ) ,
593660 volumes : Some ( vec ! [ s!( "VOL1_ARG" ) , s!( "VOL2_ARG" ) ] ) ,
@@ -643,6 +710,9 @@ mod tests {
643710 pre_build : Some ( PreBuild :: Lines ( vec ! [ s!( "echo 'Hello'" ) ] ) ) ,
644711 runner : None ,
645712 env : CrossEnvConfig {
713+ // TODO(ahuszagh) Remove
714+ cargo_config : None ,
715+ complete_cargo_config : None ,
646716 ignore_cargo_config : None ,
647717 passthrough : None ,
648718 volumes : Some ( vec ! [ s!( "VOL" ) ] ) ,
@@ -654,6 +724,9 @@ mod tests {
654724 targets : target_map,
655725 build : CrossBuildConfig {
656726 env : CrossEnvConfig {
727+ // TODO(ahuszagh) Remove
728+ cargo_config : None ,
729+ complete_cargo_config : None ,
657730 ignore_cargo_config : Some ( true ) ,
658731 volumes : None ,
659732 passthrough : Some ( vec ! [ ] ) ,
@@ -714,6 +787,9 @@ mod tests {
714787 targets : HashMap :: new ( ) ,
715788 build : CrossBuildConfig {
716789 env : CrossEnvConfig {
790+ // TODO(ahuszagh) Remove
791+ cargo_config : None ,
792+ complete_cargo_config : None ,
717793 ignore_cargo_config : None ,
718794 passthrough : None ,
719795 volumes : None ,
0 commit comments