forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#34492 - retep998:please-be-robust-already, r=…
…alexcrichton Make MSVC detection ludicrously robust Resurrection of rust-lang#31158 r? @alexcrichton
- Loading branch information
Showing
4 changed files
with
260 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![allow(non_camel_case_types, non_snake_case)] | ||
|
||
use libc::c_void; | ||
use std::mem; | ||
|
||
type DWORD = u32; | ||
type WORD = u16; | ||
type LPVOID = *mut c_void; | ||
type DWORD_PTR = usize; | ||
|
||
const PROCESSOR_ARCHITECTURE_INTEL: WORD = 0; | ||
const PROCESSOR_ARCHITECTURE_AMD64: WORD = 9; | ||
|
||
#[repr(C)] | ||
struct SYSTEM_INFO { | ||
wProcessorArchitecture: WORD, | ||
_wReserved: WORD, | ||
_dwPageSize: DWORD, | ||
_lpMinimumApplicationAddress: LPVOID, | ||
_lpMaximumApplicationAddress: LPVOID, | ||
_dwActiveProcessorMask: DWORD_PTR, | ||
_dwNumberOfProcessors: DWORD, | ||
_dwProcessorType: DWORD, | ||
_dwAllocationGranularity: DWORD, | ||
_wProcessorLevel: WORD, | ||
_wProcessorRevision: WORD, | ||
} | ||
|
||
extern "system" { | ||
fn GetNativeSystemInfo(lpSystemInfo: *mut SYSTEM_INFO); | ||
} | ||
|
||
pub enum Arch { | ||
X86, | ||
Amd64, | ||
} | ||
|
||
pub fn host_arch() -> Option<Arch> { | ||
let mut info = unsafe { mem::zeroed() }; | ||
unsafe { GetNativeSystemInfo(&mut info) }; | ||
match info.wProcessorArchitecture { | ||
PROCESSOR_ARCHITECTURE_INTEL => Some(Arch::X86), | ||
PROCESSOR_ARCHITECTURE_AMD64 => Some(Arch::Amd64), | ||
_ => None, | ||
} | ||
} |
Oops, something went wrong.