This repository has been archived by the owner on Feb 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.rs
58 lines (54 loc) · 1.86 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
use std::path::Path;
const ENZYME_VER: &str = "0.0.29";
const RUSTC_VER: &str = "1.59.0";
const LLVM_VER: &str = "13";
fn choose_library() {
let platform = std::env::var("TARGET").unwrap();
let enzyme_basedir = dirs::cache_dir().unwrap().join("enzyme");
let enzyme_path = enzyme_basedir
.join("Enzyme-".to_owned() + ENZYME_VER)
.join("enzyme")
.join("build")
.join("Enzyme");
let llvm_path = enzyme_basedir
.join("rustc-".to_owned() + RUSTC_VER + "-src")
.join("build")
.join(&platform)
.join("llvm")
.join("lib");
let enzyme_lib = "Enzyme-".to_owned() + LLVM_VER;
let llvm_lib = "LLVM-".to_owned() + LLVM_VER + "-rust-" + RUSTC_VER + "-nightly";
assert!(
enzyme_path.exists(),
"enzyme dir couldn't be found: {}",
enzyme_path.display()
);
assert!(
llvm_path.exists(),
"llvm dir couldn't be found: {}",
llvm_path.display()
);
println!("cargo:rustc-link-search={}", enzyme_path.display());
println!("cargo:rustc-link-search={}", llvm_path.display());
println!("cargo:rustc-link-lib=dylib={}", llvm_lib);
println!("cargo:rustc-link-lib=dylib={}", enzyme_lib);
}
fn copy_bindings() {
let cache_dir = dirs::cache_dir().expect("Enzyme needs access to your cache dir.");
let src = cache_dir.join("enzyme").join("enzyme.rs");
let dst = Path::new(&std::env::var("OUT_DIR").unwrap()).join("enzyme.rs");
if !src.exists() {
panic!("please first generate the bindings");
}
std::fs::copy(src, dst)
.expect("Copying over the bindings should never fail. Please submit a Bug report");
}
fn main() {
println!("cargo:rustc-env=RUSTC_VER={}", RUSTC_VER);
println!(
"cargo:rustc-env=TARGET={}",
std::env::var("TARGET").unwrap()
);
copy_bindings();
choose_library();
}