Cleanup features and fix build errors
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -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",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -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" }
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
#[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"))]
|
||||||
|
mod bpf {
|
||||||
|
use solana_runtime::bank::Bank;
|
||||||
|
use solana_runtime::loader_utils::load_program;
|
||||||
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
|
use solana_sdk::native_loader;
|
||||||
|
use solana_sdk::transaction::Transaction;
|
||||||
use std::env;
|
use std::env;
|
||||||
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))]
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))]
|
|
||||||
use std::io::Read;
|
|
||||||
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))]
|
|
||||||
use std::path::PathBuf;
|
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();
|
||||||
@ -26,6 +25,11 @@ fn create_bpf_path(name: &str) -> PathBuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "bpf_c")]
|
#[cfg(feature = "bpf_c")]
|
||||||
|
mod bpf_c {
|
||||||
|
use super::*;
|
||||||
|
use solana_sdk::bpf_loader;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_program_bpf_c_noop() {
|
fn test_program_bpf_c_noop() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
@ -51,7 +55,6 @@ fn test_program_bpf_c_noop() {
|
|||||||
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();
|
||||||
@ -95,20 +98,26 @@ fn test_program_bpf_c() {
|
|||||||
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")]
|
||||||
|
mod bpf_rust {
|
||||||
|
use super::*;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_program_bpf_rust() {
|
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();
|
||||||
|
|
||||||
@ -135,3 +144,5 @@ fn test_program_bpf_rust() {
|
|||||||
assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(())));
|
assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user