@@ -67,8 +67,8 @@ pub fn find_tool(target: &str, tool: &str) -> Option<Tool> {
6767 }
6868
6969 // 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 ) {
7272 return env:: var_os ( "PATH" )
7373 . and_then ( |path| {
7474 env:: split_paths ( & path)
@@ -91,6 +91,26 @@ pub fn find_tool(target: &str, tool: &str) -> Option<Tool> {
9191 . or_else ( || impl_:: find_msvc_11 ( tool, target) ) ;
9292}
9393
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+
94114/// A version of Visual Studio
95115#[ derive( Debug , PartialEq , Eq , Copy , Clone ) ]
96116pub enum VsVers {
0 commit comments