Skip to content

ruby-rice/ruby-bindgen

Repository files navigation

ruby-bindgen

ruby-bindgen generates Ruby bindings from C and C++ header files. It can even generate a CMake build system if needed. It has been battle-tested against large C/C++ libraries such as Proj and OpenCV.

Traditionally, wrapping large C and C++ libraries for use in Ruby has been a long, arduous task, especially for large, complex libraries . As a result, many C/C++ libraries are either never exposed to Ruby or their bindings quickly become outdated, especially in scientific and technical domains.

For much more information, read the extensive documentation.

Quick Start

Create a config file (rice-bindings.yaml):

project: my_extension
input: ./include
output: ./ext/generated
format: Rice

match:
  - "**/*.hpp"

clang:
  args:
    - -I./include
    - -std=c++17
    - -xc++

Generate bindings:

ruby-bindgen rice-bindings.yaml

This produces .cpp, .hpp, and .ipp files ready to compile as a Ruby extension.

Relative paths (./include, ./ext/generated, -I./include) are resolved relative to the config file's directory, so you can run ruby-bindgen from anywhere.

Install

gem install ruby-bindgen

Requirements

  • Ruby 3.2+
  • libclang from LLVM/Clang 17 or newer

Documentation

Full documentation is at ruby-rice.github.io/ruby-bindgen.

Real-world bindings

These projects use ruby-bindgen to generate their Ruby bindings:

  • BitmapPlusPlus-ruby — C++ bitmap library, fully automated end-to-end example.
  • proj4rb — bindings for the PROJ cartographic projections C library.
  • opencv-ruby — bindings for OpenCV (thousands of classes, tens of thousands of methods).

License

BSD-2-Clause

About

Generate FFI and Rice bindings for C and C++ code

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors