Skip to content

Commit

Permalink
Nix buildIdris improvement: precisely target executable (#3330)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mattpolzin authored Jun 26, 2024
1 parent 3649821 commit 7d33c04
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
28 changes: 19 additions & 9 deletions nix/buildIdris.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, lib, idris2Version, idris2, support, makeWrapper }:
{ stdenv, lib, idris2Version, idris2, jq, support, makeWrapper }:
# Usage: let
# pkg = idris2Pkg.buildIdris {
# src = ...;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
'';
Expand Down
9 changes: 7 additions & 2 deletions nix/package.nix
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 ]
Expand Down
7 changes: 6 additions & 1 deletion nix/support.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down

0 comments on commit 7d33c04

Please sign in to comment.