From ac82b34c642c484143dbc79c154371c044595165 Mon Sep 17 00:00:00 2001 From: Arthur Petukhovsky Date: Tue, 30 May 2023 16:43:33 +0000 Subject: [PATCH] Create more involved example --- libs/walproposer/libwalproposer.a | Bin 1490 -> 1498 bytes libs/walproposer/rust_bindings.h | 2 +- libs/walproposer/src/lib.rs | 13 ++++++++++++- libs/walproposer/src/test.rs | 2 +- libs/walproposer/test.c | 2 +- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libs/walproposer/libwalproposer.a b/libs/walproposer/libwalproposer.a index ffe6e6e3ac3770757f0a3a82a608cb59840d111f..2c0eb87e356fc941aff4775f78639e77002ccd89 100644 GIT binary patch delta 154 zcmcb_eT#cS2a~DM#4ZEIj)}Wnm<<0<{O`@m00NUe8C3m=4d8(G5(vuf4 zMld=~{>_-qXt+6 #include -void rust_function(void); +void rust_function(uint32_t a); diff --git a/libs/walproposer/src/lib.rs b/libs/walproposer/src/lib.rs index ef960f83fa..40284897c6 100644 --- a/libs/walproposer/src/lib.rs +++ b/libs/walproposer/src/lib.rs @@ -8,9 +8,20 @@ pub mod bindings { pub use bindings::TestFunc; +use std::cell::RefCell; + +thread_local! { + pub static TMP_TEST: RefCell> = RefCell::new(vec![]); +} + #[no_mangle] -pub extern "C" fn rust_function() { +pub extern "C" fn rust_function(a: u32) { println!("Hello from Rust!"); + println!("a: {}", a); + TMP_TEST.with(|f| { + f.borrow_mut().push(a); + println!("TMP_TEST: {:?}", f.borrow()); + }); } #[cfg(test)] diff --git a/libs/walproposer/src/test.rs b/libs/walproposer/src/test.rs index 4fc5533c44..31efe738b9 100644 --- a/libs/walproposer/src/test.rs +++ b/libs/walproposer/src/test.rs @@ -1,4 +1,4 @@ -use crate::TestFunc; +use crate::{TestFunc, TMP_TEST}; #[test] fn run_test() { diff --git a/libs/walproposer/test.c b/libs/walproposer/test.c index 78c5557223..98a74804f2 100644 --- a/libs/walproposer/test.c +++ b/libs/walproposer/test.c @@ -4,6 +4,6 @@ int TestFunc(int a, int b) { printf("TestFunc: %d + %d = %d\n", a, b, a + b); - rust_function(); + rust_function(0); return a + b; }