Skip to content

Commit

Permalink
实现unified-init库,支持收集初始化函数到一个数组,并统一初始化 (#474)
Browse files Browse the repository at this point in the history
* 添加“统一初始化”的过程宏,并把SystemError独立成crate

* 使用unified-init来初始化fbmem

* 更新workflow,增加内核自动化静态测试
  • Loading branch information
fslongjin committed Dec 25, 2023
1 parent f110d33 commit 91e9d4a
Show file tree
Hide file tree
Showing 158 changed files with 1,100 additions and 608 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ jobs:
~/.bashrc
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.dadk_version }}-${{ hashFiles('.github/workflows/cache-toolchain.yml') }}


- name: Format check
run: |
printf "\n" >> kernel/src/include/bindings/bindings.rs
printf "\n" >> user/libs/libc/src/include/internal/bindings/bindings.rs
FMT_CHECK=1 make fmt
- name: build the DragonOS
run: bash -c "source ~/.cargo/env && export DragonOS_GCC=$HOME/opt/dragonos-gcc/gcc-x86_64-unknown-none/bin && make -j $(nproc) "

- name: Run kernel static test
run: bash -c "source ~/.cargo/env && cd kernel && make test"
38 changes: 0 additions & 38 deletions .github/workflows/rustfmt.yml

This file was deleted.

1 change: 1 addition & 0 deletions docs/kernel/libs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@

lib_ui/scm
lib_ui/textui
unified-init

54 changes: 54 additions & 0 deletions docs/kernel/libs/unified-init.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# unified-init 统一初始化库

:::{note}
本文作者:龙进 <longjin@DragonOS.org>

2023年12月25日
:::

## 1. 简介

该库位于`kernel/crates/unified-init`中.
提供统一初始化宏,用于将函数注册到统一初始化列表中. 便于统一进行初始化.

需要注意的是,初始化器的数组是no_mangle的,因此其命名应当遵守`模块_初始化器`的规则,防止重名导致意想不到的错误.


## 2. 用法


```rust
use system_error::SystemError;
use unified_init::define_unified_initializer_slice;
use unified_init_macros::unified_init;

/// 初始化函数都将会被放到这个列表中
define_unified_initializer_slice!(INITIALIZER_LIST);

#[unified_init(INITIALIZER_LIST)]
fn init1() -> Result<(), SystemError> {
Ok(())
}

#[unified_init(INITIALIZER_LIST)]
fn init2() -> Result<(), SystemError> {
Ok(())
}

fn main() {
assert_eq!(INITIALIZER_LIST.len(), 2);
}

```

## 3.开发

需要测试的时候可以在`main.rs`写测试代码,
然后在当前目录执行 `cargo expand --bin unified-init-expand`
就可以看到把proc macro展开后的代码了.

## 4. Maintainer

龙进 <longjin@DragonOS.org>


29 changes: 15 additions & 14 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,33 @@ backtrace = []

# 运行时依赖项
[dependencies]
acpi = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/acpi-rs.git", rev = "fb69243dcf" }
atomic_enum = "0.2.0"
bit_field = "0.10"
bitflags = "1.3.2"
bitfield-struct = "0.5.3"
virtio-drivers = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/virtio-drivers.git", rev = "f1d1cbb" }
smoltcp = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/smoltcp.git", rev = "9027825", default-features = false, features = ["log", "alloc", "socket-raw", "socket-udp", "socket-tcp", "socket-icmp", "socket-dhcpv4", "socket-dns", "proto-ipv4", "proto-ipv6"]}
# num-traits 0.2.15
num-traits = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/num-traits.git", rev="1597c1c", default-features = false }
num = { version = "0.4.0", default-features = false }
num-derive = "0.3"
# 一个no_std的hashmap、hashset
hashbrown = "0.13.2"
elf = { version = "0.7.2", default-features = false }
atomic_enum = "0.2.0"
raw-cpuid = "11.0.1"
acpi = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/acpi-rs.git", rev = "fb69243dcf" }
intertrait = { path = "src/libs/intertrait" }
linkme = "0.2"
hashbrown = "0.13.2"
ida = { path = "src/libs/ida" }
klog_types = { path = "crates/klog_types" }
intertrait = { path = "src/libs/intertrait" }
kdepends = { path = "crates/kdepends" }
klog_types = { path = "crates/klog_types" }
linkme = "0.2"
num = { version = "0.4.0", default-features = false }
num-derive = "0.3"
num-traits = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/num-traits.git", rev="1597c1c", default-features = false }
raw-cpuid = "11.0.1"
smoltcp = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/smoltcp.git", rev = "9027825", default-features = false, features = ["log", "alloc", "socket-raw", "socket-udp", "socket-tcp", "socket-icmp", "socket-dhcpv4", "socket-dns", "proto-ipv4", "proto-ipv6"]}
system_error = { path = "crates/system_error" }
unified-init = { path = "crates/unified-init" }
virtio-drivers = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/virtio-drivers.git", rev = "f1d1cbb" }

# target为x86_64时,使用下面的依赖
[target.'cfg(target_arch = "x86_64")'.dependencies]
mini-backtrace = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/mini-backtrace.git", rev = "ba98506685" }
x86 = "0.52.0"
x86_64 = "0.14.10"
mini-backtrace = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/mini-backtrace.git", rev = "ba98506685" }


# 构建时依赖项
Expand Down
4 changes: 4 additions & 0 deletions kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ else ifeq ($(ARCH), riscv64)
@cargo +nightly-2023-08-15 check --workspace $(CARGO_ZBUILD) --message-format=json --target ./src/$(TARGET_JSON)
endif

test:
# 测试内核库
@cargo +nightly-2023-08-15 test --workspace --exclude dragonos_kernel

12 changes: 12 additions & 0 deletions kernel/crates/system_error/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "system_error"
version = "0.1.0"
edition = "2021"

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

[dependencies]
kdepends = { path = "../kdepends" }
num-traits = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/num-traits.git", rev="1597c1c", default-features = false }
num = { version = "0.4.0", default-features = false }
num-derive = "0.3"
Loading

0 comments on commit 91e9d4a

Please sign in to comment.