solana/programs/bpf/build.rs

119 lines
3.6 KiB
Rust
Raw Normal View History

extern crate walkdir;
2020-01-28 17:03:37 -08:00
use std::{env, path::Path, process::Command};
use walkdir::WalkDir;
fn rerun_if_changed(files: &[&str], directories: &[&str], excludes: &[&str]) {
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())
.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
})
.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_ok();
2018-11-14 12:06:06 -08:00
if bpf_c {
2020-12-09 02:14:53 -08:00
let install_dir =
"OUT_DIR=../target/".to_string() + &env::var("PROFILE").unwrap() + &"/bpf".to_string();
2018-11-14 12:06:06 -08:00
println!("cargo:warning=(not a warning) Building C-based BPF programs");
2020-12-09 02:14:53 -08:00
assert!(Command::new("make")
.current_dir("c")
.arg("programs")
.arg(&install_dir)
.status()
.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
}
let bpf_rust = env::var("CARGO_FEATURE_BPF_RUST").is_ok();
if bpf_rust {
let install_dir =
"target/".to_string() + &env::var("PROFILE").unwrap() + &"/bpf".to_string();
2019-06-18 15:56:24 -07:00
let rust_programs = [
"128bit",
2019-06-18 15:56:24 -07:00
"alloc",
2020-10-22 10:23:50 -07:00
"call_depth",
"caller_access",
2020-10-06 11:03:51 -07:00
"custom_heap",
2019-06-18 15:56:24 -07:00
"dep_crate",
"deprecated_loader",
"dup_accounts",
"error_handling",
"log_data",
"external_spend",
"finalize",
"instruction_introspection",
2020-04-28 14:33:56 -07:00
"invoke",
"invoke_and_error",
"invoke_and_ok",
"invoke_and_return",
2020-04-28 14:33:56 -07:00
"invoked",
2019-06-18 15:56:24 -07:00
"iter",
"many_args",
2020-11-05 22:20:54 -08:00
"mem",
2021-06-01 15:33:17 -07:00
"membuiltins",
2019-06-18 15:56:24 -07:00
"noop",
"panic",
"param_passing",
"rand",
"realloc",
"realloc_invoke",
"ro_modify",
"ro_account_modify",
"sanity",
"secp256k1_recover",
"sha",
2020-11-30 13:06:11 -08:00
"spoof1",
"spoof1_system",
2020-12-14 15:35:10 -08:00
"upgradeable",
"upgraded",
2019-06-18 15:56:24 -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_{}",
program
);
assert!(Command::new("../../cargo-build-bpf")
.args(&[
"--manifest-path",
&format!("rust/{}/Cargo.toml", program),
"--bpf-out-dir",
&install_dir
])
.status()
2020-10-21 17:32:51 -07:00
.expect("Error calling cargo-build-bpf from build.rs")
.success());
}
rerun_if_changed(&[], &["rust", "../../sdk", &install_dir], &["/target/"]);
}
2018-11-14 12:06:06 -08:00
}