Metadata-Version: 2.4
Name: clangir
Version: 0.3.2
Summary: C/C++ header parsing toolkit with IR, libclang backend, and CFFI writer
Project-URL: Homepage, https://github.com/axiomantic/clangir
Project-URL: Repository, https://github.com/axiomantic/clangir
Project-URL: Issues, https://github.com/axiomantic/clangir/issues
Project-URL: Changelog, https://github.com/axiomantic/clangir/blob/main/CHANGELOG.md
Author-email: elijahr <elijahr+cir@gmail.com>
License-Expression: MIT AND Apache-2.0 WITH LLVM-exception
License-File: LICENSE
License-File: clangir/_clang/LICENSE
Keywords: c,c++,cffi,code-generation,ir,libclang,parser
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: C
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Code Generators
Classifier: Topic :: Software Development :: Compilers
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: mike>=2.1; extra == 'dev'
Requires-Dist: mkdocs-material>=9.5; extra == 'dev'
Requires-Dist: mkdocs>=1.6; extra == 'dev'
Requires-Dist: mkdocstrings[python]>=0.27; extra == 'dev'
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-timeout; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mike>=2.1; extra == 'docs'
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
Requires-Dist: mkdocs>=1.6; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.27; extra == 'docs'
Provides-Extra: lint
Requires-Dist: mypy; extra == 'lint'
Requires-Dist: ruff; extra == 'lint'
Provides-Extra: test
Requires-Dist: pytest; extra == 'test'
Requires-Dist: pytest-timeout; extra == 'test'
Description-Content-Type: text/markdown

# clangir

[![CI](https://github.com/axiomantic/clangir/actions/workflows/ci.yml/badge.svg)](https://github.com/axiomantic/clangir/actions/workflows/ci.yml)
[![Docs](https://github.com/axiomantic/clangir/actions/workflows/docs.yml/badge.svg)](https://axiomantic.github.io/clangir/)
[![PyPI](https://img.shields.io/pypi/v/clangir)](https://pypi.org/project/clangir/)
[![Python](https://img.shields.io/pypi/pyversions/clangir)](https://pypi.org/project/clangir/)

C Intermediate Representation - a Python library for parsing C/C++ headers.

Full documentation: https://axiomantic.github.io/clangir/

Provides an IR data model for parsed C/C++ declarations, a libclang parser backend, and a CFFI cdef writer.

## Installation

Requires Python 3.10+.

```bash
pip install clangir
```

## System Requirements

libclang shared library must be installed:

- macOS: `brew install llvm` or Xcode Command Line Tools
- Ubuntu: `sudo apt install libclang-dev`
- Fedora: `sudo dnf install clang-devel`
- Windows: Download the [LLVM installer](https://github.com/llvm/llvm-project/releases) or `winget install LLVM.LLVM`

Supports LLVM 18, 19, 20, and 21. The appropriate version is detected automatically.

## Usage

```python
from clangir.backends import get_backend
from clangir.writers.cffi import header_to_cffi

backend = get_backend("libclang")
header = backend.parse('#include "mylib.h"', "wrapper.h", include_dirs=["/path/to/include"])
cdef = header_to_cffi(header)
print(cdef)
```

This produces CFFI-compatible C declarations that can be passed to `ffi.cdef()`:

```c
struct MyStruct {
    int field;
    ...
};
void my_function(int arg);
```

## Development

```bash
git clone https://github.com/axiomantic/clangir.git
cd clangir
pip install -e '.[dev]'
pytest
```

## License

This project is licensed under the [MIT License](LICENSE).

The vendored clang Python bindings in `clangir/_clang/v*/` are from the
[LLVM Project](https://llvm.org/) and are licensed under the
[Apache License v2.0 with LLVM Exceptions](clangir/_clang/LICENSE).
