From a9a69a3404548dce0956bbaaeaa7f152d7d19e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Thu, 20 Jun 2024 13:40:00 +0200 Subject: [PATCH] CI - SBPF program build script (#1581) * Replaces the rust build script by a makefile --- ci/bench/part2.sh | 2 + ci/test-bench.sh | 1 + ci/test-stable.sh | 15 ++--- programs/sbf/Cargo.lock | 1 - programs/sbf/Cargo.toml | 8 ++- programs/sbf/Makefile | 13 ++++ programs/sbf/build.rs | 131 ------------------------------------ programs/sbf/c/makefile | 2 - runtime/src/loader_utils.rs | 13 +++- 9 files changed, 38 insertions(+), 148 deletions(-) create mode 100755 programs/sbf/Makefile delete mode 100644 programs/sbf/build.rs delete mode 100644 programs/sbf/c/makefile diff --git a/ci/bench/part2.sh b/ci/bench/part2.sh index 44a6c46f2ed67f..76f1dfb50abffc 100755 --- a/ci/bench/part2.sh +++ b/ci/bench/part2.sh @@ -19,6 +19,8 @@ _ cargo +"$rust_nightly" bench --manifest-path runtime/Cargo.toml ${V:+--verbose _ cargo build --manifest-path=keygen/Cargo.toml export PATH="$PWD/target/debug":$PATH + _ make -C programs/sbf all + # Run sbf benches _ cargo +"$rust_nightly" bench --manifest-path programs/sbf/Cargo.toml ${V:+--verbose} --features=sbf_c \ -- -Z unstable-options --format=json --nocapture | tee -a "$BENCH_FILE" diff --git a/ci/test-bench.sh b/ci/test-bench.sh index aacc82cffbb0a6..c145512d7b1cc6 100755 --- a/ci/test-bench.sh +++ b/ci/test-bench.sh @@ -61,6 +61,7 @@ _ $cargoNightly bench --manifest-path core/Cargo.toml ${V:+--verbose} \ -- -Z unstable-options --format=json | tee -a "$BENCH_FILE" # Run sbf benches +_ make -C programs/sbf all _ $cargoNightly bench --manifest-path programs/sbf/Cargo.toml ${V:+--verbose} --features=sbf_c \ -- -Z unstable-options --format=json --nocapture | tee -a "$BENCH_FILE" diff --git a/ci/test-stable.sh b/ci/test-stable.sh index 57b561120a90d4..acd4578542f23c 100755 --- a/ci/test-stable.sh +++ b/ci/test-stable.sh @@ -50,6 +50,9 @@ test-stable-sbf) cargo_build_sbf="$(realpath ./cargo-build-sbf)" cargo_test_sbf="$(realpath ./cargo-test-sbf)" + # platform-tools version + "$cargo_build_sbf" --version + # SBF solana-sdk legacy compile test "$cargo_build_sbf" --manifest-path sdk/Cargo.toml @@ -67,12 +70,9 @@ test-stable-sbf) exit 1 fi - # SBF C program system tests + # SBF program tests export SBF_OUT_DIR=target/sbf-solana-solana/release - _ make -C programs/sbf/c tests - _ cargo test \ - --manifest-path programs/sbf/Cargo.toml \ - --no-default-features --features=sbf_c,sbf_rust -- --nocapture + _ make -C programs/sbf test # SBF Rust program unit tests for sbf_test in programs/sbf/rust/*; do @@ -100,14 +100,11 @@ test-stable-sbf) exit 1 fi - # platform-tools version - "$cargo_build_sbf" -V - # SBF program instruction count assertion sbf_target_path=programs/sbf/target _ cargo test \ --manifest-path programs/sbf/Cargo.toml \ - --no-default-features --features=sbf_c,sbf_rust assert_instruction_count \ + --features=sbf_c,sbf_rust assert_instruction_count \ -- --nocapture &> "${sbf_target_path}"/deploy/instruction_counts.txt sbf_dump_archive="sbf-dumps.tar.bz2" diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 79caf3ffa9c06f..703d5faf913ee2 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5689,7 +5689,6 @@ dependencies = [ "solana-transaction-status", "solana-type-overrides", "solana_rbpf", - "walkdir", ] [[package]] diff --git a/programs/sbf/Cargo.toml b/programs/sbf/Cargo.toml index 742f700bec4a14..d5a7c9e6590c38 100644 --- a/programs/sbf/Cargo.toml +++ b/programs/sbf/Cargo.toml @@ -69,14 +69,16 @@ homepage = { workspace = true } license = { workspace = true } edition = { workspace = true } +[profile.release] +# The test programs are build in release mode +# Minimize their file size so that they fit into the account size limit +strip = true + [features] sbf_c = [] sbf_rust = [] dummy-for-ci-check = ["sbf_c", "sbf_rust"] -[build-dependencies] -walkdir = "2" - [dev-dependencies] agave-validator = { workspace = true } bincode = { workspace = true } diff --git a/programs/sbf/Makefile b/programs/sbf/Makefile new file mode 100755 index 00000000000000..3f213d352a2995 --- /dev/null +++ b/programs/sbf/Makefile @@ -0,0 +1,13 @@ +SBF_SDK_PATH := ../../sdk/sbf +SRC_DIR := c/src +OUT_DIR := target/sbf-solana-solana/release + +test: rust all + SBF_OUT_DIR=$(OUT_DIR) cargo test --features="sbf_rust,sbf_c" $(TEST_ARGS) + +rust: + cargo +solana build --release --target sbf-solana-solana --workspace + +.PHONY: rust + +include $(SBF_SDK_PATH)/c/sbf.mk diff --git a/programs/sbf/build.rs b/programs/sbf/build.rs deleted file mode 100644 index bf3feb48c087bd..00000000000000 --- a/programs/sbf/build.rs +++ /dev/null @@ -1,131 +0,0 @@ -extern crate walkdir; - -use { - std::{env, path::Path, process::Command}, - walkdir::WalkDir, -}; - -fn rerun_if_changed(files: &[&str], directories: &[&str], excludes: &[&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| { - 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()) - .collect(); - all_files.extend_from_slice(&files_in_directory[..]); - } - - for file in all_files { - if !Path::new(&file).is_file() { - panic!("{file} is not a file"); - } - println!("cargo:rerun-if-changed={file}"); - } -} - -fn main() { - if env::var("CARGO_FEATURE_DUMMY_FOR_CI_CHECK").is_ok() { - println!("cargo:warning=(not a warning) Compiling with host toolchain for CI..."); - return; - } - - let build_profile = env::var("PROFILE").expect("`PROFILE` envvar to be set"); - let install_dir = format!("target/{build_profile}/sbf"); - let sbf_c = env::var("CARGO_FEATURE_SBF_C").is_ok(); - if sbf_c { - let install_dir = format!("OUT_DIR=../{install_dir}"); - println!("cargo:warning=(not a warning) Building C-based on-chain programs"); - assert!(Command::new("make") - .current_dir("c") - .arg("programs") - .arg(&install_dir) - .status() - .expect("Failed to build C-based SBF programs") - .success()); - - rerun_if_changed(&["c/makefile"], &["c/src", "../../sdk"], &["/target/"]); - } - - let sbf_rust = env::var("CARGO_FEATURE_SBF_RUST").is_ok(); - if sbf_rust { - let rust_programs = [ - "128bit", - "alloc", - "alt_bn128", - "alt_bn128_compression", - "big_mod_exp", - "call_depth", - "caller_access", - "curve25519", - "custom_heap", - "dep_crate", - "deprecated_loader", - "dup_accounts", - "error_handling", - "log_data", - "external_spend", - "finalize", - "get_minimum_delegation", - "inner_instruction_alignment_check", - "instruction_introspection", - "invoke", - "invoke_and_error", - "invoke_and_ok", - "invoke_and_return", - "invoked", - "iter", - "many_args", - "mem", - "membuiltins", - "noop", - "panic", - "param_passing", - "poseidon", - "rand", - "realloc", - "realloc_invoke", - "remaining_compute_units", - "ro_modify", - "ro_account_modify", - "sanity", - "secp256k1_recover", - "sha", - "sibling_inner_instructions", - "sibling_instructions", - "simulation", - "spoof1", - "spoof1_system", - "sysvar", - "upgradeable", - "upgraded", - ]; - for program in rust_programs.iter() { - println!("cargo:warning=(not a warning) Building Rust-based on-chain programs: solana_sbf_rust_{program}"); - assert!(Command::new("../../cargo-build-sbf") - .args([ - "--manifest-path", - &format!("rust/{program}/Cargo.toml"), - "--sbf-out-dir", - &install_dir - ]) - .status() - .expect("Error calling cargo-build-sbf from build.rs") - .success()); - } - - rerun_if_changed(&[], &["rust", "../../sdk", &install_dir], &["/target/"]); - } -} diff --git a/programs/sbf/c/makefile b/programs/sbf/c/makefile deleted file mode 100644 index 77b774c2a6bf82..00000000000000 --- a/programs/sbf/c/makefile +++ /dev/null @@ -1,2 +0,0 @@ -SBF_SDK := ../../../sdk/sbf/c -include $(SBF_SDK)/sbf.mk diff --git a/runtime/src/loader_utils.rs b/runtime/src/loader_utils.rs index 7265641e900bc1..436a7242d93fd7 100644 --- a/runtime/src/loader_utils.rs +++ b/runtime/src/loader_utils.rs @@ -28,9 +28,18 @@ const CHUNK_SIZE: usize = 512; // Size of chunk just needs to fit into tx pub fn load_program_from_file(name: &str) -> Vec { let mut pathbuf = { let current_exe = env::current_exe().unwrap(); - PathBuf::from(current_exe.parent().unwrap().parent().unwrap()) + PathBuf::from( + current_exe + .parent() + .unwrap() + .parent() + .unwrap() + .parent() + .unwrap(), + ) }; - pathbuf.push("sbf/"); + pathbuf.push("sbf-solana-solana"); + pathbuf.push("release"); pathbuf.push(name); pathbuf.set_extension("so"); let mut file = File::open(&pathbuf).unwrap_or_else(|err| {