Skip to content

Commit

Permalink
Migrate to Rust Edition 2024 (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarkegz authored Dec 23, 2024
1 parent 94f31ed commit 26efed9
Show file tree
Hide file tree
Showing 148 changed files with 380 additions and 389 deletions.
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
59 changes: 30 additions & 29 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
Loading

0 comments on commit 26efed9

Please sign in to comment.