autobind

Automatic C binding generator libc bindings
0.5.1 Latest release released

Autobind

Apache2.0

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: ./gen-bindings.sh

You can create a gen-bindings.sh script, with the permissions chmod 750

#!/bin/sh

# Example of generating the bindings for `errno` at `src/libc/errno.cr`
mkdir -p src/libc && lib/autobind/bin/autobind -I/usr/include errno.h > src/libc/errno.cr

The postinstall script will only be runned when included as a dependency on a project.

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 clang/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

Distributed under the Apache 2.0 license.

autobind:
  github: j8r/crystal-autobind
  version: ~> 0.5.1
License Apache-2.0
Crystal none

Authors

Dependencies 1

  • clang 349a9185bc9a1756dd4c682c000764ec31a3b5da
    {'commit' => '349a9185bc9a1756dd4c682c000764ec31a3b5da', 'github' => 'ysbaddaden/clang.cr'}

Development Dependencies 0

Dependents 0

Last synced .
search fire star recently