gz / rust-cpuid

cpuid library in rust.
https://docs.rs/raw-cpuid/
MIT License
150 stars 45 forks source link

Fixed build when native_cpuid is not avalible on target #85

Closed IsaacDynamo closed 2 years ago

IsaacDynamo commented 2 years ago

Currently building for a non-conventional x86 target fails with:

   Compiling raw-cpuid v10.2.0
error[E0433]: failed to resolve: could not find `arch` in `self`
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/raw-cpuid-10.2.0/src/lib.rs:80:37
   |
80 |         let result = unsafe { self::arch::__cpuid_count(a, c) };
   |                                     ^^^^ could not find `arch` in `self`

This is because the target has no SSE, and therefore it has no native cpuid according to this create.

This PR only enables ::native_cpuid and the functions that depend on it, when the target has support for it.

Targets that by this create are considered to not have native cpuid, can still provide there own function via CpuId::with_cpuid_fn().

If core::arch::x86::has_cpuid() stabilizes, it could be used to detect cpuid support at runtime to better cover supported target.

With these changes I was able to output the following 😁 Hello world from GenuineIntel Intel (R) Quark (TM) D1100 CPU @ 32MHz

gz commented 2 years ago

lgtm, can you rebase on the CI fixes I just merged from your other pull request?

IsaacDynamo commented 2 years ago

Done. Thanks quick response and your crates!

gz commented 2 years ago

Released as 10.3. Thanks a lot for the contribution.