forked from rustpq/pqcrypto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
75 lines (63 loc) · 2.47 KB
/
Copy pathbuild.rs
File metadata and controls
75 lines (63 loc) · 2.47 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
extern crate cc;
extern crate dunce;
use std::env;
use std::path::Path;
fn main() {
let includepath = dunce::canonicalize(Path::new("include")).unwrap();
println!("cargo:includepath={}", includepath.to_str().unwrap());
let cfiledir = Path::new("cfiles");
let common_files = vec![
cfiledir.join("fips202.c"),
cfiledir.join("aes.c"),
cfiledir.join("sha2.c"),
cfiledir.join("nistseedexpander.c"),
cfiledir.join("sp800-185.c"),
];
println!("cargo:rerun-if-changed=cfiles/");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src/");
let mut build = cc::Build::new();
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
if target_os == "wasi" {
let wasi_sdk_path =
&std::env::var("WASI_SDK_DIR").expect("missing environment variable: WASI_SDK_DIR");
build.flag(format!("--sysroot={wasi_sdk_path}").as_str());
}
build.include(&includepath);
if let Some(libc) = std::env::var_os("DEP_WASM32_UNKNOWN_UNKNOWN_OPENBSD_LIBC_INCLUDE") {
build.include(libc);
println!("cargo::rustc-link-lib=wasm32-unknown-unknown-openbsd-libc");
}
build.files(common_files).compile("pqclean_common");
println!("cargo:rustc-link-lib=pqclean_common");
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
let mut builder = cc::Build::new();
if target_os == "wasi" {
let wasi_sdk_path =
&std::env::var("WASI_SDK_DIR").expect("missing environment variable: WASI_SDK_DIR");
builder.flag(format!("--sysroot={wasi_sdk_path}").as_str());
}
if target_arch == "x86" || target_arch == "x86_64" {
if target_env == "msvc" {
builder.flag("/arch:AVX2");
} else {
builder.flag("-mavx2");
}
builder
.file(
cfiledir
.join("keccak4x")
.join("KeccakP-1600-times4-SIMD256.c"),
)
.compile("keccak4x");
println!("cargo:rustc-link-lib=keccak4x")
} else if target_arch == "aarch64" && target_env != "msvc" {
builder
.flag("-march=armv8.2-a+sha3")
.file(cfiledir.join("keccak2x").join("fips202x2.c"))
.file(cfiledir.join("keccak2x").join("feat.S"))
.compile("keccak2x");
println!("cargo:rustc-link-lib=keccak2x")
}
}