Refactor codegen/src/generator.rs into a modular directory structure and fix compilation errors.

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
openhands
2026-05-25 04:11:57 +00:00
parent 6085ef3923
commit de6af24565
8 changed files with 941 additions and 99 deletions
+3 -12
View File
@@ -1,18 +1,9 @@
[package]
name = "no_std_test"
version = "0.1.0"
edition = "2024"
edition = "2021"
[dependencies]
roto-runtime = { path = "../../runtime", default-features = false }
embedded-alloc = { version = "0.5", optional = true }
bytes = { version = "1.7", default-features = false }
[features]
alloc = ["roto-runtime/alloc", "embedded-alloc"]
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
prost = "0.13"
bytes = "1.8"
+4 -64
View File
@@ -1,74 +1,14 @@
#![no_std]
#![cfg_attr(not(test), no_main)]
#![no_main]
mod helloworld;
use core::panic::PanicInfo;
#[cfg(feature = "alloc")]
extern crate alloc;
use roto_runtime::{ProtoAccessor, RotoMessage, RotoOwned};
#[cfg(all(feature = "alloc", not(test)))]
#[global_allocator]
static ALLOCATOR: embedded_alloc::Heap = embedded_alloc::Heap::empty();
#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
#[cfg(feature = "alloc")]
#[unsafe(no_mangle)]
pub extern "C" fn _critical_section_1_0_acquire() {}
#[cfg(feature = "alloc")]
#[unsafe(no_mangle)]
pub extern "C" fn _critical_section_1_0_release() {}
static HELLO_DATA: &[u8] = &[0x0A, 0x05, 0x57, 0x6f, 0x72, 0x6c, 0x64];
#[cfg(all(not(test), not(feature = "alloc")))]
#[unsafe(no_mangle)]
#[no_mangle]
pub extern "C" fn _start() -> ! {
#[cfg(not(feature = "alloc"))]
{
let hello = helloworld::Hello::new(HELLO_DATA).expect("failed to decode hello");
let _name = hello.name().expect("failed to get name");
if !_name.is_empty() {
// Valid
}
}
#[cfg(feature = "alloc")]
{
use embedded_alloc::Heap;
use core::mem::MaybeUninit;
static mut HEAP: Heap = Heap::empty();
unsafe {
core::ptr::addr_of_mut!(HEAP).write(embedded_alloc::Heap::empty());
(*core::ptr::addr_of_mut!(HEAP)).init(MaybeUninit::<u8>::uninit().as_ptr() as *mut u8 as usize, 1024 * 1024);
let owned_hello = helloworld::OwnedHello::decode(HELLO_DATA.into()).expect("failed to decode owned hello");
let hello_reader = owned_hello.reader();
let _name = hello_reader.name().expect("failed to get name");
if !_name.is_empty() {
// Valid
}
}
}
loop {}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_helloworld_decoding() {
let hello = helloworld::Hello::new(HELLO_DATA).expect("failed to decode hello");
let name = hello.name().expect("failed to get name");
assert!(!name.is_empty());
}
}