Skip to content

Commit

Permalink
cpufeatures: support freestanding/UEFI x86 targets (#821)
Browse files Browse the repository at this point in the history
This fixes compilation of dependent crates for these targets.

For example, `sha2`:

Before:
```
$ cargo build --target x86_64-unknown-none --no-default-features
   Compiling sha2 v0.10.6 (/home/rvolosatovs/src/github.com/rustcrypto/hashes/sha2)
LLVM ERROR: Do not know how to split the result of this operator!

error: could not compile `sha2`
$ cargo build --target x86_64-unknown-uefi --no-default-features
   Compiling sha2 v0.10.6 (/home/rvolosatovs/src/github.com/rustcrypto/hashes/sha2)
LLVM ERROR: Do not know how to split the result of this operator!

error: could not compile `sha2`
```

After:
```
$ cargo build --target x86_64-unknown-none --no-default-features
   Compiling cpufeatures v0.2.5 (/home/rvolosatovs/src/github.com/rustcrypto/utils/cpufeatures)
   Compiling sha2 v0.10.6 (/home/rvolosatovs/src/github.com/rustcrypto/hashes/sha2)
    Finished dev [optimized + debuginfo] target(s) in 0.19s
$ cargo build --target x86_64-unknown-uefi --no-default-features
   Compiling cpufeatures v0.2.5 (/home/rvolosatovs/src/github.com/rustcrypto/utils/cpufeatures)
   Compiling sha2 v0.10.6 (/home/rvolosatovs/src/github.com/rustcrypto/hashes/sha2)
    Finished dev [optimized + debuginfo] target(s) in 0.19s
```

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
  • Loading branch information
rvolosatovs authored Apr 19, 2023
1 parent b326398 commit 72505ea
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cpufeatures/src/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ macro_rules! __unless_target_features {
($($tf:tt),+ => $body:expr ) => {{
#[cfg(not(all($(target_feature=$tf,)*)))]
{
#[cfg(not(target_env = "sgx"))]
#[cfg(not(any(target_env = "sgx", target_os = "none", target_os = "uefi")))]
$body

// CPUID is not available on SGX targets
#[cfg(target_env = "sgx")]
// CPUID is not available on SGX. Freestanding and UEFI targets
// do not support SIMD features with default compilation flags.
#[cfg(any(target_env = "sgx", target_os = "none", target_os = "uefi"))]
false
}

Expand Down

0 comments on commit 72505ea

Please sign in to comment.