From 7d33c0438a5f23f3d1ebcb04c2a78b3ea7c1c913 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Tue, 25 Jun 2024 19:03:54 -0500 Subject: [PATCH] Nix `buildIdris` improvement: precisely target executable (#3330) * don't assume all .so files are the exectuable * don't rebuild support or the compiler if only the buildIdris nix function has changed * fixes to nix buildIdris function --- nix/buildIdris.nix | 28 +++++++++++++++++++--------- nix/package.nix | 9 +++++++-- nix/support.nix | 7 ++++++- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/nix/buildIdris.nix b/nix/buildIdris.nix index 70cf387239..05c3cd7f13 100644 --- a/nix/buildIdris.nix +++ b/nix/buildIdris.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, idris2Version, idris2, support, makeWrapper }: +{ stdenv, lib, idris2Version, idris2, jq, support, makeWrapper }: # Usage: let # pkg = idris2Pkg.buildIdris { # src = ...; @@ -34,7 +34,7 @@ let pname = ipkgName; inherit version; src = src; - nativeBuildInputs = [ idris2 makeWrapper ] ++ attrs.nativeBuildInputs or []; + nativeBuildInputs = [ idris2 makeWrapper jq ] ++ attrs.nativeBuildInputs or []; buildInputs = propagatedIdrisLibraries ++ attrs.buildInputs or []; IDRIS2_PACKAGE_PATH = libDirs; @@ -67,15 +67,25 @@ in rec { # ^ remove after Idris2 0.8.0 is released. will be superfluous: # https://github.com/idris-lang/Idris2/pull/3189 else + executable="$(idris2 --dump-ipkg-json ${ipkgFileName} | jq -r '.executable').so" + cd build/exec/*_app - rm -f ./libidris2_support.so - for file in *.so; do - bin_name="''${file%.so}" - mv -- "$file" "$out/bin/$bin_name" - wrapProgram "$out/bin/$bin_name" \ - --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ support ]} \ - --prefix DYLD_LIBRARY_PATH : ${lib.makeLibraryPath [ support ]} + + rm -f ./libidris2_support.{so,dylib} + + bin_name="''${executable%.so}" + mv -- "$executable" "$out/bin/$bin_name" + + # remaining .so or .dylib files can be moved to lib directory + for file in *{.so,.dylib}; do + mkdir -p $out/lib + mv -- "$file" "$out/lib/" done + + wrapProgram "$out/bin/$bin_name" \ + --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ support ]}:$out/lib \ + --prefix DYLD_LIBRARY_PATH : ${lib.makeLibraryPath [ support ]}:$out/lib + fi runHook postInstall ''; diff --git a/nix/package.nix b/nix/package.nix index 7e31864b79..2ee33cfbde 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, chez, clang, gmp, fetchFromGitHub, makeWrapper, installShellFiles, support, idris2Version +{ stdenv, lib, chez, clang, gmp, makeWrapper, installShellFiles, support, idris2Version , srcRev, gambit, nodejs, zsh, idris2Bootstrap ? null }: # Uses scheme to bootstrap the build of idris2 @@ -11,7 +11,12 @@ stdenv.mkDerivation rec { pname = "idris2"; version = idris2Version; - src = ../.; + # we don't rebuild Idris when changing the buildIdris nix + # function: + src = with lib.fileset; toSource { + root = ../.; + fileset = difference ../. ../nix/buildIdris.nix; + }; strictDeps = true; nativeBuildInputs = [ makeWrapper installShellFiles clang chez ] diff --git a/nix/support.nix b/nix/support.nix index 3335373323..b21c650977 100644 --- a/nix/support.nix +++ b/nix/support.nix @@ -6,7 +6,12 @@ stdenv'.mkDerivation rec { pname = "libidris2_support"; version = idris2Version; - src = ../.; + # we don't rebuild Idris when changing the buildIdris nix + # function: + src = with lib.fileset; toSource { + root = ../.; + fileset = difference ../. ../nix/buildIdris.nix; + }; strictDeps = true; buildInputs = [ gmp ];