autobind

Automatic C binding generator libc bindings
0.3.0 released

Autobind

ISC

Automatic C bindings generator for Crystal

Built from the awesome clang.cr done by ysbaddaden

How to use (recommended)

Installation

Add this block to your application's shard.yml:

dependencies:
  autobind:
    github: j8r/crystal-autobind

scripts:
  postinstall: mkdir -p src/libc && lib/autobind/bin/autobind -I/usr/include errno.h > src/libc/errno.cr

This latest command will generate the bindings for errno at src/libc/errno.cr

Usage

The newly generated .cr bindings can be used to create a documented shard wrapper, that can be then require and used as a shard in your application.

The development headers of the library are required whether the bindings are previously generated or not.

The only caveat is to have libclang installed to regenerate the bindings.

The bindings directory can thus be ignored in .gitignore to avoid versioning:

bin
lib
shard.lock
src/libc

Build

Ensure to have libclang installed

Install dependencies:

shards install

Build autobind:

crystal build src/autobind.cr

Usage examples

You will need the development headers of your targeted library, usually coming inside the dev packages of you distribution.

./autobind -I/usr/include errno.h > errno.cr

./autobind -I/usr/lib/llvm-6.0/include llvm-c/Core.h --remove-enum-prefix=LLVM --remove-enum-suffix > Core.cr

./autobind -I/usr/lib/llvm-6.0/include clang-c/Index.h --remove-enum-prefix > Index.cr

Reference

License

ISC License

autobind:
  github: j8r/crystal-autobind
  version: ~> 0.3.0
License ISC
Crystal none

Authors

Dependencies 1

  • clang
    {'github' => 'ysbaddaden/clang.cr'}

Development Dependencies 0

Dependents 0

Last synced .
search fire star recently