-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
61 lines (53 loc) · 1.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
use std::path::PathBuf;
fn main() {
let (bin_path, header_path) = paths();
println!("cargo:rustc-link-search={}", bin_path.to_str().unwrap());
println!("cargo:rustc-link-lib=dylib=cudart");
println!("cargo:rustc-link-lib=dylib=cufft");
//println!("cargo:rustc-link-lib=static=legacy_stdio_definitions");
println!("cargo:rerun-if-changed=wrapper.h");
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.clang_arg(format!("-I{}", header_path.to_str().unwrap()))
.clang_arg("-x")
.clang_arg("c++")
.clang_arg("-Wno-everything")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.allowlist_function("cufft.*")
.allowlist_type("cufft.*")
.allowlist_var("cufft.*")
.allowlist_function("cuda.*")
.allowlist_type("cuda.*")
.allowlist_var("cuda.*")
.generate()
.expect("Unable to generate bindings");
let out = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let out = out.join("bindings.rs");
bindings
.write_to_file(out)
.expect("Couldn't write bindings!");
}
#[cfg(windows)]
fn paths() -> (PathBuf, PathBuf) {
let base_path = PathBuf::from(std::env::var("CUDA_PATH").unwrap());
(base_path.join("lib/x64"), base_path.join("include"))
}
#[cfg(unix)]
fn paths() -> (PathBuf, PathBuf) {
pkg_config::Config::new()
.atleast_version("11.0")
.probe("cuda")
.ok()
.and_then(|mut lib| Some((lib.link_paths.pop()?, lib.include_paths.pop()?)))
.unwrap_or_else(|| {
// Guess default locations
(
PathBuf::from("/usr/local/cuda/lib64"),
PathBuf::from("/usr/local/cuda/include"),
)
})
}
#[cfg(all(not(windows), not(unix)))]
fn paths() -> ! {
unimplemented!("Unsupported target");
}