Skip to content

shenffi: C-ABI + safe CasEngine embedding API, macOS xcframework slice#6

Merged
pyrex41 merged 4 commits into
mainfrom
feat/swift-ffi-bindings
Jun 21, 2026
Merged

shenffi: C-ABI + safe CasEngine embedding API, macOS xcframework slice#6
pyrex41 merged 4 commits into
mainfrom
feat/swift-ffi-bindings

Conversation

@pyrex41

@pyrex41 pyrex41 commented Jun 21, 2026

Copy link
Copy Markdown
Owner

The engine-side support for embedding tree-shaken shen-cas in non-Rust and Rust hosts — used by the ShenCalc apps (SwiftUI for iOS/macOS, and the Rust/iced desktop app).

What

  • shenffi crate — a C-ABI surface over shen-rust (shen_boot/shen_eval/shen_cas_boot/shen_cas_reduce/shen_string_free), plus the embedded tree-shaken shen-cas slice (cas-kernel.kl + cas-all.kl). Builds as a static lib / xcframework for Swift, or as an rlib for Rust.
  • Safe CasEngine { boot, reduce } — an ergonomic Rust API over the same engine, so Rust hosts (the iced app) can embed the CAS without the C-ABI raw pointers.
  • build-xcframework.sh — builds ShenRust.xcframework with iOS device, iOS simulator, and macOS (aarch64-apple-darwin) slices, so the native macOS app can link the same engine.

Consumers

  • Swift apps link target/ShenRust.xcframework.
  • The iced app path-depends on this crate and uses CasEngine.

Verified end-to-end via the apps: the CAS reduces the full op set (D / Integrate / Factor / Solve / Expand / arithmetic) on iOS sim, native macOS, and the Rust binary.

Reuben Brooks and others added 4 commits June 20, 2026 00:07
New crate crates/shenffi (staticlib + cdylib) embedding shen-rust behind a
small C ABI so it links into Swift/iOS apps. The default shen-rust build has
no JIT, so nothing relies on runtime codegen (App Store-safe).

Surface:
- shen_boot / shen_boot_embedded (FS-free; kernel via include_str!) /
  shen_boot_shaken (any Ratatoskr-shaken kernel+program slice) /
  shen_eval / shen_string_free / shen_free.
- shen-cas embedded: a Ratatoskr-shaken computer algebra system (298 KB
  kernel slice + 221 KB CAS KL) with shen_cas_boot / shen_cas_reduce, e.g.
  "D[Sin[x],x]" -> "[Cos x]".

Also: Swift wrapper (swift/ShenRust.swift), C header (include/shenffi.h),
XCFramework build script, README. Verified the Swift->Rust->Shen round-trip
on macOS and cross-compilation for aarch64-apple-ios (device + simulator).

Workspace member added; Cargo.lock updated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Lets a native macOS app embed the same CAS. Unlike the iOS simulator,
MLX/Metal runs on Apple-silicon macOS, so the on-device model is
exercisable there.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A safe `CasEngine { boot, reduce }` over the existing private
boot_shaken_inner/cas_reduce helpers, so Rust hosts can embed the
tree-shaken shen-cas as an rlib without the C-ABI raw pointers (mirrors
shen_cas_boot / shen_cas_reduce).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The C-ABI export functions deref raw pointers but are deliberately not
`unsafe fn` (C callers can't express Rust unsafe; each documents its
pointer contract in a `# Safety` section). Opt out of the lint crate-wide
rather than change every export's signature, so `gates.sh` Gate 1
(fmt + clippy -D warnings) passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pyrex41
pyrex41 merged commit 09b03c3 into main Jun 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant