mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 20:36:31 +00:00
feat: 支持在rv64下,运行rust编写的helloworld程序 (#1125)
* 添加 riscv_rust_init 这个helloworld程序 Signed-off-by: longjin <longjin@DragonOS.org> * feat: 支持在riscv下启动rust编写的hello world程序 TODO: 支持sys ppoll Signed-off-by: longjin <longjin@DragonOS.org> * chore: 更新构建容器版本至v1.9 Signed-off-by: longjin <longjin@DragonOS.org> * 1 --------- Signed-off-by: longjin <longjin@DragonOS.org>
This commit is contained in:
@ -6,15 +6,20 @@ endif
|
||||
|
||||
CC=$(CROSS_COMPILE)gcc
|
||||
|
||||
|
||||
.PHONY: all
|
||||
all: main.c
|
||||
$(CC) -static -o init main.c
|
||||
# $(CC) -static -o init main.c
|
||||
$(MAKE) -C riscv_rust_init ARCH=$(ARCH) install
|
||||
|
||||
.PHONY: install clean
|
||||
install: all
|
||||
mv init $(DADK_CURRENT_BUILD_DIR)/init
|
||||
$(MAKE) -C riscv_rust_init ARCH=$(ARCH) install
|
||||
# mv init $(DADK_CURRENT_BUILD_DIR)/init
|
||||
|
||||
|
||||
clean:
|
||||
rm init *.o
|
||||
$(MAKE) -C riscv_rust_init ARCH=$(ARCH) clean
|
||||
|
||||
fmt:
|
||||
|
2
user/apps/riscv_init/riscv_rust_init/.cargo/config.toml
Normal file
2
user/apps/riscv_init/riscv_rust_init/.cargo/config.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[target.riscv64gc-unknown-linux-musl]
|
||||
linker = "riscv64-linux-gnu-gcc"
|
1
user/apps/riscv_init/riscv_rust_init/.gitignore
vendored
Normal file
1
user/apps/riscv_init/riscv_rust_init/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
6
user/apps/riscv_init/riscv_rust_init/Cargo.toml
Normal file
6
user/apps/riscv_init/riscv_rust_init/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "riscv_rust_init"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
50
user/apps/riscv_init/riscv_rust_init/Makefile
Normal file
50
user/apps/riscv_init/riscv_rust_init/Makefile
Normal file
@ -0,0 +1,50 @@
|
||||
# The toolchain we use.
|
||||
# You can get it by running DragonOS' `tools/bootstrap.sh`
|
||||
TOOLCHAIN="+nightly-2024-11-05-x86_64-unknown-linux-gnu"
|
||||
|
||||
ifeq ($(ARCH), riscv64)
|
||||
RUSTFLAGS+="-C target-feature=+crt-static"
|
||||
endif
|
||||
|
||||
ifdef DADK_CURRENT_BUILD_DIR
|
||||
# 如果是在dadk中编译,那么安装到dadk的安装目录中
|
||||
INSTALL_DIR = $(DADK_CURRENT_BUILD_DIR)
|
||||
else
|
||||
# 如果是在本地编译,那么安装到当前目录下的install目录中
|
||||
INSTALL_DIR = ./install
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(ARCH), x86_64)
|
||||
export RUST_TARGET=x86_64-unknown-linux-musl
|
||||
else ifeq ($(ARCH), riscv64)
|
||||
export RUST_TARGET=riscv64gc-unknown-linux-musl
|
||||
else
|
||||
# 默认为x86_64,用于本地编译
|
||||
export RUST_TARGET=x86_64-unknown-linux-musl
|
||||
endif
|
||||
|
||||
build:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --target $(RUST_TARGET)
|
||||
|
||||
run-dragonreach:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --target $(RUST_TARGET) --bin DragonReach
|
||||
|
||||
clean:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean
|
||||
|
||||
build-release:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --target $(RUST_TARGET) --release
|
||||
|
||||
clean-release:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean --target $(RUST_TARGET) --release
|
||||
|
||||
fmt:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt
|
||||
|
||||
fmt-check:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt --check
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) install --target $(RUST_TARGET) --path . --no-track --root $(INSTALL_DIR) --force
|
4
user/apps/riscv_init/riscv_rust_init/src/main.rs
Normal file
4
user/apps/riscv_init/riscv_rust_init/src/main.rs
Normal file
@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
println!("rs: Hello, world!");
|
||||
loop {}
|
||||
}
|
Reference in New Issue
Block a user