1{ lib
2, buildPythonPackage
3, llvmPackages
4, setuptools
5, writeText
6}:
7
8let
9 libclang = llvmPackages.libclang;
10
11 pyproject_toml = writeText "pyproject.toml" ''
12 [build-system]
13 requires = ["setuptools>=42", "wheel"]
14 build-backend = "setuptools.build_meta"
15 '';
16
17 setup_cfg = writeText "setup.cfg" ''
18 [metadata]
19 name = clang
20 version = ${libclang.version}
21
22 [options]
23 packages = clang
24 '';
25in buildPythonPackage {
26 pname = "libclang";
27 format = "pyproject";
28
29 inherit (libclang) version src;
30
31 buildInputs = [ setuptools ];
32
33 postUnpack = ''
34 # set source root to python bindings
35 if [ -e "$sourceRoot/clang/bindings/python" ]; then
36 # LLVM 13+ puts clang sources in subdirectory instead of plain tarball
37 sourceRoot="$sourceRoot/clang/bindings/python"
38 else
39 sourceRoot="$sourceRoot/bindings/python"
40 fi
41 '';
42
43 postPatch = ''
44 # link in our own build info to build as a python package
45 ln -s ${pyproject_toml} ./pyproject.toml
46 ln -s ${setup_cfg} ./setup.cfg
47
48 # set passed libclang for runtime
49 echo 'Config.set_library_path("${lib.getLib libclang}/lib")' >>./clang/cindex.py
50 '';
51
52 meta = libclang.meta // {
53 description = "Python bindings for the C language family frontend for LLVM";
54 maintainers = with lib.maintainers; [ lilyinstarlight ];
55 };
56}