Generate an incoming C binding
Incoming FFI starts from an explicit ownership manifest. The generator never infers lifetime from a pointer or symbol name.
Minimal scalar manifest
{
"schemaVersion": 1,
"package": "fixture",
"header": "fixture.h",
"threadPolicy": "threadSafe",
"functions": [
{
"name": "Value",
"symbol": "fixture_value",
"parameters": [],
"result": "int32",
"convention": "direct"
}
]
}The corresponding C header contract is:
#include <stdint.h>
int32_t fixture_value(void);Generate the private package:
keika ffi generate \
--manifest ./scalar-ffi.json \
-o ./internal/fixtureThe command validates the complete JSON document and writes internal/fixture/generated_ffi.go. For this manifest, the generated Go API contains:
func Value() int32The documentation check runs this exact generation command and verifies the generated source is gofmt-formatted.
Integrate it safely
The header must be visible to cgo and the native symbol must be linked for a full application build. Keep generated bindings under internal/; expose a small application wrapper instead of leaking raw boundary details.
For strings, byte buffers, arrays, handles, callbacks, and status/out functions, declare ownership and release behavior in the manifest. See C ABI and FFI for lifetime and thread-policy rules.