C FFI & External Libraries
Interoperate safely with C libraries (such as SQLite or libcurl) using explicit linker flags, opaque handles, and std/resources scoped lifetimes.
Esta página aún no está disponible en tu idioma.
Because Wysna compiles directly to ANSI C99, integrating battle-tested native C libraries (such as SQLite, libcurl, or custom domain C adapters) is explicit, fast, and transparent — with zero hidden FFI magic.
1. Explicit Linking Flags
Section titled “1. Explicit Linking Flags”Both Seed and the Native SDK (v0.8.0) pass external C dependencies via explicit argument-vector flags (never shell fragments):
wysna build src/main.wysna \ --include-dir vendor/include \ --link vendor/sqlite_adapter.c \ --library-dir vendor/lib \ --library sqlite3 \ -o build/app| Flag | Purpose |
|---|---|
--include-dir <dir> |
Adds an existing header include directory |
--link <file.c|file.o> |
Compiles/links a specific C adapter source or object file |
--library-dir <dir> |
Adds a native library search path |
--library <name> |
Links a system or bundled library (e.g., sqlite3, curl) |
2. Safe Resource Lifetimes (opaque + std/resources)
Section titled “2. Safe Resource Lifetimes (opaque + std/resources)”Raw C pointers cross the boundary as opaque values. Wrap them immediately in std/resources.Resource so ownership, checked borrowing, and deterministic disposal are enforced cleanly:
import "std/resources"
# Acquire an opaque native handle with an explicit disposal callback# and guarantee cleanup via resources.scope(res, body)Key lifetime rules:
resources.acquire(handle, dispose)rejects duplicate ownership of the same handle.Resource.borrow()validates liveness and fails safely afterclose().resources.scope(resource, body)closes the handle afterbodyreturns either a value or anErr.- Note: panic/exit/hard process termination is not a language-level unwinding guarantee; release critical handles explicitly before process exit.
3. Effects & Trust Boundaries
Section titled “3. Effects & Trust Boundaries”External extern declarations outside the bundled stdlib/ directory are treated conservatively by wysna explain:
- Reported with effect
ffi.nativeandunknown(complete_within_model: false). - Static policy gates (
wysna run --allow/--deny) refuse untrusted external declarations with[W5006]. - Real-world SQLite C FFI examples live in
examples/wysofia-ops/andexamples/automation-sync/.