about summary refs log tree commit diff
path: root/pkgs/development/libraries
diff options
context:
space:
mode:
authorSandro <sandro.jaeckel@gmail.com>2021-04-23 06:36:09 +0200
committerGitHub <noreply@github.com>2021-04-23 06:36:09 +0200
commit2ce1d7a4089320e1d0ec255f2a1386db11411f46 (patch)
treeb50d4c92cf7ab50365acfe350e9b3db7d467f4ac /pkgs/development/libraries
parent1b1cd0098cf4661a2139ea3b6c267208bbb689b3 (diff)
parentfd21963e8b89571b62fe183d76a0ab7f94faba70 (diff)
Merge pull request #119997 from DeterminateSystems/lief
lief: build from source and enable python bindings
Diffstat (limited to 'pkgs/development/libraries')
-rw-r--r--pkgs/development/libraries/lief/default.nix64
1 files changed, 60 insertions, 4 deletions
diff --git a/pkgs/development/libraries/lief/default.nix b/pkgs/development/libraries/lief/default.nix
index 953eee3b8bdb5..872327ed4b8ff 100644
--- a/pkgs/development/libraries/lief/default.nix
+++ b/pkgs/development/libraries/lief/default.nix
@@ -1,8 +1,64 @@
-{ lib, fetchzip }:
+{ lib
+, stdenv
+, fetchFromGitHub
+, python
+, cmake
+}:
 
-fetchzip {
-  url = "https://github.com/lief-project/LIEF/releases/download/0.9.0/LIEF-0.9.0-Linux.tar.gz";
-  sha256 = "1c47hwd00bp4mqd4p5b6xjfl89c3wwk9ccyc3a2gk658250g2la6";
+let
+  pyEnv = python.withPackages (ps: [ ps.setuptools ]);
+in
+stdenv.mkDerivation rec {
+  pname = "lief";
+  version = "0.11.4";
+
+  src = fetchFromGitHub {
+    owner = "lief-project";
+    repo = "LIEF";
+    rev = version;
+    sha256 = "DgsTrJ2+zdXJK6CdDOan7roakaaxQiwrVeiQnzJnk0A=";
+  };
+
+  outputs = [ "out" "py" ];
+
+  nativeBuildInputs = [
+    cmake
+  ];
+
+  # Not a propagatedBuildInput because only the $py output needs it; $out is
+  # just the library itself (e.g. C/C++ headers).
+  buildInputs = [
+    python
+  ];
+
+  dontUseCmakeConfigure = true;
+
+  buildPhase = ''
+    runHook preBuild
+
+    substituteInPlace setup.py \
+      --replace 'cmake_args = []' "cmake_args = [ \"-DCMAKE_INSTALL_PREFIX=$prefix\" ]"
+    ${pyEnv.interpreter} setup.py --sdk build --parallel=$NIX_BUILD_CORES
+
+    runHook postBuild
+  '';
+
+  # I was unable to find a way to build the library itself and have it install
+  # to $out, while also installing the Python bindings to $py without building
+  # the project twice (using cmake), so this is the best we've got. It uses
+  # something called CPack to create the tarball, but it's not obvious to me
+  # *how* that happens, or how to intercept it to just get the structured
+  # library output.
+  installPhase = ''
+    runHook preInstall
+
+    mkdir -p $out $py/nix-support
+    echo "${python}" >> $py/nix-support/propagated-build-inputs
+    tar xf build/*.tar.gz --directory $out --strip-components 1
+    ${pyEnv.interpreter} setup.py install --skip-build --root=/ --prefix=$py
+
+    runHook postInstall
+  '';
 
   meta = with lib; {
     description = "Library to Instrument Executable Formats";