depot/third_party/nixpkgs/pkgs/development/python-modules/libclang/default.nix
Default email f34ce41345 Project import generated by Copybara.
GitOrigin-RevId: b73c2221a46c13557b1b3be9c2070cc42cf01eb3
2024-07-27 08:49:29 +02:00

58 lines
1.3 KiB
Nix

{
lib,
buildPythonPackage,
llvmPackages,
setuptools,
writeText,
}:
let
libclang = llvmPackages.libclang;
pyproject_toml = writeText "pyproject.toml" ''
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"
'';
setup_cfg = writeText "setup.cfg" ''
[metadata]
name = clang
version = ${libclang.version}
[options]
packages = clang
'';
in
buildPythonPackage {
pname = "libclang";
format = "pyproject";
inherit (libclang) version src;
buildInputs = [ setuptools ];
postUnpack = ''
# set source root to python bindings
if [ -e "$sourceRoot/clang/bindings/python" ]; then
# LLVM 13+ puts clang sources in subdirectory instead of plain tarball
sourceRoot="$sourceRoot/clang/bindings/python"
else
sourceRoot="$sourceRoot/bindings/python"
fi
'';
postPatch = ''
# link in our own build info to build as a python package
ln -s ${pyproject_toml} ./pyproject.toml
ln -s ${setup_cfg} ./setup.cfg
# set passed libclang for runtime
echo 'Config.set_library_path("${lib.getLib libclang}/lib")' >>./clang/cindex.py
'';
meta = libclang.meta // {
description = "Python bindings for the C language family frontend for LLVM";
maintainers = with lib.maintainers; [ ];
};
}