-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
实现unified-init库,支持收集初始化函数到一个数组,并统一初始化 (#474)
* 添加“统一初始化”的过程宏,并把SystemError独立成crate * 使用unified-init来初始化fbmem * 更新workflow,增加内核自动化静态测试
- Loading branch information
Showing
158 changed files
with
1,100 additions
and
608 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ | |
|
||
lib_ui/scm | ||
lib_ui/textui | ||
unified-init | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Oops, something went wrong.