FFI::Clang
A light-weight wrapper for Ruby exposing libclang. This project is currently tested with Clang/libclang 18 and higher.
Installation
Add this line to your application's Gemfile:
gem 'ffi-clang'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ffi-clang
Usage
Please see the project documentation for more details.
Configuration
The following environment variables can be used to configure how ffi-clang finds libclang and its resources:
| Variable | Description |
|---|---|
LLVM_CONFIG |
Path to the llvm-config binary. Used to locate the libclang shared library and clang binary. |
LLVM_VERSION |
Target LLVM version (e.g., 17). When set, disables auto-detection of llvm-config. |
LIBCLANG |
Direct path to the libclang shared library (e.g., /usr/lib/libclang.so). Overrides llvm-config based library discovery. |
LIBCLANG_RESOURCE_DIR |
Path to the clang resource directory containing compiler-intrinsic headers (stddef.h, stdarg.h, etc.). Use this if libclang cannot find its own headers. |
For example, to use a specific LLVM installation:
LLVM_CONFIG=llvm-config-17 bundle exec bake test
Releases
Please see the project releases for all releases.
v0.15.0
v0.14.0
- Helper method that returns a cursor's
FFI::Clang::Cursor#qualified_display_name. - Add release notes and documentation tooling.
- Modernize code and achieve 100% documentation coverage.
- Update minimum Ruby version to 3.2.
v0.13.0
- Add support for
clang_Type_getNamedType. (#90) - Try clang v18 + add Ruby v3.4 to test matrix. (#91)
v0.12.0
- Prefer
LIBCLANGandLLVM_CONFIGoverrides over Xcode. (#88)
v0.11.0
- Restore
visit_childrenmethod. Fixes #82. (#84) - Expose Clang's exception specification API. (#87)
- Support iterating over
Type::Functionargs and exposeLib.get_non_reference_type. (#85) - Fix qualified name. (#83)
- Update clang version. (#86)
v0.10.0
- Expose libclang's anonymous methods. (#79)
- Use Enumerable. (#80)
- Split
FFI::Clang::Typeinto a number of more cohesive subclasses inheriting fromFFI::Clang::Types::Type. (#81)
v0.9.0
- Remove duplicate mapping of
clang_getEnumDeclIntegerType. (#67) - Update bitmask options based on enums to always be an array of symbols. (#69)
- Add support for
parse_translation_unit2API. (#70) - Cursor improvements, Type improvements, Printing support. (#72)
- Fix finalizer exception in
FFI::Clang::CodeCompletion::Results. (#74) - Fix Clang 16 compatibility. (#76)
- Cursor location methods. (#78)
v0.8.0
- Modernize gem. (#58)
- Test on clang 5.0+. (#59)
- Fix
CXCursor_TranslationUnitenum value to 350. (#61) - Add
Cursor#hashandCursor#eql?. (#62) - Set
cursor_translation_unitenum value based on the Clang version. (#64) - Add various C++ introspection methods. (#66)
v0.7.0
- Fix incorrect return type of
clang_getTranslationUnitSpelling. - Fix
compilation_database_spec. - Fix libclang lookup for Xcode.
- Fix warning on class re-definition.
- Update cursor kinds.
- Find
libclang.dllunder Windows. - Allow retrieval of list of references from a Cursor.
- Implement libclang
findReferencesInFilefunctionality. - Allow
TranslationUnit#fileto return the main file.
v0.6.0
- Add missing translation unit parse flags.
Contributing
We welcome contributions to this project.
- Fork it.
- Create your feature branch (
git checkout -b my-new-feature). - Commit your changes (
git commit -am 'Add some feature'). - Push to the branch (
git push origin my-new-feature). - Create new Pull Request.
Running Tests
To run the test suite:
bundle exec susMaking Releases
To make a new release:
bundle exec bake gem:release:patch # or minor or majorDeveloper Certificate of Origin
In order to protect users of this project, we require all contributors to comply with the Developer Certificate of Origin. This ensures that all contributions are properly licensed and attributed.
Community Guidelines
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.