Skip to content

Commit f0da9d6

Browse files
IsaacDynamogz
authored andcommitted
Fixed build when native_cpuid is not avalible on target
1 parent 128a591 commit f0da9d6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ extern crate serde;
6565
#[macro_use]
6666
extern crate bitflags;
6767

68+
#[cfg_attr(any(all(target_arch = "x86", not(target_env = "sgx"), target_feature = "sse"), all(target_arch = "x86_64", not(target_env = "sgx"))), has_native_cpuid)]
69+
6870
/// Uses Rust's `cpuid` function from the `arch` module.
71+
#[cfg(has_native_cpuid)]
6972
pub mod native_cpuid {
7073
use crate::CpuIdResult;
7174

@@ -105,6 +108,7 @@ mod std {
105108
///
106109
/// First parameter is cpuid leaf (EAX register value),
107110
/// second optional parameter is the subleaf (ECX register value).
111+
#[cfg(has_native_cpuid)]
108112
#[macro_export]
109113
macro_rules! cpuid {
110114
($eax:expr) => {
@@ -175,6 +179,7 @@ impl CpuIdReader {
175179
}
176180
}
177181

182+
#[cfg(has_native_cpuid)]
178183
impl Default for CpuIdReader {
179184
fn default() -> Self {
180185
Self {
@@ -223,6 +228,7 @@ pub struct CpuId {
223228
supported_extended_leafs: u32,
224229
}
225230

231+
#[cfg(has_native_cpuid)]
226232
impl Default for CpuId {
227233
fn default() -> CpuId {
228234
CpuId::with_cpuid_fn(native_cpuid::cpuid_count)
@@ -304,6 +310,7 @@ const EAX_SVM_FEATURES: u32 = 0x8000_000A;
304310

305311
impl CpuId {
306312
/// Return new CpuId struct.
313+
#[cfg(has_native_cpuid)]
307314
pub fn new() -> Self {
308315
Self::default()
309316
}
@@ -5129,9 +5136,9 @@ impl SoCVendorInfo {
51295136
pub fn get_vendor_brand(&self) -> Option<SoCVendorBrand> {
51305137
// Leaf 17H is valid if MaxSOCID_Index >= 3.
51315138
if self.eax >= 3 {
5132-
let r1 = cpuid!(EAX_SOC_VENDOR_INFO, 1);
5133-
let r2 = cpuid!(EAX_SOC_VENDOR_INFO, 2);
5134-
let r3 = cpuid!(EAX_SOC_VENDOR_INFO, 3);
5139+
let r1 = self.read.cpuid2(EAX_SOC_VENDOR_INFO, 1);
5140+
let r2 = self.read.cpuid2(EAX_SOC_VENDOR_INFO, 2);
5141+
let r3 = self.read.cpuid2(EAX_SOC_VENDOR_INFO, 3);
51355142
Some(SoCVendorBrand { data: [r1, r2, r3] })
51365143
} else {
51375144
None

0 commit comments

Comments
 (0)