mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-19 13:16:31 +00:00
新增rust ffi (#77)
* 引入cargo * 取消对Cargo.lock的跟踪 * 解决vscode报错问题 * new: rust的代码能够调用c语言的printk_color * 1、将原本run.sh的工作拆解,变为几个不同的make命令 2、在docker镜像中编译rust * 更改workflow * update workflow * new: 解决workflow无法通过编译的问题
This commit is contained in:
26
kernel/src/lib.rs
Normal file
26
kernel/src/lib.rs
Normal file
@ -0,0 +1,26 @@
|
||||
#![no_std] // <1>
|
||||
#![no_main] // <1>
|
||||
#![feature(core_intrinsics)] // <2>
|
||||
#[allow(non_upper_case_globals)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[allow(non_snake_case)]
|
||||
|
||||
use core::ffi::c_char;
|
||||
use core::intrinsics; // <2>
|
||||
use core::panic::PanicInfo; // <3>
|
||||
include!("include/bindings/bindings.rs");
|
||||
|
||||
#[panic_handler]
|
||||
#[no_mangle]
|
||||
pub fn panic(_info: &PanicInfo) -> ! {
|
||||
intrinsics::abort(); // <4>
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn __rust_demo_func() -> i32 {
|
||||
unsafe{
|
||||
let f = b"\nDragonOS's Rust lib called printk_color()\n".as_ptr() as *const c_char;
|
||||
printk_color(GREEN, BLACK, f);
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user