EN
Herramientas y ArquitecturaCompiler · ABI v3

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.


Both Seed and the Native SDK (v0.8.0) pass external C dependencies via explicit argument-vector flags (never shell fragments):

Terminal window
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 after close().
  • resources.scope(resource, body) closes the handle after body returns either a value or an Err.
  • Note: panic/exit/hard process termination is not a language-level unwinding guarantee; release critical handles explicitly before process exit.

External extern declarations outside the bundled stdlib/ directory are treated conservatively by wysna explain:

  • Reported with effect ffi.native and unknown (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/ and examples/automation-sync/.