Skip to content

Commit c344ac6

Browse files
authored
Merge pull request #29 from miiyakumo/main Closes #21
格式化代码并在ci中引入代码检查
2 parents 45cd56a + 6ffd1f2 commit c344ac6

36 files changed

Lines changed: 243 additions & 179 deletions
Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
name: Run tests
1+
name: Run tests & Code Quality Checks
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- main # 在代码合并到 main 分支后,仍然运行一次完整的 CI
7+
pull_request:
8+
branches:
9+
- main # 在针对 main 分支的 PR 提出/更新时运行 CI
410

511
env:
612
CARGO_TERM_COLOR: always
7-
RUST_TOOLCHAIN: nightly-2025-01-13
8-
9-
QEMU_VERSION: qemu-9.2.1
10-
QEMU_BUILD_PATH: ${{ github.workspace }}/qemu-build-cache
13+
RUST_TOOLCHAIN: nightly-2025-01-13
14+
15+
QEMU_VERSION: qemu-9.2.1
16+
QEMU_BUILD_PATH: ${{ github.workspace }}/qemu-build-cache
1117

1218
jobs:
1319
run-tests:
@@ -16,29 +22,55 @@ jobs:
1622
- name: ⬇️ Checkout code
1723
uses: actions/checkout@v4
1824

19-
# --- 1. 缓存 Cargo 依赖项 ---
20-
- name: 📦 Cache Cargo Dependencies & Build Artifacts
21-
uses: actions/cache@v4
25+
# --- 1. 缓存 Cargo 依赖项 (使用 Swatinem/rust-cache) ---
26+
# ⚠️ 替换了原有的 actions/cache@v4,更高效地管理 Cargo 缓存
27+
- name: 📦 Setup Rust Cache
28+
uses: Swatinem/rust-cache@v2
2229
with:
23-
path: |
24-
~/.cargo/registry
25-
~/.cargo/git
26-
target
27-
key: ${{ runner.os }}-cargo-${{ env.RUST_TOOLCHAIN }}-${{ hashFiles('**/Cargo.lock') }}
28-
restore-keys: |
29-
${{ runner.os }}-cargo-${{ env.RUST_TOOLCHAIN }}-
30+
# 仅需传递 key 相关的变量,该 Action 会自动处理路径
31+
key: ${{ runner.os }}-${{ env.RUST_TOOLCHAIN }}-${{ hashFiles('**/Cargo.lock') }}
3032

3133
# --- 2. 安装 Rust Toolchain 和 Target ---
3234
- name: 🛠️ Setup Rust Toolchain and Target
3335
uses: dtolnay/rust-toolchain@master
3436
with:
35-
toolchain: ${{ env.RUST_TOOLCHAIN }}
37+
toolchain: ${{ env.RUST_TOOLCHAIN }}
3638
targets: riscv64gc-unknown-none-elf
39+
# 确保安装了 rustfmt 和 clippy
3740
components: rust-src, rustfmt, clippy, llvm-tools-preview
3841

42+
# --- 2.1 代码质量检查 (优先执行) ---
43+
44+
- name: 🔍 Cargo Check (快速验证编译)
45+
working-directory: os
46+
run: cargo check --target riscv64gc-unknown-none-elf
47+
48+
- name: 📏 Run Code Formatting Check
49+
working-directory: os
50+
# 使用 --check 模式,如果代码未格式化,则 CI 失败
51+
run: cargo fmt --all -- --check
52+
53+
- name: 🔬 Run Clippy Lint Check
54+
working-directory: os
55+
# 使用 -D warnings 强制将所有警告升级为错误,确保 PR 必须解决所有代码异味
56+
run: cargo clippy --target riscv64gc-unknown-none-elf -- -D warnings
57+
58+
# --- 2.2 安装辅助工具 ---
59+
3960
- name: Install cargo-binutils
4061
run: cargo install cargo-binutils
4162

63+
# --- 2.5 缓存 Apt 包 (优化 QEMU 依赖安装时间) ---
64+
- name: 📦 Cache APT Dependencies
65+
uses: actions/cache@v4
66+
with:
67+
path: |
68+
/var/cache/apt/archives
69+
/var/lib/apt/lists
70+
key: ${{ runner.os }}-apt-qemu-deps-v1
71+
restore-keys: |
72+
${{ runner.os }}-apt-qemu-deps-
73+
4274
# --- 3. QEMU 编译和缓存 ---
4375
- name: 🧱 Install QEMU Dependencies
4476
run: |

document/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
在这个文件夹里记录一些模块设计思路和硬件细节

document/Task.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# 进程模块的设计
2+
3+
## 概要
4+
总体而言,我准备效仿Linux,将其称为Task并对于进程线程不加以区分,即认为:
5+
6+
**线程不过是与别的Task共享某些资源的Task**

os/src/arch/loongarch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mod mm;
1+
mod mm;

os/src/arch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ mod riscv;
55
pub use self::loongarch::*;
66

77
#[cfg(target_arch = "riscv64")]
8-
pub use riscv::*;
8+
pub use riscv::*;

os/src/arch/riscv/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#![allow(unused)]
22
/// riscv sstatus 寄存器中 SIE 位的掩码
3-
pub const SSTATUS_SIE: usize = 1 << 1;
3+
pub const SSTATUS_SIE: usize = 1 << 1;

os/src/arch/riscv/intr/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#![allow(unused)]
2-
use riscv::register::{sie, sstatus::{self, Sstatus}};
2+
use riscv::register::{
3+
sie,
4+
sstatus::{self, Sstatus},
5+
};
36

47
/// 启用定时器中断
58
pub unsafe fn enable_timer_interrupt() {
@@ -47,4 +50,4 @@ pub unsafe fn read_and_disable_interrupts() -> usize {
4750
pub unsafe fn restore_interrupts(flags: usize) {
4851
// XXX: 与 read_and_disable_interrupts 配合使用时,中断禁用期间其它并发可能会改变寄存器状态,此时要恢复它们吗?
4952
unsafe { sstatus::write(Sstatus::from_bits(flags)) };
50-
}
53+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/// 在发生调度时保存的上下文信息
22
/// 相较于TrapFram只保存切换所需的最少量寄存器
3+
#[allow(dead_code)]
34
pub struct Context {
45
/// 返回地址
56
pub ra: usize,
67
/// 栈指针
78
pub sp: usize,
89
/// 保存s0-s11寄存器
910
pub s: [usize; 12],
10-
}
11+
}

os/src/arch/riscv/kernel/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub mod context;
1+
pub mod context;

os/src/arch/riscv/mm/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ pub const fn vaddr_to_paddr(vaddr: usize) -> usize {
6161
/// This function must be implemented in all architecture-specific mm modules.
6262
pub const fn paddr_to_vaddr(paddr: usize) -> usize {
6363
paddr | VADDR_START
64-
}
64+
}

0 commit comments

Comments
 (0)