feat(sdk): rename attribute to #[chain_module], keep #[fai_module] alias
Some checks failed
CI / Linux x86_64 (Forgejo) (push) Failing after 2s
Some checks failed
CI / Linux x86_64 (Forgejo) (push) Failing after 2s
The public macro name was the last product-scoped 'fai' identifier in the SDK surface. #[chain_module] is now the primary attribute (README + examples updated); #[fai_module] stays as a delegating alias so modules written before the rename keep compiling. 0.2.1. Signed-off-by: flemming-it <sf@flemming.it>
This commit is contained in:
parent
40f3dbd885
commit
4b4de3374c
9 changed files with 33 additions and 19 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -43,7 +43,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chain-module-sdk"
|
name = "chain-module-sdk"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chain-module-sdk-macros",
|
"chain-module-sdk-macros",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
@ -55,7 +55,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chain-module-sdk-macros"
|
name = "chain-module-sdk-macros"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ members = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
authors = ["Dr. Stefan Flemming <chain@flemming.ai>"]
|
authors = ["Dr. Stefan Flemming <chain@flemming.ai>"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ A module written against this crate looks like:
|
||||||
```rust
|
```rust
|
||||||
use chain_module_sdk::prelude::*;
|
use chain_module_sdk::prelude::*;
|
||||||
|
|
||||||
#[fai_module]
|
#[chain_module]
|
||||||
fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
||||||
let text = inputs.require_text("input")?;
|
let text = inputs.require_text("input")?;
|
||||||
Ok(Outputs::new().with_text("output", format!("echo: {text}")))
|
Ok(Outputs::new().with_text("output", format!("echo: {text}")))
|
||||||
|
|
@ -16,7 +16,7 @@ fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
||||||
|
|
||||||
That single function — plus a `Cargo.toml` listing
|
That single function — plus a `Cargo.toml` listing
|
||||||
`chain-module-sdk` as a dependency — is the entire module. The
|
`chain-module-sdk` as a dependency — is the entire module. The
|
||||||
`#[fai_module]` macro generates the `wit_bindgen` invocation, the
|
`#[chain_module]` macro generates the `wit_bindgen` invocation, the
|
||||||
`Guest` implementation, the type conversions, and the
|
`Guest` implementation, the type conversions, and the
|
||||||
`wit_bindgen::export!` glue behind the scenes.
|
`wit_bindgen::export!` glue behind the scenes.
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ That single function — plus a `Cargo.toml` listing
|
||||||
| `Outputs::new().with_json(...)?` | building `Vec<(String, Payload)>` by hand |
|
| `Outputs::new().with_json(...)?` | building `Vec<(String, Payload)>` by hand |
|
||||||
| `ModuleError::invalid_input("...")` | constructing WIT `invocation-error` variants |
|
| `ModuleError::invalid_input("...")` | constructing WIT `invocation-error` variants |
|
||||||
| `ctx.emit("progress", ...)` | hand-rolling the `host.emit-event` import (WIT 1.1) |
|
| `ctx.emit("progress", ...)` | hand-rolling the `host.emit-event` import (WIT 1.1) |
|
||||||
| `#[fai_module]` | `wit_bindgen::generate!` + `Guest` impl + `export!` + `#![allow(unsafe_op_in_unsafe_fn)]` |
|
| `#[chain_module]` | `wit_bindgen::generate!` + `Guest` impl + `export!` + `#![allow(unsafe_op_in_unsafe_fn)]` |
|
||||||
|
|
||||||
## Stability
|
## Stability
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
//! Procedural macros powering `chain-module-sdk`.
|
//! Procedural macros powering `chain-module-sdk`.
|
||||||
//!
|
//!
|
||||||
//! This crate exists only to host the `#[fai_module]` attribute.
|
//! This crate exists only to host the `#[chain_module]` attribute
|
||||||
|
//! (and its legacy alias `#[fai_module]`).
|
||||||
//! Module authors should depend on `chain-module-sdk` (which
|
//! Module authors should depend on `chain-module-sdk` (which
|
||||||
//! re-exports the macro), not on this crate directly.
|
//! re-exports the macro), not on this crate directly.
|
||||||
|
|
||||||
|
|
@ -26,7 +27,19 @@ const WIT_INLINE: &str = include_str!("../../../wit/world.wit");
|
||||||
/// the `wit_bindgen::export!` call. The function can be named
|
/// the `wit_bindgen::export!` call. The function can be named
|
||||||
/// anything — only its signature matters.
|
/// anything — only its signature matters.
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
|
pub fn chain_module(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
|
expand_module(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Legacy alias for [`chain_module`], kept so modules written
|
||||||
|
/// before the product rename keep compiling. New code uses
|
||||||
|
/// `#[chain_module]`.
|
||||||
|
#[proc_macro_attribute]
|
||||||
pub fn fai_module(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
pub fn fai_module(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
|
expand_module(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn expand_module(input: TokenStream) -> TokenStream {
|
||||||
let user_fn = parse_macro_input!(input as ItemFn);
|
let user_fn = parse_macro_input!(input as ItemFn);
|
||||||
let user_fn_name = user_fn.sig.ident.clone();
|
let user_fn_name = user_fn.sig.ident.clone();
|
||||||
let wit_literal = WIT_INLINE;
|
let wit_literal = WIT_INLINE;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
//! ```ignore
|
//! ```ignore
|
||||||
//! use chain_module_sdk::prelude::*;
|
//! use chain_module_sdk::prelude::*;
|
||||||
//!
|
//!
|
||||||
//! #[fai_module]
|
//! #[chain_module]
|
||||||
//! fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
//! fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
||||||
//! let text = inputs.require_text("input")?;
|
//! let text = inputs.require_text("input")?;
|
||||||
//! Ok(Outputs::new().with_text("output", format!("got: {text}")))
|
//! Ok(Outputs::new().with_text("output", format!("got: {text}")))
|
||||||
|
|
@ -36,9 +36,9 @@ pub use inputs::Inputs;
|
||||||
pub use outputs::Outputs;
|
pub use outputs::Outputs;
|
||||||
pub use payload::{BytesValue, FileRef, Payload};
|
pub use payload::{BytesValue, FileRef, Payload};
|
||||||
|
|
||||||
pub use chain_module_sdk_macros::fai_module;
|
pub use chain_module_sdk_macros::{chain_module, fai_module};
|
||||||
|
|
||||||
// Emit-hook plumbing used by the `#[fai_module]` expansion (wasm32)
|
// Emit-hook plumbing used by the `#[chain_module]` expansion (wasm32)
|
||||||
// so `Context::emit` reaches the WIT `emit-event` host import.
|
// so `Context::emit` reaches the WIT `emit-event` host import.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use host::__set_emit_hook;
|
pub use host::__set_emit_hook;
|
||||||
|
|
@ -48,11 +48,12 @@ pub(crate) use host::emit;
|
||||||
/// every type a typical module needs into scope.
|
/// every type a typical module needs into scope.
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use super::{
|
pub use super::{
|
||||||
BytesValue, Context, FileRef, Inputs, ModuleError, Outputs, Payload, fai_module,
|
BytesValue, Context, FileRef, Inputs, ModuleError, Outputs, Payload, chain_module,
|
||||||
|
fai_module,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Internal re-exports the `#[fai_module]` macro expansion depends on.
|
/// Internal re-exports the `#[chain_module]` macro expansion depends on.
|
||||||
///
|
///
|
||||||
/// Not part of the public API. Anything in this module may change
|
/// Not part of the public API. Anything in this module may change
|
||||||
/// between SDK patch releases.
|
/// between SDK patch releases.
|
||||||
|
|
|
||||||
4
examples/echo/Cargo.lock
generated
4
examples/echo/Cargo.lock
generated
|
|
@ -34,7 +34,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chain-module-sdk"
|
name = "chain-module-sdk"
|
||||||
version = "0.1.2"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chain-module-sdk-macros",
|
"chain-module-sdk-macros",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
@ -45,7 +45,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chain-module-sdk-macros"
|
name = "chain-module-sdk-macros"
|
||||||
version = "0.1.2"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
//! Minimum-viable F∆I module — echoes the first text input.
|
//! Minimum-viable F∆I module — echoes the first text input.
|
||||||
//!
|
//!
|
||||||
//! Demonstrates the entire authoring surface: a single function
|
//! Demonstrates the entire authoring surface: a single function
|
||||||
//! decorated with `#[fai_module]`. No `wit_bindgen`, no
|
//! decorated with `#[chain_module]`. No `wit_bindgen`, no
|
||||||
//! `unsafe_op_in_unsafe_fn` allow, no `export!` call, no manual
|
//! `unsafe_op_in_unsafe_fn` allow, no `export!` call, no manual
|
||||||
//! Payload-variant matching.
|
//! Payload-variant matching.
|
||||||
|
|
||||||
use chain_module_sdk::prelude::*;
|
use chain_module_sdk::prelude::*;
|
||||||
|
|
||||||
#[fai_module]
|
#[chain_module]
|
||||||
fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
||||||
let text = inputs.require_text("input")?;
|
let text = inputs.require_text("input")?;
|
||||||
Ok(Outputs::new().with_text("output", format!("echo: {text}")))
|
Ok(Outputs::new().with_text("output", format!("echo: {text}")))
|
||||||
|
|
|
||||||
4
examples/progress/Cargo.lock
generated
4
examples/progress/Cargo.lock
generated
|
|
@ -34,7 +34,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chain-module-sdk"
|
name = "chain-module-sdk"
|
||||||
version = "0.1.2"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chain-module-sdk-macros",
|
"chain-module-sdk-macros",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
@ -45,7 +45,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chain-module-sdk-macros"
|
name = "chain-module-sdk-macros"
|
||||||
version = "0.1.2"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
use chain_module_sdk::prelude::*;
|
use chain_module_sdk::prelude::*;
|
||||||
|
|
||||||
#[fai_module]
|
#[chain_module]
|
||||||
fn invoke(ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
fn invoke(ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
||||||
let text = inputs.require_text("input")?;
|
let text = inputs.require_text("input")?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue