@@ -67,8 +67,8 @@ pub fn find_tool(target: &str, tool: &str) -> Option<Tool> {
67
67
}
68
68
69
69
// If VCINSTALLDIR is set, then someone's probably already run vcvars and we
70
- // should just find whatever that indicates.
71
- if env:: var_os ( "VCINSTALLDIR" ) . is_some ( ) {
70
+ // should just find whatever that indicates, unless its target arch differs .
71
+ if env:: var_os ( "VCINSTALLDIR" ) . is_some ( ) && is_vscmd_target ( target ) {
72
72
return env:: var_os ( "PATH" )
73
73
. and_then ( |path| {
74
74
env:: split_paths ( & path)
@@ -91,6 +91,26 @@ pub fn find_tool(target: &str, tool: &str) -> Option<Tool> {
91
91
. or_else ( || impl_:: find_msvc_11 ( tool, target) ) ;
92
92
}
93
93
94
+ /// Checks to see if the `VSCMD_ARG_TGT_ARCH` environment variable matches the
95
+ /// given target's arch. Returns false otherwise.
96
+ /// Fixes: https://github.com/rust-lang/rust/issues/43468
97
+ #[ cfg( windows) ]
98
+ fn is_vscmd_target ( target : & str ) -> bool {
99
+ // Convert the Rust target arch to its VS arch equivalent.
100
+ let arch = match target. split ( "-" ) . next ( ) {
101
+ Some ( "x86_64" ) => "x64" ,
102
+ Some ( "aarch64" ) => "arm64" ,
103
+ Some ( "i686" ) | Some ( "i586" ) => "x86" ,
104
+ Some ( "thumbv7a" ) => "arm" ,
105
+ _ => return false ,
106
+ } ;
107
+ if let Ok ( vscmd_target) = std:: env:: var ( "VSCMD_ARG_TGT_ARCH" ) {
108
+ vscmd_target == arch
109
+ } else {
110
+ false
111
+ }
112
+ }
113
+
94
114
/// A version of Visual Studio
95
115
#[ derive( Debug , PartialEq , Eq , Copy , Clone ) ]
96
116
pub enum VsVers {
0 commit comments