├── .github ├── free-disk-space.sh ├── script-to-build-aarch64.sh ├── script-to-build-alpine.sh ├── script-to-build-manylinux2010.sh └── workflows │ ├── libclang-alpine-amd64.yml │ ├── libclang-linux-aarch64.yml │ ├── libclang-linux-amd64.yml │ ├── libclang-linux-arm.yml │ ├── libclang-macosx-amd64.yml │ ├── libclang-macosx-arm64.yml │ ├── libclang-windows-aarch64.yml │ └── libclang-windows-amd64.yml ├── .gitignore ├── LICENSE.TXT ├── README.md ├── docs ├── Makefile ├── conf.py └── index.rst ├── force_glibc_2_17.h ├── native └── .gitignore ├── python ├── README.txt ├── clang │ ├── __init__.py │ ├── cindex.py │ ├── enumerations.py │ └── native │ │ ├── .gitignore │ │ └── __init__.py └── examples │ └── cindex │ ├── cindex-dump.py │ └── cindex-includes.py ├── scripts ├── data │ └── clang_bindings.patch └── update_python_clang_bindings.sh ├── setup.cfg ├── setup.py └── setup_ext.py /.github/free-disk-space.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | # 19 | # The Azure provided machines typically have the following disk allocation: 20 | # Total space: 85GB 21 | # Allocated: 67 GB 22 | # Free: 17 GB 23 | # This script frees up 28 GB of disk space by deleting unneeded packages and 24 | # large directories. 25 | # The Flink end to end tests download and generate more than 17 GB of files, 26 | # causing unpredictable behavior and build failures. 27 | # 28 | echo "==============================================================================" 29 | echo "Freeing up disk space on CI system" 30 | echo "==============================================================================" 31 | 32 | echo "Listing 100 largest packages" 33 | dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -n 100 34 | df -h 35 | echo "Removing large packages" 36 | sudo apt-get remove -y '^ghc-8.*' 37 | sudo apt-get remove -y '^dotnet-.*' 38 | sudo apt-get remove -y '^llvm-.*' 39 | sudo apt-get remove -y 'php.*' 40 | sudo apt-get remove -y azure-cli google-cloud-sdk hhvm google-chrome-stable firefox powershell mono-devel 41 | sudo apt-get autoremove -y 42 | sudo apt-get clean 43 | df -h 44 | echo "Removing large directories" 45 | # deleting 15GB 46 | rm -rf /usr/share/dotnet/ 47 | sudo rm -rf /usr/share/dotnet 48 | sudo rm -rf /usr/local/lib/android 49 | sudo rm -rf /opt/ghc 50 | sudo rm -rf /opt/hostedtoolcache/CodeQL 51 | df -h 52 | -------------------------------------------------------------------------------- /.github/script-to-build-aarch64.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -x 4 | 5 | sudo docker run --privileged --network=host --rm -v `pwd`:/work quay.io/pypa/manylinux2014_aarch64:latest \ 6 | sh -c 'mkdir -p /work/build && \ 7 | cd /work/build && \ 8 | cmake ../llvm \ 9 | -DLLVM_ENABLE_PROJECTS=clang \ 10 | -DBUILD_SHARED_LIBS=OFF \ 11 | -DLLVM_ENABLE_ZLIB=OFF \ 12 | -DLLVM_ENABLE_ZSTD=OFF \ 13 | -DLLVM_ENABLE_TERMINFO=OFF \ 14 | -DLLVM_TARGETS_TO_BUILD=AArch64 \ 15 | -DCMAKE_BUILD_TYPE=RelWithDebInfo \ 16 | -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g -DNDEBUG -static-libgcc -static-libstdc++" && \ 17 | make libclang -j$(nproc) && \ 18 | aarch64-linux-gnu-strip lib/libclang.so' 19 | sudo chmod -R a+wr `pwd`/build 20 | -------------------------------------------------------------------------------- /.github/script-to-build-alpine.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -x 4 | 5 | sudo docker run --privileged --network=host --rm -v `pwd`:/work frolvlad/alpine-gxx \ 6 | sh -c 'apk add python3 cmake make && \ 7 | mkdir -p /work/build && \ 8 | cd /work/build && \ 9 | cmake ../llvm \ 10 | -DLLVM_ENABLE_PROJECTS=clang \ 11 | -DBUILD_SHARED_LIBS=OFF \ 12 | -DLLVM_ENABLE_ZLIB=OFF \ 13 | -DLLVM_ENABLE_ZSTD=OFF \ 14 | -DLLVM_ENABLE_TERMINFO=OFF \ 15 | -DLLVM_TARGETS_TO_BUILD=X86 \ 16 | -DCMAKE_BUILD_TYPE=RelWithDebInfo \ 17 | -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g -DNDEBUG -static-libgcc -static-libstdc++" && \ 18 | make libclang -j$(nproc) && \ 19 | strip lib/libclang.so' 20 | sudo chmod -R a+wr `pwd`/build 21 | -------------------------------------------------------------------------------- /.github/script-to-build-manylinux2010.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -x 4 | 5 | sudo docker run --privileged --network=host --rm -v `pwd`:/work quay.io/pypa/manylinux2010_x86_64:latest \ 6 | sh -c 'export PATH=$PATH:/opt/python/cp39-cp39/bin && \ 7 | mkdir -p /work/build && \ 8 | cd /work/build && \ 9 | cmake ../llvm \ 10 | -DLLVM_ENABLE_PROJECTS=clang \ 11 | -DBUILD_SHARED_LIBS=OFF \ 12 | -DLLVM_ENABLE_ZLIB=OFF \ 13 | -DLLVM_ENABLE_ZSTD=OFF \ 14 | -DLLVM_ENABLE_TERMINFO=OFF \ 15 | -DLLVM_TARGETS_TO_BUILD=X86 \ 16 | -DCMAKE_BUILD_TYPE=RelWithDebInfo \ 17 | -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g -DNDEBUG -static-libgcc -static-libstdc++" && \ 18 | make libclang -j$(nproc) && \ 19 | strip lib/libclang.so' 20 | sudo chmod -R a+wr `pwd`/build 21 | -------------------------------------------------------------------------------- /.github/workflows/libclang-alpine-amd64.yml: -------------------------------------------------------------------------------- 1 | name: libclang-alpine-amd64 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | LLVM_VER: 19.1.3 7 | 8 | concurrency: 9 | group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} 10 | cancel-in-progress: true 11 | 12 | jobs: 13 | build-and-deploy: 14 | if: "!contains(github.event.head_commit.message, 'skip ci')" 15 | runs-on: ubuntu-20.04 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: free disk spaces 19 | run: | 20 | ./.github/free-disk-space.sh || true 21 | - uses: actions/setup-python@v5 22 | with: 23 | python-version: '3.10' 24 | - name: install wheel dependencies 25 | run: | 26 | pip3 install wheel 27 | - name: get llvm-project 28 | run: | 29 | wget -q https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VER/llvm-project-$LLVM_VER.src.tar.xz 30 | tar xf llvm-project-$LLVM_VER.src.tar.xz 31 | mv llvm-project-$LLVM_VER.src llvm-project-$LLVM_VER 32 | - name: make build directory 33 | run: mkdir -p llvm-project-$LLVM_VER/build 34 | - name: pull docker 35 | run: | 36 | sudo docker pull frolvlad/alpine-gxx 37 | - name: cmake & build in docker 38 | run: | 39 | cp .github/script-to-build-alpine.sh ./llvm-project-$LLVM_VER/ 40 | cd llvm-project-$LLVM_VER 41 | bash ./script-to-build-alpine.sh 42 | - name: print dependencies 43 | run: | 44 | du -csh $(realpath llvm-project-$LLVM_VER/build/lib/libclang.so) 45 | file $(realpath llvm-project-$LLVM_VER/build/lib/libclang.so) 46 | - name: create and print sha512sum 47 | run: | 48 | cd llvm-project-$LLVM_VER/build/lib 49 | sha512sum libclang.so > libclang.so.$LLVM_VER.alpine-amd64.sha512sum 50 | echo "Checksum is: " 51 | cat libclang.so.$LLVM_VER.alpine-amd64.sha512sum 52 | tar zcvfh libclang.so.$LLVM_VER.alpine-amd64.tar.gz libclang.so libclang.so.$LLVM_VER.alpine-amd64.sha512sum 53 | shasum -a512 libclang.so.$LLVM_VER.alpine-amd64.tar.gz 54 | - uses: actions/upload-artifact@v4 55 | with: 56 | name: libclang.so.${{env.LLVM_VER}}.alpine-amd64.tar.gz 57 | path: llvm-project-${{env.LLVM_VER}}/build/lib/libclang.so.${{env.LLVM_VER}}.alpine-amd64.tar.gz 58 | - name: generate wheel package 59 | run: | 60 | cp llvm-project-$LLVM_VER/build/lib/libclang.so native/ 61 | python3 setup_ext.py bdist_wheel --universal --plat-name=musllinux_1_2_x86_64 62 | - uses: actions/upload-artifact@v4 63 | with: 64 | name: wheel-${{env.LLVM_VER}}-musllinux_1_2_x86_64 65 | path: dist/*.whl 66 | - name: Publish to PyPI 67 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') 68 | uses: pypa/gh-action-pypi-publish@release/v1 69 | with: 70 | packages_dir: dist/ 71 | password: ${{ secrets.PYPI_TOKEN }} 72 | verbose: true 73 | print_hash: true 74 | -------------------------------------------------------------------------------- /.github/workflows/libclang-linux-aarch64.yml: -------------------------------------------------------------------------------- 1 | name: libclang-linux-aarch64 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | LLVM_VER: 19.1.3 7 | 8 | concurrency: 9 | group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} 10 | cancel-in-progress: true 11 | 12 | jobs: 13 | build-and-deploy: 14 | if: "!contains(github.event.head_commit.message, 'skip ci')" 15 | runs-on: ubuntu-20.04 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: free disk spaces 19 | run: | 20 | ./.github/free-disk-space.sh || true 21 | - uses: actions/setup-python@v5 22 | with: 23 | python-version: '3.10' 24 | - name: install wheel dependencies 25 | run: | 26 | pip3 install wheel 27 | - name: get llvm-project 28 | run: | 29 | wget -q https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VER/llvm-project-$LLVM_VER.src.tar.xz 30 | tar xf llvm-project-$LLVM_VER.src.tar.xz 31 | mv llvm-project-$LLVM_VER.src llvm-project-$LLVM_VER 32 | - name: install cross compilation toolchain 33 | run: | 34 | sudo apt-get update 35 | sudo apt-get install -y \ 36 | binutils-aarch64-linux-gnu \ 37 | gcc-8 \ 38 | g++-8 \ 39 | gcc-8-aarch64-linux-gnu \ 40 | g++-8-aarch64-linux-gnu 41 | - name: build host llvmtblgen/clangtblgen 42 | run: | 43 | mkdir llvm-project-$LLVM_VER/build-host 44 | cd llvm-project-$LLVM_VER/build-host 45 | cmake ../llvm \ 46 | -DLLVM_ENABLE_PROJECTS=clang \ 47 | -DBUILD_SHARED_LIBS=OFF \ 48 | -DLLVM_ENABLE_ZLIB=OFF \ 49 | -DLLVM_ENABLE_ZSTD=OFF \ 50 | -DLLVM_ENABLE_TERMINFO=OFF \ 51 | -DLLVM_TARGETS_TO_BUILD=X86 \ 52 | -DCMAKE_BUILD_TYPE=RelWithDebInfo \ 53 | -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g -DNDEBUG -static-libgcc -static-libstdc++" \ 54 | -DCMAKE_C_COMPILER=gcc-8 \ 55 | -DCMAKE_CXX_COMPILER=g++-8 56 | make clang-tblgen llvm-tblgen -j$(nproc) 57 | 58 | # copy the artifacts to an absolute path 59 | sudo cp ./bin/* /usr/bin/ 60 | - name: make build directory 61 | run: mkdir -p llvm-project-$LLVM_VER/build 62 | - name: cmake 63 | run: | 64 | cd llvm-project-$LLVM_VER/build 65 | cmake ../llvm \ 66 | -DLLVM_ENABLE_PROJECTS=clang \ 67 | -DBUILD_SHARED_LIBS=OFF \ 68 | -DLLVM_ENABLE_ZLIB=OFF \ 69 | -DLLVM_ENABLE_ZSTD=OFF \ 70 | -DLLVM_ENABLE_TERMINFO=OFF \ 71 | -DCMAKE_SYSTEM_NAME=Linux \ 72 | -DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-linux-gnu \ 73 | -DLLVM_TARGET_ARCH=AArch64 \ 74 | -DLLVM_TARGETS_TO_BUILD=AArch64 \ 75 | -DLLVM_TABLEGEN=/usr/bin/llvm-tblgen \ 76 | -DCLANG_TABLEGEN=/usr/bin/clang-tblgen \ 77 | -DCMAKE_BUILD_TYPE=RelWithDebInfo \ 78 | -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g -DNDEBUG -static-libgcc -static-libstdc++" \ 79 | -DCMAKE_C_FLAGS="-include $(realpath ../../force_glibc_2_17.h)" \ 80 | -DCMAKE_CXX_FLAGS="-include $(realpath ../../force_glibc_2_17.h)" \ 81 | -DCMAKE_EXE_LINKER_FLAGS="-lm" \ 82 | -DCMAKE_SHARED_LINKER_FLAGS="-lm" \ 83 | -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc-8 \ 84 | -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++-8 85 | - name: build 86 | run: | 87 | cd llvm-project-$LLVM_VER/build 88 | make libclang -j$(nproc) 89 | aarch64-linux-gnu-strip lib/libclang.so 90 | - name: print dependencies 91 | run: | 92 | du -csh $(realpath llvm-project-$LLVM_VER/build/lib/libclang.so) 93 | file $(realpath llvm-project-$LLVM_VER/build/lib/libclang.so) 94 | strings llvm-project-$LLVM_VER/build/lib/libclang.so | grep GLIBC 95 | nm --dynamic --undefined-only --with-symbol-versions llvm-project-$LLVM_VER/build/lib/libclang.so 96 | - name: create and print sha512sum 97 | run: | 98 | cd llvm-project-$LLVM_VER/build/lib 99 | sha512sum libclang.so > libclang.so.$LLVM_VER.linux-aarch64.sha512sum 100 | echo "Checksum is: " 101 | cat libclang.so.$LLVM_VER.linux-aarch64.sha512sum 102 | tar zcvfh libclang.so.$LLVM_VER.linux-aarch64.tar.gz libclang.so libclang.so.$LLVM_VER.linux-aarch64.sha512sum 103 | shasum -a512 libclang.so.$LLVM_VER.linux-aarch64.tar.gz 104 | - uses: actions/upload-artifact@v4 105 | with: 106 | name: libclang.so.${{env.LLVM_VER}}.linux-aarch64.tar.gz 107 | path: llvm-project-${{env.LLVM_VER}}/build/lib/libclang.so.${{env.LLVM_VER}}.linux-aarch64.tar.gz 108 | - name: generate wheel package 109 | run: | 110 | cp llvm-project-$LLVM_VER/build/lib/libclang.so native/ 111 | python3 setup_ext.py bdist_wheel --universal --plat-name=manylinux2014_aarch64 112 | - uses: actions/upload-artifact@v4 113 | with: 114 | name: wheel-${{env.LLVM_VER}}-manylinux2014_aarch64 115 | path: dist/*.whl 116 | - name: Publish to PyPI 117 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') 118 | uses: pypa/gh-action-pypi-publish@release/v1 119 | with: 120 | packages_dir: dist/ 121 | password: ${{ secrets.PYPI_TOKEN }} 122 | verbose: true 123 | print_hash: true 124 | -------------------------------------------------------------------------------- /.github/workflows/libclang-linux-amd64.yml: -------------------------------------------------------------------------------- 1 | name: libclang-linux-amd64 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | LLVM_VER: 19.1.3 7 | 8 | concurrency: 9 | group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} 10 | cancel-in-progress: true 11 | 12 | jobs: 13 | build-and-deploy: 14 | if: "!contains(github.event.head_commit.message, 'skip ci')" 15 | runs-on: ubuntu-20.04 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: free disk spaces 19 | run: | 20 | ./.github/free-disk-space.sh || true 21 | - uses: actions/setup-python@v5 22 | with: 23 | python-version: '3.10' 24 | - name: install wheel dependencies 25 | run: | 26 | pip3 install wheel 27 | - name: get llvm-project 28 | run: | 29 | wget -q https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VER/llvm-project-$LLVM_VER.src.tar.xz 30 | tar xf llvm-project-$LLVM_VER.src.tar.xz 31 | mv llvm-project-$LLVM_VER.src llvm-project-$LLVM_VER 32 | - name: make build directory 33 | run: mkdir -p llvm-project-$LLVM_VER/build 34 | - name: pull docker 35 | run: | 36 | sudo docker pull quay.io/pypa/manylinux2010_x86_64:latest 37 | - name: cmake & build in docker 38 | run: | 39 | cp .github/script-to-build-manylinux2010.sh ./llvm-project-$LLVM_VER/ 40 | cd llvm-project-$LLVM_VER 41 | bash ./script-to-build-manylinux2010.sh 42 | - name: print dependencies 43 | run: | 44 | du -csh $(realpath llvm-project-$LLVM_VER/build/lib/libclang.so) 45 | file $(realpath llvm-project-$LLVM_VER/build/lib/libclang.so) 46 | ldd llvm-project-$LLVM_VER/build/lib/libclang.so 47 | strings llvm-project-$LLVM_VER/build/lib/libclang.so | grep GLIBC 48 | nm --dynamic --undefined-only --with-symbol-versions llvm-project-$LLVM_VER/build/lib/libclang.so 49 | - name: create and print sha512sum 50 | run: | 51 | cd llvm-project-$LLVM_VER/build/lib 52 | sha512sum libclang.so > libclang.so.$LLVM_VER.linux-amd64.sha512sum 53 | echo "Checksum is: " 54 | cat libclang.so.$LLVM_VER.linux-amd64.sha512sum 55 | tar zcvfh libclang.so.$LLVM_VER.linux-amd64.tar.gz libclang.so libclang.so.$LLVM_VER.linux-amd64.sha512sum 56 | shasum -a512 libclang.so.$LLVM_VER.linux-amd64.tar.gz 57 | - uses: actions/upload-artifact@v4 58 | with: 59 | name: libclang.so.${{env.LLVM_VER}}.linux-amd64.tar.gz 60 | path: llvm-project-${{env.LLVM_VER}}/build/lib/libclang.so.${{env.LLVM_VER}}.linux-amd64.tar.gz 61 | - name: generate wheel package 62 | run: | 63 | cp llvm-project-$LLVM_VER/build/lib/libclang.so native/ 64 | python3 setup_ext.py bdist_wheel --universal --plat-name=manylinux2010_x86_64 65 | - uses: actions/upload-artifact@v4 66 | with: 67 | name: wheel-${{env.LLVM_VER}}-manylinux2010_x86_64 68 | path: dist/*.whl 69 | - name: Publish to PyPI 70 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') 71 | uses: pypa/gh-action-pypi-publish@release/v1 72 | with: 73 | packages_dir: dist/ 74 | password: ${{ secrets.PYPI_TOKEN }} 75 | verbose: true 76 | print_hash: true 77 | 78 | build-and-deploy-sdist: 79 | if: "!contains(github.event.head_commit.message, 'skip ci')" 80 | runs-on: ubuntu-latest 81 | needs: [build-and-deploy] 82 | steps: 83 | - uses: actions/checkout@v4 84 | - uses: actions/setup-python@v5 85 | with: 86 | python-version: '3.10' 87 | - name: install wheel dependencies 88 | run: | 89 | pip3 install wheel 90 | - name: get llvm-project 91 | run: | 92 | wget -q https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VER/llvm-project-$LLVM_VER.src.tar.xz 93 | tar xf llvm-project-$LLVM_VER.src.tar.xz 94 | mv llvm-project-$LLVM_VER.src llvm-project-$LLVM_VER 95 | - name: generate wheel package 96 | run: | 97 | python3 setup.py sdist 98 | - uses: actions/upload-artifact@v4 99 | with: 100 | name: wheel-${{env.LLVM_VER}}-sdist 101 | path: dist/*.tar.gz 102 | - name: Publish to PyPI 103 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') 104 | uses: pypa/gh-action-pypi-publish@release/v1 105 | with: 106 | packages_dir: dist/ 107 | password: ${{ secrets.PYPI_TOKEN }} 108 | verbose: true 109 | print_hash: true 110 | -------------------------------------------------------------------------------- /.github/workflows/libclang-linux-arm.yml: -------------------------------------------------------------------------------- 1 | name: libclang-linux-arm 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | LLVM_VER: 19.1.3 7 | 8 | concurrency: 9 | group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} 10 | cancel-in-progress: true 11 | 12 | jobs: 13 | build-and-deploy: 14 | if: "!contains(github.event.head_commit.message, 'skip ci')" 15 | runs-on: ubuntu-20.04 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: free disk spaces 19 | run: | 20 | ./.github/free-disk-space.sh || true 21 | - uses: actions/setup-python@v5 22 | with: 23 | python-version: '3.10' 24 | - name: install wheel dependencies 25 | run: | 26 | pip3 install wheel 27 | - name: get llvm-project 28 | run: | 29 | wget -q https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VER/llvm-project-$LLVM_VER.src.tar.xz 30 | tar xf llvm-project-$LLVM_VER.src.tar.xz 31 | mv llvm-project-$LLVM_VER.src llvm-project-$LLVM_VER 32 | - name: install cross compilation toolchain 33 | run: | 34 | sudo apt-get update 35 | sudo apt-get install -y \ 36 | binutils-arm-linux-gnueabihf \ 37 | gcc-8 \ 38 | g++-8 \ 39 | gcc-8-arm-linux-gnueabihf \ 40 | g++-8-arm-linux-gnueabihf 41 | - name: build host llvmtblgen/clangtblgen 42 | run: | 43 | mkdir llvm-project-$LLVM_VER/build-host 44 | cd llvm-project-$LLVM_VER/build-host 45 | cmake ../llvm \ 46 | -DLLVM_ENABLE_PROJECTS=clang \ 47 | -DBUILD_SHARED_LIBS=OFF \ 48 | -DLLVM_ENABLE_ZLIB=OFF \ 49 | -DLLVM_ENABLE_ZSTD=OFF \ 50 | -DLLVM_ENABLE_TERMINFO=OFF \ 51 | -DLLVM_TARGETS_TO_BUILD=X86 \ 52 | -DCMAKE_BUILD_TYPE=RelWithDebInfo \ 53 | -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g -DNDEBUG -static-libgcc -static-libstdc++" \ 54 | -DCMAKE_C_COMPILER=gcc-8 \ 55 | -DCMAKE_CXX_COMPILER=g++-8 56 | make clang-tblgen llvm-tblgen -j$(nproc) 57 | 58 | # copy the artifacts to an absolute path 59 | sudo cp ./bin/* /usr/bin/ 60 | - name: make build directory 61 | run: mkdir -p llvm-project-$LLVM_VER/build 62 | - name: cmake 63 | run: | 64 | cd llvm-project-$LLVM_VER/build 65 | cmake ../llvm \ 66 | -DLLVM_ENABLE_PROJECTS=clang \ 67 | -DBUILD_SHARED_LIBS=OFF \ 68 | -DLLVM_ENABLE_ZLIB=OFF \ 69 | -DLLVM_ENABLE_ZSTD=OFF \ 70 | -DLLVM_ENABLE_TERMINFO=OFF \ 71 | -DCMAKE_SYSTEM_NAME=Linux \ 72 | -DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf \ 73 | -DLLVM_TARGET_ARCH=ARM \ 74 | -DLLVM_TARGETS_TO_BUILD=ARM \ 75 | -DLLVM_TABLEGEN=/usr/bin/llvm-tblgen \ 76 | -DCLANG_TABLEGEN=/usr/bin/clang-tblgen \ 77 | -DCMAKE_BUILD_TYPE=RelWithDebInfo \ 78 | -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g -DNDEBUG -static-libgcc -static-libstdc++" \ 79 | -DCMAKE_C_FLAGS="-march=armv7 -include $(realpath ../../force_glibc_2_17.h)" \ 80 | -DCMAKE_CXX_FLAGS="-march=armv7 -include $(realpath ../../force_glibc_2_17.h)" \ 81 | -DCMAKE_EXE_LINKER_FLAGS="-lm" \ 82 | -DCMAKE_SHARED_LINKER_FLAGS="-lm" \ 83 | -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc-8 \ 84 | -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++-8 85 | - name: build 86 | run: | 87 | cd llvm-project-$LLVM_VER/build 88 | make libclang -j$(nproc) 89 | arm-linux-gnueabihf-strip lib/libclang.so 90 | - name: print dependencies 91 | run: | 92 | du -csh $(realpath llvm-project-$LLVM_VER/build/lib/libclang.so) 93 | file $(realpath llvm-project-$LLVM_VER/build/lib/libclang.so) 94 | strings llvm-project-$LLVM_VER/build/lib/libclang.so | grep GLIBC 95 | nm --dynamic --undefined-only --with-symbol-versions llvm-project-$LLVM_VER/build/lib/libclang.so 96 | - name: create and print sha512sum 97 | run: | 98 | cd llvm-project-$LLVM_VER/build/lib 99 | sha512sum libclang.so > libclang.so.$LLVM_VER.linux-arm.sha512sum 100 | echo "Checksum is: " 101 | cat libclang.so.$LLVM_VER.linux-arm.sha512sum 102 | tar zcvfh libclang.so.$LLVM_VER.linux-arm.tar.gz libclang.so libclang.so.$LLVM_VER.linux-arm.sha512sum 103 | shasum -a512 libclang.so.$LLVM_VER.linux-arm.tar.gz 104 | - uses: actions/upload-artifact@v4 105 | with: 106 | name: libclang.so.${{env.LLVM_VER}}.linux-arm.tar.gz 107 | path: llvm-project-${{env.LLVM_VER}}/build/lib/libclang.so.${{env.LLVM_VER}}.linux-arm.tar.gz 108 | - name: generate wheel package 109 | run: | 110 | cp llvm-project-$LLVM_VER/build/lib/libclang.so native/ 111 | python3 setup_ext.py bdist_wheel --universal --plat-name=manylinux2014_armv7l 112 | - uses: actions/upload-artifact@v4 113 | with: 114 | name: wheel-${{env.LLVM_VER}}-manylinux2014_armv7l 115 | path: dist/*.whl 116 | - name: Publish to PyPI 117 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') 118 | uses: pypa/gh-action-pypi-publish@release/v1 119 | with: 120 | packages_dir: dist/ 121 | password: ${{ secrets.PYPI_TOKEN }} 122 | verbose: true 123 | print_hash: true 124 | -------------------------------------------------------------------------------- /.github/workflows/libclang-macosx-amd64.yml: -------------------------------------------------------------------------------- 1 | name: libclang-macosx-amd64 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | LLVM_VER: 19.1.3 7 | MACOSX_DEPLOYMENT_TARGET: "10.9" 8 | 9 | concurrency: 10 | group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} 11 | cancel-in-progress: true 12 | 13 | jobs: 14 | build-and-deploy: 15 | if: "!contains(github.event.head_commit.message, 'skip ci')" 16 | runs-on: macos-11 17 | steps: 18 | - uses: actions/checkout@v4 19 | - uses: actions/setup-python@v5 20 | with: 21 | python-version: '3.10' 22 | - name: install wheel dependencies 23 | run: | 24 | pip3 install wheel 25 | - name: install gnu-tar 26 | run: | 27 | brew install gnu-tar 28 | - name: get llvm-project 29 | run: | 30 | wget -q https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VER/llvm-project-$LLVM_VER.src.tar.xz 31 | tar xf llvm-project-$LLVM_VER.src.tar.xz 32 | mv llvm-project-$LLVM_VER.src llvm-project-$LLVM_VER 33 | - name: make build directory 34 | run: mkdir -p llvm-project-$LLVM_VER/build 35 | - name: cmake 36 | run: | 37 | cd llvm-project-$LLVM_VER/build 38 | cmake ../llvm \ 39 | -DLLVM_ENABLE_PROJECTS=clang \ 40 | -DBUILD_SHARED_LIBS=OFF \ 41 | -DLLVM_ENABLE_ZLIB=OFF \ 42 | -DLLVM_ENABLE_ZSTD=OFF \ 43 | -DLLVM_ENABLE_TERMINFO=OFF \ 44 | -DLLVM_TARGETS_TO_BUILD=X86 \ 45 | -DCMAKE_BUILD_TYPE=RelWithDebInfo \ 46 | -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g -DNDEBUG -static-libgcc -static-libstdc++" \ 47 | -DCMAKE_C_COMPILER=gcc-10 \ 48 | -DCMAKE_CXX_COMPILER=g++-10 \ 49 | -DCMAKE_OSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET 50 | - name: build 51 | run: cd llvm-project-$LLVM_VER/build && make libclang -j$(sysctl -n hw.ncpu) 52 | - name: print dependencies 53 | run: | 54 | du -csh llvm-project-$LLVM_VER/build/lib/libclang.dylib 55 | file llvm-project-$LLVM_VER/build/lib/libclang.dylib 56 | otool -L llvm-project-$LLVM_VER/build/lib/libclang.dylib 57 | dyldinfo -platform -dependents libclang.dylib || true 58 | - name: create and print sha512sum 59 | run: | 60 | cd llvm-project-$LLVM_VER/build/lib 61 | shasum -a512 libclang.dylib > libclang.dylib.$LLVM_VER.macosx-amd64.sha512sum 62 | echo "Checksum is: " 63 | cat libclang.dylib.$LLVM_VER.macosx-amd64.sha512sum 64 | gtar zcvf libclang.dylib.$LLVM_VER.macosx-amd64.tar.gz libclang.dylib libclang.dylib.$LLVM_VER.macosx-amd64.sha512sum 65 | shasum -a512 libclang.dylib.$LLVM_VER.macosx-amd64.tar.gz 66 | - uses: actions/upload-artifact@v4 67 | with: 68 | name: libclang.dylib.${{env.LLVM_VER}}.macosx-amd64.tar.gz 69 | path: llvm-project-${{env.LLVM_VER}}/build/lib/libclang.dylib.${{env.LLVM_VER}}.macosx-amd64.tar.gz 70 | - name: generate wheel package 71 | run: | 72 | cp llvm-project-$LLVM_VER/build/lib/libclang.dylib native/ 73 | python3 setup_ext.py bdist_wheel --universal --plat-name=macosx_10_9_x86_64 74 | - uses: actions/upload-artifact@v4 75 | with: 76 | name: wheel-${{env.LLVM_VER}}-macosx_10_9_x86_64 77 | path: dist/*.whl 78 | 79 | upload-to-pypi: 80 | runs-on: ubuntu-latest 81 | needs: [build-and-deploy] 82 | steps: 83 | - uses: actions/download-artifact@v4 84 | with: 85 | name: wheel-${{env.LLVM_VER}}-macosx_10_9_x86_64 86 | path: dist/ 87 | - name: Publish to PyPI 88 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') 89 | uses: pypa/gh-action-pypi-publish@release/v1 90 | with: 91 | packages_dir: dist/ 92 | password: ${{ secrets.PYPI_TOKEN }} 93 | verbose: true 94 | print_hash: true 95 | -------------------------------------------------------------------------------- /.github/workflows/libclang-macosx-arm64.yml: -------------------------------------------------------------------------------- 1 | name: libclang-macosx-arm64 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | LLVM_VER: 19.1.3 7 | MACOSX_DEPLOYMENT_TARGET: "10.15" 8 | 9 | concurrency: 10 | group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} 11 | cancel-in-progress: true 12 | 13 | jobs: 14 | build-and-deploy: 15 | if: "!contains(github.event.head_commit.message, 'skip ci')" 16 | runs-on: macos-14 17 | steps: 18 | - uses: actions/checkout@v4 19 | - uses: actions/setup-python@v5 20 | with: 21 | python-version: '3.10' 22 | - name: install wheel dependencies 23 | run: | 24 | pip3 install wheel 25 | - name: install gnu-tar 26 | run: | 27 | brew install gnu-tar 28 | - name: install gcc@11 29 | run: | 30 | brew install gcc@11 31 | - name: get llvm-project 32 | run: | 33 | wget -q https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VER/llvm-project-$LLVM_VER.src.tar.xz 34 | tar xf llvm-project-$LLVM_VER.src.tar.xz 35 | mv llvm-project-$LLVM_VER.src llvm-project-$LLVM_VER 36 | - name: make build directory 37 | run: mkdir -p llvm-project-$LLVM_VER/build 38 | - name: cmake 39 | run: | 40 | cd llvm-project-$LLVM_VER/build 41 | cmake ../llvm \ 42 | -DLLVM_ENABLE_PROJECTS=clang \ 43 | -DBUILD_SHARED_LIBS=OFF \ 44 | -DLLVM_ENABLE_ZLIB=OFF \ 45 | -DLLVM_ENABLE_ZSTD=OFF \ 46 | -DLLVM_ENABLE_TERMINFO=OFF \ 47 | -DLLVM_TARGETS_TO_BUILD=AArch64 \ 48 | -DCMAKE_BUILD_TYPE=RelWithDebInfo \ 49 | -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g -DNDEBUG -static-libgcc -static-libstdc++" \ 50 | -DCMAKE_C_COMPILER=$(brew --prefix gcc@11)/bin/gcc-11 \ 51 | -DCMAKE_CXX_COMPILER=$(brew --prefix gcc@11)/bin/g++-11 \ 52 | -DCMAKE_OSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET 53 | - name: build 54 | run: cd llvm-project-$LLVM_VER/build && make libclang -j$(sysctl -n hw.ncpu) 55 | - name: print dependencies 56 | run: | 57 | du -csh llvm-project-$LLVM_VER/build/lib/libclang.dylib 58 | file llvm-project-$LLVM_VER/build/lib/libclang.dylib 59 | otool -L llvm-project-$LLVM_VER/build/lib/libclang.dylib 60 | dyldinfo -platform -dependents libclang.dylib || true 61 | - name: create and print sha512sum 62 | run: | 63 | cd llvm-project-$LLVM_VER/build/lib 64 | shasum -a512 libclang.dylib > libclang.dylib.$LLVM_VER.macosx-arm64.sha512sum 65 | echo "Checksum is: " 66 | cat libclang.dylib.$LLVM_VER.macosx-arm64.sha512sum 67 | gtar zcvf libclang.dylib.$LLVM_VER.macosx-arm64.tar.gz libclang.dylib libclang.dylib.$LLVM_VER.macosx-arm64.sha512sum 68 | shasum -a512 libclang.dylib.$LLVM_VER.macosx-arm64.tar.gz 69 | - uses: actions/upload-artifact@v4 70 | with: 71 | name: libclang.dylib.${{env.LLVM_VER}}.macosx-arm64.tar.gz 72 | path: llvm-project-${{env.LLVM_VER}}/build/lib/libclang.dylib.${{env.LLVM_VER}}.macosx-arm64.tar.gz 73 | - name: generate wheel package 74 | run: | 75 | cp llvm-project-$LLVM_VER/build/lib/libclang.dylib native/ 76 | python3 setup_ext.py bdist_wheel --universal --plat-name=macosx_11_0_arm64 77 | - uses: actions/upload-artifact@v4 78 | with: 79 | name: wheel-${{env.LLVM_VER}}-macosx_11_0_arm64 80 | path: dist/*.whl 81 | 82 | upload-to-pypi: 83 | runs-on: ubuntu-latest 84 | needs: [build-and-deploy] 85 | steps: 86 | - uses: actions/download-artifact@v4 87 | with: 88 | name: wheel-${{env.LLVM_VER}}-macosx_11_0_arm64 89 | path: dist/ 90 | - name: Publish to PyPI 91 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') 92 | uses: pypa/gh-action-pypi-publish@release/v1 93 | with: 94 | packages_dir: dist/ 95 | password: ${{ secrets.PYPI_TOKEN }} 96 | verbose: true 97 | print_hash: true 98 | -------------------------------------------------------------------------------- /.github/workflows/libclang-windows-aarch64.yml: -------------------------------------------------------------------------------- 1 | name: libclang-windows-aarch64 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | LLVM_VER: 19.1.3 7 | 8 | concurrency: 9 | group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} 10 | cancel-in-progress: true 11 | 12 | jobs: 13 | build-and-deploy: 14 | if: "!contains(github.event.head_commit.message, 'skip ci')" 15 | runs-on: windows-latest 16 | steps: 17 | - uses: actions/checkout@v4 18 | - uses: actions/setup-python@v5 19 | with: 20 | python-version: '3.10' 21 | - name: install wheel dependencies 22 | run: | 23 | pip3 install wheel 24 | - name: get llvm-project 25 | run: | 26 | choco install wget git 27 | git clone https://github.com/llvm/llvm-project.git llvm-project-$env:LLVM_VER -b llvmorg-$env:LLVM_VER --depth=1 28 | - name: build host llvm-tblgen/clang-tblgen 29 | run: | 30 | mkdir llvm-project-$env:LLVM_VER/build-host 31 | cd llvm-project-$env:LLVM_VER/build-host 32 | cmake ../llvm ` 33 | -Thost=x64 ` 34 | -DLLVM_ENABLE_PROJECTS=clang ` 35 | -DBUILD_SHARED_LIBS=OFF ` 36 | -DLLVM_ENABLE_ZLIB=OFF ` 37 | -DLLVM_ENABLE_ZSTD=OFF ` 38 | -DLLVM_ENABLE_TERMINFO=OFF ` 39 | -DLLVM_TARGETS_TO_BUILD=X86 ` 40 | -DCMAKE_BUILD_TYPE=RelWithDebInfo ` 41 | -DCMAKE_CXX_FLAGS="/MP" ` 42 | -DLLVM_USE_CRT_MINSIZEREL="MT" 43 | cmake --build . --config RelWithDebInfo --target clang-tblgen 44 | cmake --build . --config RelWithDebInfo --target llvm-tblgen 45 | cd RelWithDebInfo 46 | mkdir C:\llvm 47 | cp bin\clang-tblgen.exe C:\llvm 48 | cp bin\llvm-tblgen.exe C:\llvm 49 | - name: cmake 50 | run: | 51 | mkdir -p llvm-project-$env:LLVM_VER/build 52 | cd llvm-project-$env:LLVM_VER/build 53 | cmake ../llvm ` 54 | -A ARM64 ` 55 | -Thost=x64 ` 56 | -DCMAKE_SYSTEM_NAME=Windows ` 57 | -DLLVM_ENABLE_PROJECTS=clang ` 58 | -DBUILD_SHARED_LIBS=OFF ` 59 | -DLLVM_ENABLE_ZLIB=OFF ` 60 | -DLLVM_ENABLE_ZSTD=OFF ` 61 | -DLLVM_ENABLE_TERMINFO=OFF ` 62 | -DLLVM_TARGETS_TO_BUILD=AArch64 ` 63 | -DLLVM_TABLEGEN=C:\llvm\llvm-tblgen.exe ` 64 | -DCLANG_TABLEGEN=C:\llvm\clang-tblgen.exe ` 65 | -DCMAKE_CXX_FLAGS="/MP" ` 66 | -DLLVM_USE_CRT_MINSIZEREL="MT" 67 | - name: build 68 | run: cd llvm-project-$env:LLVM_VER/build && cmake --build . --config RelWithDebInfo --target libclang 69 | - name: create and print sha512sum 70 | run: | 71 | $env:Path = "C:\Program Files\Git\usr\bin;$env:Path" 72 | cd llvm-project-$env:LLVM_VER\build\RelWithDebInfo\bin 73 | sha512sum.exe libclang.dll > libclang.dll.$env:LLVM_VER.windows-aarch64.sha512sum 74 | echo "Checksum is: " 75 | Get-Content -Path libclang.dll.$env:LLVM_VER.windows-aarch64.sha512sum 76 | tar zcvf libclang.dll.$env:LLVM_VER.windows-aarch64.tar.gz libclang.dll libclang.dll.$env:LLVM_VER.windows-aarch64.sha512sum 77 | sha512sum.exe libclang.dll.$env:LLVM_VER.windows-aarch64.tar.gz 78 | - uses: actions/upload-artifact@v4 79 | with: 80 | name: libclang.dll.${{env.LLVM_VER}}.windows-aarch64.tar.gz 81 | path: llvm-project-${{env.LLVM_VER}}\build\RelWithDebInfo\bin\libclang.dll.${{env.LLVM_VER}}.windows-aarch64.tar.gz 82 | - name: generate wheel package 83 | run: | 84 | cp llvm-project-${{env.LLVM_VER}}\build\RelWithDebInfo\bin\libclang.dll native/ 85 | python3 setup_ext.py bdist_wheel --universal --plat-name=win_arm64 86 | - uses: actions/upload-artifact@v4 87 | with: 88 | name: wheel-${{env.LLVM_VER}}-win_arm64 89 | path: dist/*.whl 90 | 91 | upload-to-pypi: 92 | runs-on: ubuntu-latest 93 | needs: [build-and-deploy] 94 | steps: 95 | - uses: actions/download-artifact@v4 96 | with: 97 | name: wheel-${{env.LLVM_VER}}-win_arm64 98 | path: dist/ 99 | - name: Publish to PyPI 100 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') 101 | uses: pypa/gh-action-pypi-publish@release/v1 102 | with: 103 | packages_dir: dist/ 104 | password: ${{ secrets.PYPI_TOKEN }} 105 | verbose: true 106 | print_hash: true 107 | -------------------------------------------------------------------------------- /.github/workflows/libclang-windows-amd64.yml: -------------------------------------------------------------------------------- 1 | name: libclang-windows-amd64 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | LLVM_VER: 19.1.3 7 | 8 | concurrency: 9 | group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} 10 | cancel-in-progress: true 11 | 12 | jobs: 13 | build-and-deploy: 14 | if: "!contains(github.event.head_commit.message, 'skip ci')" 15 | runs-on: windows-latest 16 | steps: 17 | - uses: actions/checkout@v4 18 | - uses: actions/setup-python@v5 19 | with: 20 | python-version: '3.10' 21 | - name: install wheel dependencies 22 | run: | 23 | pip3 install wheel 24 | - name: get llvm-project 25 | run: | 26 | choco install wget git 27 | git clone https://github.com/llvm/llvm-project.git llvm-project-$env:LLVM_VER -b llvmorg-$env:LLVM_VER --depth=1 28 | - name: make build directory 29 | run: mkdir -p llvm-project-$env:LLVM_VER/build 30 | - name: cmake 31 | run: | 32 | cd llvm-project-$env:LLVM_VER/build 33 | cmake ../llvm ` 34 | -Thost=x64 ` 35 | -DLLVM_ENABLE_PROJECTS=clang ` 36 | -DBUILD_SHARED_LIBS=OFF ` 37 | -DLLVM_ENABLE_ZLIB=OFF ` 38 | -DLLVM_ENABLE_ZSTD=OFF ` 39 | -DLLVM_ENABLE_TERMINFO=OFF ` 40 | -DLLVM_TARGETS_TO_BUILD=X86 ` 41 | -DCMAKE_CXX_FLAGS="/MP" ` 42 | -DLLVM_USE_CRT_MINSIZEREL="MT" 43 | - name: build 44 | run: cd llvm-project-$env:LLVM_VER/build && cmake --build . --config RelWithDebInfo --target libclang 45 | - name: create and print sha512sum 46 | run: | 47 | $env:Path = "C:\Program Files\Git\usr\bin;$env:Path" 48 | cd llvm-project-$env:LLVM_VER\build\RelWithDebInfo\bin 49 | sha512sum.exe libclang.dll > libclang.dll.$env:LLVM_VER.windows-amd64.sha512sum 50 | echo "Checksum is: " 51 | Get-Content -Path libclang.dll.$env:LLVM_VER.windows-amd64.sha512sum 52 | tar zcvf libclang.dll.$env:LLVM_VER.windows-amd64.tar.gz libclang.dll libclang.dll.$env:LLVM_VER.windows-amd64.sha512sum 53 | sha512sum.exe libclang.dll.$env:LLVM_VER.windows-amd64.tar.gz 54 | - uses: actions/upload-artifact@v4 55 | with: 56 | name: libclang.dll.${{env.LLVM_VER}}.windows-amd64.tar.gz 57 | path: llvm-project-${{env.LLVM_VER}}\build\RelWithDebInfo\bin\libclang.dll.${{env.LLVM_VER}}.windows-amd64.tar.gz 58 | - name: generate wheel package 59 | run: | 60 | cp llvm-project-${{env.LLVM_VER}}\build\RelWithDebInfo\bin\libclang.dll native/ 61 | python3 setup_ext.py bdist_wheel --universal --plat-name=win_amd64 62 | - uses: actions/upload-artifact@v4 63 | with: 64 | name: wheel-${{env.LLVM_VER}}-win_amd64 65 | path: dist/*.whl 66 | 67 | upload-to-pypi: 68 | runs-on: ubuntu-latest 69 | needs: [build-and-deploy] 70 | steps: 71 | - uses: actions/download-artifact@v4 72 | with: 73 | name: wheel-${{env.LLVM_VER}}-win_amd64 74 | path: dist/ 75 | - name: Publish to PyPI 76 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') 77 | uses: pypa/gh-action-pypi-publish@release/v1 78 | with: 79 | packages_dir: dist/ 80 | password: ${{ secrets.PYPI_TOKEN }} 81 | verbose: true 82 | print_hash: true 83 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 98 | __pypackages__/ 99 | 100 | # Celery stuff 101 | celerybeat-schedule 102 | celerybeat.pid 103 | 104 | # SageMath parsed files 105 | *.sage.py 106 | 107 | # Environments 108 | .env 109 | .venv 110 | env/ 111 | venv/ 112 | ENV/ 113 | env.bak/ 114 | venv.bak/ 115 | 116 | # Spyder project settings 117 | .spyderproject 118 | .spyproject 119 | 120 | # Rope project settings 121 | .ropeproject 122 | 123 | # mkdocs documentation 124 | /site 125 | 126 | # mypy 127 | .mypy_cache/ 128 | .dmypy.json 129 | dmypy.json 130 | 131 | # Pyre type checker 132 | .pyre/ 133 | 134 | # pytype static type analyzer 135 | .pytype/ 136 | 137 | # Cython debug symbols 138 | cython_debug/ -------------------------------------------------------------------------------- /LICENSE.TXT: -------------------------------------------------------------------------------- 1 | ============================================================================== 2 | The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: 3 | ============================================================================== 4 | 5 | Apache License 6 | Version 2.0, January 2004 7 | http://www.apache.org/licenses/ 8 | 9 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 10 | 11 | 1. Definitions. 12 | 13 | "License" shall mean the terms and conditions for use, reproduction, 14 | and distribution as defined by Sections 1 through 9 of this document. 15 | 16 | "Licensor" shall mean the copyright owner or entity authorized by 17 | the copyright owner that is granting the License. 18 | 19 | "Legal Entity" shall mean the union of the acting entity and all 20 | other entities that control, are controlled by, or are under common 21 | control with that entity. For the purposes of this definition, 22 | "control" means (i) the power, direct or indirect, to cause the 23 | direction or management of such entity, whether by contract or 24 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 25 | outstanding shares, or (iii) beneficial ownership of such entity. 26 | 27 | "You" (or "Your") shall mean an individual or Legal Entity 28 | exercising permissions granted by this License. 29 | 30 | "Source" form shall mean the preferred form for making modifications, 31 | including but not limited to software source code, documentation 32 | source, and configuration files. 33 | 34 | "Object" form shall mean any form resulting from mechanical 35 | transformation or translation of a Source form, including but 36 | not limited to compiled object code, generated documentation, 37 | and conversions to other media types. 38 | 39 | "Work" shall mean the work of authorship, whether in Source or 40 | Object form, made available under the License, as indicated by a 41 | copyright notice that is included in or attached to the work 42 | (an example is provided in the Appendix below). 43 | 44 | "Derivative Works" shall mean any work, whether in Source or Object 45 | form, that is based on (or derived from) the Work and for which the 46 | editorial revisions, annotations, elaborations, or other modifications 47 | represent, as a whole, an original work of authorship. For the purposes 48 | of this License, Derivative Works shall not include works that remain 49 | separable from, or merely link (or bind by name) to the interfaces of, 50 | the Work and Derivative Works thereof. 51 | 52 | "Contribution" shall mean any work of authorship, including 53 | the original version of the Work and any modifications or additions 54 | to that Work or Derivative Works thereof, that is intentionally 55 | submitted to Licensor for inclusion in the Work by the copyright owner 56 | or by an individual or Legal Entity authorized to submit on behalf of 57 | the copyright owner. For the purposes of this definition, "submitted" 58 | means any form of electronic, verbal, or written communication sent 59 | to the Licensor or its representatives, including but not limited to 60 | communication on electronic mailing lists, source code control systems, 61 | and issue tracking systems that are managed by, or on behalf of, the 62 | Licensor for the purpose of discussing and improving the Work, but 63 | excluding communication that is conspicuously marked or otherwise 64 | designated in writing by the copyright owner as "Not a Contribution." 65 | 66 | "Contributor" shall mean Licensor and any individual or Legal Entity 67 | on behalf of whom a Contribution has been received by Licensor and 68 | subsequently incorporated within the Work. 69 | 70 | 2. Grant of Copyright License. Subject to the terms and conditions of 71 | this License, each Contributor hereby grants to You a perpetual, 72 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 73 | copyright license to reproduce, prepare Derivative Works of, 74 | publicly display, publicly perform, sublicense, and distribute the 75 | Work and such Derivative Works in Source or Object form. 76 | 77 | 3. Grant of Patent License. Subject to the terms and conditions of 78 | this License, each Contributor hereby grants to You a perpetual, 79 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 80 | (except as stated in this section) patent license to make, have made, 81 | use, offer to sell, sell, import, and otherwise transfer the Work, 82 | where such license applies only to those patent claims licensable 83 | by such Contributor that are necessarily infringed by their 84 | Contribution(s) alone or by combination of their Contribution(s) 85 | with the Work to which such Contribution(s) was submitted. If You 86 | institute patent litigation against any entity (including a 87 | cross-claim or counterclaim in a lawsuit) alleging that the Work 88 | or a Contribution incorporated within the Work constitutes direct 89 | or contributory patent infringement, then any patent licenses 90 | granted to You under this License for that Work shall terminate 91 | as of the date such litigation is filed. 92 | 93 | 4. Redistribution. You may reproduce and distribute copies of the 94 | Work or Derivative Works thereof in any medium, with or without 95 | modifications, and in Source or Object form, provided that You 96 | meet the following conditions: 97 | 98 | (a) You must give any other recipients of the Work or 99 | Derivative Works a copy of this License; and 100 | 101 | (b) You must cause any modified files to carry prominent notices 102 | stating that You changed the files; and 103 | 104 | (c) You must retain, in the Source form of any Derivative Works 105 | that You distribute, all copyright, patent, trademark, and 106 | attribution notices from the Source form of the Work, 107 | excluding those notices that do not pertain to any part of 108 | the Derivative Works; and 109 | 110 | (d) If the Work includes a "NOTICE" text file as part of its 111 | distribution, then any Derivative Works that You distribute must 112 | include a readable copy of the attribution notices contained 113 | within such NOTICE file, excluding those notices that do not 114 | pertain to any part of the Derivative Works, in at least one 115 | of the following places: within a NOTICE text file distributed 116 | as part of the Derivative Works; within the Source form or 117 | documentation, if provided along with the Derivative Works; or, 118 | within a display generated by the Derivative Works, if and 119 | wherever such third-party notices normally appear. The contents 120 | of the NOTICE file are for informational purposes only and 121 | do not modify the License. You may add Your own attribution 122 | notices within Derivative Works that You distribute, alongside 123 | or as an addendum to the NOTICE text from the Work, provided 124 | that such additional attribution notices cannot be construed 125 | as modifying the License. 126 | 127 | You may add Your own copyright statement to Your modifications and 128 | may provide additional or different license terms and conditions 129 | for use, reproduction, or distribution of Your modifications, or 130 | for any such Derivative Works as a whole, provided Your use, 131 | reproduction, and distribution of the Work otherwise complies with 132 | the conditions stated in this License. 133 | 134 | 5. Submission of Contributions. Unless You explicitly state otherwise, 135 | any Contribution intentionally submitted for inclusion in the Work 136 | by You to the Licensor shall be under the terms and conditions of 137 | this License, without any additional terms or conditions. 138 | Notwithstanding the above, nothing herein shall supersede or modify 139 | the terms of any separate license agreement you may have executed 140 | with Licensor regarding such Contributions. 141 | 142 | 6. Trademarks. This License does not grant permission to use the trade 143 | names, trademarks, service marks, or product names of the Licensor, 144 | except as required for reasonable and customary use in describing the 145 | origin of the Work and reproducing the content of the NOTICE file. 146 | 147 | 7. Disclaimer of Warranty. Unless required by applicable law or 148 | agreed to in writing, Licensor provides the Work (and each 149 | Contributor provides its Contributions) on an "AS IS" BASIS, 150 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 151 | implied, including, without limitation, any warranties or conditions 152 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 153 | PARTICULAR PURPOSE. You are solely responsible for determining the 154 | appropriateness of using or redistributing the Work and assume any 155 | risks associated with Your exercise of permissions under this License. 156 | 157 | 8. Limitation of Liability. In no event and under no legal theory, 158 | whether in tort (including negligence), contract, or otherwise, 159 | unless required by applicable law (such as deliberate and grossly 160 | negligent acts) or agreed to in writing, shall any Contributor be 161 | liable to You for damages, including any direct, indirect, special, 162 | incidental, or consequential damages of any character arising as a 163 | result of this License or out of the use or inability to use the 164 | Work (including but not limited to damages for loss of goodwill, 165 | work stoppage, computer failure or malfunction, or any and all 166 | other commercial damages or losses), even if such Contributor 167 | has been advised of the possibility of such damages. 168 | 169 | 9. Accepting Warranty or Additional Liability. While redistributing 170 | the Work or Derivative Works thereof, You may choose to offer, 171 | and charge a fee for, acceptance of support, warranty, indemnity, 172 | or other liability obligations and/or rights consistent with this 173 | License. However, in accepting such obligations, You may act only 174 | on Your own behalf and on Your sole responsibility, not on behalf 175 | of any other Contributor, and only if You agree to indemnify, 176 | defend, and hold each Contributor harmless for any liability 177 | incurred by, or claims asserted against, such Contributor by reason 178 | of your accepting any such warranty or additional liability. 179 | 180 | END OF TERMS AND CONDITIONS 181 | 182 | APPENDIX: How to apply the Apache License to your work. 183 | 184 | To apply the Apache License to your work, attach the following 185 | boilerplate notice, with the fields enclosed by brackets "[]" 186 | replaced with your own identifying information. (Don't include 187 | the brackets!) The text should be enclosed in the appropriate 188 | comment syntax for the file format. We also recommend that a 189 | file or class name and description of purpose be included on the 190 | same "printed page" as the copyright notice for easier 191 | identification within third-party archives. 192 | 193 | Copyright [yyyy] [name of copyright owner] 194 | 195 | Licensed under the Apache License, Version 2.0 (the "License"); 196 | you may not use this file except in compliance with the License. 197 | You may obtain a copy of the License at 198 | 199 | http://www.apache.org/licenses/LICENSE-2.0 200 | 201 | Unless required by applicable law or agreed to in writing, software 202 | distributed under the License is distributed on an "AS IS" BASIS, 203 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 204 | See the License for the specific language governing permissions and 205 | limitations under the License. 206 | 207 | 208 | ---- LLVM Exceptions to the Apache 2.0 License ---- 209 | 210 | As an exception, if, as a result of your compiling your source code, portions 211 | of this Software are embedded into an Object form of such source code, you 212 | may redistribute such embedded portions in such Object form without complying 213 | with the conditions of Sections 4(a), 4(b) and 4(d) of the License. 214 | 215 | In addition, if you combine or link compiled forms of this Software with 216 | software that is licensed under the GPLv2 ("Combined Software") and if a 217 | court of competent jurisdiction determines that the patent provision (Section 218 | 3), the indemnity provision (Section 9) or other Section of the License 219 | conflicts with the conditions of the GPLv2, you may retroactively and 220 | prospectively choose to deem waived or otherwise exclude such Section(s) of 221 | the License, but only in their entirety and only with respect to the Combined 222 | Software. 223 | 224 | ============================================================================== 225 | Software from third parties included in the LLVM Project: 226 | ============================================================================== 227 | The LLVM Project contains third party software which is under different license 228 | terms. All such code will be identified clearly using at least one of two 229 | mechanisms: 230 | 1) It will be in a separate directory tree with its own `LICENSE.txt` or 231 | `LICENSE` file at the top containing the specific license and restrictions 232 | which apply to that software, or 233 | 2) It will contain specific license and restriction terms at the top of every 234 | file. 235 | 236 | ============================================================================== 237 | Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): 238 | ============================================================================== 239 | University of Illinois/NCSA 240 | Open Source License 241 | 242 | Copyright (c) 2007-2019 University of Illinois at Urbana-Champaign. 243 | All rights reserved. 244 | 245 | Developed by: 246 | 247 | LLVM Team 248 | 249 | University of Illinois at Urbana-Champaign 250 | 251 | http://llvm.org 252 | 253 | Permission is hereby granted, free of charge, to any person obtaining a copy of 254 | this software and associated documentation files (the "Software"), to deal with 255 | the Software without restriction, including without limitation the rights to 256 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 257 | of the Software, and to permit persons to whom the Software is furnished to do 258 | so, subject to the following conditions: 259 | 260 | * Redistributions of source code must retain the above copyright notice, 261 | this list of conditions and the following disclaimers. 262 | 263 | * Redistributions in binary form must reproduce the above copyright notice, 264 | this list of conditions and the following disclaimers in the 265 | documentation and/or other materials provided with the distribution. 266 | 267 | * Neither the names of the LLVM Team, University of Illinois at 268 | Urbana-Champaign, nor the names of its contributors may be used to 269 | endorse or promote products derived from this Software without specific 270 | prior written permission. 271 | 272 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 273 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 274 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 275 | CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 276 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 277 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE 278 | SOFTWARE. 279 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | libclang-for-pip 2 | ================ 3 | 4 | [![PyPI](https://img.shields.io/pypi/v/libclang)](https://pypi.org/project/libclang) 5 | ![Python](https://img.shields.io/pypi/pyversions/libclang) 6 | ![Downloads](https://img.shields.io/pypi/dw/libclang) 7 | [![License](https://img.shields.io/pypi/l/libclang)](https://github.com/sighingnow/libclang/blob/master/LICENSE.TXT) 8 | 9 | [![Arch: x86\_64](https://img.shields.io/badge/arch-x86__64-brightgreen)](https://pypi.org/project/libclang/#files) 10 | [![Arch: aarch64](https://img.shields.io/badge/arch-aarch64-yellowgreen)](https://pypi.org/project/libclang/#files) 11 | [![Arch: arm](https://img.shields.io/badge/arch-arm-orange)](https://pypi.org/project/libclang/#files) 12 | 13 | [![Linux](https://github.com/sighingnow/libclang/workflows/libclang-linux-amd64/badge.svg)](https://github.com/sighingnow/libclang/actions/workflows/libclang-linux-amd64.yml) 14 | [![Linux Arm](https://github.com/sighingnow/libclang/workflows/libclang-linux-arm/badge.svg)](https://github.com/sighingnow/libclang/actions/workflows/libclang-linux-arm.yml) 15 | [![Linux AArch64](https://github.com/sighingnow/libclang/workflows/libclang-linux-aarch64/badge.svg)](https://github.com/sighingnow/libclang/actions/workflows/libclang-linux-aarch64.yml) 16 | [![Linux Alpine](https://github.com/sighingnow/libclang/workflows/libclang-alpine-amd64/badge.svg)](https://github.com/sighingnow/libclang/actions/workflows/libclang-alpine-amd64.yml) 17 | 18 | [![MacOS Intel](https://github.com/sighingnow/libclang/workflows/libclang-macosx-amd64/badge.svg)](https://github.com/sighingnow/libclang/actions/workflows/libclang-macosx-amd64.yml) 19 | [![MacOS M1](https://img.shields.io/cirrus/github/sighingnow/libclang?label=libclang-macosx-arm64)](https://cirrus-ci.com/github/sighingnow/libclang) 20 | 21 | [![Windows](https://github.com/sighingnow/libclang/workflows/libclang-windows-amd64/badge.svg)](https://github.com/sighingnow/libclang/actions/workflows/libclang-windows-amd64.yml) 22 | [![Windows AArch64](https://github.com/sighingnow/libclang/workflows/libclang-windows-aarch64/badge.svg)](https://github.com/sighingnow/libclang/actions/workflows/libclang-windows-aarch64.yml) 23 | 24 | The repository contains code taken from [the LLVM project][1], to make it easier to install 25 | clang's python bindings. 26 | 27 | The repository copies necessary Python binding files from LLVM repo, adds packaging scripts 28 | to make it a valid Python package and finally uploads the package to [pypi][2]. To make the libclang 29 | available without installing the LLVM toolkits, this package provides bundled static-linked libclang 30 | shared library for different platforms, which, should work well on OSX, Windows, as well as 31 | usual Linux distributions. 32 | 33 | The aim of this project is to make the `clang.cindex` (aka., Clang Python Bindings) 34 | available for more Python users, without setting up the LLVM environment. To install the package, 35 | you just need to run 36 | 37 | ```bash 38 | pip install libclang 39 | ``` 40 | 41 | Note that the library is named `libclang`, the package `clang` on PyPi is another package and 42 | doesn't bundle the prebuilt shared library. 43 | 44 | Internals 45 | --------- 46 | 47 | Update class variable `library_path` of `Config` in `cindex.py` as: 48 | 49 | ```python 50 | library_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'native') 51 | ``` 52 | 53 | License 54 | ------- 55 | 56 | This repository follows the license agreement of the LLVM project, see [Apache-2.0 WITH LLVM-exception](./LICENSE.TXT). 57 | 58 | [1]: https://github.com/llvm/llvm-project/tree/main/clang/bindings/python 59 | [2]: https://pypi.org/project/libclang 60 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " applehelp to make an Apple Help Book" 34 | @echo " devhelp to make HTML files and a Devhelp project" 35 | @echo " epub to make an epub" 36 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 37 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 38 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 39 | @echo " text to make text files" 40 | @echo " man to make manual pages" 41 | @echo " texinfo to make Texinfo files" 42 | @echo " info to make Texinfo files and run them through makeinfo" 43 | @echo " gettext to make PO message catalogs" 44 | @echo " changes to make an overview of all changed/added/deprecated items" 45 | @echo " xml to make Docutils-native XML files" 46 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 47 | @echo " linkcheck to check all external links for integrity" 48 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 49 | @echo " coverage to run coverage check of the documentation (if enabled)" 50 | 51 | clean: 52 | rm -rf $(BUILDDIR)/* 53 | 54 | html: 55 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 56 | @echo 57 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 58 | 59 | dirhtml: 60 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 61 | @echo 62 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 63 | 64 | singlehtml: 65 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 66 | @echo 67 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 68 | 69 | pickle: 70 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 71 | @echo 72 | @echo "Build finished; now you can process the pickle files." 73 | 74 | json: 75 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 76 | @echo 77 | @echo "Build finished; now you can process the JSON files." 78 | 79 | htmlhelp: 80 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 81 | @echo 82 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 83 | ".hhp project file in $(BUILDDIR)/htmlhelp." 84 | 85 | qthelp: 86 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 87 | @echo 88 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 89 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 90 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/libclang.qhcp" 91 | @echo "To view the help file:" 92 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/libclang.qhc" 93 | 94 | applehelp: 95 | $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp 96 | @echo 97 | @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." 98 | @echo "N.B. You won't be able to view it unless you put it in" \ 99 | "~/Library/Documentation/Help or install it in your application" \ 100 | "bundle." 101 | 102 | devhelp: 103 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 104 | @echo 105 | @echo "Build finished." 106 | @echo "To view the help file:" 107 | @echo "# mkdir -p $$HOME/.local/share/devhelp/libclang" 108 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/libclang" 109 | @echo "# devhelp" 110 | 111 | epub: 112 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 113 | @echo 114 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 115 | 116 | latex: 117 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 118 | @echo 119 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 120 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 121 | "(use \`make latexpdf' here to do that automatically)." 122 | 123 | latexpdf: 124 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 125 | @echo "Running LaTeX files through pdflatex..." 126 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 127 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 128 | 129 | latexpdfja: 130 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 131 | @echo "Running LaTeX files through platex and dvipdfmx..." 132 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 133 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 134 | 135 | text: 136 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 137 | @echo 138 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 139 | 140 | man: 141 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 142 | @echo 143 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 144 | 145 | texinfo: 146 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 147 | @echo 148 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 149 | @echo "Run \`make' in that directory to run these through makeinfo" \ 150 | "(use \`make info' here to do that automatically)." 151 | 152 | info: 153 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 154 | @echo "Running Texinfo files through makeinfo..." 155 | make -C $(BUILDDIR)/texinfo info 156 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 157 | 158 | gettext: 159 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 160 | @echo 161 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 162 | 163 | changes: 164 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 165 | @echo 166 | @echo "The overview file is in $(BUILDDIR)/changes." 167 | 168 | linkcheck: 169 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 170 | @echo 171 | @echo "Link check complete; look for any errors in the above output " \ 172 | "or in $(BUILDDIR)/linkcheck/output.txt." 173 | 174 | doctest: 175 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 176 | @echo "Testing of doctests in the sources finished, look at the " \ 177 | "results in $(BUILDDIR)/doctest/output.txt." 178 | 179 | coverage: 180 | $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage 181 | @echo "Testing of coverage in the sources finished, look at the " \ 182 | "results in $(BUILDDIR)/coverage/python.txt." 183 | 184 | xml: 185 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 186 | @echo 187 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 188 | 189 | pseudoxml: 190 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 191 | @echo 192 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 193 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # a documentation build configuration file, created by 5 | # sphinx-quickstart on Thu Nov 5 17:47:26 2015. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | import sys 17 | import os 18 | import shlex 19 | 20 | sys.path.insert(0, os.path.abspath('../python')) 21 | 22 | # If extensions (or modules to document with autodoc) are in another directory, 23 | # add these directories to sys.path here. If the directory is relative to the 24 | # documentation root, use os.path.abspath to make it absolute, like shown here. 25 | #sys.path.insert(0, os.path.abspath('.')) 26 | 27 | # -- General configuration ------------------------------------------------ 28 | 29 | # If your documentation needs a minimal Sphinx version, state it here. 30 | #needs_sphinx = '1.0' 31 | 32 | # Add any Sphinx extension module names here, as strings. They can be 33 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 34 | # ones. 35 | extensions = [ 36 | 'sphinx.ext.autodoc', 37 | 'sphinx.ext.coverage', 38 | 'sphinx.ext.intersphinx', 39 | 'sphinx.ext.todo', 40 | 'sphinx.ext.viewcode', 41 | ] 42 | 43 | # Add any paths that contain templates here, relative to this directory. 44 | # templates_path = ['_templates'] 45 | 46 | # The suffix(es) of source filenames. 47 | # You can specify multiple suffix as a list of string: 48 | source_suffix = ['.rst'] 49 | 50 | # The encoding of source files. 51 | source_encoding = 'utf-8-sig' 52 | 53 | # The master toctree document. 54 | master_doc = 'index' 55 | 56 | # General information about the project. 57 | project = 'libclang' 58 | copyright = 'The LLVM Team' 59 | author = 'The LLVM Team' 60 | 61 | # The version info for the project you're documenting, acts as replacement for 62 | # |version| and |release|, also used in various other places throughout the 63 | # built documents. 64 | # 65 | # The short X.Y version. 66 | version = '19.1.3' 67 | # The full version, including alpha/beta/rc tags. 68 | release = '19.1.3' 69 | 70 | # The language for content autogenerated by Sphinx. Refer to documentation 71 | # for a list of supported languages. 72 | # 73 | # This is also used if you do content translation via gettext catalogs. 74 | # Usually you set "language" from the command line for these cases. 75 | language = None 76 | 77 | # There are two options for replacing |today|: either, you set today to some 78 | # non-false value, then it is used: 79 | #today = '' 80 | # Else, today_fmt is used as the format for a strftime call. 81 | #today_fmt = '%B %d, %Y' 82 | 83 | # List of patterns, relative to source directory, that match files and 84 | # directories to ignore when looking for source files. 85 | exclude_patterns = [] 86 | 87 | # The reST default role (used for this markup: `text`) to use for all 88 | # documents. 89 | #default_role = None 90 | 91 | # If true, '()' will be appended to :func: etc. cross-reference text. 92 | #add_function_parentheses = True 93 | 94 | # If true, the current module name will be prepended to all description 95 | # unit titles (such as .. function::). 96 | #add_module_names = True 97 | 98 | # If true, sectionauthor and moduleauthor directives will be shown in the 99 | # output. They are ignored by default. 100 | #show_authors = False 101 | 102 | # The name of the Pygments (syntax highlighting) style to use. 103 | pygments_style = 'sphinx' 104 | 105 | # A list of ignored prefixes for module index sorting. 106 | #modindex_common_prefix = [] 107 | 108 | # If true, keep warnings as "system message" paragraphs in the built documents. 109 | #keep_warnings = False 110 | 111 | # If true, `todo` and `todoList` produce output, else they produce nothing. 112 | todo_include_todos = True 113 | 114 | 115 | # -- Options for HTML output ---------------------------------------------- 116 | 117 | # The theme to use for HTML and HTML Help pages. See the documentation for 118 | # a list of builtin themes. 119 | html_theme = 'sphinxdoc' 120 | 121 | # Theme options are theme-specific and customize the look and feel of a theme 122 | # further. For a list of options available for each theme, see the 123 | # documentation. 124 | #html_theme_options = {} 125 | 126 | # Add any paths that contain custom themes here, relative to this directory. 127 | #html_theme_path = [] 128 | 129 | # The name for this set of Sphinx documents. If None, it defaults to 130 | # " v documentation". 131 | #html_title = None 132 | 133 | # A shorter title for the navigation bar. Default is the same as html_title. 134 | #html_short_title = None 135 | 136 | # The name of an image file (relative to this directory) to place at the top 137 | # of the sidebar. 138 | #html_logo = None 139 | 140 | # The name of an image file (within the static path) to use as favicon of the 141 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 142 | # pixels large. 143 | #html_favicon = None 144 | 145 | # Add any paths that contain custom static files (such as style sheets) here, 146 | # relative to this directory. They are copied after the builtin static files, 147 | # so a file named "default.css" will overwrite the builtin "default.css". 148 | # html_static_path = ['_static'] 149 | 150 | # Add any extra paths that contain custom files (such as robots.txt or 151 | # .htaccess) here, relative to this directory. These files are copied 152 | # directly to the root of the documentation. 153 | #html_extra_path = [] 154 | 155 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 156 | # using the given strftime format. 157 | #html_last_updated_fmt = '%b %d, %Y' 158 | 159 | # If true, SmartyPants will be used to convert quotes and dashes to 160 | # typographically correct entities. 161 | #html_use_smartypants = True 162 | 163 | # Custom sidebar templates, maps document names to template names. 164 | #html_sidebars = {} 165 | 166 | # Additional templates that should be rendered to pages, maps page names to 167 | # template names. 168 | #html_additional_pages = {} 169 | 170 | # If false, no module index is generated. 171 | html_domain_indices = True 172 | 173 | # If false, no index is generated. 174 | html_use_index = True 175 | 176 | # If true, the index is split into individual pages for each letter. 177 | html_split_index = False 178 | 179 | # If true, links to the reST sources are added to the pages. 180 | html_show_sourcelink = True 181 | 182 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 183 | html_show_sphinx = True 184 | 185 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 186 | html_show_copyright = True 187 | 188 | # If true, an OpenSearch description file will be output, and all pages will 189 | # contain a tag referring to it. The value of this option must be the 190 | # base URL from which the finished HTML is served. 191 | #html_use_opensearch = '' 192 | 193 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 194 | #html_file_suffix = None 195 | 196 | # Language to be used for generating the HTML full-text search index. 197 | # Sphinx supports the following languages: 198 | # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja' 199 | # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr' 200 | #html_search_language = 'en' 201 | 202 | # A dictionary with options for the search language support, empty by default. 203 | # Now only 'ja' uses this config value 204 | #html_search_options = {'type': 'default'} 205 | 206 | # The name of a javascript file (relative to the configuration directory) that 207 | # implements a search results scorer. If empty, the default will be used. 208 | #html_search_scorer = 'scorer.js' 209 | 210 | # Output file base name for HTML help builder. 211 | htmlhelp_basename = 'adoc' 212 | 213 | # -- Options for LaTeX output --------------------------------------------- 214 | 215 | latex_elements = { 216 | # The paper size ('letterpaper' or 'a4paper'). 217 | #'papersize': 'letterpaper', 218 | 219 | # The font size ('10pt', '11pt' or '12pt'). 220 | #'pointsize': '10pt', 221 | 222 | # Additional stuff for the LaTeX preamble. 223 | #'preamble': '', 224 | 225 | # Latex figure (float) alignment 226 | #'figure_align': 'htbp', 227 | } 228 | 229 | # Grouping the document tree into LaTeX files. List of tuples 230 | # (source start file, target name, title, 231 | # author, documentclass [howto, manual, or own class]). 232 | latex_documents = [ 233 | (master_doc, 'libclang.tex', 'libclang documentation', 234 | 'libclang', 'manual'), 235 | ] 236 | 237 | # The name of an image file (relative to this directory) to place at the top of 238 | # the title page. 239 | #latex_logo = None 240 | 241 | # For "manual" documents, if this is true, then toplevel headings are parts, 242 | # not chapters. 243 | #latex_use_parts = False 244 | 245 | # If true, show page references after internal links. 246 | #latex_show_pagerefs = False 247 | 248 | # If true, show URL addresses after external links. 249 | #latex_show_urls = False 250 | 251 | # Documents to append as an appendix to all manuals. 252 | #latex_appendices = [] 253 | 254 | # If false, no module index is generated. 255 | #latex_domain_indices = True 256 | 257 | 258 | # -- Options for manual page output --------------------------------------- 259 | 260 | # One entry per manual page. List of tuples 261 | # (source start file, name, description, authors, manual section). 262 | man_pages = [ 263 | (master_doc, 'libclang', 'libclang documentation', 264 | [author], 1) 265 | ] 266 | 267 | # If true, show URL addresses after external links. 268 | #man_show_urls = False 269 | 270 | 271 | # -- Options for Texinfo output ------------------------------------------- 272 | 273 | # Grouping the document tree into Texinfo files. List of tuples 274 | # (source start file, target name, title, author, 275 | # dir menu entry, description, category) 276 | texinfo_documents = [ 277 | (master_doc, 'libclang', 'libclang documentation', 278 | author, 'libclang', 'Clang Python Bindings.', 279 | 'Miscellaneous'), 280 | ] 281 | 282 | # Documents to append as an appendix to all manuals. 283 | #texinfo_appendices = [] 284 | 285 | # If false, no module index is generated. 286 | #texinfo_domain_indices = True 287 | 288 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 289 | #texinfo_show_urls = 'footnote' 290 | 291 | # If true, do not generate a @detailmenu in the "Top" node's menu. 292 | #texinfo_no_detailmenu = False 293 | 294 | 295 | # Example configuration for intersphinx: refer to the Python standard library. 296 | intersphinx_mapping = {'https://docs.python.org/': None} 297 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | :Date: 2021-04-17 2 | :Version: 19.1.3 3 | :Authors: - The LLVM Team 4 | 5 | .. meta:: 6 | :http-equiv=Content-Type: text/html; charset=utf-8 7 | :keywords: Clang, Python, Bindings 8 | :description lang=en: Clang Python Bindings. 9 | 10 | .. automodule:: clang.cindex 11 | :members: 12 | -------------------------------------------------------------------------------- /force_glibc_2_17.h: -------------------------------------------------------------------------------- 1 | #ifndef __FORCE_GLIBC_2_17_H__ 2 | #define __FORCE_GLIBC_2_17_H__ 3 | 4 | #if defined(__x86_64__) && __x86_64__ 5 | __asm__(".symver exp,exp@GLIBC_2.2.5"); 6 | __asm__(".symver pow,pow@GLIBC_2.2.5"); 7 | __asm__(".symver log,log@GLIBC_2.2.5"); 8 | __asm__(".symver log2,log2@GLIBC_2.2.5"); 9 | #endif 10 | 11 | #if defined(__aarch64__) && __aarch64__ 12 | __asm__(".symver exp,exp@GLIBC_2.17"); 13 | __asm__(".symver pow,pow@GLIBC_2.17"); 14 | __asm__(".symver log,log@GLIBC_2.17"); 15 | __asm__(".symver log2,log2@GLIBC_2.17"); 16 | #endif 17 | 18 | #if defined(__arm__) && __arm__ 19 | __asm__(".symver exp,exp@GLIBC_2.4"); 20 | __asm__(".symver pow,pow@GLIBC_2.4"); 21 | __asm__(".symver log,log@GLIBC_2.4"); 22 | __asm__(".symver log2,log2@GLIBC_2.4"); 23 | #endif 24 | 25 | #endif // __FORCE_GLIBC_2_17_H__ 26 | -------------------------------------------------------------------------------- /native/.gitignore: -------------------------------------------------------------------------------- 1 | /* 2 | !/.gitignore -------------------------------------------------------------------------------- /python/README.txt: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Clang Python Bindings 3 | //===----------------------------------------------------------------------===// 4 | 5 | This directory implements Python bindings for Clang. 6 | 7 | You may need to set CLANG_LIBRARY_PATH so that the Clang library can be 8 | found. The unit tests are designed to be run with any standard test 9 | runner. For example: 10 | -- 11 | $ env PYTHONPATH=$(echo ~/llvm/tools/clang/bindings/python/) \ 12 | CLANG_LIBRARY_PATH=$(llvm-config --libdir) \ 13 | python -m unittest discover -v 14 | tests.cindex.test_index.test_create ... ok 15 | ... 16 | 17 | OK 18 | -- 19 | -------------------------------------------------------------------------------- /python/clang/__init__.py: -------------------------------------------------------------------------------- 1 | # ===- __init__.py - Clang Python Bindings --------------------*- python -*--===# 2 | # 3 | # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | # See https://llvm.org/LICENSE.txt for license information. 5 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | # 7 | # ===------------------------------------------------------------------------===# 8 | 9 | r""" 10 | Clang Library Bindings 11 | ====================== 12 | 13 | This package provides access to the Clang compiler and libraries. 14 | 15 | The available modules are: 16 | 17 | cindex 18 | 19 | Bindings for the Clang indexing library. 20 | """ 21 | 22 | __all__ = ["cindex"] 23 | -------------------------------------------------------------------------------- /python/clang/enumerations.py: -------------------------------------------------------------------------------- 1 | # ===- enumerations.py - Python Enumerations ------------------*- python -*--===# 2 | # 3 | # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | # See https://llvm.org/LICENSE.txt for license information. 5 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | # 7 | # ===------------------------------------------------------------------------===# 8 | 9 | """ 10 | Clang Enumerations 11 | ================== 12 | 13 | This module provides static definitions of enumerations that exist in libclang. 14 | 15 | Enumerations are typically defined as a list of tuples. The exported values are 16 | typically munged into other types or classes at module load time. 17 | 18 | All enumerations are centrally defined in this file so they are all grouped 19 | together and easier to audit. And, maybe even one day this file will be 20 | automatically generated by scanning the libclang headers! 21 | """ 22 | 23 | # Maps to CXTokenKind. Note that libclang maintains a separate set of token 24 | # enumerations from the C++ API. 25 | TokenKinds = [ 26 | ("PUNCTUATION", 0), 27 | ("KEYWORD", 1), 28 | ("IDENTIFIER", 2), 29 | ("LITERAL", 3), 30 | ("COMMENT", 4), 31 | ] 32 | 33 | __all__ = ["TokenKinds"] 34 | -------------------------------------------------------------------------------- /python/clang/native/.gitignore: -------------------------------------------------------------------------------- 1 | *.dylib 2 | *.so 3 | *.dll 4 | *.lib 5 | -------------------------------------------------------------------------------- /python/clang/native/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- -------------------------------------------------------------------------------- /python/examples/cindex/cindex-dump.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | #===- cindex-dump.py - cindex/Python Source Dump -------------*- python -*--===# 4 | # 5 | # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 6 | # See https://llvm.org/LICENSE.txt for license information. 7 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 8 | # 9 | #===------------------------------------------------------------------------===# 10 | 11 | """ 12 | A simple command line tool for dumping a source file using the Clang Index 13 | Library. 14 | """ 15 | 16 | def get_diag_info(diag): 17 | return { 'severity' : diag.severity, 18 | 'location' : diag.location, 19 | 'spelling' : diag.spelling, 20 | 'ranges' : diag.ranges, 21 | 'fixits' : diag.fixits } 22 | 23 | def get_cursor_id(cursor, cursor_list = []): 24 | if not opts.showIDs: 25 | return None 26 | 27 | if cursor is None: 28 | return None 29 | 30 | # FIXME: This is really slow. It would be nice if the index API exposed 31 | # something that let us hash cursors. 32 | for i,c in enumerate(cursor_list): 33 | if cursor == c: 34 | return i 35 | cursor_list.append(cursor) 36 | return len(cursor_list) - 1 37 | 38 | def get_info(node, depth=0): 39 | if opts.maxDepth is not None and depth >= opts.maxDepth: 40 | children = None 41 | else: 42 | children = [get_info(c, depth+1) 43 | for c in node.get_children()] 44 | return { 'id' : get_cursor_id(node), 45 | 'kind' : node.kind, 46 | 'usr' : node.get_usr(), 47 | 'spelling' : node.spelling, 48 | 'location' : node.location, 49 | 'extent.start' : node.extent.start, 50 | 'extent.end' : node.extent.end, 51 | 'is_definition' : node.is_definition(), 52 | 'definition id' : get_cursor_id(node.get_definition()), 53 | 'children' : children } 54 | 55 | def main(): 56 | from clang.cindex import Index 57 | from pprint import pprint 58 | 59 | from optparse import OptionParser, OptionGroup 60 | 61 | global opts 62 | 63 | parser = OptionParser("usage: %prog [options] {filename} [clang-args*]") 64 | parser.add_option("", "--show-ids", dest="showIDs", 65 | help="Compute cursor IDs (very slow)", 66 | action="store_true", default=False) 67 | parser.add_option("", "--max-depth", dest="maxDepth", 68 | help="Limit cursor expansion to depth N", 69 | metavar="N", type=int, default=None) 70 | parser.disable_interspersed_args() 71 | (opts, args) = parser.parse_args() 72 | 73 | if len(args) == 0: 74 | parser.error('invalid number arguments') 75 | 76 | index = Index.create() 77 | tu = index.parse(None, args) 78 | if not tu: 79 | parser.error("unable to load input") 80 | 81 | pprint(('diags', [get_diag_info(d) for d in tu.diagnostics])) 82 | pprint(('nodes', get_info(tu.cursor))) 83 | 84 | if __name__ == '__main__': 85 | main() 86 | 87 | -------------------------------------------------------------------------------- /python/examples/cindex/cindex-includes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | #===- cindex-includes.py - cindex/Python Inclusion Graph -----*- python -*--===# 4 | # 5 | # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 6 | # See https://llvm.org/LICENSE.txt for license information. 7 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 8 | # 9 | #===------------------------------------------------------------------------===# 10 | 11 | """ 12 | A simple command line tool for dumping a Graphviz description (dot) that 13 | describes include dependencies. 14 | """ 15 | 16 | def main(): 17 | import sys 18 | from clang.cindex import Index 19 | 20 | from optparse import OptionParser, OptionGroup 21 | 22 | parser = OptionParser("usage: %prog [options] {filename} [clang-args*]") 23 | parser.disable_interspersed_args() 24 | (opts, args) = parser.parse_args() 25 | if len(args) == 0: 26 | parser.error('invalid number arguments') 27 | 28 | # FIXME: Add an output file option 29 | out = sys.stdout 30 | 31 | index = Index.create() 32 | tu = index.parse(None, args) 33 | if not tu: 34 | parser.error("unable to load input") 35 | 36 | # A helper function for generating the node name. 37 | def name(f): 38 | if f: 39 | return "\"" + f.name + "\"" 40 | 41 | # Generate the include graph 42 | out.write("digraph G {\n") 43 | for i in tu.get_includes(): 44 | line = " "; 45 | if i.is_input_file: 46 | # Always write the input file as a node just in case it doesn't 47 | # actually include anything. This would generate a 1 node graph. 48 | line += name(i.include) 49 | else: 50 | line += '%s->%s' % (name(i.source), name(i.include)) 51 | line += "\n"; 52 | out.write(line) 53 | out.write("}\n") 54 | 55 | if __name__ == '__main__': 56 | main() 57 | 58 | -------------------------------------------------------------------------------- /scripts/data/clang_bindings.patch: -------------------------------------------------------------------------------- 1 | diff -aruN a/python/clang/cindex.py b/python/clang/cindex.py 2 | --- a/python/clang/cindex.py 2024-03-17 21:19:17 3 | +++ b/python/clang/cindex.py 2024-03-17 21:18:28 4 | @@ -1441,6 +1557,9 @@ 5 | 6 | return cursor 7 | 8 | + def __hash__(self): 9 | + return self.hash 10 | + 11 | def __eq__(self, other): 12 | return conf.lib.clang_equalCursors(self, other) 13 | 14 | @@ -3841,7 +3960,7 @@ 15 | 16 | 17 | class Config: 18 | - library_path = None 19 | + library_path = os.environ.get("LIBCLANG_LIBRARY_PATH", os.path.join(os.path.dirname(os.path.realpath(__file__)), "native")) 20 | library_file = None 21 | compatibility_check = True 22 | loaded = False 23 | @@ -3916,7 +4035,7 @@ 24 | else: 25 | file = "libclang.so" 26 | 27 | - if Config.library_path: 28 | + if Config.library_path and os.path.isfile(Config.library_path + "/" + file): 29 | file = Config.library_path + "/" + file 30 | 31 | return file 32 | -------------------------------------------------------------------------------- /scripts/update_python_clang_bindings.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | set -euo pipefail 3 | 4 | TOP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" 5 | 6 | LLVM_VERSION="${LLVM_VERSION:-19.1.3}" 7 | LLVM_URL_PREFIX="https://raw.githubusercontent.com/llvm/llvm-project/llvmorg-${LLVM_VERSION}/clang/bindings/python" 8 | 9 | LISTING=( 10 | "clang/__init__.py" 11 | "clang/cindex.py" 12 | ) 13 | 14 | function run() { 15 | echo >&2 "$*" 16 | "$@" 17 | } 18 | 19 | BINDINGS_DIR="${TOP_DIR}/python" 20 | 21 | for clang_py_file in "${LISTING[@]}"; do 22 | run curl --insecure -fsSL "${LLVM_URL_PREFIX}/${clang_py_file}" -o "${BINDINGS_DIR}/${clang_py_file}" 23 | done 24 | 25 | pushd "${TOP_DIR}" > /dev/null 26 | run patch -p1 < "${TOP_DIR}/scripts/data/clang_bindings.patch" 27 | popd > /dev/null 28 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal = 1 3 | 4 | [build_sphinx] 5 | source-dir = docs 6 | build-dir = build 7 | all_files = 1 8 | 9 | [upload_docs] 10 | upload-dir = build/html 11 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import os 5 | from setuptools import setup, find_packages 6 | 7 | 8 | with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.md'), encoding='utf-8', mode='r') as fp: 9 | long_description = fp.read() 10 | 11 | setup( 12 | name='libclang', 13 | version='19.1.3', 14 | description='Clang Python Bindings, mirrored from the official LLVM repo: https://github.com/llvm/llvm-project/tree/main/clang/bindings/python, to make the installation process easier.', 15 | long_description=long_description, 16 | long_description_content_type='text/markdown', 17 | author='Tao He', 18 | author_email='sighingnow@gmail.com', 19 | url='https://github.com/sighingnow/libclang', 20 | license='Apache License 2.0', 21 | classifiers=[ 22 | 'Development Status :: 5 - Production/Stable', 23 | 'Intended Audience :: Developers', 24 | "Topic :: Software Development :: Compilers", 25 | 'Operating System :: MacOS :: MacOS X', 26 | 'Operating System :: Microsoft :: Windows', 27 | 'Operating System :: POSIX', 28 | 'Programming Language :: Python', 29 | 'Programming Language :: Python :: 2', 30 | 'Programming Language :: Python :: 2.7', 31 | 'Programming Language :: Python :: 3', 32 | 'Programming Language :: Python :: 3.3', 33 | 'Programming Language :: Python :: 3.4', 34 | 'Programming Language :: Python :: 3.5', 35 | 'Programming Language :: Python :: 3.6', 36 | 'Programming Language :: Python :: 3.7', 37 | 'Programming Language :: Python :: 3.8', 38 | 'Programming Language :: Python :: 3.9', 39 | 'Programming Language :: Python :: 3.10', 40 | 'Programming Language :: Python :: 3.11', 41 | 'Programming Language :: Python :: 3.12', 42 | "License :: OSI Approved :: Apache Software License", 43 | ], 44 | platforms='any', 45 | keywords='Clang Python Bindings', 46 | 47 | 48 | zip_safe=False, 49 | 50 | package_dir={'': 'python'}, 51 | packages=find_packages('python'), 52 | 53 | test_suite='python/tests', 54 | 55 | project_urls={ 56 | 'Documentation': 'https://libclang.readthedocs.io', 57 | 'Source': 'https://github.com/sighingnow/libclang', 58 | 'Tracker': 'https://github.com/sighingnow/libclang/issues', 59 | }, 60 | ) 61 | -------------------------------------------------------------------------------- /setup_ext.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import os 5 | 6 | from distutils.command.build import build 7 | from distutils.dir_util import mkpath 8 | from setuptools import setup, find_packages, Extension 9 | from setuptools.command.build_ext import build_ext 10 | from wheel.bdist_wheel import get_platform, bdist_wheel 11 | 12 | 13 | def platform_ext(plat): 14 | if 'linux' in plat: 15 | return '.so' 16 | if 'macosx' in plat: 17 | return '.dylib' 18 | if 'win' in plat: 19 | return '.dll' 20 | raise RuntimeError('Invalid platform value: %s' % plat) 21 | 22 | 23 | platform = get_platform(None) 24 | 25 | 26 | class bdist_wheel_injected(bdist_wheel): 27 | def finalize_options(self): 28 | super(bdist_wheel_injected, self).finalize_options() 29 | self.root_is_pure = True 30 | 31 | def run(self): 32 | global platform 33 | platform = self.plat_name 34 | super(bdist_wheel_injected, self).run() 35 | 36 | 37 | class CopyNativeExtension(Extension): 38 | def __init__(self, name): 39 | super(CopyNativeExtension, self).__init__(name, sources=[]) 40 | 41 | 42 | class CopyNativeCommand(build_ext): 43 | def run(self): 44 | for ext in self.extensions: 45 | source_dir = './native/' 46 | target_dir = os.path.dirname(self.get_ext_fullpath(ext.name)) 47 | libname = 'libclang' + platform_ext(platform) 48 | mkpath(target_dir) 49 | self.copy_file(os.path.join(source_dir, libname), 50 | os.path.join(target_dir, libname)) 51 | 52 | with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.md'), encoding='utf-8', mode='r') as fp: 53 | long_description = fp.read() 54 | 55 | setup( 56 | name='libclang', 57 | version='19.1.3', 58 | description='Clang Python Bindings, mirrored from the official LLVM repo: https://github.com/llvm/llvm-project/tree/main/clang/bindings/python, to make the installation process easier.', 59 | long_description=long_description, 60 | long_description_content_type='text/markdown', 61 | author='Tao He', 62 | author_email='sighingnow@gmail.com', 63 | url='https://github.com/sighingnow/libclang', 64 | license='Apache License 2.0', 65 | classifiers=[ 66 | 'Development Status :: 5 - Production/Stable', 67 | 'Intended Audience :: Developers', 68 | "Topic :: Software Development :: Compilers", 69 | 'Operating System :: MacOS :: MacOS X', 70 | 'Operating System :: Microsoft :: Windows', 71 | 'Operating System :: POSIX', 72 | 'Programming Language :: Python', 73 | 'Programming Language :: Python :: 2', 74 | 'Programming Language :: Python :: 2.7', 75 | 'Programming Language :: Python :: 3', 76 | 'Programming Language :: Python :: 3.3', 77 | 'Programming Language :: Python :: 3.4', 78 | 'Programming Language :: Python :: 3.5', 79 | 'Programming Language :: Python :: 3.6', 80 | 'Programming Language :: Python :: 3.7', 81 | 'Programming Language :: Python :: 3.8', 82 | 'Programming Language :: Python :: 3.9', 83 | 'Programming Language :: Python :: 3.10', 84 | 'Programming Language :: Python :: 3.11', 85 | 'Programming Language :: Python :: 3.12', 86 | "License :: OSI Approved :: Apache Software License", 87 | ], 88 | platforms='any', 89 | keywords='Clang Python Bindings', 90 | 91 | ext_modules=[CopyNativeExtension('clang.native.clang')], 92 | cmdclass={ 93 | 'build_ext': CopyNativeCommand, 94 | 'bdist_wheel': bdist_wheel_injected, 95 | }, 96 | 97 | zip_safe=False, 98 | 99 | package_dir={'': 'python'}, 100 | packages=find_packages('python'), 101 | 102 | test_suite='python/tests', 103 | 104 | project_urls={ 105 | 'Documentation': 'https://libclang.readthedocs.io', 106 | 'Source': 'https://github.com/sighingnow/libclang', 107 | 'Tracker': 'https://github.com/sighingnow/libclang/issues', 108 | }, 109 | ) 110 | --------------------------------------------------------------------------------