1
1
use std:: collections:: HashSet ;
2
- use std:: env;
3
- use std:: fs;
4
2
use std:: path:: { Path , PathBuf } ;
5
3
use std:: process:: { Command , Stdio } ;
4
+ use std:: { env, fs} ;
6
5
7
6
fn build_backend ( ) {
8
7
println ! ( "Building Backend!" ) ;
@@ -85,15 +84,19 @@ fn main() {
85
84
if env:: var_os ( "CARGO_FEATURE_STATICLIB" ) . is_some ( ) {
86
85
return ;
87
86
}
88
-
87
+
89
88
build_backend ( ) ;
90
89
}
91
90
92
91
/// Returns the Rustup proxy for Cargo.
93
92
// Adapted from Hermit.
94
- fn cargo ( ) -> Command {
95
- let cargo = {
96
- let exe = format ! ( "cargo{}" , env:: consts:: EXE_SUFFIX ) ;
93
+ pub fn cargo ( ) -> Command {
94
+ sanitize ( "cargo" )
95
+ }
96
+
97
+ fn sanitize ( cmd : & str ) -> Command {
98
+ let cmd = {
99
+ let exe = format ! ( "{cmd}{}" , env:: consts:: EXE_SUFFIX ) ;
97
100
// On windows, the userspace toolchain ends up in front of the rustup proxy in $PATH.
98
101
// To reach the rustup proxy nonetheless, we explicitly query $CARGO_HOME.
99
102
let mut cargo_home = PathBuf :: from ( env:: var_os ( "CARGO_HOME" ) . unwrap ( ) ) ;
@@ -106,17 +109,22 @@ fn cargo() -> Command {
106
109
}
107
110
} ;
108
111
109
- let mut cargo = Command :: new ( cargo) ;
112
+ let mut cmd = Command :: new ( cmd) ;
113
+
114
+ cmd. current_dir ( env:: var_os ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ) ;
110
115
111
116
// Remove rust-toolchain-specific environment variables from kernel cargo
112
- cargo . env_remove ( "LD_LIBRARY_PATH" ) ;
117
+ cmd . env_remove ( "LD_LIBRARY_PATH" ) ;
113
118
env:: vars ( )
114
- . filter ( |( key, _value) | key. starts_with ( "CARGO" ) || key. starts_with ( "RUST" ) )
119
+ . filter ( |( key, _value) | {
120
+ key. starts_with ( "CARGO" ) && !key. starts_with ( "CARGO_HOME" )
121
+ || key. starts_with ( "RUST" ) && !key. starts_with ( "RUSTUP_HOME" )
122
+ } )
115
123
. for_each ( |( key, _value) | {
116
- cargo . env_remove ( & key) ;
124
+ cmd . env_remove ( & key) ;
117
125
} ) ;
118
126
119
- cargo
127
+ cmd
120
128
}
121
129
122
130
/// Makes all internal symbols private to avoid duplicated symbols.
0 commit comments