docs / wrap

Wrapping C: host main + fx library

fx’s only FFI is the C ABI. That is intentional: wrap mature C, emit readable C, and let other languages reach fx output through their own C interop.

Two ownership patterns

Bundled demo

fx run examples/showcase_wrap/compute.fx --host examples/showcase_wrap/host.c

Expected exit code 42.

FileRole
examples/showcase_wrap/compute.fxfx functions (score, clamp01)
examples/showcase_wrap/host.cC main that calls into fx

Declaring C functions from fx

extern "c" {
    fn puts(s: string) -> i32;
    fn sha256_hex_equals(msg: string, expected: string) -> i32;
}

fx emits a prototype and expects the real symbol at link time. Provide the implementation via --host and/or --link-args-file / --link-lib / --link-dir.

Related flags

fx run lib.fx --host host.c
fx build lib.fx --host host.c -o out
fx run lib.fx --link-args-file link.args
fx emit-c lib.fx -o out_c

Full flag list: CLI.

Why this matters

Honesty bound