-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.rs
71 lines (54 loc) · 2.02 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::cfg;
use std::env;
use std::path::PathBuf;
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=build.rs");
let target = env::var("TARGET")?;
// Cortex-M33 is compatible with Cortex-M4 and its DSP extension instruction UMAAL.
let cortex_m4 = target.starts_with("thumbv7em") || target.starts_with("thumbv8m.main");
let mut builder = cc::Build::new();
let mut builder = builder
.flag("-std=c11")
.file("micro-ecc/uECC.c")
// .define("uECC_SUPPORTS_secp160r1", "0")
// .define("uECC_SUPPORTS_secp192r1", "0")
// .define("uECC_SUPPORTS_secp224r1", "0")
// .define("uECC_SUPPORTS_secp256k1", "0")
// .define("uECC_SUPPORTS_secp256r1", "1")
;
// turn on optimizations in release builds
if cfg!(not(debug_assertions)) {
builder = builder
.define("uECC_OPTIMIZATION_LEVEL", "4")
.flag("-fomit-frame-pointer");
}
// uECC_OPTIMIZATION_LEVEL > 2 pulls in UMAAL assembly instructions for Cortex-M4/M33.
// Need to tell the compiler to enable them.
if cortex_m4 {
builder = builder
.flag("-march=armv7e-m")
// .define("uECC_VLI_NATIVE_LITTLE_ENDIAN", "1")
}
// for timing the effect of umaal purposes
if cfg!(feature = "no-umaal") {
builder = builder.define("uECC_ARM_USE_UMAAL", "0")
}
if cfg!(feature = "square") {
builder = builder.define("uECC_SQUARE_FUNC", "1")
}
builder.compile("micro-ecc-sys");
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let bindings = bindgen::Builder::default()
.header("micro-ecc/uECC.h")
.clang_arg(format!("--target={}", target))
.use_core()
.ctypes_prefix("cty")
.rustfmt_bindings(true)
.generate()
.expect("Unable to generate bindings");
let out_file = out_dir.join("bindings.rs");
bindings
.write_to_file(out_file)
.expect("Couldn't write bindings!");
Ok(())
}