Skip to content

Veski0/libclang-json-bindgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libclang JSON Binding Generator

This tool generates a JSON structure that represents a subset of C declarations from a provided C header file. It leverages clang's C Interface, which is discussed in detail here.

🔍 Note: The generated JSON is not a complete representation of the parsed header file. It does not contain all the information needed for a full reconstruction of the header file, but it captures the elements essential to automatically generating bindings to a C library.

If this is useful to you and you would like to add to it, please submit a PR.

Requirements

To use this tool, you need to have libclang-dev installed on your system. If you're using Ubuntu, you can install it with:

sudo apt update
sudo apt install libclang-dev

Build

To build the project, run:

make

Usage

To generate the JSON bindings from a C header file, use the something like:

./generate /path/to/header.h > bindings.json

Replace /path/to/header.h with the path to your C header file, and bindings.json with the file to which output should be redirected.

Basic Testing

The repository includes a simple test script written in JavaScript. This script reads the generated JSON file, parses it using JSON.parse, and then stringifies it using JSON.stringify. This process serves as a basic test to ensure the integrity of the JSON structure. You can run it with: bun check-json.ts bindings.json.

Troubleshooting

If you are not using llvm version 14, or if you encounter issues locating the correct headers, you can search for them using the following command: find /usr -name Index.h 2>/dev/null | grep clang-c Once you locate the headers, update the Makefile accordingly to ensure the build process can find the necessary files.

About

Generates a JSON structure that represents a subset of C declarations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors