Commit graph

4 commits

Author SHA1 Message Date
5fe32eac8d chore: rename repo + dir to fai_module_sdk_rust / module-sdk-rust
Some checks failed
CI / Linux x86_64 (Forgejo) (push) Failing after 2s
Adopts the three SDK families convention documented in
fai/platform/docs/architecture/sdks.md — `<base>-sdk-<lang>`
for repo and `fai_<base>_sdk_<lang>` for working directory.
Crate name `fai-module-sdk` stays as is.

Signed-off-by: flemming-it <sf@flemming.it>
2026-05-26 13:16:17 +02:00
f209fbc86f fix(workspace): drop the strict =0.1.0 pin on fai-module-sdk-macros
All checks were successful
CI / Linux x86_64 (Forgejo) (push) Successful in 1m33s
The previous commit (eb7a1d5) bumped the workspace version to
0.1.1 but kept the SDK's dep on the macros crate pinned at
exactly 0.1.0. Result: cargo refused to resolve a workspace
build because the path-resolved macros crate was 0.1.1 while
the dep required =0.1.0. The Cargo.lock from that commit
landed unchanged from the pre-bump state, masking the
breakage in CI artifacts but failing on a fresh build.

Drop the strict pin and use path-only resolution for now,
matching the convention used by tokio/tokio-macros and similar
workspace pairings. The two crates will still move in lockstep
because they share a workspace.package version line.

Bumps the workspace patch version 0.1.1 -> 0.1.2 per the
per-commit policy.

Signed-off-by: flemming-it <sf@flemming.it>
2026-05-01 14:58:35 +02:00
eb7a1d5d42 fix(macros): emit WASM glue only on target_arch = "wasm32"
Some checks failed
CI / Linux x86_64 (Forgejo) (push) Has been cancelled
The #[fai_module] expansion previously always inserted the
wit_bindgen::generate! call, the Guest impl, and the export!
macro. That is correct on the wasm32 target but causes host
compilation of a module crate to fail because wit_bindgen's
runtime types are not in scope on a non-wasm target.

The orchestrator-llm module worked around this with a manual
#[cfg(target_arch = "wasm32")] gate around its hand-written
wit_bindgen call. The point of the SDK is to remove that
boilerplate, so the gate now lives inside the macro itself.

Module crates can now declare crate-type = ["cdylib", "rlib"]
and run integration tests via `cargo test` against the
`invoke` function directly without having the WASM glue on
the host build.

Bumps the SDK patch version 0.1.0 -> 0.1.1 per the per-commit
policy.

Signed-off-by: flemming-it <sf@flemming.it>
2026-05-01 14:57:44 +02:00
d3642853ec feat: initial fai-module-sdk v0.1.0 with #[fai_module] macro
All checks were successful
CI / Linux x86_64 (Forgejo) (push) Successful in 1m41s
The SDK provides a stable, ergonomic Rust surface for writing
F∆I Platform modules. A module is now a single decorated
function:

    #[fai_module]
    fn invoke(_ctx: Context, inputs: Inputs)
        -> Result<Outputs, ModuleError>
    {
        let text = inputs.require_text("input")?;
        Ok(Outputs::new().with_text("output", format!("echo: {text}")))
    }

The macro absorbs every piece of WASM-module boilerplate that
previously lived per-repo: the wit_bindgen::generate! call, the
Guest trait impl, the WIT-to-SDK type conversions, the
wit_bindgen::export! glue, and the unsafe_op_in_unsafe_fn allow
attribute. Module repos depend only on fai-module-sdk and need
no wit/ directory of their own — the SDK ships a verified
mirror of the platform's frozen v1.0 WIT contract.

The SDK is the central lever for keeping the contract stable
without freezing module ergonomics. If the platform ever bumps
the WIT contract (additive minor or coordinated v2.0), the
change is absorbed inside the SDK; existing module source
keeps compiling against a new SDK release.

Components in this initial drop:

  crates/fai-module-sdk
      Public types — Context, Inputs, Outputs, Payload,
      ModuleError. Helpers like require_text / require_json /
      with_bytes / with_json. Pure Rust, no wit_bindgen
      dependency in user-facing code.

  crates/fai-module-sdk-macros
      The proc-macro crate that emits the wit_bindgen call,
      the Guest impl, the WIT<->SDK conversion code, and the
      export! invocation. Uses runtime_path to route the
      generated bindings through the SDK's re-export of
      wit_bindgen::rt so user crates need no direct dep.

  wit/world.wit
      Mirror of fai/platform :: wit/world.wit, frozen at v1.0.
      A snapshot test (crates/fai-module-sdk/tests/wit_freeze.rs)
      asserts the SHA-256 matches the platform constant; CI
      fails if the two ever drift.

  examples/echo
      Reference module that demonstrates the entire authoring
      surface. Compiles to wasm32-wasip2 with the correct
      v1.0 imports baked in (verified manually; CI runs the
      same build).

Tests: 7 unit tests + 1 snapshot test. Cargo fmt and clippy
clean across the workspace and the example.

Forgejo CI workflow mirrors the platform pattern (manual
external-URL checkout + libssl-dev system deps + wasm32-wasip2
target + workspace fmt/clippy/build/test + example wasm build).

Signed-off-by: flemming-it <sf@flemming.it>
2026-05-01 02:23:44 +02:00