Skip to content

Commit 7f13bc9

Browse files
committed
Automatically set the global mem pool from kconfig
1 parent af87c46 commit 7f13bc9

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ ExternalProject_Add(
7373
env
7474
"ZEPHYR_BINDGEN=${zephyr_bindgen}"
7575
"CONFIG_USERSPACE=${CONFIG_USERSPACE}"
76+
"CONFIG_RUST_ALLOC_POOL=${CONFIG_RUST_ALLOC_POOL}"
7677
"TARGET_CFLAGS=${external_project_cflags} --target=${clang_target}"
7778
"SYSROOT=${rust_sysroot}"
7879
"SYSROOT_BUILD=${rust_sysroot_build}"

rust/zephyr-core/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ fn main() {
22
if std::env::var("CONFIG_USERSPACE").expect("CONFIG_USERSPACE must be set") == "y" {
33
println!("cargo:rustc-cfg=usermode");
44
}
5+
if std::env::var("CONFIG_RUST_ALLOC_POOL").expect("CONFIG_RUST_ALLOC_POOL must be set") == "y" {
6+
println!("cargo:rustc-cfg=mempool");
7+
}
58
}

rust/zephyr-core/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ pub use time::*;
1717
// Set from environment from build.rs
1818
pub const CONFIG_USERSPACE: bool = cfg!(usermode);
1919

20+
// Use this mem pool for global allocs instead of kmalloc
21+
#[cfg(mempool)]
22+
crate::global_sys_mem_pool!(rust_std_mem_pool);
23+
2024
/// Convert a negative error code to a Result
2125
pub trait NegErr {
2226
fn neg_err(&self) -> Result<u32, u32>;

samples/rust-app/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ use zephyr::mutex::*;
1818
use zephyr::semaphore::*;
1919
use zephyr::thread::ThreadSyscalls;
2020

21-
// Use this mem pool for global allocs instead of kmalloc
22-
zephyr::global_sys_mem_pool!(rust_std_mem_pool);
23-
2421
thread_local!(static TLS: RefCell<u8> = RefCell::new(1));
2522

2623
zephyr_macros::k_mutex_define!(MUTEX);

0 commit comments

Comments
 (0)