2018-03-26 21:07:11 -07:00
|
|
|
use std::env;
|
2018-08-20 11:51:36 -07:00
|
|
|
use std::fs;
|
2018-10-04 09:44:44 -07:00
|
|
|
use std::process::Command;
|
2018-03-26 21:07:11 -07:00
|
|
|
|
|
|
|
fn main() {
|
2018-08-20 11:51:36 -07:00
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
|
|
|
|
// Ensure target/perf-libs/ exists. It's been observed that
|
|
|
|
// a cargo:rerun-if-changed= directive with a non-existent
|
|
|
|
// directory triggers a rebuild on every |cargo build| invocation
|
|
|
|
fs::create_dir("target/perf-libs").unwrap_or_else(|err| {
|
|
|
|
if err.kind() != std::io::ErrorKind::AlreadyExists {
|
|
|
|
panic!("Unable to create target/perf-libs: {:?}", err);
|
|
|
|
}
|
|
|
|
});
|
2018-08-16 18:49:23 -07:00
|
|
|
|
2018-10-04 09:44:44 -07:00
|
|
|
let bpf_c = !env::var("CARGO_FEATURE_BPF_C").is_err();
|
|
|
|
let chacha = !env::var("CARGO_FEATURE_CHACHA").is_err();
|
2018-08-16 18:49:23 -07:00
|
|
|
let cuda = !env::var("CARGO_FEATURE_CUDA").is_err();
|
|
|
|
let erasure = !env::var("CARGO_FEATURE_ERASURE").is_err();
|
|
|
|
|
2018-10-04 09:44:44 -07:00
|
|
|
if bpf_c {
|
2018-10-26 19:38:07 -07:00
|
|
|
let out_dir = "OUT_DIR=../../../target/".to_string()
|
|
|
|
+ &env::var("PROFILE").unwrap()
|
|
|
|
+ &"/bpf".to_string();
|
|
|
|
|
2018-10-29 20:44:04 -07:00
|
|
|
println!("cargo:rerun-if-changed=programs/bpf/c/sdk/bpf.mk");
|
2018-10-31 23:13:09 -07:00
|
|
|
println!("cargo:rerun-if-changed=programs/bpf/c/sdk/inc/solana_sdk.h");
|
2018-10-26 19:38:07 -07:00
|
|
|
println!("cargo:rerun-if-changed=programs/bpf/c/makefile");
|
|
|
|
println!("cargo:rerun-if-changed=programs/bpf/c/src/move_funds.c");
|
|
|
|
println!("cargo:rerun-if-changed=programs/bpf/c/src/noop.c");
|
|
|
|
println!("cargo:warning=(not a warning) Compiling C-based BPF programs");
|
|
|
|
let status = Command::new("make")
|
|
|
|
.current_dir("programs/bpf/c")
|
|
|
|
.arg("all")
|
2018-10-18 14:19:25 -07:00
|
|
|
.arg(&out_dir)
|
|
|
|
.status()
|
2018-10-26 19:38:07 -07:00
|
|
|
.expect("Failed to build C-based BPF programs");
|
2018-10-18 14:19:25 -07:00
|
|
|
assert!(status.success());
|
2018-10-04 09:44:44 -07:00
|
|
|
}
|
|
|
|
if chacha || cuda || erasure {
|
2018-10-19 10:39:58 -07:00
|
|
|
println!("cargo:rerun-if-changed=target/perf-libs");
|
2018-08-16 18:49:23 -07:00
|
|
|
println!("cargo:rustc-link-search=native=target/perf-libs");
|
|
|
|
}
|
2018-10-19 10:39:58 -07:00
|
|
|
if chacha {
|
|
|
|
println!("cargo:rerun-if-changed=target/perf-libs/libcpu-crypt.a");
|
|
|
|
}
|
2018-08-16 18:49:23 -07:00
|
|
|
if cuda {
|
2018-10-19 10:39:58 -07:00
|
|
|
println!("cargo:rerun-if-changed=target/perf-libs/libcuda-crypt.a");
|
2018-10-08 13:12:33 -07:00
|
|
|
println!("cargo:rustc-link-lib=static=cuda-crypt");
|
2018-03-26 21:07:11 -07:00
|
|
|
println!("cargo:rustc-link-search=native=/usr/local/cuda/lib64");
|
|
|
|
println!("cargo:rustc-link-lib=dylib=cudart");
|
|
|
|
println!("cargo:rustc-link-lib=dylib=cuda");
|
|
|
|
println!("cargo:rustc-link-lib=dylib=cudadevrt");
|
|
|
|
}
|
2018-08-16 18:49:23 -07:00
|
|
|
if erasure {
|
2018-10-19 10:39:58 -07:00
|
|
|
println!("cargo:rerun-if-changed=target/perf-libs/libgf_complete.so");
|
|
|
|
println!("cargo:rerun-if-changed=target/perf-libs/libJerasure.so");
|
2018-04-18 19:34:57 -07:00
|
|
|
println!("cargo:rustc-link-lib=dylib=Jerasure");
|
2018-06-23 02:15:38 -07:00
|
|
|
println!("cargo:rustc-link-lib=dylib=gf_complete");
|
2018-04-18 19:34:57 -07:00
|
|
|
}
|
2018-03-26 21:07:11 -07:00
|
|
|
}
|