Embed in C, Swift, or Kotlin
crates/dealbreaker-ffi exposes a small JSON-in/JSON-out C ABI with thread-safe cooperative cancellation—making it straightforward to embed Dealbreaker in C, C++, Swift (iOS/macOS), Kotlin/JNI (Android), Go, or Zig.
Build the Native Library
sh
cargo build --release -p dealbreaker-ffiThis produces target/release/libdealbreaker_ffi.{a,dylib,so,dll} alongside the header at crates/dealbreaker-ffi/include/dealbreaker.h.
Build an Apple XCFramework (iOS + macOS)
sh
./scripts/build-xcframework.shThis builds Dealbreaker.xcframework ready to drop into an Xcode project or Swift Package.
Minimal C Example
c
#include <stdio.h>
#include "dealbreaker.h"
int main(void) {
DealbreakerSolver *solver = dealbreaker_solver_from_preset("freecell");
char *state = dealbreaker_solver_deal_microsoft(solver, 1);
char *result = dealbreaker_solver_solve(solver, state, NULL, NULL);
printf("%s\n", result);
dealbreaker_string_free(result);
dealbreaker_string_free(state);
dealbreaker_solver_free(solver);
return 0;
}Thread Safety & Memory Ownership
DealbreakerSolveris thread-safe for concurrentsolve/hint/bestcalls once created.- Free returned
char *strings withdealbreaker_string_free—exceptdealbreaker_last_error(), which returns a thread-local pointer owned by Dealbreaker. - Cancel from another thread by passing a
DealbreakerCancel *tosolve/best/hintand callingdealbreaker_cancel_trigger()when needed.
See the auto-generated C ABI Reference for every function prototype.