Cleanup features and fix build errors

This commit is contained in:
Michael Vines
2019-03-02 21:33:02 -08:00
committed by Grimes
parent 534619f72f
commit 109101c2dc
3 changed files with 137 additions and 124 deletions

1
Cargo.lock generated
View File

@ -2035,6 +2035,7 @@ dependencies = [
"solana-bpfloader 0.12.0", "solana-bpfloader 0.12.0",
"solana-logger 0.12.0", "solana-logger 0.12.0",
"solana-native-loader 0.12.0", "solana-native-loader 0.12.0",
"solana-runtime 0.12.0",
"solana-sdk 0.12.0", "solana-sdk 0.12.0",
] ]

View File

@ -22,4 +22,5 @@ solana = { path = "../../core", version = "0.12.0" }
solana-bpfloader = { path = "../bpf_loader", version = "0.12.0" } solana-bpfloader = { path = "../bpf_loader", version = "0.12.0" }
solana-logger = { path = "../../logger", version = "0.12.0" } solana-logger = { path = "../../logger", version = "0.12.0" }
solana-native-loader = { path = "../native_loader", version = "0.12.0" } solana-native-loader = { path = "../native_loader", version = "0.12.0" }
solana-runtime = { path = "../../runtime", version = "0.12.0" }
solana-sdk = { path = "../../sdk", version = "0.12.0" } solana-sdk = { path = "../../sdk", version = "0.12.0" }

View File

@ -1,20 +1,19 @@
#[cfg(feature = "bpf_c")]
use solana_sdk::bpf_loader;
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))] #[cfg(any(feature = "bpf_c", feature = "bpf_rust"))]
use std::env; mod bpf {
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))] use solana_runtime::bank::Bank;
use std::fs::File; use solana_runtime::loader_utils::load_program;
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))] use solana_sdk::genesis_block::GenesisBlock;
use std::io::Read; use solana_sdk::native_loader;
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))] use solana_sdk::transaction::Transaction;
use std::path::PathBuf; use std::env;
use std::fs::File;
use std::path::PathBuf;
/// BPF program file extension /// BPF program file extension
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))] const PLATFORM_FILE_EXTENSION_BPF: &str = "so";
const PLATFORM_FILE_EXTENSION_BPF: &str = "so";
/// Create a BPF program file name /// Create a BPF program file name
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))] fn create_bpf_path(name: &str) -> PathBuf {
fn create_bpf_path(name: &str) -> PathBuf {
let mut pathbuf = { let mut pathbuf = {
let current_exe = env::current_exe().unwrap(); let current_exe = env::current_exe().unwrap();
PathBuf::from(current_exe.parent().unwrap().parent().unwrap()) PathBuf::from(current_exe.parent().unwrap().parent().unwrap())
@ -23,11 +22,16 @@ fn create_bpf_path(name: &str) -> PathBuf {
pathbuf.push(name); pathbuf.push(name);
pathbuf.set_extension(PLATFORM_FILE_EXTENSION_BPF); pathbuf.set_extension(PLATFORM_FILE_EXTENSION_BPF);
pathbuf pathbuf
} }
#[cfg(feature = "bpf_c")] #[cfg(feature = "bpf_c")]
#[test] mod bpf_c {
fn test_program_bpf_c_noop() { use super::*;
use solana_sdk::bpf_loader;
use std::io::Read;
#[test]
fn test_program_bpf_c_noop() {
solana_logger::setup(); solana_logger::setup();
let mut file = File::open(create_bpf_path("noop")).expect("file open failed"); let mut file = File::open(create_bpf_path("noop")).expect("file open failed");
@ -49,11 +53,10 @@ fn test_program_bpf_c_noop() {
); );
bank.process_transaction(&tx).unwrap(); bank.process_transaction(&tx).unwrap();
assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(()))); assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(())));
} }
#[cfg(feature = "bpf_c")] #[test]
#[test] fn test_program_bpf_c() {
fn test_program_bpf_c() {
solana_logger::setup(); solana_logger::setup();
let programs = [ let programs = [
@ -94,21 +97,27 @@ fn test_program_bpf_c() {
bank.process_transaction(&tx).unwrap(); bank.process_transaction(&tx).unwrap();
assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(()))); assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(())));
} }
} }
}
// Cannot currently build the Rust BPF program as part // Cannot currently build the Rust BPF program as part
// of the rest of the build due to recursive `cargo build` causing // of the rest of the build due to recursive `cargo build` causing
// a build deadlock. Therefore you must build the Rust programs // a build deadlock. Therefore you must build the Rust programs
// yourself first by calling `make all` in the Rust BPF program's directory // yourself first by calling `make all` in the Rust BPF program's directory
#[cfg(feature = "bpf_rust")] #[cfg(feature = "bpf_rust")]
#[test] mod bpf_rust {
fn test_program_bpf_rust() { use super::*;
use std::io::Read;
#[test]
fn test_program_bpf_rust() {
solana_logger::setup(); solana_logger::setup();
let programs = ["solana_bpf_rust_noop"]; let programs = ["solana_bpf_rust_noop"];
for program in programs.iter() { for program in programs.iter() {
println!("Test program: {:?}", program); let filename = create_bpf_path(program);
let mut file = File::open(create_bpf_path(program)).expect("file open failed"); println!("Test program: {:?} from {:?}", program, filename);
let mut file = File::open(filename).unwrap();
let mut elf = Vec::new(); let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap(); file.read_to_end(&mut elf).unwrap();
@ -134,4 +143,6 @@ fn test_program_bpf_rust() {
bank.process_transaction(&tx).unwrap(); bank.process_transaction(&tx).unwrap();
assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(()))); assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(())));
} }
}
}
} }