Export a C ABI library
This recipe exports one fixed-width integer function and one floating-point function through explicit stable symbols.
Project tree
c-library/
└── library.kmSource
function add(left: int32, right: int32): int32 {
return left + right;
}
function scale(value: float64, factor: float64): float64 {
return value * factor;
}
export c("kinmokusei_add", "kinmokusei_scale") { add, scale };Generate artifacts
keika check library.km
keika emit-c-abi -o ./generated-c-abi library.kmGenerated tree:
generated-c-abi/
├── generated.go
├── generated_cabi.go
├── kinmokusei_abi.h
└── kinmokusei_abi.jsongenerated.go contains the ordinary Go implementations. generated_cabi.go contains panic-isolating cgo gateways. The header exposes explicit status/out signatures and KINMOKUSEI_ABI_* metadata constants, while the canonical JSON manifest supplies the ABI fingerprint. Exported example symbols use the lowercase kinmokusei_* prefix.
Check a later version
Keep the previous manifest and compare before publishing:
keika abi check --baseline ./previous/kinmokusei_abi.json library.kmAdding a symbol is compatible. Removing or renaming a symbol, changing parameter/result transport, or changing the gateway contract is reported as breaking.
Machine-width int/uint, strings, slices, maps, objects, classes, interfaces, pointers, channels, and errors are deliberately rejected from this stable outgoing boundary.
See C ABI and FFI for status codes, boolean normalization, ownership, incoming bindings, and thread policies.