@@ -12,6 +12,8 @@ pub struct CrossEnvConfig {
1212 volumes : Vec < String > ,
1313 #[ serde( default ) ]
1414 passthrough : Vec < String > ,
15+ #[ serde( default , alias = "var" ) ]
16+ variable : HashMap < String , String > ,
1517}
1618
1719/// Build configuration
@@ -79,17 +81,28 @@ impl CrossToml {
7981 . map_or ( Vec :: new ( ) , |t| t. env . passthrough . clone ( ) )
8082 }
8183
82- /// Returns the list of environment variables to pass through for `build`,
84+ /// Returns the list of environment variables to use for/as volumes in `build`,
8385 pub fn env_volumes_build ( & self ) -> Vec < String > {
8486 self . build . env . volumes . clone ( )
8587 }
8688
87- /// Returns the list of environment variables to pass through for `target`,
89+ /// Returns the list of environment variables to use for/as volumes in `target`,
8890 pub fn env_volumes_target ( & self , target : & Target ) -> Vec < String > {
8991 self . get_target ( target)
9092 . map_or ( Vec :: new ( ) , |t| t. env . volumes . clone ( ) )
9193 }
9294
95+ /// Returns the list of environment variables to set and pass through
96+ pub fn env_variable_target ( & self , target : & Target ) -> HashMap < String , String > {
97+ self . get_target ( target)
98+ . map_or ( HashMap :: new ( ) , |t| t. env . variable . clone ( ) )
99+ }
100+
101+ /// Returns the list of environment variables to set and pass through
102+ pub fn env_variable_build ( & self ) -> HashMap < String , String > {
103+ self . build . env . variable . clone ( )
104+ }
105+
93106 /// Returns the default target to build,
94107 pub fn default_target ( & self , target_list : & TargetList ) -> Option < Target > {
95108 self . build
@@ -129,6 +142,7 @@ mod tests {
129142 env : CrossEnvConfig {
130143 volumes : vec ! [ "VOL1_ARG" . to_string( ) , "VOL2_ARG" . to_string( ) ] ,
131144 passthrough : vec ! [ "VAR1" . to_string( ) , "VAR2" . to_string( ) ] ,
145+ variable : [ ( "ARG1" . to_owned ( ) , "value" . to_owned ( ) ) ] . into ( ) ,
132146 } ,
133147 xargo : Some ( true ) ,
134148 default_target : None ,
@@ -142,6 +156,7 @@ mod tests {
142156 [build.env]
143157 volumes = ["VOL1_ARG", "VOL2_ARG"]
144158 passthrough = ["VAR1", "VAR2"]
159+ var.ARG1 = "value"
145160 "# ;
146161 let parsed_cfg = CrossToml :: from_str ( test_str) ?;
147162
@@ -161,6 +176,7 @@ mod tests {
161176 env : CrossEnvConfig {
162177 passthrough : vec ! [ "VAR1" . to_string( ) , "VAR2" . to_string( ) ] ,
163178 volumes : vec ! [ "VOL1_ARG" . to_string( ) , "VOL2_ARG" . to_string( ) ] ,
179+ variable : [ ( "ARG1" . to_owned ( ) , "value" . to_owned ( ) ) ] . into ( ) ,
164180 } ,
165181 xargo : Some ( false ) ,
166182 image : Some ( "test-image" . to_string ( ) ) ,
@@ -177,6 +193,7 @@ mod tests {
177193 [target.aarch64-unknown-linux-gnu.env]
178194 volumes = ["VOL1_ARG", "VOL2_ARG"]
179195 passthrough = ["VAR1", "VAR2"]
196+ var.ARG1 = "value"
180197 [target.aarch64-unknown-linux-gnu]
181198 xargo = false
182199 image = "test-image"
0 commit comments