-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.rs
93 lines (79 loc) · 2.84 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use std::env;
use std::path::PathBuf;
fn main() {
if env::var("DOCS_RS").is_ok() {
// Skip everything when building docs on docs.rs
return;
}
// Account for cross-compilation
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap();
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
// Set CC environment variable to choose alternative C compiler.
// Optimization level depends on whether or not --release is passed
// or implied.
if target_env == "msvc" && env::var("CC").is_err() && which::which("clang-cl").is_ok() {
env::set_var("CC", "clang-cl");
}
let mut cc = cc::Build::new();
cc.extra_warnings(true);
cc.warnings_into_errors(true);
let mut files = vec![PathBuf::from("src/cpu/sloth256_189.c")];
if cfg!(feature = "no-asm") {
println!("Compiling without assembly module");
cc.define("__SLOTH256_189_NO_ASM__", None);
} else if target_arch == "x86_64" {
if target_env == "msvc" {
files.push(PathBuf::from("src/cpu/win64/mod256-189-x86_64.asm"));
} else {
files.push(PathBuf::from("src/cpu/assembly.S"));
}
}
if target_family == "wasm" {
cc.archiver("llvm-ar");
}
cc
// avoid costly transitions
.flag_if_supported("-mno-avx")
.flag_if_supported("-fno-builtin-memcpy")
.flag_if_supported("-Wno-unused-command-line-argument");
cc.files(&files).compile("sloth256_189");
if target_os == "windows" && target_env != "msvc" {
return;
}
if cfg!(feature = "cuda") {
cc::Build::new()
.cuda(true)
.cudart("static")
.extra_warnings(true)
.warnings_into_errors(true)
.file("src/cuda/ptx.cu")
.compile("sloth256_189_cuda");
}
if cfg!(feature = "opencl") {
env::var("DEP_OPENMP_FLAG")
.unwrap()
.split(' ')
.for_each(|f| {
cc.flag(f);
});
println!("cargo:rustc-link-lib=OpenCL");
let mut cuda_include: String = "".to_string();
if let Ok(cuda_path) = env::var("CUDA_PATH") {
println!("cargo:rustc-link-search={}/lib/x64", cuda_path);
cuda_include = cuda_path + "/include";
}
cc::Build::new()
.cpp(true)
.flag_if_supported("-pthread")
.flag_if_supported("-fopenmp")
.flag_if_supported("/openmp")
.flag_if_supported("-std:c++17")
.flag_if_supported("/EHsc")
.flag_if_supported("-std=c++17")
.include(cuda_include)
.file("src/opencl/opencl.cpp")
.compile("sloth256_189_opencl");
}
}