forked from RustCrypto/asm-hashes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
49 lines (45 loc) · 1.58 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use std::collections::HashSet;
fn main() {
use std::env;
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap_or_default();
let features: HashSet<String> = env::var("CARGO_CFG_TARGET_FEATURE")
.unwrap_or_default()
.split(',')
.map(|x| x.to_string())
.collect();
let mut build256 = cc::Build::new();
let (sha256_path, sha512_path) = if target_arch == "x86" {
("src/sha256_x86.S", "src/sha512_x86.S")
} else if target_arch == "x86_64" {
let sha512 = if features.contains("avx2") {
"src/sha512_x64_avx2.S"
} else {
"src/sha512_x64.S"
};
// Prioritizing aes-ni, cause it's fastest
let sha256 = if features.contains("aes") {
"src/sha256_x64_ni.S"
} else if features.contains("avx2") {
"src/sha256_x64_avx2.S"
} else {
"src/sha256_x64.S"
};
(sha256, sha512)
} else if target_arch == "aarch64" && target_vendor == "apple" {
build256.flag("-march=armv8-a+crypto");
("src/sha256_aarch64_apple.S", "")
} else if target_arch == "aarch64" {
build256.flag("-march=armv8-a+crypto");
("src/sha256_aarch64.S", "")
} else {
panic!("Unsupported target architecture");
};
if target_arch != "aarch64" {
cc::Build::new()
.flag("-c")
.file(sha512_path)
.compile("libsha512.a");
}
build256.flag("-c").file(sha256_path).compile("libsha256.a");
}