Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to libclang #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 24 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,30 @@ jobs:
- name: Test package
run: python -m pytest --forked

# Commented for now -- msys2 Clang (v15) and the clang Python package (v14) are incompatible
#
# checks_windows:
# strategy:
# fail-fast: false
# matrix:
# python-version:
# - "3.8"
# - "3.9"
# runs-on:
# - windows-latest
# runs-on: ${{ matrix.runs-on }}
# name: Test • 🐍 ${{ matrix.python-version }} • ${{matrix.runs-on}}
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-python@v4
# with:
# python-version: ${{ matrix.python-version }}
#
# - name: Install package
# run: python -m pip install .[test]
#
# - name: Install clang
# run: C:\msys64\usr\bin\pacman.exe -S clang64/mingw-w64-clang-x86_64-clang --noconfirm
#
# - name: Test package
# env:
# LIBCLANG_PATH: C:\msys64\clang64\bin\libclang.dll
# run: python -m pytest -n2
checks_windows:
strategy:
fail-fast: false
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
runs-on:
- windows-latest
runs-on: ${{ matrix.runs-on }}
name: Test • 🐍 ${{ matrix.python-version }} • ${{matrix.runs-on}}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install package
run: python -m pip install .[test]

- name: Test package
run: python -m pytest -n2

dist:
runs-on: ubuntu-latest
Expand Down
23 changes: 14 additions & 9 deletions pybind11_mkdoc/mkdoc_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def read_args(args):
sdk_dir = dev_path + 'Platforms/MacOSX.platform/Developer/SDKs'
libclang = lib_dir + 'libclang.dylib'

if os.path.exists(libclang):
if cindex.Config.library_path is None and os.path.exists(libclang):
cindex.Config.set_library_path(os.path.dirname(libclang))

if os.path.exists(sdk_dir):
Expand All @@ -285,7 +285,7 @@ def read_args(args):
else:
raise FileNotFoundError("Failed to find libclang.dll! "
"Set the LIBCLANG_PATH environment variable to provide a path to it.")
else:
elif cindex.Config.library_path is None:
library_file = ctypes.util.find_library('libclang.dll')
if library_file is not None:
cindex.Config.set_library_file(library_file)
Expand All @@ -306,7 +306,7 @@ def folder_version(d):
# Ability to override LLVM/libclang paths
if 'LLVM_DIR_PATH' in os.environ:
llvm_dir = os.environ['LLVM_DIR_PATH']
elif llvm_dir is None:
elif llvm_dir is None and cindex.Config.library_path is None:
raise FileNotFoundError(
"Failed to find a LLVM installation providing the file "
"/usr/lib{32,64}/llvm-{VER}/lib/libclang.so.1. Make sure that "
Expand All @@ -319,12 +319,12 @@ def folder_version(d):
"variables.")

if 'LIBCLANG_PATH' in os.environ:
libclang_dir = os.environ['LIBCLANG_PATH']
else:
libclang_dir = os.path.join(llvm_dir, 'lib', 'libclang.so.1')
cindex.Config.set_library_file(os.environ['LIBCLANG_PATH'])
elif cindex.Config.library_path is None:
cindex.Config.set_library_file(os.path.join(llvm_dir, 'lib',
'libclang.so.1'))

cindex.Config.set_library_file(libclang_dir)
cpp_dirs = [ ]
cpp_dirs = []

if '-stdlib=libc++' not in args:
cpp_dirs.append(max(
Expand All @@ -335,11 +335,16 @@ def folder_version(d):
glob('/usr/include/%s-linux-gnu/c++/*' % platform.machine()
), default=None, key=folder_version))
else:
if llvm_dir is None:
raise FileNotFoundError(
"-stdlib=libc++ has been specified, but no LLVM "
"installation have been found on the system.")

cpp_dirs.append(os.path.join(llvm_dir, 'include', 'c++', 'v1'))

if 'CLANG_INCLUDE_DIR' in os.environ:
cpp_dirs.append(os.environ['CLANG_INCLUDE_DIR'])
else:
elif llvm_dir is not None:
cpp_dirs.append(max(
glob(os.path.join(llvm_dir, 'lib', 'clang', '*', 'include')
), default=None, key=folder_version))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ classifiers = [
"Operating System :: POSIX",
"Operating System :: MacOS"
]
requires = ["clang"]
requires = ["libclang"]
requires-python = ">=3.6"

[tool.flit.scripts]
Expand Down