This guide walks you through generating Rice (C++) bindings for a C++ library.
Create a file named rice-bindings.yaml:
project: my_extension
input: ./include
output: ./ext/generated
format: Rice
match:
- "**/*.hpp"
clang:
args:
- -I./include
- -std=c++17
- -xc++Key options:
project— name used for the extension init function (Init_MyExtension) and project wrapper filesinput— directory containing header filesoutput— where generated C++ files are writtenmatch— glob patterns selecting which headers to processclang.args— compiler arguments;-xc++tells clang to parse as C++,-std=c++17sets the language standard
Paths are relative to the config file's directory, not the working directory.
See Configuration for all options, including symbol filtering, export macros, name mappings, and version guards.
ruby-bindgen rice-bindings.yamlThis produces .cpp, .hpp, and optionally .ipp files for each matched header, plus project wrapper files. See Rice Output for details.
If you want ruby-bindgen to generate CMake build files, create a second config:
cmake-bindings.yaml:
project: my_extension
output: ./ext/generated
format: CMake
include_dirs:
- "${CMAKE_CURRENT_SOURCE_DIR}/../include"Then run it after the Rice generation:
ruby-bindgen cmake-bindings.yamlSee CMake Bindings for details.
cd ./ext/generated
cmake --preset linux-debug # or macos-debug, msvc-debug, etc.
cmake --build build/linux-debugFor packaging your extension as a gem, see the Rice Packaging documentation.
For a complete, fully automated example see BitmapPlusPlus-ruby.