@@ -4,12 +4,15 @@ use std::path::{Path, PathBuf};
44
55use serde:: { Deserialize , Serialize } ;
66
7- #[ derive( Debug , Clone , Default , Deserialize , Serialize ) ]
7+ #[ derive( Debug , Clone , Deserialize , Serialize ) ]
88#[ serde( rename_all = "kebab-case" , deny_unknown_fields) ]
99pub struct RustBackendConfig {
1010 /// Extra args to pass for cargo
1111 #[ serde( default ) ]
1212 pub extra_args : Vec < String > ,
13+ /// System environment variables
14+ #[ serde( skip) ]
15+ pub system_env : IndexMap < String , String > ,
1316 /// Environment Variables
1417 #[ serde( default ) ]
1518 pub env : IndexMap < String , String > ,
@@ -28,7 +31,38 @@ pub struct RustBackendConfig {
2831 pub compilers : Option < Vec < String > > ,
2932}
3033
34+ impl Default for RustBackendConfig {
35+ fn default ( ) -> Self {
36+ Self :: new_with_system_environment ( )
37+ }
38+ }
39+
40+ fn collect_system_env ( ) -> IndexMap < String , String > {
41+ std:: env:: vars ( ) . collect ( )
42+ }
43+
3144impl RustBackendConfig {
45+ /// Create a new `RustBackendConfiguration` with the current system environment.
46+ pub fn new_with_system_environment ( ) -> Self {
47+ Self {
48+ system_env : collect_system_env ( ) ,
49+ ..Self :: new_with_clean_environment ( )
50+ }
51+ }
52+
53+ /// Create a new `RustBackendConfiguration` with an empty system environment.
54+ pub fn new_with_clean_environment ( ) -> Self {
55+ Self {
56+ system_env : Default :: default ( ) ,
57+ extra_args : Default :: default ( ) ,
58+ env : Default :: default ( ) ,
59+ debug_dir : Default :: default ( ) ,
60+ extra_input_globs : Default :: default ( ) ,
61+ ignore_cargo_manifest : Default :: default ( ) ,
62+ compilers : Default :: default ( ) ,
63+ }
64+ }
65+
3266 /// Creates a new [`RustBackendConfig`] with default values and
3367 /// `ignore_cargo_manifest` set to `true`.
3468 #[ cfg( test) ]
@@ -62,6 +96,7 @@ impl BackendConfig for RustBackendConfig {
6296 } else {
6397 target_config. extra_args . clone ( )
6498 } ,
99+ system_env : collect_system_env ( ) ,
65100 env : {
66101 let mut merged_env = self . env . clone ( ) ;
67102 merged_env. extend ( target_config. env . clone ( ) ) ;
@@ -123,6 +158,7 @@ mod tests {
123158 let base_config = RustBackendConfig {
124159 extra_args : vec ! [ "--base-arg" . to_string( ) ] ,
125160 env : base_env,
161+ system_env : Default :: default ( ) ,
126162 debug_dir : Some ( PathBuf :: from ( "/base/debug" ) ) ,
127163 extra_input_globs : vec ! [ "*.base" . to_string( ) ] ,
128164 ignore_cargo_manifest : None ,
@@ -136,6 +172,7 @@ mod tests {
136172 let target_config = RustBackendConfig {
137173 extra_args : vec ! [ "--target-arg" . to_string( ) ] ,
138174 env : target_env,
175+ system_env : Default :: default ( ) ,
139176 debug_dir : None ,
140177 extra_input_globs : vec ! [ "*.target" . to_string( ) ] ,
141178 ignore_cargo_manifest : Some ( true ) ,
@@ -181,6 +218,7 @@ mod tests {
181218 let base_config = RustBackendConfig {
182219 extra_args : vec ! [ "--base-arg" . to_string( ) ] ,
183220 env : base_env,
221+ system_env : Default :: default ( ) ,
184222 debug_dir : Some ( PathBuf :: from ( "/base/debug" ) ) ,
185223 extra_input_globs : vec ! [ "*.base" . to_string( ) ] ,
186224 ignore_cargo_manifest : None ,
0 commit comments