Cleanup Rust BPF program building (#4318)
This commit is contained in:
parent
b3e45fd6b7
commit
9271ba0039
|
@ -47,7 +47,6 @@ test-stable-perf)
|
||||||
|
|
||||||
# BPF program tests
|
# BPF program tests
|
||||||
_ make -C programs/bpf/c tests
|
_ make -C programs/bpf/c tests
|
||||||
_ programs/bpf/rust/noop/build.sh # Must be built out of band
|
|
||||||
_ cargo +"$rust_stable" test \
|
_ cargo +"$rust_stable" test \
|
||||||
--manifest-path programs/bpf/Cargo.toml \
|
--manifest-path programs/bpf/Cargo.toml \
|
||||||
--no-default-features --features=bpf_c,bpf_rust
|
--no-default-features --features=bpf_c,bpf_rust
|
||||||
|
|
|
@ -5,14 +5,24 @@ use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
fn rerun_if_changed(files: &[&str], directories: &[&str]) {
|
fn rerun_if_changed(files: &[&str], directories: &[&str], excludes: &[&str]) {
|
||||||
let mut all_files: Vec<_> = files.iter().map(|f| f.to_string()).collect();
|
let mut all_files: Vec<_> = files.iter().map(|f| f.to_string()).collect();
|
||||||
|
|
||||||
for directory in directories {
|
for directory in directories {
|
||||||
let files_in_directory: Vec<_> = WalkDir::new(directory)
|
let files_in_directory: Vec<_> = WalkDir::new(directory)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|entry| entry.unwrap())
|
.map(|entry| entry.unwrap())
|
||||||
.filter(|entry| entry.file_type().is_file())
|
.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())
|
.map(|f| f.path().to_str().unwrap().to_owned())
|
||||||
.collect();
|
.collect();
|
||||||
all_files.extend_from_slice(&files_in_directory[..]);
|
all_files.extend_from_slice(&files_in_directory[..]);
|
||||||
|
@ -27,73 +37,62 @@ fn rerun_if_changed(files: &[&str], directories: &[&str]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
|
||||||
|
|
||||||
let bpf_c = !env::var("CARGO_FEATURE_BPF_C").is_err();
|
let bpf_c = !env::var("CARGO_FEATURE_BPF_C").is_err();
|
||||||
if bpf_c {
|
if bpf_c {
|
||||||
let out_dir = "OUT_DIR=../../../target/".to_string()
|
let install_dir = "OUT_DIR=../../../target/".to_string()
|
||||||
+ &env::var("PROFILE").unwrap()
|
+ &env::var("PROFILE").unwrap()
|
||||||
+ &"/bpf".to_string();
|
+ &"/bpf".to_string();
|
||||||
|
|
||||||
rerun_if_changed(
|
println!("cargo:warning=(not a warning) Building C-based BPF programs");
|
||||||
&["../../sdk/bpf/bpf.ld", "../../sdk/bpf/bpf.mk", "c/makefile"],
|
assert!(Command::new("make")
|
||||||
&["../../sdk/bpf/inc", "../../sdk/bpf/scripts", "c/src"],
|
|
||||||
);
|
|
||||||
|
|
||||||
println!("cargo:warning=(not a warning) Compiling C-based BPF programs");
|
|
||||||
let status = Command::new("make")
|
|
||||||
.current_dir("c")
|
.current_dir("c")
|
||||||
.arg("programs")
|
.arg("programs")
|
||||||
.arg(&out_dir)
|
.arg(&install_dir)
|
||||||
.status()
|
.status()
|
||||||
.expect("Failed to build C-based BPF programs");
|
.expect("Failed to build C-based BPF programs")
|
||||||
assert!(status.success());
|
.success());
|
||||||
|
|
||||||
|
rerun_if_changed(&["c/makefile"], &["c/src", "../../sdk"], &["/target/"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let bpf_rust = !env::var("CARGO_FEATURE_BPF_RUST").is_err();
|
let bpf_rust = !env::var("CARGO_FEATURE_BPF_RUST").is_err();
|
||||||
if bpf_rust {
|
if bpf_rust {
|
||||||
let install_dir =
|
let install_dir =
|
||||||
"../../../../target/".to_string() + &env::var("PROFILE").unwrap() + &"/bpf".to_string();
|
"../../target/".to_string() + &env::var("PROFILE").unwrap() + &"/bpf".to_string();
|
||||||
|
|
||||||
if !Path::new("rust/noop/target/bpfel-unknown-unknown/release/solana_bpf_rust_noop.so")
|
assert!(Command::new("mkdir")
|
||||||
.is_file()
|
|
||||||
{
|
|
||||||
// Cannot build Rust BPF programs as part of main build because
|
|
||||||
// to build it requires calling Cargo with different parameters which
|
|
||||||
// would deadlock due to recursive cargo calls
|
|
||||||
panic!(
|
|
||||||
"solana_bpf_rust_noop.so not found, you must manually run \
|
|
||||||
`programs/bpf/rust/noop/build.sh` to build it"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
rerun_if_changed(
|
|
||||||
&[
|
|
||||||
"rust/noop/bpf.ld",
|
|
||||||
"rust/noop/build.sh",
|
|
||||||
"rust/noop/Cargo.toml",
|
|
||||||
"rust/noop/target/bpfel-unknown-unknown/release/solana_bpf_rust_noop.so",
|
|
||||||
],
|
|
||||||
&["rust/noop/src"],
|
|
||||||
);
|
|
||||||
|
|
||||||
println!(
|
|
||||||
"cargo:warning=(not a warning) Installing Rust-based BPF program: solana_bpf_rust_noop"
|
|
||||||
);
|
|
||||||
let status = Command::new("mkdir")
|
|
||||||
.current_dir("rust/noop")
|
|
||||||
.arg("-p")
|
.arg("-p")
|
||||||
.arg(&install_dir)
|
.arg(&install_dir)
|
||||||
.status()
|
.status()
|
||||||
.expect("Unable to create BPF install directory");
|
.expect("Unable to create BPF install directory")
|
||||||
assert!(status.success());
|
.success());
|
||||||
|
|
||||||
let status = Command::new("cp")
|
let rust_programs = ["noop"];
|
||||||
.current_dir("rust/noop")
|
for program in rust_programs.iter() {
|
||||||
.arg("target/bpfel-unknown-unknown/release/solana_bpf_rust_noop.so")
|
println!(
|
||||||
.arg(&install_dir)
|
"cargo:warning=(not a warning) Building Rust-based BPF program: solana_bpf_rust_{}",
|
||||||
.status()
|
program
|
||||||
.expect("Failed to copy solana_rust_bpf_noop.so to install directory");
|
);
|
||||||
assert!(status.success());
|
assert!(Command::new("./build.sh")
|
||||||
|
.current_dir(format!("rust/{}", program))
|
||||||
|
.status()
|
||||||
|
.expect(&format!(
|
||||||
|
"Failed to call solana-bpf-rust-{}'s build.sh",
|
||||||
|
program
|
||||||
|
))
|
||||||
|
.success());
|
||||||
|
let src = format!(
|
||||||
|
"rust/{}/target/bpfel-unknown-unknown/release/solana_bpf_rust_{}.so",
|
||||||
|
program, program,
|
||||||
|
);
|
||||||
|
assert!(Command::new("cp")
|
||||||
|
.arg(&src)
|
||||||
|
.arg(&install_dir)
|
||||||
|
.status()
|
||||||
|
.expect(&format!("Failed to cp {} to {}", src, install_dir))
|
||||||
|
.success());
|
||||||
|
}
|
||||||
|
|
||||||
|
rerun_if_changed(&[], &["rust", "../../sdk", &install_dir], &["/target/"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,12 @@ cargo install xargo
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Ensure the sdk is installed
|
bpf_sdk=../../../../sdk/bpf
|
||||||
../../../../sdk/bpf/scripts/install.sh
|
|
||||||
rustup override set bpf
|
|
||||||
|
|
||||||
|
# Ensure the sdk is installed
|
||||||
|
"$bpf_sdk"/scripts/install.sh
|
||||||
|
|
||||||
|
export RUSTUP_TOOLCHAIN=bpf
|
||||||
export RUSTFLAGS="$RUSTFLAGS \
|
export RUSTFLAGS="$RUSTFLAGS \
|
||||||
-C lto=no \
|
-C lto=no \
|
||||||
-C opt-level=2 \
|
-C opt-level=2 \
|
||||||
|
@ -18,10 +20,9 @@ export RUSTFLAGS="$RUSTFLAGS \
|
||||||
-C link-arg=--Bdynamic \
|
-C link-arg=--Bdynamic \
|
||||||
-C link-arg=-shared \
|
-C link-arg=-shared \
|
||||||
-C link-arg=--entry=entrypoint \
|
-C link-arg=--entry=entrypoint \
|
||||||
-C linker=../../../../sdk/bpf/llvm-native/bin/ld.lld"
|
-C linker=$bpf_sdk/llvm-native/bin/ld.lld"
|
||||||
export XARGO_HOME="$PWD/target/xargo"
|
export XARGO_HOME="$PWD/target/xargo"
|
||||||
export XARGO_RUST_SRC="../../../../sdk/bpf/rust-bpf-sysroot/src"
|
export XARGO_RUST_SRC="$bpf_sdk/rust-bpf-sysroot/src"
|
||||||
# export XARGO_RUST_SRC="../../../../../rust-bpf-sysroot/src"
|
|
||||||
xargo build --target bpfel-unknown-unknown --release -v
|
xargo build --target bpfel-unknown-unknown --release -v
|
||||||
|
|
||||||
{ { set +x; } 2>/dev/null; echo Success; }
|
{ { set +x; } 2>/dev/null; echo Success; }
|
||||||
|
|
|
@ -7,6 +7,6 @@ set -e
|
||||||
|
|
||||||
./clean.sh
|
./clean.sh
|
||||||
./build.sh
|
./build.sh
|
||||||
ls -la ./target/bpfel_unknown_unknown/release/solana_bpf_rust_noop.so > dump.txt
|
ls -la ./target/bpfel-unknown-unknown/release/solana_bpf_rust_noop.so > dump.txt
|
||||||
greadelf -aW ./target/bpfel_unknown_unknown/release/solana_bpf_rust_noop.so | rustfilt >> dump.txt
|
greadelf -aW ./target/bpfel-unknown-unknown/release/solana_bpf_rust_noop.so | rustfilt >> dump.txt
|
||||||
llvm-objdump -print-imm-hex --source --disassemble ./target/bpfel_unknown_unknown/release/solana_bpf_rust_noop.so >> dump.txt
|
llvm-objdump -print-imm-hex --source --disassemble ./target/bpfel-unknown-unknown/release/solana_bpf_rust_noop.so >> dump.txt
|
||||||
|
|
Loading…
Reference in New Issue