Rust fix compilation for no_std targets #2 (#7553)

* Fix nightly no_std

* Fix nightly no_std
This commit is contained in:
Dan Lapid
2022-10-19 16:14:41 +03:00
committed by GitHub
parent 0edb275285
commit 5792623df4
11 changed files with 187 additions and 35 deletions

View File

@@ -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 ..

View File

@@ -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

View File

@@ -0,0 +1,5 @@
[build]
target = "thumbv7m-none-eabi"
[unstable]
build-std = ["core", "alloc"]

View 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"

View 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
}

View File

@@ -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"