| 
									
										
										
										
											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() {
 | 
					
						
							| 
									
										
										
										
											2020-09-01 17:25:55 -07:00
										 |  |  |     let bpf_c = env::var("CARGO_FEATURE_BPF_C").is_ok();
 | 
					
						
							| 
									
										
										
										
											2018-11-14 12:06:06 -08:00
										 |  |  |     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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-01 17:25:55 -07:00
										 |  |  |     let bpf_rust = env::var("CARGO_FEATURE_BPF_RUST").is_ok();
 | 
					
						
							| 
									
										
										
										
											2019-01-02 15:12:42 -08:00
										 |  |  |     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-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",
 | 
					
						
							| 
									
										
										
										
											2020-10-24 17:25:22 +00:00
										 |  |  |             "call_depth",
 | 
					
						
							| 
									
										
										
										
											2020-10-06 11:03:51 -07:00
										 |  |  |             "custom_heap",
 | 
					
						
							| 
									
										
										
										
											2019-06-18 15:56:24 -07:00
										 |  |  |             "dep_crate",
 | 
					
						
							| 
									
										
										
										
											2020-08-31 14:06:58 -07:00
										 |  |  |             "deprecated_loader",
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:59:19 -08:00
										 |  |  |             "dup_accounts",
 | 
					
						
							| 
									
										
										
										
											2020-01-30 09:47:22 -08:00
										 |  |  |             "error_handling",
 | 
					
						
							|  |  |  |             "external_spend",
 | 
					
						
							| 
									
										
										
										
											2020-09-19 12:17:46 -07:00
										 |  |  |             "instruction_introspection",
 | 
					
						
							| 
									
										
										
										
											2020-04-28 14:33:56 -07:00
										 |  |  |             "invoke",
 | 
					
						
							|  |  |  |             "invoked",
 | 
					
						
							| 
									
										
										
										
											2019-06-18 15:56:24 -07:00
										 |  |  |             "iter",
 | 
					
						
							|  |  |  |             "many_args",
 | 
					
						
							| 
									
										
										
										
											2020-11-07 01:15:35 +00:00
										 |  |  |             "mem",
 | 
					
						
							| 
									
										
										
										
											2019-06-18 15:56:24 -07:00
										 |  |  |             "noop",
 | 
					
						
							|  |  |  |             "panic",
 | 
					
						
							| 
									
										
										
										
											2019-08-29 11:25:22 -07:00
										 |  |  |             "param_passing",
 | 
					
						
							| 
									
										
										
										
											2020-09-29 17:25:51 -07:00
										 |  |  |             "rand",
 | 
					
						
							| 
									
										
										
										
											2020-10-06 23:52:13 -07:00
										 |  |  |             "ristretto",
 | 
					
						
							| 
									
										
										
										
											2020-09-11 18:49:00 -07:00
										 |  |  |             "sanity",
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:29:20 -07:00
										 |  |  |             "sha256",
 | 
					
						
							| 
									
										
										
										
											2020-10-09 22:08:01 +00:00
										 |  |  |             "call_depth",
 | 
					
						
							| 
									
										
										
										
											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-10-23 07:56:35 +00:00
										 |  |  |             assert!(Command::new("../../cargo-build-bpf")
 | 
					
						
							|  |  |  |                 .args(&[
 | 
					
						
							|  |  |  |                     "--manifest-path",
 | 
					
						
							|  |  |  |                     &format!("rust/{}/Cargo.toml", program),
 | 
					
						
							|  |  |  |                     "--bpf-out-dir",
 | 
					
						
							|  |  |  |                     &install_dir
 | 
					
						
							|  |  |  |                 ])
 | 
					
						
							| 
									
										
										
										
											2019-05-16 17:35:42 -07:00
										 |  |  |                 .status()
 | 
					
						
							| 
									
										
										
										
											2020-10-22 03:09:52 +00:00
										 |  |  |                 .expect("Error calling cargo-build-bpf from build.rs")
 | 
					
						
							| 
									
										
										
										
											2019-05-16 17:35:42 -07:00
										 |  |  |                 .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
										 |  |  | }
 |