Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Rust Edition 2024 #212

Merged
merged 26 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
23eb4a3
update to edition 2024
aarkegz Dec 5, 2024
2a1dc35
remove unused feature flags in axhal and axtask
aarkegz Dec 5, 2024
8d221f0
fix errors during updating
aarkegz Dec 5, 2024
7a2c619
fix remaining errors
aarkegz Dec 5, 2024
7ec2845
fix some warnings
aarkegz Dec 5, 2024
1823279
fix some warnings
aarkegz Dec 5, 2024
2c7ab80
fix more warnings
aarkegz Dec 5, 2024
850d5f6
fix some warnings
aarkegz Dec 12, 2024
ba68a3f
update to edition 2024
aarkegz Dec 12, 2024
bbdb925
update to 2024-12-12
aarkegz Dec 12, 2024
752d23f
migrate to edition 2024
aarkegz Dec 20, 2024
110c150
fix "dropped here while still borrowed" in `examples/shell` cause by …
aarkegz Dec 20, 2024
beccf34
formatted
aarkegz Dec 20, 2024
0aab899
try adding `unsafe` to `linkme`
aarkegz Dec 20, 2024
16a27d7
revert the previous commit, update `linkme` to 0.3.31
aarkegz Dec 20, 2024
af516df
Merge branch 'upstream_main' into edition_2024
aarkegz Dec 20, 2024
680ee02
format code on main with newer rustfmt
aarkegz Dec 20, 2024
765b127
update arceos-app
aarkegz Dec 20, 2024
8b7b5c7
fix some warnings
aarkegz Dec 20, 2024
3b53fb4
remove mistakenly added "unsafe" in c/c++ header files
aarkegz Dec 21, 2024
e536257
update `page_table_*` and `flatten_objects`
aarkegz Dec 21, 2024
eb27d16
fix clippy warnings
aarkegz Dec 21, 2024
53fb216
allow `unsafe_op_in_unsafe_fn` during building
aarkegz Dec 23, 2024
1238464
fix `RUSTFLAGS` in makefile scripts
aarkegz Dec 23, 2024
a5b1849
update percpu and allocator, revert changes in strftime
aarkegz Dec 23, 2024
4890541
formatted
aarkegz Dec 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
rust-toolchain: [nightly, nightly-2024-05-02]
rust-toolchain: [nightly, nightly-2024-12-12]
env:
RUSTUP_TOOLCHAIN: ${{ matrix.rust-toolchain }}
steps:
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
matrix:
os: [ubuntu-latest]
arch: [x86_64, riscv64, aarch64]
rust-toolchain: [nightly, nightly-2024-05-02]
rust-toolchain: [nightly, nightly-2024-12-12]
env:
RUSTUP_TOOLCHAIN: ${{ matrix.rust-toolchain }}
steps:
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
rust-toolchain: [nightly, nightly-2024-05-02]
rust-toolchain: [nightly, nightly-2024-12-12]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build & Deploy docs
on: [push, pull_request]

env:
rust-toolchain: nightly-2024-05-02
rust-toolchain: nightly-2024-12-12

jobs:
doc:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on: [push, pull_request]

env:
qemu-version: 8.2.0
rust-toolchain: nightly-2024-05-02
arceos-apps: 'da1caa5'
rust-toolchain: nightly-2024-12-12
arceos-apps: '57c8074'

jobs:
unit-test:
Expand Down
42 changes: 21 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ members = [

[workspace.package]
version = "0.1.0"
edition = "2024"
authors = ["Yuekai Jia <[email protected]>"]
license = "GPL-3.0-or-later OR Apache-2.0 OR MulanPSL-2.0"
homepage = "https://github.com/arceos-org/arceos"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Examples are given below and in the [app-helloworld](https://github.com/arceos-o

3. Call library functions from `axstd` in your code, just like the Rust [std](https://doc.rust-lang.org/std/) library.

Remember to annotate the `main` function with `#[no_mangle]` (see this [example](examples/helloworld/src/main.rs)).
Remember to annotate the `main` function with `#[unsafe(no_mangle)]` (see this [example](examples/helloworld/src/main.rs)).

4. Build your application with ArceOS, by running the `make` command in the application directory:

Expand Down
2 changes: 1 addition & 1 deletion api/arceos_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "arceos_api"
version.workspace = true
edition = "2021"
edition.workspace = true
authors = ["Yuekai Jia <[email protected]>"]
description = "Public APIs and types for ArceOS modules"
license.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion api/arceos_api/src/imp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod stdio {

mod time {
pub use axhal::time::{
monotonic_time as ax_monotonic_time, wall_time as ax_wall_time, TimeValue as AxTimeValue,
TimeValue as AxTimeValue, monotonic_time as ax_monotonic_time, wall_time as ax_wall_time,
};
}

Expand Down
2 changes: 1 addition & 1 deletion api/arceos_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ pub mod fs {

/// Networking primitives for TCP/UDP communication.
pub mod net {
use crate::{io::AxPollState, AxResult};
use crate::{AxResult, io::AxPollState};
use core::net::{IpAddr, SocketAddr};

define_api_type! {
Expand Down
4 changes: 2 additions & 2 deletions api/arceos_posix_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "arceos_posix_api"
version.workspace = true
edition = "2021"
edition.workspace = true
authors = [
"Yuekai Jia <[email protected]>",
"yanjuguang <[email protected]>",
Expand Down Expand Up @@ -46,7 +46,7 @@ axnet = { workspace = true, optional = true }
# Other crates
axio = "0.1"
axerrno = "0.1"
flatten_objects = "0.1"
flatten_objects = "0.2"
static_assertions = "1.1.0"
spin = { version = "0.9" }
lazy_static = { version = "1.5", features = ["spin_no_std"] }
Expand Down
10 changes: 5 additions & 5 deletions api/arceos_posix_api/src/imp/fd_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ pub trait FileLike: Send + Sync {
lazy_static::lazy_static! {
static ref FD_TABLE: RwLock<FlattenObjects<Arc<dyn FileLike>, AX_FILE_LIMIT>> = {
let mut fd_table = FlattenObjects::new();
fd_table.add_at(0, Arc::new(stdin()) as _).unwrap(); // stdin
fd_table.add_at(1, Arc::new(stdout()) as _).unwrap(); // stdout
fd_table.add_at(2, Arc::new(stdout()) as _).unwrap(); // stderr
fd_table.add_at(0, Arc::new(stdin()) as _).unwrap_or_else(|_| panic!()); // stdin
fd_table.add_at(1, Arc::new(stdout()) as _).unwrap_or_else(|_| panic!()); // stdout
fd_table.add_at(2, Arc::new(stdout()) as _).unwrap_or_else(|_| panic!()); // stderr
RwLock::new(fd_table)
};
}
Expand All @@ -40,7 +40,7 @@ pub fn get_file_like(fd: c_int) -> LinuxResult<Arc<dyn FileLike>> {
}

pub fn add_file_like(f: Arc<dyn FileLike>) -> LinuxResult<c_int> {
Ok(FD_TABLE.write().add(f).ok_or(LinuxError::EMFILE)? as c_int)
Ok(FD_TABLE.write().add(f).map_err(|_| LinuxError::EMFILE)? as c_int)
}

pub fn close_file_like(fd: c_int) -> LinuxResult {
Expand Down Expand Up @@ -95,7 +95,7 @@ pub fn sys_dup2(old_fd: c_int, new_fd: c_int) -> c_int {
FD_TABLE
.write()
.add_at(new_fd as usize, f)
.ok_or(LinuxError::EMFILE)?;
.map_err(|_| LinuxError::EMFILE)?;

Ok(new_fd)
})
Expand Down
3 changes: 2 additions & 1 deletion api/arceos_posix_api/src/imp/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use axfs::fops::OpenOptions;
use axio::{PollState, SeekFrom};
use axsync::Mutex;

use super::fd_ops::{get_file_like, FileLike};
use super::fd_ops::{FileLike, get_file_like};
use crate::{ctypes, utils::char_ptr_to_str};

pub struct File {
Expand Down Expand Up @@ -183,6 +183,7 @@ pub unsafe fn sys_lstat(path: *const c_char, buf: *mut ctypes::stat) -> ctypes::
}

/// Get the path of the current directory.
#[allow(clippy::unnecessary_cast)] // `c_char` is either `i8` or `u8`
pub fn sys_getcwd(buf: *mut c_char, size: usize) -> *mut c_char {
debug!("sys_getcwd <= {:#x} {}", buf as usize, size);
syscall_body!(sys_getcwd, {
Expand Down
6 changes: 3 additions & 3 deletions api/arceos_posix_api/src/imp/io_mpx/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//!
//! TODO: do not support `EPOLLET` flag

use alloc::collections::btree_map::Entry;
use alloc::collections::BTreeMap;
use alloc::collections::btree_map::Entry;
use alloc::sync::Arc;
use core::{ffi::c_int, time::Duration};

Expand All @@ -12,7 +12,7 @@ use axhal::time::wall_time;
use axsync::Mutex;

use crate::ctypes;
use crate::imp::fd_ops::{add_file_like, get_file_like, FileLike};
use crate::imp::fd_ops::{FileLike, add_file_like, get_file_like};

pub struct EpollInstance {
events: Mutex<BTreeMap<usize, ctypes::epoll_event>>,
Expand Down Expand Up @@ -195,7 +195,7 @@ pub unsafe fn sys_epoll_wait(
return Ok(events_num as c_int);
}

if deadline.map_or(false, |ddl| wall_time() >= ddl) {
if deadline.is_some_and(|ddl| wall_time() >= ddl) {
debug!(" timeout!");
return Ok(0);
}
Expand Down
2 changes: 1 addition & 1 deletion api/arceos_posix_api/src/imp/io_mpx/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub unsafe fn sys_select(
return Ok(res);
}

if deadline.map_or(false, |ddl| wall_time() >= ddl) {
if deadline.is_some_and(|ddl| wall_time() >= ddl) {
debug!(" timeout!");
return Ok(0);
}
Expand Down
2 changes: 1 addition & 1 deletion api/arceos_posix_api/src/imp/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use axerrno::{LinuxError, LinuxResult};
use axio::PollState;
use axsync::Mutex;

use super::fd_ops::{add_file_like, close_file_like, FileLike};
use super::fd_ops::{FileLike, add_file_like, close_file_like};
use crate::ctypes;

#[derive(Copy, Clone, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion api/arceos_posix_api/src/imp/pthread/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use axerrno::LinuxResult;
use axsync::Mutex;

use core::ffi::c_int;
use core::mem::{size_of, ManuallyDrop};
use core::mem::{ManuallyDrop, size_of};

static_assertions::const_assert_eq!(
size_of::<ctypes::pthread_mutex_t>(),
Expand Down
2 changes: 1 addition & 1 deletion api/arceos_posix_api/src/imp/stdio.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axerrno::AxResult;
use axio::{prelude::*, BufReader};
use axio::{BufReader, prelude::*};
use axsync::Mutex;

#[cfg(feature = "fd")]
Expand Down
2 changes: 1 addition & 1 deletion api/arceos_posix_api/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(unused_macros)]

use axerrno::{LinuxError, LinuxResult};
use core::ffi::{c_char, CStr};
use core::ffi::{CStr, c_char};

pub fn char_ptr_to_str<'a>(str: *const c_char) -> LinuxResult<&'a str> {
if str.is_null() {
Expand Down
2 changes: 1 addition & 1 deletion api/axfeat/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "axfeat"
version.workspace = true
edition = "2021"
edition.workspace = true
authors = ["Yuekai Jia <[email protected]>"]
description = "Top-level feature selection for ArceOS"
license.workspace = true
Expand Down
9 changes: 4 additions & 5 deletions doc/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ What happens when "make A=apps/net/httpserver ARCH=aarch64 LOG=info NET=y SMP=1
- At runtime, Arceos first performs some boot operations, such as executing in the riscv64 environment:
```rust
#[naked]
#[no_mangle]
#[link_section = ".text.boot"]
#[unsafe(no_mangle)]
#[unsafe(link_section = ".text.boot")]
unsafe extern "C" fn _start() -> ! {
extern "C" {
unsafe extern "C" {
fn rust_main();
}
// PC = 0x8020_0000
// a0 = hartid
// a1 = dtb
core::arch::asm!("
core::arch::naked_asm!("
mv s0, a0 // save hartid
mv s1, a1 // save DTB pointer
la sp, {boot_stack}
Expand Down Expand Up @@ -82,7 +82,6 @@ What happens when "make A=apps/net/httpserver ARCH=aarch64 LOG=info NET=y SMP=1
init_mmu = sym init_mmu,
platform_init = sym super::platform_init,
rust_main = sym rust_main,
options(noreturn),
)
}
```
Expand Down
Loading
Loading