Skip to content

Commit

Permalink
First Commit!
Browse files Browse the repository at this point in the history
  • Loading branch information
edimetia3d committed Oct 19, 2023
0 parents commit ca9409e
Show file tree
Hide file tree
Showing 25 changed files with 33,047 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graft c_src
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# PyLibClang

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

It distinguishes itself from the official [clang python bindings](https://libclang.readthedocs.io/en/latest/) in the following ways:
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.
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.
3. It is exported from C++, thereby facilitating faster performance than the official binding.
4. It is directly accessible from PYPI.

## Installation

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

### From PYPI
```bash
pip install pylibclang
```

### From source

Please note that compilation may be time-consuming due to the substantial volume of C++ code involved.

```bash
git clone https://gihub.com/edimetia3d/pylibclang
cd pylibclang
pip install .
```

## Usage

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:

```python
import pylibclang._C as libclang
print(libclang.clang_getCString(libclang.clang_getClangVersion()))
```
20 changes: 20 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#/!/bin/bash
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
cd $SCRIPT_DIR

rm -rf ./wheelhouse
PLAT=manylinux_2_28_x86_64
DOCKER_IMAGE="quay.io/pypa/${PLAT}"
docker pull $DOCKER_IMAGE
docker run --rm -i -e PLAT=${PLAT} -v `pwd`:/io $DOCKER_IMAGE /io/build_wheels.sh
python3 -m pip install --upgrade build twine
python3 -m build -o ./wheelhouse --sdist

if [ "$1" = "upload" ];
then
python3 -m twine upload wheelhouse/*
else
echo Uploading ignored
fi


27 changes: 27 additions & 0 deletions build_wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
set -e -u -x

function repair_wheel {
wheel="$1"
if ! auditwheel show "$wheel"; then
echo "Skipping non-platform wheel $wheel"
else
auditwheel repair "$wheel" --plat "$PLAT" -w /io/wheelhouse/
fi
}

# Compile wheels
rm -rf /io/wheelhouse/*
mkdir -p /io/wheelhouse/
chmod 777 /io/wheelhouse
cp -r /io ~/src
rm -rf /opt/python/cp36*
for PYBIN in /opt/python/cp*/bin; do
"${PYBIN}/pip" install --upgrade build
"${PYBIN}/python" -m build ~/src -o ~/src/wheelhouse/ -w
done

# Bundle external shared libraries into the wheels
for whl in ~/src/wheelhouse/*.whl; do
repair_wheel "$whl"
done
Loading

0 comments on commit ca9409e

Please sign in to comment.