rust_rdrand icon indicating copy to clipboard operation
rust_rdrand copied to clipboard

Doesn't compile on Apple Silicon

Open smessmer opened this issue 3 years ago • 2 comments

Trying to compile this crate on Apple M1 Silicon errors with

error[E0425]: cannot find function `__cpuid` in module `arch`
   --> /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/rdrand-0.8.2/src/lib.rs:163:33
    |
163 |     let cpuid0 = unsafe { arch::__cpuid(0) };
    |                                 ^^^^^^^ not found in `arch`

error[E0412]: cannot find type `CpuidResult` in module `arch`
   --> /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/rdrand-0.8.2/src/lib.rs:171:30
    |
171 | fn amd_family(cpuid1: &arch::CpuidResult) -> u32 {
    |                              ^^^^^^^^^^^ not found in `arch`

error[E0412]: cannot find type `CpuidResult` in module `arch`
   --> /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/rdrand-0.8.2/src/lib.rs:176:30
    |
176 | fn has_rdrand(cpuid1: &arch::CpuidResult) -> bool {
    |                              ^^^^^^^^^^^ not found in `arch`

error[E0425]: cannot find function `__cpuid` in module `arch`
   --> /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/rdrand-0.8.2/src/lib.rs:184:20
    |
184 |     unsafe { arch::__cpuid(7).ebx & FLAG == FLAG }
    |                    ^^^^^^^ not found in `arch`

smessmer avatar Apr 27 '22 22:04 smessmer

Oh thinking a bit further about it, is do those chips even have a rdrand instruction?

smessmer avatar Apr 27 '22 22:04 smessmer

Apple Silicon does not support the instruction, but it would still be nice to compile to a crate that does not have any functionality and just returns errors at runtime, just like they return errors when the instruction is not supported on x86_64, so that this kind of conditionality wasn’t necessary in the users’ code.

nagisa avatar Jan 18 '23 16:01 nagisa