shenffi: C-ABI + safe CasEngine embedding API, macOS xcframework slice#6
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
shenfficrate — 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 anrlibfor Rust.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— buildsShenRust.xcframeworkwith iOS device, iOS simulator, and macOS (aarch64-apple-darwin) slices, so the native macOS app can link the same engine.Consumers
target/ShenRust.xcframework.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.