This repository has been archived by the owner. It is now read-only.

crystal-autobind

Automatic C bindings generator for Crystal

Autobind

DEPRECATED use https://github.com/crystal-lang/clang.cr instead.

This project duplicates the original one, which have fixes not backported here.

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.

Repository

crystal-autobind

Owner
Statistic
  • 14
  • 2
  • 0
  • 1
  • 0
  • about 5 years ago
  • June 7, 2018
License

Other

Links
Synced at

Mon, 25 Nov 2024 05:02:58 GMT

Languages