Skip to content

Commit 945af78

Browse files
committed
fix: update cindex.py to fit pylibclang
1 parent 745a707 commit 945af78

File tree

8 files changed

+1411
-2568
lines changed

8 files changed

+1411
-2568
lines changed

README.md

+43-7
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22

33
PyLibClang is a comprehensive Python binding for [libclang](https://clang.llvm.org/docs/LibClang.html).
44

5-
It distinguishes itself from the official [clang python bindings](https://libclang.readthedocs.io/en/latest/) in the following ways:
6-
1. It is a comprehensive binding, meaning it brings all libclang APIs into the Python environment. Conversely, the official binding only exposes a subset of the APIs.
7-
2. The binding is automatically generated from libclang header files using [pybind11-weaver](https://pypi.org/project/pybind11-weaver/), simplifying the process of remaining current with the latest libclang.
5+
It distinguishes itself from the official [clang python bindings](https://libclang.readthedocs.io/en/latest/) in the
6+
following ways:
7+
8+
1. It is a comprehensive binding, meaning it brings all libclang APIs into the Python environment. Conversely, the
9+
official binding only exposes a subset of the APIs.
10+
2. The binding is automatically generated from libclang header files
11+
using [pybind11-weaver](https://pypi.org/project/pybind11-weaver/), simplifying the process of remaining current with
12+
the latest libclang.
813
3. It is exported from C++, thereby facilitating faster performance than the official binding.
914
4. It is directly accessible from PYPI.
1015

1116
## Installation
1217

1318
At present, only Linux builds have been tested.
14-
Windows/MacOS users may need to install from source and potentially modify some compilation flags in `setup.py` to enable successful compilation.
19+
Windows/MacOS users may need to install from source and potentially modify some compilation flags in `setup.py` to
20+
enable successful compilation.
1521

1622
### From PYPI
23+
1724
```bash
1825
pip install pylibclang
1926
```
@@ -30,9 +37,38 @@ pip install .
3037

3138
## Usage
3239

33-
As no wrapper exists yet, the raw C API from the `pylibclang._C` module must be used directly, and every C-API is accessible from it. For instance, to obtain the version of libclang:
40+
### Regarding the Version Number
41+
42+
The version number adopts the format of `{pylibclang_ver}{clang_ver}`, wherein `pylibclang_ver` is an integer
43+
and `clang_ver` represents the version of the underlying libclang. For example, `9817.0.3` indicates that the version of
44+
pylibclang is `98`, and the version of libclang is `17.0.3`.
45+
46+
### Cindex
47+
48+
There is a `cindex.py`, ported from the official clang python
49+
bindings, [`cindex.py`](https://github.com/llvm/llvm-project/blob/main/clang/bindings/python/clang/cindex.py), which
50+
serves as a wrapper around the raw C API.
51+
52+
Though not thoroughly tested, it should suffice for most use cases and is recommended as the initial entry point to the
53+
library.
54+
55+
Should you encounter any issues, please report them on Github, or attempt to rectify them yourself and submit a pull
56+
request. Typically, there are two kinds of problems you might face:
57+
58+
1. Unresolved `cindex.py` code. In this case, updating the `cindex.py` may be necessary.
59+
2. Incompatible C-API call. For instance, a function might require an `int *` as both input and output, but `cindex.py`
60+
only passes an `int` as input. Owing to the constraints of Pybind11, this value will never be updated. In such cases,
61+
adding a new binding code in `c_src/binding.cpp`, rebuilding the project, and then calling it from `cindex.py` may be
62+
required.
63+
64+
### Raw C API
65+
66+
`pylibclang._C` is the pybind11 binding for all the C APIs in libclang. If anything is missing in `cindex.py`, the raw C
67+
API can always be directly utilized. For instance, `cindex.py` does not expose `clang_getClangVersion`, but you can
68+
still invoke it from `pylibclang._C`:
3469

3570
```python
36-
import pylibclang._C as libclang
37-
print(libclang.clang_getCString(libclang.clang_getClangVersion()))
71+
import pylibclang._C as C
72+
73+
print(C.clang_getCString(C.clang_getClangVersion()))
3874
```
File renamed without changes.

build.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
33
cd $SCRIPT_DIR
44

5-
rm -rf ./wheelhouse
65
PLAT=manylinux_2_28_x86_64
76
DOCKER_IMAGE="quay.io/pypa/${PLAT}"
87
docker pull $DOCKER_IMAGE
9-
docker run --rm -i -e PLAT=${PLAT} -v `pwd`:/io $DOCKER_IMAGE /io/build_wheels.sh
8+
docker run --rm -i -e PLAT=${PLAT} -v `pwd`:/io $DOCKER_IMAGE /io/_build_wheels.sh
109
python3 -m pip install --upgrade build twine
1110
python3 -m build -o ./wheelhouse --sdist
1211

0 commit comments

Comments
 (0)