@@ -228,24 +228,30 @@ impl TargetTriple {
228
228
pub ( crate ) fn from_host ( ) -> Option < Self > {
229
229
#[ cfg( windows) ]
230
230
fn inner ( ) -> Option < TargetTriple > {
231
- use std :: mem ;
232
- use winapi:: um:: sysinfoapi :: GetNativeSystemInfo ;
231
+ use winapi :: um :: processthreadsapi :: GetCurrentProcess ;
232
+ use winapi:: um:: wow64apiset :: IsWow64Process2 ;
233
233
234
234
// First detect architecture
235
- const PROCESSOR_ARCHITECTURE_AMD64 : u16 = 9 ;
236
- const PROCESSOR_ARCHITECTURE_INTEL : u16 = 0 ;
237
- const PROCESSOR_ARCHITECTURE_ARM64 : u16 = 12 ;
238
-
239
- let mut sys_info;
240
- unsafe {
241
- sys_info = mem:: zeroed ( ) ;
242
- GetNativeSystemInfo ( & mut sys_info) ;
243
- }
235
+ const IMAGE_FILE_MACHINE_ARM64 : u16 = 0xAA64 ;
236
+ const IMAGE_FILE_MACHINE_AMD64 : u16 = 0x8664 ;
237
+ const IMAGE_FILE_MACHINE_I386 : u16 = 0x014c ;
238
+
239
+ let native_machine = unsafe {
240
+ // cannot fail; handle does not need to be closed.
241
+ let process = GetCurrentProcess ( ) ;
242
+ let mut _machine = 0 ;
243
+ let mut native_machine = 0 ;
244
+ // native_machine is the native architecture of host system.
245
+ if IsWow64Process2 ( process, & mut _machine, & mut native_machine) == 0 {
246
+ return None ;
247
+ }
248
+ native_machine
249
+ } ;
244
250
245
- let arch = match unsafe { sys_info . u . s ( ) } . wProcessorArchitecture {
246
- PROCESSOR_ARCHITECTURE_AMD64 => "x86_64" ,
247
- PROCESSOR_ARCHITECTURE_INTEL => "i686" ,
248
- PROCESSOR_ARCHITECTURE_ARM64 => "aarch64" ,
251
+ let arch = match native_machine {
252
+ IMAGE_FILE_MACHINE_AMD64 => "x86_64" ,
253
+ IMAGE_FILE_MACHINE_I386 => "i686" ,
254
+ IMAGE_FILE_MACHINE_ARM64 => "aarch64" ,
249
255
_ => return None ,
250
256
} ;
251
257
@@ -328,12 +334,12 @@ impl TargetTriple {
328
334
let ret = if partial_self. os != partial_other. os {
329
335
false
330
336
} else if partial_self. os . as_deref ( ) == Some ( "pc-windows" ) {
331
- // Windows is a special case here, we know we can run 32bit on 64bit
332
- // and we know we can run gnu and msvc on the same system
333
- // We don't immediately assume we can cross between x86 and aarch64 though
337
+ // Windows is a special case here: we can run gnu and msvc on the same system,
338
+ // i686 can run on x86_64, and both x86_64 and i686 can run on aarch64 through emulation
334
339
( partial_self. arch == partial_other. arch )
335
340
|| ( partial_self. arch . as_deref ( ) == Some ( "x86_64" )
336
341
&& partial_other. arch . as_deref ( ) == Some ( "i686" ) )
342
+ || partial_self. arch . as_deref ( ) == Some ( "aarch64" )
337
343
} else {
338
344
// For other OSes, for now, we assume other toolchains won't run
339
345
false
0 commit comments