Skip to content

Export a C ABI library ​

This recipe exports one fixed-width integer function and one floating-point function through explicit stable symbols.

Project tree ​

text
c-library/
└── library.km

Source ​

ts
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 ​

sh
keika check library.km
keika emit-c-abi -o ./generated-c-abi library.km

Generated tree:

text
generated-c-abi/
├── generated.go
├── generated_cabi.go
├── kinmokusei_abi.h
└── kinmokusei_abi.json

generated.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:

sh
keika abi check --baseline ./previous/kinmokusei_abi.json library.km

Adding 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.

Kinmokusei is a pre-1.0 project. Documentation describes implemented behavior.