Some arg Fun in Rust. (0.38.1)
This commit is contained in:
parent
87833b0c1e
commit
543483041b
16 changed files with 167 additions and 66 deletions
|
|
@ -6,6 +6,9 @@ edition = "2021"
|
|||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
# Optimize for minimal size
|
||||
|
|
|
|||
2
src/rust/eh_personality.c
Normal file
2
src/rust/eh_personality.c
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/* Workaround for linking Rust staticlib in no_std/abort mode on some toolchains */
|
||||
void rust_eh_personality(void) {}
|
||||
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
#![no_std]
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Vm;
|
||||
// Use an FFI-safe opaque handle for the VM pointer
|
||||
pub type Vm = core::ffi::c_void;
|
||||
|
||||
extern "C" {
|
||||
fn vm_pop_i64(vm: *mut Vm) -> i64;
|
||||
|
|
@ -37,6 +37,23 @@ pub extern "C" fn fun_rust_get_string() -> *const core::ffi::c_char {
|
|||
b"Hello from Rust ops!\0".as_ptr() as *const _
|
||||
}
|
||||
|
||||
// Print a C string via libc printf to stdout (acceptable under no_std via extern)
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fun_rust_print_string(msg: *const core::ffi::c_char) -> i32 {
|
||||
unsafe {
|
||||
extern "C" {
|
||||
fn printf(fmt: *const core::ffi::c_char, ...) -> i32;
|
||||
}
|
||||
let fmt = b"%s\n\0".as_ptr() as *const core::ffi::c_char;
|
||||
printf(fmt, msg);
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
// Provide personality symbol to satisfy some linkers in no_std builds
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rust_eh_personality() {}
|
||||
|
||||
// Minimal panic handler for no_std; abort behavior requested via Cargo profile
|
||||
#[panic_handler]
|
||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue