-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.rs
49 lines (40 loc) · 1.52 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
#![allow(unused_imports)]
extern crate cc;
use std::env;
use std::path::{Path, PathBuf};
#[cfg(target_env = "msvc")]
fn assembly(files: &mut Vec<PathBuf>) {
files.push(PathBuf::from("src/win64/add_mod_pasta-x86_64.asm"));
files.push(PathBuf::from("src/win64/mulq_mont_pasta-x86_64.asm"));
files.push(PathBuf::from("src/win64/mulx_mont_pasta-x86_64.asm"));
}
#[cfg(not(target_env = "msvc"))]
fn assembly(files: &mut Vec<PathBuf>) {
files.push(PathBuf::from("src/assembly.S"));
}
fn main() {
// Set CC environment variable to choose alternative C compiler.
// Optimization level depends on whether or not --release is passed
// or implied.
let mut cc = cc::Build::new();
let mut files = vec![PathBuf::from("src/pasta_vdf.c")];
// account for cross-compilation
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
if target_arch.eq("x86_64") || target_arch.eq("aarch64") {
assembly(&mut files);
} else {
panic!("{}: unsupported platform", target_arch);
}
#[cfg(target_arch = "x86_64")]
if target_arch.eq("x86_64") && std::is_x86_feature_detected!("adx") {
println!("Enabling ADX because it was detected on the host");
cc.define("__ADX__", None);
}
cc.flag_if_supported("-mno-avx") // avoid costly transitions
.flag_if_supported("-fno-builtin-memcpy")
.flag_if_supported("-Wno-unused-command-line-argument");
if !cfg!(debug_assertions) {
cc.opt_level(3);
}
cc.files(&files).compile("libpasta_vdf.a");
}