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

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