From 00b5399a81a700e4a42206b1b1d88bb2d62e8ddf Mon Sep 17 00:00:00 2001 From: Nicola Corna Date: Tue, 20 Jun 2023 22:19:35 +0200 Subject: [PATCH 1/3] Add support for the libclang package A newer package provigind the python libclang bindings is available, called "libclang". Unlike "clang", this package ships the libclang library, removing the dependency from the system's one. This commit adds support for it, using the libclang's builtin library if found and if LIBCLANG_PATH and LLVM_DIR_PATH are not defined. As libclang does not ship the clang standard library headers, some system headers may not be found (like stddef.h), but the documentation generation completes successfully anyways. --- pybind11_mkdoc/mkdoc_lib.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pybind11_mkdoc/mkdoc_lib.py b/pybind11_mkdoc/mkdoc_lib.py index 0d591d4..cbc21b2 100755 --- a/pybind11_mkdoc/mkdoc_lib.py +++ b/pybind11_mkdoc/mkdoc_lib.py @@ -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): @@ -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) @@ -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 " @@ -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( @@ -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)) From cd1abe46301105b70af838f9dc62d7cf7ce6561c Mon Sep 17 00:00:00 2001 From: Nicola Corna Date: Tue, 20 Jun 2023 22:19:40 +0200 Subject: [PATCH 2/3] Replace clang with libclang --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4139ffb..77d29e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ classifiers = [ "Operating System :: POSIX", "Operating System :: MacOS" ] -requires = ["clang"] +requires = ["libclang"] requires-python = ">=3.6" [tool.flit.scripts] From e71d15f12f4c6eee1d04c724cb5946a5d8ef149d Mon Sep 17 00:00:00 2001 From: Nicola Corna Date: Tue, 11 Jul 2023 06:41:34 +0200 Subject: [PATCH 3/3] Re-enable Windows CI job --- .github/workflows/ci.yml | 53 ++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 177c93d..ffd536e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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