diff --git a/web3.js/examples/bpf-c-noop/src/noop/noop.c b/web3.js/examples/bpf-c-noop/src/noop/noop.c index b0f1fa7886..d5b8b3050a 100644 --- a/web3.js/examples/bpf-c-noop/src/noop/noop.c +++ b/web3.js/examples/bpf-c-noop/src/noop/noop.c @@ -5,15 +5,15 @@ #include -extern bool entrypoint(const uint8_t *input) { +extern uint32_t entrypoint(const uint8_t *input) { SolKeyedAccount ka[1]; SolParameters params = (SolParameters) { .ka = ka }; sol_log("Hello World"); if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) { - return false; + return 1; } sol_log_params(¶ms); - return true; + return SUCCESS; } diff --git a/web3.js/examples/bpf-rust-noop/Cargo.toml b/web3.js/examples/bpf-rust-noop/Cargo.toml index ef5a25e2f5..a2a197c158 100644 --- a/web3.js/examples/bpf-rust-noop/Cargo.toml +++ b/web3.js/examples/bpf-rust-noop/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "solana-bpf-rust-noop" -version = "0.16.0" +version = "0.19.0-pre0" description = "Solana BPF noop program written in Rust" authors = ["Solana Maintainers "] repository = "https://github.com/solana-labs/solana" @@ -12,11 +12,11 @@ homepage = "https://solana.com/" edition = "2018" [dependencies] -solana-sdk-bpf-utils = { path = "../../bpf-sdk/rust/rust-utils" } -solana-sdk-bpf-no-std = { path = "../../bpf-sdk/rust/rust-no-std" } +solana-sdk = { git = "https://github.com/solana-labs/solana", default-features = false } -[dev_dependencies] -solana-sdk-bpf-test = { path = "../../bpf-sdk/rust/rust-test"} +[features] +program = ["solana-sdk/program"] +default = ["program"] [workspace] members = [] diff --git a/web3.js/examples/bpf-rust-noop/Xargo.toml b/web3.js/examples/bpf-rust-noop/Xargo.toml index 330342622c..1744f098ae 100644 --- a/web3.js/examples/bpf-rust-noop/Xargo.toml +++ b/web3.js/examples/bpf-rust-noop/Xargo.toml @@ -1,6 +1,2 @@ -[dependencies.compiler_builtins] -path = "../../bpf-sdk/dependencies/rust-bpf-sysroot/src/compiler-builtins" -features = ["c", "mem"] - -[target.bpfel-unknown-unknown.dependencies] -alloc = { path = "../../bpf-sdk/dependencies/rust-bpf-sysroot/src/liballoc" } \ No newline at end of file +[target.bpfel-unknown-unknown.dependencies.std] +features = [] \ No newline at end of file diff --git a/web3.js/examples/bpf-rust-noop/do.sh b/web3.js/examples/bpf-rust-noop/do.sh index 07031d76cc..d9eeb21e9a 100755 --- a/web3.js/examples/bpf-rust-noop/do.sh +++ b/web3.js/examples/bpf-rust-noop/do.sh @@ -20,26 +20,37 @@ Supported actions: EOF } +sdkDir=../../bpf-sdk +targetDir="$PWD"/target +profile=bpfel-unknown-unknown/release + perform_action() { set -e case "$1" in build) - ../../bpf-sdk/rust/build.sh "$PWD" + "$sdkDir"/rust/build.sh "$PWD" + + so_path="$targetDir/$profile" + so_name="solana_bpf_rust_noop" + if [ -f "$so_path/${so_name}.so" ]; then + cp "$so_path/${so_name}.so" "$so_path/${so_name}_debug.so" + "$sdkDir"/dependencies/llvm-native/bin/llvm-objcopy --strip-all "$so_path/${so_name}.so" "$so_path/$so_name.so" + fi ;; clean) - ../../bpf-sdk/rust/clean.sh "$PWD" + "$sdkDir"/rust/clean.sh "$PWD" ;; test) - echo "test $2" - cargo +nightly test + echo "test" + cargo +nightly test ;; clippy) - echo "clippy $2" - cargo +nightly clippy + echo "clippy" + cargo +nightly clippy ;; fmt) - echo "formatting $2" - cargo fmt + echo "formatting" + cargo fmt ;; help) usage diff --git a/web3.js/examples/bpf-rust-noop/src/lib.rs b/web3.js/examples/bpf-rust-noop/src/lib.rs index 7e3215d059..d1ed6eca61 100644 --- a/web3.js/examples/bpf-rust-noop/src/lib.rs +++ b/web3.js/examples/bpf-rust-noop/src/lib.rs @@ -1,17 +1,13 @@ //! @brief Example Rust-based BPF program that prints out the parameters passed to it -#![no_std] #![allow(unreachable_code)] -#![allow(unused_attributes)] -#[cfg(not(test))] -extern crate solana_sdk_bpf_no_std; -extern crate solana_sdk_bpf_utils; - -use solana_sdk_bpf_utils::entrypoint::*; -use solana_sdk_bpf_utils::log::*; -use solana_sdk_bpf_utils::{entrypoint, info}; +extern crate solana_sdk; +use solana_sdk::{ + account_info::AccountInfo, entrypoint, entrypoint::SUCCESS, info, log::*, pubkey::Pubkey, +}; +#[derive(Debug, PartialEq)] struct SStruct { x: u64, y: u64, @@ -24,28 +20,22 @@ fn return_sstruct() -> SStruct { } entrypoint!(process_instruction); -fn process_instruction(ka: &mut [SolKeyedAccount], info: &SolClusterInfo, data: &[u8]) -> bool { +fn process_instruction(program_id: &Pubkey, accounts: &mut [AccountInfo], data: &[u8]) -> u32 { info!("Program identifier:"); - sol_log_key(&info.program_id); + program_id.log(); // Log the provided account keys and instruction input data. In the case of // the no-op program, no account keys or input data are expected but real // programs will have specific requirements so they can do their work. info!("Account keys and instruction input data:"); - sol_log_params(ka, data); + sol_log_params(accounts, data); { - // Test - arch config - #[cfg(not(target_arch = "bpf"))] - panic!(); - } - - { - // Test - use core methods, unwrap + // Test - use std methods, unwrap // valid bytes, in a stack-allocated array let sparkle_heart = [240, 159, 146, 150]; - let result_str = core::str::from_utf8(&sparkle_heart).unwrap(); + let result_str = std::str::from_utf8(&sparkle_heart).unwrap(); assert_eq!(4, result_str.len()); assert_eq!("💖", result_str); info!(result_str); @@ -58,6 +48,21 @@ fn process_instruction(ka: &mut [SolKeyedAccount], info: &SolClusterInfo, data: assert_eq!(s.x + s.y + s.z, 6); } - info!("Success"); - true + { + // Test - arch config + #[cfg(not(target_arch = "bpf"))] + panic!(); + } + + SUCCESS +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_return_sstruct() { + assert_eq!(SStruct { x: 1, y: 2, z: 3 }, return_sstruct()); + } } diff --git a/web3.js/test/fixtures/noop-c/noop.so b/web3.js/test/fixtures/noop-c/noop.so index 6f694f7709..4f8f9d5d04 100755 Binary files a/web3.js/test/fixtures/noop-c/noop.so and b/web3.js/test/fixtures/noop-c/noop.so differ diff --git a/web3.js/test/fixtures/noop-rust/solana_bpf_rust_noop.so b/web3.js/test/fixtures/noop-rust/solana_bpf_rust_noop.so index 8bdba6fc69..baa5457164 100755 Binary files a/web3.js/test/fixtures/noop-rust/solana_bpf_rust_noop.so and b/web3.js/test/fixtures/noop-rust/solana_bpf_rust_noop.so differ