Skip to content

Commit

Permalink
[feat] Migrate to Rust Edition 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
Azure-stars committed Feb 7, 2025
1 parent ed2162b commit ae6a5dc
Show file tree
Hide file tree
Showing 50 changed files with 216 additions and 1,578 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
rust-toolchain: [nightly]
targets: [x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none-softfloat]
targets: [x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -26,7 +26,7 @@ jobs:
run: cargo fmt --all -- --check
- name: Clippy
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' }}
run: cargo clippy --target ${{ matrix.targets }} --all-features -- -D warnings -A clippy::new_without_default
run: make clippy TARGET=${{ matrix.targets }}

build:
runs-on: ${{ matrix.os }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
*.bin
apps/*/build/
**/target/
**/Cargo.lock
**/Cargo.lock
/.axconfig.*
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "starry"
version = "0.1.0"
edition = "2021"
edition = "2024"
authors = ["Azure-stars <[email protected]>", "Yuekai Jia <[email protected]>"]
homepage = "https://github.com/arceos-org/arceos"
repository = "https://github.com/arceos-org/starry-next"
Expand All @@ -12,19 +12,24 @@ linkme = "0.3"
axerrno = "0.1"
memory_addr = "0.3"
xmas-elf = "0.9"
spin = "0.9"
crate_interface = "0.1"
bitflags = "2.6"

kernel-elf-parser = "0.1.0"
num_enum = { version = "0.7", default-features = false }
syscalls = { version = "0.6", default-features = false }

axconfig = { git = "https://github.com/arceos-org/arceos.git" }
axfs = { git = "https://github.com/arceos-org/arceos.git", features = ["thread-local"] }
axstd = { git = "https://github.com/arceos-org/arceos.git", features = ["paging"] }
axhal = { git = "https://github.com/arceos-org/arceos.git", features = ["uspace"] }
axmm = { git = "https://github.com/arceos-org/arceos.git" }
axtask = { git = "https://github.com/arceos-org/arceos.git" }
axsync = { git = "https://github.com/arceos-org/arceos.git" }
axruntime = { git = "https://github.com/arceos-org/arceos.git", features = ["multitask"] }
arceos_posix_api = { git = "https://github.com/arceos-org/arceos.git" }
arceos_posix_api = { git = "https://github.com/arceos-org/arceos.git", features = ["uspace"] }
axns = { git = "https://github.com/arceos-org/arceos.git", features = ["thread-local"] }

[target.'cfg(target_arch = "x86_64")'.dependencies]
x86 = "0.52"
Expand Down
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AX_ROOT ?= $(PWD)/.arceos
AX_TESTCASE ?= nimbos
ARCH ?= x86_64
AX_TESTCASES_LIST=$(shell cat ./apps/$(AX_TESTCASE)/testcase_list | tr '\n' ',')

TARGET ?= x86_64-unknown-none
RUSTDOCFLAGS := -Z unstable-options --enable-index-page -D rustdoc::broken_intra_doc_links -D missing-docs

ifneq ($(filter $(MAKECMDGOALS),doc_check_missing),) # make doc_check_missing
Expand All @@ -13,16 +13,26 @@ endif

all: build

TARGET_LIST := x86_64-unknown-none riscv64gc-unknown-none-elf aarch64-unknown-none
ifeq ($(filter $(TARGET),$(TARGET_LIST)),)
$(error TARGET must be one of $(TARGET_LIST))
endif

# export dummy config for clippy
clippy:
@AX_CONFIG_PATH=$(PWD)/configs/dummy.toml cargo clippy --target $(TARGET) --all-features -- -D warnings -A clippy::new_without_default

ax_root:
@./scripts/set_ax_root.sh $(AX_ROOT)
@make -C $(AX_ROOT) disk_img

user_apps:
@make -C ./apps/$(AX_TESTCASE) ARCH=$(ARCH) build

test:
@./scripts/app_test.sh

build run justrun debug disasm: ax_root
defconfig build run justrun debug disasm: ax_root
@make -C $(AX_ROOT) A=$(PWD) $@

clean: ax_root
Expand Down
2 changes: 1 addition & 1 deletion apps/libc/rust/helloworld/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "helloworld"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
2 changes: 1 addition & 1 deletion apps/libc/rust/task/sleep/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sleep"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
2 changes: 1 addition & 1 deletion apps/libc/test_cmd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test_one "LOG=off FEATURES=fp_simd" "expect_off.out"
test_one "LOG=off FEATURES=fp_simd BLK=y NET=y" "expect_off.out"
12 changes: 6 additions & 6 deletions apps/nimbos/expect_off.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ log_level = off

Hello world from user mode program!
Hello, world!
Hello, I am process 2.
Back in process 2, iteration 0.
Back in process 2, iteration 1.
Back in process 2, iteration 2.
Back in process 2, iteration 3.
Back in process 2, iteration 4.
Hello, I am process 6.
Back in process 6, iteration 0.
Back in process 6, iteration 1.
Back in process 6, iteration 2.
Back in process 6, iteration 3.
Back in process 6, iteration 4.
yield passed!
into sleep test!
simple_sleep passed!
2 changes: 1 addition & 1 deletion apps/nimbos/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "user_lib"
version = "0.1.0"
authors = ["Yifan Wu <[email protected]>", "Yuekai Jia <[email protected]>"]
edition = "2021"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion apps/nimbos/rust/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARCH ?= x86_64
MODE ?= release
MODE ?= debug

ifeq ($(ARCH), x86_64)
target := x86_64-unknown-none
Expand Down
2 changes: 1 addition & 1 deletion apps/nimbos/rust/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
profile = "minimal"
# use the nightly version of the last stable toolchain, see <https://forge.rust-lang.org/>
channel = "nightly-2024-05-02"
channel = "nightly-2024-12-25"
components = ["rust-src", "llvm-tools-preview", "rustfmt", "clippy"]
11 changes: 5 additions & 6 deletions apps/nimbos/rust/src/arch/aarch64.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::arch::asm;
use core::arch::{asm, naked_asm};

use crate::syscall::{SYSCALL_CLONE, SYSCALL_EXIT};

Expand All @@ -24,7 +24,7 @@ pub extern "C" fn sys_clone(_entry: fn(usize) -> i32, _arg: usize, _newsp: usize
// syscall(SYSCALL_CLONE, newsp)
// x8, x0
unsafe {
asm!("
naked_asm!("
// align stack and save entry,arg to the new stack
and x2, x2, #-16
stp x0, x1, [x2, #-16]!
Expand All @@ -34,19 +34,18 @@ pub extern "C" fn sys_clone(_entry: fn(usize) -> i32, _arg: usize, _newsp: usize
mov x8, {sys_clone}
svc #0
cbz x0, 1f
cbz x0, 2f
// parent
ret
1:
2:
// child
ldp x1, x0, [sp], #16
blr x1
// syscall(SYSCALL_EXIT, ret)
mov x8, {sys_exit}
svc #0",
sys_clone = const SYSCALL_CLONE,
sys_exit = const SYSCALL_EXIT,
options(noreturn)
sys_exit = const SYSCALL_EXIT
)
}
}
11 changes: 5 additions & 6 deletions apps/nimbos/rust/src/arch/riscv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::arch::asm;
use core::arch::{asm, naked_asm};

use crate::syscall::{SYSCALL_CLONE, SYSCALL_EXIT};

Expand All @@ -24,7 +24,7 @@ pub extern "C" fn sys_clone(_entry: fn(usize) -> i32, _arg: usize, _newsp: usize
// syscall(SYSCALL_CLONE, newsp)
// a7, x0
unsafe {
asm!("
naked_asm!("
// align stack and save entry,arg to the new stack
andi a2, a2, -16
addi a2, a2, -16
Expand All @@ -36,10 +36,10 @@ pub extern "C" fn sys_clone(_entry: fn(usize) -> i32, _arg: usize, _newsp: usize
li a7, {sys_clone}
ecall
beqz a0, 1f
beqz a0, 2f
// parent
ret
1:
2:
// child
ld a0, 8(sp)
ld a1, 0(sp)
Expand All @@ -48,8 +48,7 @@ pub extern "C" fn sys_clone(_entry: fn(usize) -> i32, _arg: usize, _newsp: usize
li a7, {sys_exit}
ecall",
sys_clone = const SYSCALL_CLONE,
sys_exit = const SYSCALL_EXIT,
options(noreturn),
sys_exit = const SYSCALL_EXIT
)
}
}
11 changes: 5 additions & 6 deletions apps/nimbos/rust/src/arch/x86_64.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::arch::asm;
use core::arch::{asm, naked_asm};

use crate::syscall::{SYSCALL_CLONE, SYSCALL_EXIT};

Expand Down Expand Up @@ -26,7 +26,7 @@ pub extern "C" fn sys_clone(_entry: fn(usize) -> i32, _arg: usize, _newsp: usize
// syscall(SYSCALL_CLONE, newsp)
// rax, rdi
unsafe {
asm!("
naked_asm!("
// push arg (rsi) to stack, set func (rdi) to r9
and rdx, -16
sub rdx, 8
Expand All @@ -39,10 +39,10 @@ pub extern "C" fn sys_clone(_entry: fn(usize) -> i32, _arg: usize, _newsp: usize
syscall
test rax, rax
jz 1f
jz 2f
// parent
ret
1:
2:
// child
xor rbp, rbp
pop rdi
Expand All @@ -52,8 +52,7 @@ pub extern "C" fn sys_clone(_entry: fn(usize) -> i32, _arg: usize, _newsp: usize
mov rax, {sys_exit}
syscall",
sys_clone = const SYSCALL_CLONE,
sys_exit = const SYSCALL_EXIT,
options(noreturn),
sys_exit = const SYSCALL_EXIT
)
}
}
2 changes: 1 addition & 1 deletion apps/nimbos/rust/src/bin/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use user_lib::{exit, fork, sched_yield, wait, waitpid};

const MAGIC: i32 = -0x10384;

#[no_mangle]
#[unsafe(no_mangle)]
pub fn main() -> i32 {
println!("I am the parent. Forking the child...");
let pid = fork();
Expand Down
6 changes: 3 additions & 3 deletions apps/nimbos/rust/src/bin/fantastic_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
extern crate user_lib;

macro_rules! color_text {
($text:expr, $color:expr) => {{
($text:expr, $color:expr) => {
format_args!("\x1b[{}m{}\x1b[0m", $color, $text)
}};
};
}

#[no_mangle]
#[unsafe(no_mangle)]
pub fn main() -> i32 {
println!(
"{}{}{}{}{}{} {}{}{}{} {}{}{}{}{}",
Expand Down
2 changes: 1 addition & 1 deletion apps/nimbos/rust/src/bin/forktest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use user_lib::{exit, fork, wait};

const MAX_CHILD: usize = 30;

#[no_mangle]
#[unsafe(no_mangle)]
pub fn main() -> i32 {
for i in 0..MAX_CHILD {
let pid = fork();
Expand Down
2 changes: 1 addition & 1 deletion apps/nimbos/rust/src/bin/forktest2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use user_lib::{exit, fork, get_time_us, getpid, usleep, wait};

static NUM: usize = 30;

#[no_mangle]
#[unsafe(no_mangle)]
pub fn main() -> i32 {
for _ in 0..NUM {
let pid = fork();
Expand Down
2 changes: 1 addition & 1 deletion apps/nimbos/rust/src/bin/forktest_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate user_lib;

use user_lib::{fork, getpid};

#[no_mangle]
#[unsafe(no_mangle)]
pub fn main() -> i32 {
println!("parent start, pid = {}!", getpid());
let pid = fork();
Expand Down
2 changes: 1 addition & 1 deletion apps/nimbos/rust/src/bin/forktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn fork_tree(cur: &str) {
fork_child(cur, '1');
}

#[no_mangle]
#[unsafe(no_mangle)]
pub fn main() -> i32 {
fork_tree("");
sleep(3);
Expand Down
2 changes: 1 addition & 1 deletion apps/nimbos/rust/src/bin/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#[macro_use]
extern crate user_lib;

#[no_mangle]
#[unsafe(no_mangle)]
pub fn main() -> i32 {
println!("Hello world from user mode program!");
0
Expand Down
2 changes: 1 addition & 1 deletion apps/nimbos/rust/src/bin/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn work(times: isize) {
exit(0);
}

#[no_mangle]
#[unsafe(no_mangle)]
pub fn main() -> i32 {
for _ in 0..NUM {
let pid = fork();
Expand Down
2 changes: 1 addition & 1 deletion apps/nimbos/rust/src/bin/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn sleepy() {
exit(0);
}

#[no_mangle]
#[unsafe(no_mangle)]
pub fn main() -> i32 {
let current_time = get_time_us();
let pid = fork();
Expand Down
2 changes: 1 addition & 1 deletion apps/nimbos/rust/src/bin/sleep_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate user_lib;

use user_lib::{get_time_us, sleep};

#[no_mangle]
#[unsafe(no_mangle)]
pub fn main() -> i32 {
println!("into sleep test!");
let start = get_time_us();
Expand Down
2 changes: 1 addition & 1 deletion apps/nimbos/rust/src/bin/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn f(d: usize) {
f(d + 1);
}

#[no_mangle]
#[unsafe(no_mangle)]
pub fn main() -> i32 {
println!("It should trigger segmentation fault!");
f(0);
Expand Down
2 changes: 1 addition & 1 deletion apps/nimbos/rust/src/bin/thread_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn get_sp() -> usize {
sp
}

#[no_mangle]
#[unsafe(no_mangle)]
pub fn main() -> i32 {
let test_user_thread = |arg| {
for _ in 0..100 {
Expand Down
2 changes: 1 addition & 1 deletion apps/nimbos/rust/src/bin/user_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use user_lib::{exec, fork, waitpid};

const MAX_CMD_LEN: usize = 256;

#[no_mangle]
#[unsafe(no_mangle)]
pub fn main() -> i32 {
println!("Rust user shell");
let mut line = [0; MAX_CMD_LEN];
Expand Down
Loading

0 comments on commit ae6a5dc

Please sign in to comment.