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