git.iko.soy/typeable/nixpkgs
on master help sign in
lief: build from source and enable python bindings
commitfd21963e8b89571b62fe183d76a0ab7f94faba70 authorCole Helbling <cole.e.helbling@outlook.com> dateFri 16 Apr 2021, 13:25 (6 years ago) parent294d192
3 files changed+67−5
pkgs/development/libraries/lief/default.nix+60−4 pkgs/top-level/all-packages.nix+3−1 pkgs/top-level/python-packages.nix+4
pkgs/development/libraries/lief/default.nix+60−4
@@ -1,8 +1,64 @@
1−{ lib, fetchzip }:
1+{ lib
2+, stdenv
3+, fetchFromGitHub
4+, python
5+, cmake
6+}:
27
3−fetchzip {
4− url = "https://github.com/lief-project/LIEF/releases/download/0.9.0/LIEF-0.9.0-Linux.tar.gz";
5− sha256 = "1c47hwd00bp4mqd4p5b6xjfl89c3wwk9ccyc3a2gk658250g2la6";
8+let
9+ pyEnv = python.withPackages (ps: [ ps.setuptools ]);
10+in
11+stdenv.mkDerivation rec {
12+ pname = "lief";
13+ version = "0.11.4";
14+
15+ src = fetchFromGitHub {
16+ owner = "lief-project";
17+ repo = "LIEF";
18+ rev = version;
19+ sha256 = "DgsTrJ2+zdXJK6CdDOan7roakaaxQiwrVeiQnzJnk0A=";
20+ };
21+
22+ outputs = [ "out" "py" ];
23+
24+ nativeBuildInputs = [
25+ cmake
26+ ];
27+
28+ # Not a propagatedBuildInput because only the $py output needs it; $out is
29+ # just the library itself (e.g. C/C++ headers).
30+ buildInputs = [
31+ python
32+ ];
33+
34+ dontUseCmakeConfigure = true;
35+
36+ buildPhase = ''
37+ runHook preBuild
38+
39+ substituteInPlace setup.py \
40+ --replace 'cmake_args = []' "cmake_args = [ \"-DCMAKE_INSTALL_PREFIX=$prefix\" ]"
41+ ${pyEnv.interpreter} setup.py --sdk build --parallel=$NIX_BUILD_CORES
42+
43+ runHook postBuild
44+ '';
45+
46+ # I was unable to find a way to build the library itself and have it install
47+ # to $out, while also installing the Python bindings to $py without building
48+ # the project twice (using cmake), so this is the best we've got. It uses
49+ # something called CPack to create the tarball, but it's not obvious to me
50+ # *how* that happens, or how to intercept it to just get the structured
51+ # library output.
52+ installPhase = ''
53+ runHook preInstall
54+
55+ mkdir -p $out $py/nix-support
56+ echo "${python}" >> $py/nix-support/propagated-build-inputs
57+ tar xf build/*.tar.gz --directory $out --strip-components 1
58+ ${pyEnv.interpreter} setup.py install --skip-build --root=/ --prefix=$py
59+
60+ runHook postInstall
61+ '';
662
763 meta = with lib; {
864 description = "Library to Instrument Executable Formats";
pkgs/top-level/all-packages.nix+3−1
@@ -2691,7 +2691,9 @@ in
26912691
26922692 lexicon = callPackage ../tools/admin/lexicon { };
26932693
2694− lief = callPackage ../development/libraries/lief {};
2694+ lief = callPackage ../development/libraries/lief {
2695+ python = python3;
2696+ };
26952697
26962698 libnbd = callPackage ../development/libraries/libnbd { };
26972699
pkgs/top-level/python-packages.nix+4
@@ -3996,6 +3996,10 @@ in {
39963996
39973997 license-expression = callPackage ../development/python-modules/license-expression { };
39983998
3999+ lief = (toPythonModule (pkgs.lief.override {
4000+ inherit python;
4001+ })).py;
4002+
39994003 lightblue = callPackage ../development/python-modules/lightblue { };
40004004
40014005 lightgbm = callPackage ../development/python-modules/lightgbm { };