Skip to content

Commit 227d8ba

Browse files
cornahenryiii
authored andcommitted
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.
1 parent f81b092 commit 227d8ba

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

pybind11_mkdoc/mkdoc_lib.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def read_args(args):
270270
sdk_dir = dev_path + 'Platforms/MacOSX.platform/Developer/SDKs'
271271
libclang = lib_dir + 'libclang.dylib'
272272

273-
if os.path.exists(libclang):
273+
if cindex.Config.library_path is None and os.path.exists(libclang):
274274
cindex.Config.set_library_path(os.path.dirname(libclang))
275275

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

321321
if 'LIBCLANG_PATH' in os.environ:
322-
libclang_dir = os.environ['LIBCLANG_PATH']
323-
else:
324-
libclang_dir = os.path.join(llvm_dir, 'lib', 'libclang.so.1')
322+
cindex.Config.set_library_file(os.environ['LIBCLANG_PATH'])
323+
elif cindex.Config.library_path is None:
324+
cindex.Config.set_library_file(os.path.join(llvm_dir, 'lib',
325+
'libclang.so.1'))
325326

326-
cindex.Config.set_library_file(libclang_dir)
327-
cpp_dirs = [ ]
327+
cpp_dirs = []
328328

329329
if '-stdlib=libc++' not in args:
330330
cpp_dirs.append(max(
@@ -335,11 +335,16 @@ def folder_version(d):
335335
glob('/usr/include/%s-linux-gnu/c++/*' % platform.machine()
336336
), default=None, key=folder_version))
337337
else:
338+
if llvm_dir is None:
339+
raise FileNotFoundError(
340+
"-stdlib=libc++ has been specified, but no LLVM "
341+
"installation have been found on the system.")
342+
338343
cpp_dirs.append(os.path.join(llvm_dir, 'include', 'c++', 'v1'))
339344

340345
if 'CLANG_INCLUDE_DIR' in os.environ:
341346
cpp_dirs.append(os.environ['CLANG_INCLUDE_DIR'])
342-
else:
347+
elif llvm_dir is not None:
343348
cpp_dirs.append(max(
344349
glob(os.path.join(llvm_dir, 'lib', 'clang', '*', 'include')
345350
), default=None, key=folder_version))

0 commit comments

Comments
 (0)