Unverified Commit 09ab507c authored by Lily Foster's avatar Lily Foster
Browse files

python3Packages.libclang: init

parent a0923a3f
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
{ 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; [ lilyinstarlight ];
  };
}
+4 −4
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
, setuptools
, toposort
, wheezy-template
, libclang
, llvmPackages
, gst_all_1
}:

@@ -100,9 +100,9 @@ buildPythonApplication rec {
  postPatch = ''
    substituteInPlace hotdoc/extensions/c/c_extension.py \
      --replace "shutil.which('llvm-config')" 'True' \
      --replace "subprocess.check_output(['llvm-config', '--version']).strip().decode()" '"${libclang.version}"' \
      --replace "subprocess.check_output(['llvm-config', '--prefix']).strip().decode()" '"${libclang.lib}"' \
      --replace "subprocess.check_output(['llvm-config', '--libdir']).strip().decode()" '"${libclang.lib}/lib"'
      --replace "subprocess.check_output(['llvm-config', '--version']).strip().decode()" '"${llvmPackages.libclang.version}"' \
      --replace "subprocess.check_output(['llvm-config', '--prefix']).strip().decode()" '"${llvmPackages.libclang.lib}"' \
      --replace "subprocess.check_output(['llvm-config', '--libdir']).strip().decode()" '"${llvmPackages.libclang.lib}/lib"'
  '';

  # Make pytest run from a temp dir to have it pick up installed package for cmark
+2 −0
Original line number Diff line number Diff line
@@ -6121,6 +6121,8 @@ self: super: with self; {
    inherit (pkgs) libasyncns;
  };
  libclang = callPackage ../development/python-modules/libclang { };
  libcloud = callPackage ../development/python-modules/libcloud { };
  libcst = callPackage ../development/python-modules/libcst { };