marmot bind
Generate Go bindings from a C header.
Read a C header through clang and write a cgo file with idiomatic Go bindings. Functions get Go types: strings, byte slices, errors from status results, and out parameters as results. Opaque structs become handle types with methods and Close. Enums become typed constants with String, and #define constants become consts. The header's comments become doc comments. What bind cannot decide (who frees a returned pointer, unsupported types) is listed, to be settled in bind.toml. The output is plain cgo and builds with go too.
marmot bind HEADER [flags]Examples
marmot bind -o zlib.go zlib.h
marmot bind -config bind.toml -o sqlite3.go sqlite3.h
marmot bind -pkg-config libcurl -o curl.go curl/curl.hmarmot bind reads a C header through clang and writes one cgo file. The output is plain cgo, so
go build builds it too. See cgo for how marmot builds cgo packages.
Settle what bind cannot decide in bind.toml: who frees a returned pointer, prefixes, renames
and status codes. bind lists these points in its report.
Flags
Flags take one dash or two: -release and --release are the same.
| Flag | Meaning |
|---|---|
-config string | bind.toml with prefixes, renames, status codes and ownership (default: bind.toml beside the output, if any) |
-o string | write the Go file here (default: standard output) |
-pkg string | Go package name (default: from the header name) |
-pkg-config string | pkg-config name of the library: its cflags, and #cgo pkg-config in the output |
-report string | write the report (what was not bound and why) here too |
Full help
Read a C header through clang and write a cgo file with idiomatic Go bindings. Functions get Go types: strings, byte slices, errors from status results, and out parameters as results. Opaque structs become handle types with methods and Close. Enums become typed constants with String, and #define constants become consts. The header's comments become doc comments. What bind cannot decide (who frees a returned pointer, unsupported types) is listed, to be settled in bind.toml. The output is plain cgo and builds with go too.
Usage:
marmot bind HEADER [flags]
Examples:
marmot bind -o zlib.go zlib.h
marmot bind -config bind.toml -o sqlite3.go sqlite3.h
marmot bind -pkg-config libcurl -o curl.go curl/curl.h
Flags:
--config string bind.toml with prefixes, renames, status codes and ownership (default: bind.toml beside the output, if any)
-h, --help help for bind
--o string write the Go file here (default: standard output)
--pkg string Go package name (default: from the header name)
--pkg-config string pkg-config name of the library: its cflags, and #cgo pkg-config in the output
--report string write the report (what was not bound and why) here too