From 9a4c4491358530130210ec77718dd8b893a06d7e Mon Sep 17 00:00:00 2001 From: Jack May Date: Fri, 7 Jun 2019 14:38:49 -0700 Subject: [PATCH] Builtins (#4594) automerge --- programs/bpf/rust/alloc/Xargo.toml | 1 + programs/bpf/rust/alloc/src/lib.rs | 30 ++++++++++++++++++++++-------- programs/bpf/rust/iter/Xargo.toml | 1 + programs/bpf/rust/noop/Xargo.toml | 1 + sdk/bpf/rust-utils/build.sh | 4 ++++ sdk/bpf/rust-utils/src/lib.rs | 4 ++++ sdk/bpf/scripts/install.sh | 4 ++-- 7 files changed, 35 insertions(+), 10 deletions(-) diff --git a/programs/bpf/rust/alloc/Xargo.toml b/programs/bpf/rust/alloc/Xargo.toml index 4203d10a3e..c2898d9b0d 100644 --- a/programs/bpf/rust/alloc/Xargo.toml +++ b/programs/bpf/rust/alloc/Xargo.toml @@ -2,6 +2,7 @@ [dependencies.compiler_builtins] path = "../../../../sdk/bpf/rust-bpf-sysroot/src/compiler-builtins" +features = ["c", "mem"] [target.bpfel-unknown-unknown.dependencies] alloc = { path = "../../../../sdk/bpf/rust-bpf-sysroot/src/liballoc" } \ No newline at end of file diff --git a/programs/bpf/rust/alloc/src/lib.rs b/programs/bpf/rust/alloc/src/lib.rs index 163fbc50e4..d63773c4cc 100644 --- a/programs/bpf/rust/alloc/src/lib.rs +++ b/programs/bpf/rust/alloc/src/lib.rs @@ -2,13 +2,14 @@ #![no_std] -#[macro_use] +// #[macro_use] extern crate alloc; extern crate solana_sdk_bpf_utils; use solana_sdk_bpf_utils::log::*; use core::alloc::Layout; +// use alloc::vec::Vec; use core::mem; #[no_mangle] @@ -82,15 +83,28 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> bool { // // Test allocated vector // const ITERS: usize = 100; - // let ones = vec![1_u64; ITERS]; - // let mut sum: u64 = 0; + // let ones = vec![1_usize; ITERS]; + // let mut sum: usize = 0; - // for (i, v) in ones.iter().enumerate() { - // sol_log_64(i as u64, 0, 0, 0, 0); - // sum += ones[i as usize]; + // for v in ones.iter() { + // sum += ones[*v]; // } - // sol_log_64(0x4, 0, 0, 0, sum); - // assert_eq!(sum, ITERS as u64); + // sol_log_64(0x0, 0, 0, 0, sum as u64); + // assert_eq!(sum, ITERS); + // } + + // { + // // TODO test Vec::new() + + // const ITERS: usize = 100; + // let mut v = Vec::new(); + + // for i in 0..ITERS { + // sol_log_64(i as u64, 0, 0, 0, 0); + // v.push(i); + // } + // sol_log_64(0x4, 0, 0, 0, v.len() as u64); + // assert_eq!(v.len(), ITERS); // } sol_log("Success"); diff --git a/programs/bpf/rust/iter/Xargo.toml b/programs/bpf/rust/iter/Xargo.toml index 4203d10a3e..c2898d9b0d 100644 --- a/programs/bpf/rust/iter/Xargo.toml +++ b/programs/bpf/rust/iter/Xargo.toml @@ -2,6 +2,7 @@ [dependencies.compiler_builtins] path = "../../../../sdk/bpf/rust-bpf-sysroot/src/compiler-builtins" +features = ["c", "mem"] [target.bpfel-unknown-unknown.dependencies] alloc = { path = "../../../../sdk/bpf/rust-bpf-sysroot/src/liballoc" } \ No newline at end of file diff --git a/programs/bpf/rust/noop/Xargo.toml b/programs/bpf/rust/noop/Xargo.toml index 4203d10a3e..c2898d9b0d 100644 --- a/programs/bpf/rust/noop/Xargo.toml +++ b/programs/bpf/rust/noop/Xargo.toml @@ -2,6 +2,7 @@ [dependencies.compiler_builtins] path = "../../../../sdk/bpf/rust-bpf-sysroot/src/compiler-builtins" +features = ["c", "mem"] [target.bpfel-unknown-unknown.dependencies] alloc = { path = "../../../../sdk/bpf/rust-bpf-sysroot/src/liballoc" } \ No newline at end of file diff --git a/sdk/bpf/rust-utils/build.sh b/sdk/bpf/rust-utils/build.sh index e760da0acc..332bf067ab 100755 --- a/sdk/bpf/rust-utils/build.sh +++ b/sdk/bpf/rust-utils/build.sh @@ -22,6 +22,10 @@ set -e # Ensure the sdk is installed "$bpf_sdk"/scripts/install.sh +# Use the SDK's version of llvm to build the compiler-builtins for BPF +export CC="$bpf_sdk/llvm-native/bin/clang" +export AR="$bpf_sdk/llvm-native/bin/llvm-ar" +# Use the SDK's version of Rust to build for BPF export RUSTUP_TOOLCHAIN=bpf export RUSTFLAGS=" --emit=llvm-ir \ diff --git a/sdk/bpf/rust-utils/src/lib.rs b/sdk/bpf/rust-utils/src/lib.rs index b5d4b353e4..861b56d1be 100644 --- a/sdk/bpf/rust-utils/src/lib.rs +++ b/sdk/bpf/rust-utils/src/lib.rs @@ -3,6 +3,10 @@ #![no_std] #![feature(allocator_api)] #![feature(alloc_error_handler)] +#![feature(panic_info_message)] +#![feature(compiler_builtins_lib)] + +extern crate compiler_builtins; pub mod alloc; pub mod entrypoint; diff --git a/sdk/bpf/scripts/install.sh b/sdk/bpf/scripts/install.sh index 5e1de9d212..5f2f7d29f0 100755 --- a/sdk/bpf/scripts/install.sh +++ b/sdk/bpf/scripts/install.sh @@ -48,7 +48,7 @@ if [[ ! -r criterion-$machine-$version.md ]]; then fi # Install LLVM -version=v0.0.9 +version=v0.0.10 if [[ ! -f llvm-native-$machine-$version.md ]]; then ( filename=solana-llvm-$machine.tar.bz2 @@ -108,7 +108,7 @@ if [[ ! -f rust-bpf-$machine-$version.md ]]; then fi # Install Rust-BPF Sysroot sources -version=v0.2 +version=v0.3 if [[ ! -f rust-bpf-sysroot-$version.md ]]; then ( set -ex