diff --git a/Cargo.lock b/Cargo.lock index bc7153975f..be6c78c710 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1683,6 +1683,14 @@ name = "safemem" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "same-file" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "schannel" version = "0.1.14" @@ -1913,6 +1921,7 @@ dependencies = [ "solana-logger 0.12.0", "solana-sdk 0.12.0", "solana_rbpf 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2802,6 +2811,16 @@ name = "void" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "walkdir" +version = "2.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "want" version = "0.0.6" @@ -3091,6 +3110,7 @@ dependencies = [ "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" +"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" "checksum schannel 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "0e1a231dc10abf6749cfa5d7767f25888d484201accbd919b66ab5413c502d56" "checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" @@ -3172,6 +3192,7 @@ dependencies = [ "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +"checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" "checksum want 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "797464475f30ddb8830cc529aaaae648d581f99e2036a928877dfde027ddf6b3" "checksum which 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e84a603e7e0b1ce1aa1ee2b109c7be00155ce52df5081590d1ffb93f4f515cb2" "checksum widestring 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7157704c2e12e3d2189c507b7482c52820a16dfa4465ba91add92f266667cadb" diff --git a/programs/native/bpf_loader/Cargo.toml b/programs/native/bpf_loader/Cargo.toml index a748717a67..47186cc414 100644 --- a/programs/native/bpf_loader/Cargo.toml +++ b/programs/native/bpf_loader/Cargo.toml @@ -23,6 +23,9 @@ serde = "1.0.84" solana-logger = { path = "../../../logger", version = "0.12.0" } solana-sdk = { path = "../../../sdk", version = "0.12.0" } +[build-dependencies] +walkdir = "2" + [lib] name = "solana_bpf_loader" crate-type = ["lib", "cdylib"] diff --git a/programs/native/bpf_loader/build.rs b/programs/native/bpf_loader/build.rs index 6550923316..21b2114983 100644 --- a/programs/native/bpf_loader/build.rs +++ b/programs/native/bpf_loader/build.rs @@ -1,6 +1,30 @@ +extern crate walkdir; + use std::env; use std::path::Path; use std::process::Command; +use walkdir::WalkDir; + +fn rerun_if_changed(files: &[&str], directories: &[&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| entry.file_type().is_file()) + .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); + } +} fn main() { println!("cargo:rerun-if-changed=build.rs"); @@ -11,24 +35,18 @@ fn main() { + &env::var("PROFILE").unwrap() + &"/bpf".to_string(); - let rerun_if_changed_files = vec![ - "../../../sdk/bpf/bpf.mk", - "../../../sdk/bpf/inc/solana_sdk.h", - "../../bpf/c/makefile", - "../../bpf/c/src/bench_alu.c", - "../../bpf/c/src/move_funds.c", - "../../bpf/c/src/noop++.cc", - "../../bpf/c/src/noop.c", - "../../bpf/c/src/struct_pass.c", - "../../bpf/c/src/struct_ret.c", - ]; - - for file in rerun_if_changed_files { - if !Path::new(file).is_file() { - panic!("{} is not a file", file); - } - println!("cargo:rerun-if-changed={}", file); - } + rerun_if_changed( + &[ + "../../../sdk/bpf/bpf.ld", + "../../../sdk/bpf/bpf.mk", + "../../bpf/c/makefile", + ], + &[ + "../../../sdk/bpf/inc", + "../../../sdk/bpf/scripts", + "../../bpf/c/src", + ], + ); println!("cargo:warning=(not a warning) Compiling C-based BPF programs"); let status = Command::new("make") @@ -56,18 +74,14 @@ fn main() { ); } - let rerun_if_changed_files = vec![ - "../../bpf/rust/noop/bpf.ld", - "../../bpf/rust/noop/makefile", - "../../bpf/rust/noop/out/solana_bpf_rust_noop.so", - ]; - - for file in rerun_if_changed_files { - if !Path::new(file).is_file() { - panic!("{} is not a file", file); - } - println!("cargo:rerun-if-changed={}", file); - } + rerun_if_changed( + &[ + "../../bpf/rust/noop/bpf.ld", + "../../bpf/rust/noop/makefile", + "../../bpf/rust/noop/out/solana_bpf_rust_noop.so", + ], + &[], + ); println!( "cargo:warning=(not a warning) Installing Rust-based BPF program: solana_bpf_rust_noop"