From 2c3e17a727a5ae0ae0f479e895bc2b12b58e9bad Mon Sep 17 00:00:00 2001 From: Cameron Mulhern Date: Mon, 6 Jul 2026 00:21:27 -0400 Subject: [PATCH 1/2] Run Rust runtime tests during testing --- tests/RustTest.bat | 9 ++++++++- tests/RustTest.sh | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/RustTest.bat b/tests/RustTest.bat index 56f43f2d03..6cabe3f75e 100644 --- a/tests/RustTest.bat +++ b/tests/RustTest.bat @@ -29,5 +29,12 @@ cargo test -- --quiet || exit /b 1 cargo run --bin=flatbuffers_alloc_check || exit /b 1 cargo run --bin=flexbuffers_alloc_check || exit /b 1 cargo run --bin=monster_example || exit /b 1 -cd .. +cd ..\..\rust\flatbuffers +cargo test -- --quiet || exit /b 1 + +cd ..\flexbuffers +cargo test -- --quiet || exit /b 1 + +cd ..\reflection +cargo test -- --quiet || exit /b 1 diff --git a/tests/RustTest.sh b/tests/RustTest.sh index 1e7d0eed9d..9a825d5fa8 100755 --- a/tests/RustTest.sh +++ b/tests/RustTest.sh @@ -74,3 +74,18 @@ if [[ $RUST_NIGHTLY == 1 ]]; then rustup +nightly component add miri MIRIFLAGS="-Zmiri-disable-isolation" cargo +nightly miri test fi + +cd ../../rust/flatbuffers +cargo test $TARGET_FLAG -- --quiet +check_test_result "Rust flatbuffers runtime tests" + +cargo test $TARGET_FLAG --no-default-features -- --quiet +check_test_result "Rust flatbuffers runtime tests (no_std)" + +cd ../flexbuffers +cargo test $TARGET_FLAG -- --quiet +check_test_result "Rust flexbuffers runtime tests" + +cd ../reflection +cargo test $TARGET_FLAG -- --quiet +check_test_result "Rust reflection runtime tests" From cbc9e8c0328d533077e75e6cdd55b6f5c77e7fe9 Mon Sep 17 00:00:00 2001 From: Cameron Mulhern Date: Mon, 6 Jul 2026 00:40:40 -0400 Subject: [PATCH 2/2] Fixes broken Rust test --- rust/flatbuffers/src/builder.rs | 9 +++++++++ rust/flatbuffers/src/lib.rs | 3 +++ 2 files changed, 12 insertions(+) diff --git a/rust/flatbuffers/src/builder.rs b/rust/flatbuffers/src/builder.rs index 2607921a68..09da7f9c11 100644 --- a/rust/flatbuffers/src/builder.rs +++ b/rust/flatbuffers/src/builder.rs @@ -1227,13 +1227,18 @@ impl IndexMut for [T] { #[cfg(test)] mod tests { use super::*; + #[cfg(not(feature = "std"))] use core::sync::atomic::{AtomicUsize, Ordering}; + #[cfg(not(feature = "std"))] use std::alloc::{GlobalAlloc, Layout, System}; + #[cfg(not(feature = "std"))] static ALLOC_COUNT: AtomicUsize = AtomicUsize::new(0); + #[cfg(not(feature = "std"))] struct CountingAllocator; + #[cfg(not(feature = "std"))] unsafe impl GlobalAlloc for CountingAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { ALLOC_COUNT.fetch_add(1, Ordering::Relaxed); @@ -1244,13 +1249,16 @@ mod tests { } } + #[cfg(not(feature = "std"))] #[global_allocator] static GLOBAL: CountingAllocator = CountingAllocator; + #[cfg(not(feature = "std"))] fn reset_alloc_count() { ALLOC_COUNT.store(0, Ordering::Relaxed); } + #[cfg(not(feature = "std"))] fn alloc_count() -> usize { ALLOC_COUNT.load(Ordering::Relaxed) } @@ -1264,6 +1272,7 @@ mod tests { assert_eq!(idx.to_forward_index(&buf), 4); } + #[cfg(not(feature = "std"))] #[test] fn with_internal_capacity_preallocates_vecs() { let mut builder = FlatBufferBuilder::with_internal_capacity(64, 8, 16, 32); diff --git a/rust/flatbuffers/src/lib.rs b/rust/flatbuffers/src/lib.rs index ed2bc173de..c9171630af 100644 --- a/rust/flatbuffers/src/lib.rs +++ b/rust/flatbuffers/src/lib.rs @@ -35,6 +35,9 @@ #[cfg(not(feature = "std"))] extern crate alloc; +#[cfg(all(test, not(feature = "std")))] +extern crate std; + mod array; mod builder; mod endian_scalar;