Compare commits
No commits in common. "main" and "v0.2.1" have entirely different histories.
13 changed files with 31 additions and 17 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.3.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.3.0"
|
version = "0.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ members = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.3.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"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
//! Procedural macros powering `chain-module-sdk`.
|
//! Procedural macros powering `chain-module-sdk`.
|
||||||
//!
|
//!
|
||||||
//! This crate exists only to host the `#[chain_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.
|
||||||
|
|
||||||
|
|
@ -27,6 +28,18 @@ const WIT_INLINE: &str = include_str!("../../../wit/world.wit");
|
||||||
/// 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 {
|
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 {
|
||||||
|
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;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
//! Invocation context passed to a module on every call.
|
//! Invocation context passed to a module on every call.
|
||||||
//!
|
//!
|
||||||
//! Mirrors the WIT `invocation-context` record. The
|
//! Mirrors the WIT `invocation-context` record. The
|
||||||
//! `#[chain_module]` macro builds this from the WIT-generated value
|
//! `#[fai_module]` macro builds this from the WIT-generated value
|
||||||
//! before handing it to user code.
|
//! before handing it to user code.
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
//! Host-callback plumbing for `Context::emit` (WIT 1.1 `emit-event`).
|
//! Host-callback plumbing for `Context::emit` (WIT 1.1 `emit-event`).
|
||||||
//!
|
//!
|
||||||
//! The WIT host imports (`emit-event`) are only reachable from the
|
//! The WIT host imports (`emit-event`) are only reachable from the
|
||||||
//! `wit_bindgen`-generated glue inside the `#[chain_module]` expansion,
|
//! `wit_bindgen`-generated glue inside the `#[fai_module]` expansion,
|
||||||
//! which lives in the module crate — not here. So the macro installs a
|
//! which lives in the module crate — not here. So the macro installs a
|
||||||
//! function pointer that reaches the real host import, and
|
//! function pointer that reaches the real host import, and
|
||||||
//! [`Context::emit`](crate::Context::emit) calls it through this hook.
|
//! [`Context::emit`](crate::Context::emit) calls it through this hook.
|
||||||
|
|
@ -18,7 +18,7 @@ thread_local! {
|
||||||
static EMIT_HOOK: Cell<Option<fn(&str, Payload)>> = const { Cell::new(None) };
|
static EMIT_HOOK: Cell<Option<fn(&str, Payload)>> = const { Cell::new(None) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Install the emit hook. Called by the `#[chain_module]` expansion at
|
/// Install the emit hook. Called by the `#[fai_module]` expansion at
|
||||||
/// the start of each invocation. Not part of the stable public API.
|
/// the start of each invocation. Not part of the stable public API.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn __set_emit_hook(f: fn(&str, Payload)) {
|
pub fn __set_emit_hook(f: fn(&str, Payload)) {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ pub struct Inputs {
|
||||||
|
|
||||||
impl Inputs {
|
impl Inputs {
|
||||||
/// Build directly from a list of `(name, payload)` pairs.
|
/// Build directly from a list of `(name, payload)` pairs.
|
||||||
/// Used by the `#[chain_module]` macro after WIT conversion.
|
/// Used by the `#[fai_module]` macro after WIT conversion.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn __from_pairs(items: Vec<(String, Payload)>) -> Self {
|
pub fn __from_pairs(items: Vec<(String, Payload)>) -> Self {
|
||||||
Self { items }
|
Self { items }
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ 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::chain_module;
|
pub use chain_module_sdk_macros::{chain_module, fai_module};
|
||||||
|
|
||||||
// Emit-hook plumbing used by the `#[chain_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.
|
||||||
|
|
@ -49,6 +49,7 @@ pub(crate) use host::emit;
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use super::{
|
pub use super::{
|
||||||
BytesValue, Context, FileRef, Inputs, ModuleError, Outputs, Payload, chain_module,
|
BytesValue, Context, FileRef, Inputs, ModuleError, Outputs, Payload, chain_module,
|
||||||
|
fai_module,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ impl Outputs {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consume the builder into the underlying `(name, payload)` list.
|
/// Consume the builder into the underlying `(name, payload)` list.
|
||||||
/// Used by the `#[chain_module]` macro after WIT conversion.
|
/// Used by the `#[fai_module]` macro after WIT conversion.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn __into_pairs(self) -> Vec<(String, Payload)> {
|
pub fn __into_pairs(self) -> Vec<(String, Payload)> {
|
||||||
self.items
|
self.items
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
//!
|
//!
|
||||||
//! The shape is fixed by the v1.0 WIT freeze. Field-by-field
|
//! The shape is fixed by the v1.0 WIT freeze. Field-by-field
|
||||||
//! conversion to and from the WIT-generated type happens inside
|
//! conversion to and from the WIT-generated type happens inside
|
||||||
//! the `#[chain_module]` macro expansion in the user crate.
|
//! the `#[fai_module]` macro expansion in the user crate.
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
|
|
||||||
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.2.1"
|
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.2.1"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
publish = false
|
publish = false
|
||||||
description = "Reference module showing the minimum needed to write a Ch∆In module with chain-module-sdk."
|
description = "Reference module showing the minimum needed to write an F∆I module with chain-module-sdk."
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
//! Minimum-viable Ch∆In 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 `#[chain_module]`. No `wit_bindgen`, no
|
//! decorated with `#[chain_module]`. No `wit_bindgen`, no
|
||||||
|
|
|
||||||
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.3.0"
|
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.3.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue