From e002152383ead51471a4a76c54617b691efe36d2 Mon Sep 17 00:00:00 2001 From: login Date: Mon, 24 Oct 2022 21:29:58 +0800 Subject: [PATCH] =?UTF-8?q?new:=20=E5=9C=A8lib=E4=B8=8B=E5=BC=95=E5=85=A5?= =?UTF-8?q?=E4=B8=80=E4=B8=AArust=E7=9A=84helloworld=EF=BC=81=20(#68)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 ++ kernel/lib/Makefile | 2 +- kernel/lib/rust_helloworld/Makefile | 13 +++++++++++++ kernel/lib/rust_helloworld/helloworld.rs | 17 +++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 kernel/lib/rust_helloworld/Makefile create mode 100644 kernel/lib/rust_helloworld/helloworld.rs diff --git a/Makefile b/Makefile index 733313b9..6cd38550 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,8 @@ endif export ARCH=__x86_64__ export ROOT_PATH=$(shell pwd) +export RUSTC=$(shell which rustc) + export DEBUG=DEBUG export GLOBAL_CFLAGS := -mcmodel=large -fno-builtin -m64 -fno-stack-protector -D $(ARCH) -D $(EMULATOR) -O1 diff --git a/kernel/lib/Makefile b/kernel/lib/Makefile index 8a0b85bc..a41cad46 100644 --- a/kernel/lib/Makefile +++ b/kernel/lib/Makefile @@ -1,7 +1,7 @@ CFLAGS += -I . -kernel_lib_subdirs:= libUI sys libELF +kernel_lib_subdirs:= libUI sys libELF rust_helloworld kernel_lib_objs:= $(shell find ./*.c) diff --git a/kernel/lib/rust_helloworld/Makefile b/kernel/lib/rust_helloworld/Makefile new file mode 100644 index 00000000..fc8dc6dd --- /dev/null +++ b/kernel/lib/rust_helloworld/Makefile @@ -0,0 +1,13 @@ + +rust_helloworld_objs:= + +ifneq ("$(RUSTC)", "") + rust_helloworld_objs += helloworld.o +endif + +all: $(rust_helloworld_objs) + +helloworld.o: helloworld.rs + @echo Compile helloworld.o + @echo rustc=$(which rustc) + $(shell $(RUSTC) --crate-type staticlib --target x86_64-unknown-none -o helloworld.o helloworld.rs) \ No newline at end of file diff --git a/kernel/lib/rust_helloworld/helloworld.rs b/kernel/lib/rust_helloworld/helloworld.rs new file mode 100644 index 00000000..fe6d167f --- /dev/null +++ b/kernel/lib/rust_helloworld/helloworld.rs @@ -0,0 +1,17 @@ +#![no_std] +#![no_main] + +use core::panic::PanicInfo; + +#[no_mangle] +pub extern "C" fn rust_helloworld_a_plus_b(a: i32, b: i32) -> i32 { + return a+b; +} + +/// 这个函数将在panic时被调用 +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + loop {} +} + +// rustc --crate-type staticlib --target x86_64-unknown-none -o helloworld.o helloworld.rs \ No newline at end of file