Skip to content

Commit b5dc2b6

Browse files
authored
Remove #[axplat_macros::def_plat_interface] (#46)
* [feat] remove axplat_macros::def_plat_interface It can be replaced with `crate_interface::def_interface(gen_caller)` with crate_interface >= 0.2.0 * [chore] bump version of axplat axplat 0.3.0 -> 0.4.0 axplat_macros 0.1.0 -> 0.2.0 cargo-axplat 0.2.5 -> 0.3.0
1 parent 35e807a commit b5dc2b6

File tree

55 files changed

+78
-124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+78
-124
lines changed

Cargo.lock

Lines changed: 16 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ repository = "https://github.com/arceos-org/axplat_crates"
3636

3737
[workspace.dependencies]
3838
axcpu = "0.2"
39-
axplat = { version = "0.3.0", path = "./axplat" }
40-
axplat-macros = { version = "0.1.0", path = "./axplat-macros" }
41-
axplat-aarch64-peripherals = { version = "0.3.0", path = "platforms/axplat-aarch64-peripherals" }
39+
axplat = { version = "0.4.0", path = "./axplat" }
40+
axplat-macros = { version = "0.2.0", path = "./axplat-macros" }
41+
axplat-aarch64-peripherals = { version = "0.3.0", path = "platforms/axplat-aarch64-peripherals" }

axplat-macros/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "axplat-macros"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
description = "Procedural macros for the `axplat` crate"
55
documentation = "https://docs.rs/axplat-macros"
66
keywords = ["arceos", "os", "hal", "embedded", "macros"]
@@ -16,8 +16,5 @@ proc-macro2 = "1.0"
1616
quote = "1.0"
1717
syn = { version = "2.0", features = ["full"] }
1818

19-
[dev-dependencies]
20-
crate_interface = "0.1"
21-
2219
[lib]
2320
proc-macro = true

axplat-macros/src/lib.rs

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use proc_macro::TokenStream;
44
use proc_macro2::Span;
55
use quote::quote;
6-
use syn::{Error, FnArg, ItemFn, ItemTrait, ReturnType, TraitItem};
6+
use syn::{Error, FnArg, ItemFn, ReturnType};
77

88
fn compiler_error(err: Error) -> TokenStream {
99
err.to_compile_error().into()
@@ -104,55 +104,3 @@ pub fn secondary_main(attr: TokenStream, item: TokenStream) -> TokenStream {
104104
"expect a function with type `fn(cpu_id: usize) -> !`",
105105
)
106106
}
107-
108-
#[doc(hidden)]
109-
#[proc_macro_attribute]
110-
pub fn def_plat_interface(attr: TokenStream, item: TokenStream) -> TokenStream {
111-
if !attr.is_empty() {
112-
return compiler_error(Error::new(
113-
Span::call_site(),
114-
"expect an empty attribute: `#[def_plat_interface]`",
115-
));
116-
}
117-
118-
let trait_ast = syn::parse_macro_input!(item as ItemTrait);
119-
let trait_name = &trait_ast.ident;
120-
121-
let mut fn_list = vec![];
122-
for item in &trait_ast.items {
123-
if let TraitItem::Fn(method) = item {
124-
let attrs = &method.attrs;
125-
let sig = &method.sig;
126-
let fn_name = &sig.ident;
127-
128-
let mut args = vec![];
129-
for arg in &sig.inputs {
130-
match arg {
131-
FnArg::Receiver(_) => {
132-
return compiler_error(Error::new_spanned(
133-
arg,
134-
"`self` is not allowed in the interface definition",
135-
));
136-
}
137-
FnArg::Typed(ty) => args.push(ty.pat.clone()),
138-
}
139-
}
140-
141-
fn_list.push(quote! {
142-
#(#attrs)*
143-
#[inline]
144-
pub #sig {
145-
crate::__priv::call_interface!(#trait_name::#fn_name, #(#args),* )
146-
}
147-
});
148-
}
149-
}
150-
151-
quote! {
152-
#[crate::__priv::def_interface]
153-
#trait_ast
154-
155-
#(#fn_list)*
156-
}
157-
.into()
158-
}

axplat/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "axplat"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
description = "This crate provides a unified abstraction layer for diverse hardware platforms."
55
documentation = "https://docs.rs/axplat"
66
keywords = ["arceos", "os", "hal", "embedded"]
@@ -18,11 +18,11 @@ irq = ["dep:handler_table"]
1818
[dependencies]
1919
memory_addr = "0.4"
2020
bitflags = "2.6"
21-
crate_interface = "0.1"
21+
crate_interface = "0.3"
2222
handler_table = { version = "0.1.2", optional = true }
2323
const-str = "0.6.2"
24-
axplat-macros = { workspace = true }
2524
kspin = "0.1"
25+
axplat-macros = { workspace = true }
2626

2727
[package.metadata.docs.rs]
2828
all-features = true

axplat/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Crates.io](https://img.shields.io/crates/v/axplat)](https://crates.io/crates/axplat)
44
[![Docs.rs](https://docs.rs/axplat/badge.svg)](https://docs.rs/axplat)
5-
[![CI](https://github.com/arceos-org/axplat_crates/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/arceos-org/axplat_crates/actions/workflows/ci.yml)
5+
[![CI](https://github.com/arceos-org/axplat_crates/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/arceos-org/axplat_crates/actions/workflows/test.yml)
66

77
This crate provides a unified abstraction layer for diverse hardware platforms. It allows kernel developers to bootstrap custom kernels across various platforms and interact with essential peripherals using hardware-agnostic APIs.
88

@@ -48,12 +48,12 @@ More APIs can be found in the [documentation](https://docs.rs/axplat/latest/axpl
4848
#### 1. Implement each interface trait
4949

5050
```rust
51-
use axplat::impl_plat_interface;
51+
use axplat::impl_interface;
5252

5353
/// Implementation of Platform initialization.
5454
struct InitIfImpl;
5555

56-
#[impl_plat_interface]
56+
#[impl_interface]
5757
impl axplat::init::InitIf for InitIfImpl {
5858
fn init_early(cpu_id: usize, arg: usize) { /* ... */ }
5959
fn init_later(cpu_id: usize, arg: usize) { /* ... */ }
@@ -64,7 +64,7 @@ impl axplat::init::InitIf for InitIfImpl {
6464
/// Implementation of Console input and output.
6565
struct ConsoleIfImpl;
6666

67-
#[impl_plat_interface]
67+
#[impl_interface]
6868
impl axplat::console::ConsoleIf for ConsoleIfImpl {
6969
fn write_bytes(bytes: &[u8]) { /* ... */ }
7070
fn read_bytes(bytes: &mut [u8]) -> usize { /* ... */ 0 }

axplat/src/console.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use core::fmt::{Arguments, Result, Write};
44

55
/// Console input and output interface.
6-
#[def_plat_interface]
6+
#[def_interface(gen_caller)]
77
pub trait ConsoleIf {
88
/// Writes given bytes to the console.
99
fn write_bytes(bytes: &[u8]);

axplat/src/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Platform initialization.
22
33
/// Platform initialization interface.
4-
#[def_plat_interface]
4+
#[def_interface(gen_caller)]
55
pub trait InitIf {
66
/// Initializes the platform at the early stage for the primary core.
77
///

axplat/src/irq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub enum IpiTarget {
2727
}
2828

2929
/// IRQ management interface.
30-
#[def_plat_interface]
30+
#[def_interface(gen_caller)]
3131
pub trait IrqIf {
3232
/// Enables or disables the given IRQ.
3333
fn set_enable(irq: usize, enabled: bool);

axplat/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![doc = include_str!("../README.md")]
44

55
#[macro_use]
6-
extern crate axplat_macros;
6+
extern crate crate_interface;
77

88
pub mod console;
99
pub mod init;
@@ -14,15 +14,14 @@ pub mod power;
1414
pub mod time;
1515

1616
pub use axplat_macros::main;
17-
pub use crate_interface::impl_interface as impl_plat_interface;
17+
pub use crate_interface::impl_interface;
1818

1919
#[cfg(feature = "smp")]
2020
pub use axplat_macros::secondary_main;
2121

2222
#[doc(hidden)]
2323
pub mod __priv {
2424
pub use const_str::equal as const_str_eq;
25-
pub use crate_interface::{call_interface, def_interface};
2625
}
2726

2827
/// Checks that two strings are equal. If they are not equal, it will cause a compile-time

0 commit comments

Comments
 (0)