Add --bpf-out-dir argument to control where the final build products land
This commit is contained in:
parent
4669fa0f98
commit
b169d9cfbe
|
@ -57,13 +57,6 @@ fn main() {
|
||||||
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();
|
||||||
|
|
||||||
assert!(Command::new("mkdir")
|
|
||||||
.arg("-p")
|
|
||||||
.arg(&install_dir)
|
|
||||||
.status()
|
|
||||||
.expect("Unable to create BPF install directory")
|
|
||||||
.success());
|
|
||||||
|
|
||||||
let rust_programs = [
|
let rust_programs = [
|
||||||
"128bit",
|
"128bit",
|
||||||
"alloc",
|
"alloc",
|
||||||
|
@ -93,22 +86,16 @@ fn main() {
|
||||||
"cargo:warning=(not a warning) Building Rust-based BPF programs: solana_bpf_rust_{}",
|
"cargo:warning=(not a warning) Building Rust-based BPF programs: solana_bpf_rust_{}",
|
||||||
program
|
program
|
||||||
);
|
);
|
||||||
assert!(Command::new("bash")
|
assert!(Command::new("../../cargo-build-bpf")
|
||||||
.current_dir(format!("rust/{}", program))
|
.args(&[
|
||||||
.args(&["../../../../cargo-build-bpf"])
|
"--manifest-path",
|
||||||
|
&format!("rust/{}/Cargo.toml", program),
|
||||||
|
"--bpf-out-dir",
|
||||||
|
&install_dir
|
||||||
|
])
|
||||||
.status()
|
.status()
|
||||||
.expect("Error calling cargo-build-bpf from build.rs")
|
.expect("Error calling cargo-build-bpf from build.rs")
|
||||||
.success());
|
.success());
|
||||||
let src = format!(
|
|
||||||
"rust/{0}/solana_bpf_rust_{0}.so",
|
|
||||||
program,
|
|
||||||
);
|
|
||||||
assert!(Command::new("mv")
|
|
||||||
.arg(&src)
|
|
||||||
.arg(&install_dir)
|
|
||||||
.status()
|
|
||||||
.unwrap_or_else(|_| panic!("Failed to cp {} to {}", src, install_dir))
|
|
||||||
.success());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rerun_if_changed(&[], &["rust", "../../sdk", &install_dir], &["/target/"]);
|
rerun_if_changed(&[], &["rust", "../../sdk", &install_dir], &["/target/"]);
|
||||||
|
|
|
@ -54,7 +54,9 @@ fn load_bpf_program(
|
||||||
name: &str,
|
name: &str,
|
||||||
) -> Pubkey {
|
) -> Pubkey {
|
||||||
let path = create_bpf_path(name);
|
let path = create_bpf_path(name);
|
||||||
let mut file = File::open(path).unwrap();
|
let mut file = File::open(&path).unwrap_or_else(|err| {
|
||||||
|
panic!("Failed to open {}: {}", path.display(), err);
|
||||||
|
});
|
||||||
let mut elf = Vec::new();
|
let mut elf = Vec::new();
|
||||||
file.read_to_end(&mut elf).unwrap();
|
file.read_to_end(&mut elf).unwrap();
|
||||||
load_program(bank_client, payer_keypair, loader_id, elf)
|
load_program(bank_client, payer_keypair, loader_id, elf)
|
||||||
|
|
|
@ -29,6 +29,11 @@ if ! command -v readelf > /dev/null; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
set -e
|
||||||
|
out_dir=$(dirname "$dump")
|
||||||
|
if [[ ! -d $out_dir ]]; then
|
||||||
|
mkdir -p "$out_dir"
|
||||||
|
fi
|
||||||
dump_mangled=$dump.mangled
|
dump_mangled=$dump.mangled
|
||||||
|
|
||||||
(
|
(
|
||||||
|
|
|
@ -14,4 +14,10 @@ fi
|
||||||
bpf_sdk=$(cd "$(dirname "$0")/.." && pwd)
|
bpf_sdk=$(cd "$(dirname "$0")/.." && pwd)
|
||||||
# shellcheck source=sdk/bpf/env.sh
|
# shellcheck source=sdk/bpf/env.sh
|
||||||
source "$bpf_sdk"/env.sh
|
source "$bpf_sdk"/env.sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
out_dir=$(dirname "$so_stripped")
|
||||||
|
if [[ ! -d $out_dir ]]; then
|
||||||
|
mkdir -p "$out_dir"
|
||||||
|
fi
|
||||||
"$bpf_sdk"/dependencies/llvm-native/bin/llvm-objcopy --strip-all "$so" "$so_stripped"
|
"$bpf_sdk"/dependencies/llvm-native/bin/llvm-objcopy --strip-all "$so" "$so_stripped"
|
||||||
|
|
|
@ -12,6 +12,7 @@ use std::{
|
||||||
|
|
||||||
struct Config {
|
struct Config {
|
||||||
bpf_sdk: PathBuf,
|
bpf_sdk: PathBuf,
|
||||||
|
bpf_out_dir: PathBuf,
|
||||||
dump: bool,
|
dump: bool,
|
||||||
features: Vec<String>,
|
features: Vec<String>,
|
||||||
manifest_path: Option<PathBuf>,
|
manifest_path: Option<PathBuf>,
|
||||||
|
@ -22,11 +23,12 @@ impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
bpf_sdk: env::current_exe()
|
bpf_sdk: env::current_exe()
|
||||||
.expect("Unable to get current directory")
|
.expect("Unable to get current executable")
|
||||||
.parent()
|
.parent()
|
||||||
.expect("Unable to get parent directory")
|
.expect("Unable to get parent directory")
|
||||||
.to_path_buf()
|
.to_path_buf()
|
||||||
.join("sdk/bpf"),
|
.join("sdk/bpf"),
|
||||||
|
bpf_out_dir: env::current_dir().expect("Unable to get current directory"),
|
||||||
features: vec![],
|
features: vec![],
|
||||||
manifest_path: None,
|
manifest_path: None,
|
||||||
no_default_features: false,
|
no_default_features: false,
|
||||||
|
@ -165,8 +167,10 @@ fn build_bpf(config: Config) {
|
||||||
|
|
||||||
if let Some(program_name) = program_name {
|
if let Some(program_name) = program_name {
|
||||||
let program_unstripped_so = target_build_directory.join(&format!("{}.so", program_name));
|
let program_unstripped_so = target_build_directory.join(&format!("{}.so", program_name));
|
||||||
let program_dump = PathBuf::from(format!("{}-dump.txt", program_name));
|
let program_dump = config
|
||||||
let program_so = PathBuf::from(format!("{}.so", program_name));
|
.bpf_out_dir
|
||||||
|
.join(&format!("{}-dump.txt", program_name));
|
||||||
|
let program_so = config.bpf_out_dir.join(&format!("{}.so", program_name));
|
||||||
|
|
||||||
spawn(
|
spawn(
|
||||||
&config.bpf_sdk.join("scripts/strip.sh"),
|
&config.bpf_sdk.join("scripts/strip.sh"),
|
||||||
|
@ -185,7 +189,9 @@ fn build_bpf(config: Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let default_bpf_sdk = format!("{}", Config::default().bpf_sdk.display());
|
let default_config = Config::default();
|
||||||
|
let default_bpf_sdk = format!("{}", default_config.bpf_sdk.display());
|
||||||
|
let default_bpf_out_dir = format!("{}", default_config.bpf_out_dir.display());
|
||||||
|
|
||||||
let mut args = env::args().collect::<Vec<_>>();
|
let mut args = env::args().collect::<Vec<_>>();
|
||||||
// When run as a cargo subcommand, the first program argument is the subcommand name.
|
// When run as a cargo subcommand, the first program argument is the subcommand name.
|
||||||
|
@ -234,9 +240,18 @@ fn main() {
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.help("Path to Cargo.toml"),
|
.help("Path to Cargo.toml"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("bpf_out_dir")
|
||||||
|
.long("bpf-out-dir")
|
||||||
|
.value_name("DIRECTORY")
|
||||||
|
.takes_value(true)
|
||||||
|
.default_value(&default_bpf_out_dir)
|
||||||
|
.help("Place final BPF build artifacts in this directory"),
|
||||||
|
)
|
||||||
.get_matches_from(args);
|
.get_matches_from(args);
|
||||||
|
|
||||||
let bpf_sdk = value_t_or_exit!(matches, "bpf_sdk", PathBuf);
|
let bpf_sdk = value_t_or_exit!(matches, "bpf_sdk", PathBuf);
|
||||||
|
let bpf_out_dir = value_t_or_exit!(matches, "bpf_out_dir", PathBuf);
|
||||||
|
|
||||||
let config = Config {
|
let config = Config {
|
||||||
bpf_sdk: fs::canonicalize(&bpf_sdk).unwrap_or_else(|err| {
|
bpf_sdk: fs::canonicalize(&bpf_sdk).unwrap_or_else(|err| {
|
||||||
|
@ -247,6 +262,13 @@ fn main() {
|
||||||
);
|
);
|
||||||
exit(1);
|
exit(1);
|
||||||
}),
|
}),
|
||||||
|
bpf_out_dir: if bpf_out_dir.is_absolute() {
|
||||||
|
bpf_out_dir
|
||||||
|
} else {
|
||||||
|
env::current_dir()
|
||||||
|
.expect("Unable to get current working directory")
|
||||||
|
.join(bpf_out_dir)
|
||||||
|
},
|
||||||
dump: matches.is_present("dump"),
|
dump: matches.is_present("dump"),
|
||||||
features: values_t!(matches, "features", String)
|
features: values_t!(matches, "features", String)
|
||||||
.ok()
|
.ok()
|
||||||
|
|
Loading…
Reference in New Issue