2019-01-09 09:56:23 -08:00
|
|
|
extern crate walkdir;
|
|
|
|
|
2020-01-28 17:03:37 -08:00
|
|
|
use std::{env, path::Path, process::Command};
|
2019-01-09 09:56:23 -08:00
|
|
|
use walkdir::WalkDir;
|
|
|
|
|
2019-05-16 17:35:42 -07:00
|
|
|
fn rerun_if_changed(files: &[&str], directories: &[&str], excludes: &[&str]) {
|
2019-01-09 09:56:23 -08:00
|
|
|
let mut all_files: Vec<_> = files.iter().map(|f| f.to_string()).collect();
|
|
|
|
|
|
|
|
for directory in directories {
|
|
|
|
let files_in_directory: Vec<_> = WalkDir::new(directory)
|
|
|
|
.into_iter()
|
|
|
|
.map(|entry| entry.unwrap())
|
2019-05-16 17:35:42 -07:00
|
|
|
.filter(|entry| {
|
|
|
|
if !entry.file_type().is_file() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for exclude in excludes.iter() {
|
|
|
|
if entry.path().to_str().unwrap().contains(exclude) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
true
|
|
|
|
})
|
2019-01-09 09:56:23 -08:00
|
|
|
.map(|f| f.path().to_str().unwrap().to_owned())
|
|
|
|
.collect();
|
|
|
|
all_files.extend_from_slice(&files_in_directory[..]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for file in all_files {
|
|
|
|
if !Path::new(&file).is_file() {
|
|
|
|
panic!("{} is not a file", file);
|
|
|
|
}
|
|
|
|
println!("cargo:rerun-if-changed={}", file);
|
|
|
|
}
|
|
|
|
}
|
2018-11-14 12:06:06 -08:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let bpf_c = !env::var("CARGO_FEATURE_BPF_C").is_err();
|
|
|
|
if bpf_c {
|
2019-09-18 19:54:10 -07:00
|
|
|
let install_dir =
|
|
|
|
"OUT_DIR=../target/".to_string() + &env::var("PROFILE").unwrap() + &"/bpf".to_string();
|
2018-11-14 12:06:06 -08:00
|
|
|
|
2019-05-16 17:35:42 -07:00
|
|
|
println!("cargo:warning=(not a warning) Building C-based BPF programs");
|
|
|
|
assert!(Command::new("make")
|
2019-03-04 10:08:21 -08:00
|
|
|
.current_dir("c")
|
2019-01-24 12:15:37 -08:00
|
|
|
.arg("programs")
|
2019-05-16 17:35:42 -07:00
|
|
|
.arg(&install_dir)
|
2018-11-14 12:06:06 -08:00
|
|
|
.status()
|
2019-05-16 17:35:42 -07:00
|
|
|
.expect("Failed to build C-based BPF programs")
|
|
|
|
.success());
|
|
|
|
|
|
|
|
rerun_if_changed(&["c/makefile"], &["c/src", "../../sdk"], &["/target/"]);
|
2018-11-14 12:06:06 -08:00
|
|
|
}
|
2019-01-02 15:12:42 -08:00
|
|
|
|
|
|
|
let bpf_rust = !env::var("CARGO_FEATURE_BPF_RUST").is_err();
|
|
|
|
if bpf_rust {
|
2019-02-28 22:05:11 -08:00
|
|
|
let install_dir =
|
2019-09-11 14:55:58 -07:00
|
|
|
"target/".to_string() + &env::var("PROFILE").unwrap() + &"/bpf".to_string();
|
2019-01-02 15:12:42 -08:00
|
|
|
|
2019-05-16 17:35:42 -07:00
|
|
|
assert!(Command::new("mkdir")
|
2019-02-28 22:05:11 -08:00
|
|
|
.arg("-p")
|
2019-01-02 15:12:42 -08:00
|
|
|
.arg(&install_dir)
|
|
|
|
.status()
|
2019-05-16 17:35:42 -07:00
|
|
|
.expect("Unable to create BPF install directory")
|
|
|
|
.success());
|
2019-02-28 22:05:11 -08:00
|
|
|
|
2019-06-18 15:56:24 -07:00
|
|
|
let rust_programs = [
|
2019-06-21 02:43:50 -07:00
|
|
|
"128bit",
|
2019-06-18 15:56:24 -07:00
|
|
|
"alloc",
|
|
|
|
"dep_crate",
|
2020-01-21 10:59:19 -08:00
|
|
|
"dup_accounts",
|
2020-01-30 09:47:22 -08:00
|
|
|
"error_handling",
|
|
|
|
"external_spend",
|
2019-06-18 15:56:24 -07:00
|
|
|
"iter",
|
|
|
|
"many_args",
|
|
|
|
"noop",
|
|
|
|
"panic",
|
2019-08-29 11:25:22 -07:00
|
|
|
"param_passing",
|
2019-09-10 18:53:02 -07:00
|
|
|
"sysval",
|
2019-06-18 15:56:24 -07:00
|
|
|
];
|
2019-05-16 17:35:42 -07:00
|
|
|
for program in rust_programs.iter() {
|
|
|
|
println!(
|
2019-05-21 11:22:33 -07:00
|
|
|
"cargo:warning=(not a warning) Building Rust-based BPF programs: solana_bpf_rust_{}",
|
2019-05-16 17:35:42 -07:00
|
|
|
program
|
|
|
|
);
|
2020-01-10 10:28:55 -08:00
|
|
|
assert!(Command::new("bash")
|
2019-05-21 11:22:33 -07:00
|
|
|
.current_dir("rust")
|
2020-01-10 10:28:55 -08:00
|
|
|
.args(&["./do.sh", "build", program])
|
2019-05-16 17:35:42 -07:00
|
|
|
.status()
|
2020-01-10 10:28:55 -08:00
|
|
|
.expect("Error calling do.sh from build.rs")
|
2019-05-16 17:35:42 -07:00
|
|
|
.success());
|
|
|
|
let src = format!(
|
2019-09-11 14:55:58 -07:00
|
|
|
"target/bpfel-unknown-unknown/release/solana_bpf_rust_{}.so",
|
|
|
|
program,
|
2019-05-16 17:35:42 -07:00
|
|
|
);
|
|
|
|
assert!(Command::new("cp")
|
|
|
|
.arg(&src)
|
|
|
|
.arg(&install_dir)
|
|
|
|
.status()
|
|
|
|
.expect(&format!("Failed to cp {} to {}", src, install_dir))
|
|
|
|
.success());
|
|
|
|
}
|
|
|
|
|
|
|
|
rerun_if_changed(&[], &["rust", "../../sdk", &install_dir], &["/target/"]);
|
2019-01-02 15:12:42 -08:00
|
|
|
}
|
2018-11-14 12:06:06 -08:00
|
|
|
}
|