From 0122eeadf7f5ef538ba86e3b33a9a8eb58f68390 Mon Sep 17 00:00:00 2001 From: Quentin Kaiser Date: Mon, 16 Oct 2023 17:31:56 +0200 Subject: [PATCH] chore(deps): adapt nix derivation for lief. Adapted CXX flags so warnings are no longer displayed when building with clang++ on OSX. The nixpkgs derivation[0] for lief made use of "/build/source" symlink, which is not available on Darwin. build commands are taken from LIEF build scripts [1] [0]: https://github.com/NixOS/nixpkgs/blob/8efd5d1e283604f75a808a20e6cde0ef313d07d4/pkgs/development/libraries/lief/default.nix#L37 [1]: https://github.com/lief-project/LIEF/tree/master/scripts --- nix/_sources/generated.json | 20 +++++++++++ nix/_sources/generated.nix | 11 +++++++ nvfetcher.toml | 4 +++ overlay.nix | 66 ++++++++++++++++++++++++++++++++----- 4 files changed, 92 insertions(+), 9 deletions(-) diff --git a/nix/_sources/generated.json b/nix/_sources/generated.json index b40a3d51d2..1c3e7b022c 100644 --- a/nix/_sources/generated.json +++ b/nix/_sources/generated.json @@ -14,6 +14,26 @@ }, "version": "0.4.5" }, + "lief": { + "cargoLocks": null, + "date": null, + "extract": null, + "name": "lief", + "passthru": null, + "pinned": false, + "src": { + "deepClone": false, + "fetchSubmodules": false, + "leaveDotGit": false, + "name": null, + "owner": "lief-project", + "repo": "LIEF", + "rev": "0.13.2", + "sha256": "sha256-lH4SqwPB2Jp/wUI2Cll67PQbHbwMqpNuLy/ei8roiHg=", + "type": "github" + }, + "version": "0.13.2" + }, "lzallright": { "cargoLocks": { "Cargo.lock": [ diff --git a/nix/_sources/generated.nix b/nix/_sources/generated.nix index 2191a8280c..8d8619a003 100644 --- a/nix/_sources/generated.nix +++ b/nix/_sources/generated.nix @@ -9,6 +9,17 @@ sha256 = "sha256-+cPOzzO3bCQAu8LrbjUJ5S/SR5OFitOYLIu5L9t/q+k="; }; }; + lief = { + pname = "lief"; + version = "0.13.2"; + src = fetchFromGitHub { + owner = "lief-project"; + repo = "LIEF"; + rev = "0.13.2"; + fetchSubmodules = false; + sha256 = "sha256-lH4SqwPB2Jp/wUI2Cll67PQbHbwMqpNuLy/ei8roiHg="; + }; + }; lzallright = { pname = "lzallright"; version = "v0.2.3"; diff --git a/nvfetcher.toml b/nvfetcher.toml index 66d9c20a7b..998e279575 100644 --- a/nvfetcher.toml +++ b/nvfetcher.toml @@ -18,3 +18,7 @@ fetch.pypi = "treelib" [pyfatfs] src.pypi = "pyfatfs" fetch.pypi = "pyfatfs" + +[lief] +src.github_tag = "lief-project/LIEF" +fetch.github = "lief-project/LIEF" diff --git a/overlay.nix b/overlay.nix index 1b19017a5a..d303d4b327 100644 --- a/overlay.nix +++ b/overlay.nix @@ -11,18 +11,66 @@ inputs: final: prev: hardeningDisable = (super.hardeningDisable or [ ]) ++ [ "fortify3" ]; }); - # Lief 12.3 incompatibility with Cmake 3.26 + # Own package updated independently of nixpkgs + jefferson = final.callPackage ./nix/jefferson { }; + lief = prev.lief.overrideAttrs (super: { - postPatch = '' - substituteInPlace setup.py \ - --replace \ - 'cmake_args = ["-DLIEF_FORCE_API_EXPORTS=ON", "-DLIEF_PYTHON_API=on"]' \ - 'cmake_args = ["-DLIEF_FORCE_API_EXPORTS=ON", "-DLIEF_PYTHON_API=on", "-DLIEF_EXAMPLES=off"]' + + outputs = [ "out" "py" ]; + + nativeBuildInputs = [ + final.cmake + final.ninja + ]; + + # Not a propagatedBuildInput because only the $py output needs it; $out is + # just the library itself (e.g. C/C++ headers). + buildInputs = [ + final.python3 + final.python3.pkgs.setuptools + final.python3.pkgs.tomli + ]; + + CXXFLAGS = final.lib.optional final.stdenv.isLinux [ "-ffunction-sections" "-fdata-sections" "-fvisibility-inlines-hidden" "-static-libstdc++" "-static-libgcc" ] ++ final.lib.optional final.stdenv.isDarwin [ "-faligned-allocation" "-fno-aligned-new" "-fvisibility=hidden" ]; + + CFLAGS = final.lib.optional final.stdenv.isLinux [ "-ffunction-sections" "-fdata-sections" "-static-libstdc++" "-static-libgcc" ]; + LDFLAGS = final.lib.optional final.stdenv.isLinux [ "-Wl,--gc-sections" "-Wl,--exclude-libs,ALL" ]; + + + dontUseCmakeConfigure = true; + + buildPhase = '' + runHook preBuild + + mkdir -p build + cmake -S . -B build -GNinja -DCMAKE_LINK_WHAT_YOU_USE=on -DBUILD_SHARED_LIBS=on -DLIEF_INSTALL_COMPILED_EXAMPLES=off -DCMAKE_INSTALL_PREFIX=$out -DCMAKE_BUILD_TYPE=Release + + cmake --build build --target all + + runHook postBuild ''; - }); - # Own package updated independently of nixpkgs - jefferson = final.callPackage ./nix/jefferson { }; + postBuild = '' + pushd api/python + ${final.python3.interpreter} setup.py build --parallel=$NIX_BUILD_CORES + popd + ''; + + installPhase = '' + runHook preInstall + + cmake --build build --target install + + runHook postInstall + ''; + + postInstall = '' + pushd api/python + ${final.python3.interpreter} setup.py install --skip-build --root=/ --prefix=$py + popd + ''; + + }); python3 = prev.python3 // { pkgs = prev.python3.pkgs.overrideScope