mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-15 00:38:52 +00:00
* Fix nightly no_std * Fix nightly no_std
This commit is contained in:
@@ -21,3 +21,10 @@ 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_no_std_compilation_test
|
||||
rustup install nightly
|
||||
rustup component add rust-src --toolchain nightly
|
||||
rustup target add thumbv7m-none-eabi
|
||||
cargo build || exit /b 1
|
||||
cd ..
|
||||
|
||||
@@ -35,11 +35,18 @@ cd ./rust_serialize_test
|
||||
cargo run $TARGET_FLAG -- --quiet
|
||||
check_test_result "Rust serde tests"
|
||||
|
||||
cd ../rust_no_std_compilation_test
|
||||
rustup install nightly
|
||||
rustup component add rust-src --toolchain nightly
|
||||
rustup target add thumbv7m-none-eabi
|
||||
cargo +nightly build
|
||||
check_test_result "Rust flatbuffers test no_std compilation"
|
||||
|
||||
cd ../rust_usage_test
|
||||
cargo test $TARGET_FLAG -- --quiet
|
||||
check_test_result "Rust tests"
|
||||
|
||||
cargo test $TARGET_FLAG --no-default-features --features no_std -- --quiet
|
||||
cargo test $TARGET_FLAG --no-default-features -- --quiet
|
||||
check_test_result "Rust tests (no_std)"
|
||||
|
||||
cargo run $TARGET_FLAG --bin=flatbuffers_alloc_check
|
||||
|
||||
5
tests/rust_no_std_compilation_test/.cargo/config.toml
Normal file
5
tests/rust_no_std_compilation_test/.cargo/config.toml
Normal file
@@ -0,0 +1,5 @@
|
||||
[build]
|
||||
target = "thumbv7m-none-eabi"
|
||||
|
||||
[unstable]
|
||||
build-std = ["core", "alloc"]
|
||||
13
tests/rust_no_std_compilation_test/Cargo.toml
Normal file
13
tests/rust_no_std_compilation_test/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "rust_test_no_std_compilation"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
flatbuffers = { path = "../../rust/flatbuffers", default-features = false }
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
34
tests/rust_no_std_compilation_test/src/main.rs
Normal file
34
tests/rust_no_std_compilation_test/src/main.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(default_alloc_error_handler)]
|
||||
|
||||
// Include flatbuffers purely to check that it compiles in a no_std binary
|
||||
#[allow(unused_imports)]
|
||||
use flatbuffers;
|
||||
|
||||
// The rest is just no_std boilerplate
|
||||
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
|
||||
struct NullAllocator;
|
||||
unsafe impl GlobalAlloc for NullAllocator {
|
||||
unsafe fn alloc(&self, _lt: Layout) -> *mut u8 {
|
||||
core::ptr::null_mut()
|
||||
}
|
||||
unsafe fn dealloc(&self, _ptr: *mut u8, _lt: Layout) {
|
||||
panic!("won't deallocate: we never allocated!");
|
||||
}
|
||||
}
|
||||
|
||||
#[global_allocator]
|
||||
static A: NullAllocator = NullAllocator;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn main(_argc: i32, _argv: *const *const u8) -> i32 {
|
||||
0
|
||||
}
|
||||
@@ -16,7 +16,7 @@ libc_alloc = { version = "1.0.3", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["flatbuffers/default"]
|
||||
no_std = ["flatbuffers/no_std", "libc_alloc"]
|
||||
no_std = ["libc_alloc"]
|
||||
|
||||
[[bin]]
|
||||
name = "monster_example"
|
||||
|
||||
Reference in New Issue
Block a user