From 0a3480974cb468fb4ffe4d658edb5a44c090958c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= <2642849+elopez@users.noreply.github.com> Date: Thu, 4 Jan 2024 05:55:08 -0300 Subject: [PATCH] echidna-redistributable: fix static builds (#1156) * echidna-redistributable: alert if nix deps remain on binary * echidna-redistributable: link cxxabi as well on darwin * echidna-redistributable: use pkgsStatic for haskell operations --- flake.nix | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 00f6a1464..9574993b1 100644 --- a/flake.nix +++ b/flake.nix @@ -78,6 +78,7 @@ "--extra-lib-dirs=${stripDylib (ncurses-static)}/lib" ] ++ (if stdenv.hostPlatform.isDarwin then [ "--extra-lib-dirs=${stripDylib (libiconv.override { enableStatic = true; })}/lib" + "--extra-lib-dirs=${stripDylib (libcxxabi)}/lib" ] else []))) (haskell.lib.compose.enableCabalFlag "static") ]; @@ -97,22 +98,28 @@ in if pkgs.stdenv.isLinux then pkgs.runCommand "echidna-stripNixRefs" {} '' mkdir -p $out/bin - cp ${pkgs.haskell.lib.dontCheck echidna-static}/bin/echidna $out/bin/ + cp ${pkgsStatic.haskell.lib.dontCheck echidna-static}/bin/echidna $out/bin/ # fix TERMINFO path in ncurses ${perl} -i -pe 's#(${ncurses-static}/share/terminfo)#"/usr/share/terminfo" . "\x0" x (length($1) - 19)#e' $out/bin/echidna chmod 555 $out/bin/echidna '' else pkgs.runCommand "echidna-stripNixRefs" {} '' mkdir -p $out/bin - cp ${pkgs.haskell.lib.dontCheck echidna-static}/bin/echidna $out/bin/ + cp ${pkgsStatic.haskell.lib.dontCheck echidna-static}/bin/echidna $out/bin/ # get the list of dynamic libs from otool and tidy the output libs=$(${otool} -L $out/bin/echidna | tail -n +2 | sed 's/^[[:space:]]*//' | cut -d' ' -f1) # get the path for libcxx - cxx=$(echo "$libs" | ${grep} '^/nix/store/.*-libcxx') + cxx=$(echo "$libs" | ${grep} '^/nix/store/.*-libcxx-') # rewrite /nix/... library paths to point to /usr/lib chmod 777 $out/bin/echidna ${install_name_tool} -change "$cxx" /usr/lib/libc++.1.dylib $out/bin/echidna # fix TERMINFO path in ncurses ${perl} -i -pe 's#(${ncurses-static}/share/terminfo)#"/usr/share/terminfo" . "\x0" x (length($1) - 19)#e' $out/bin/echidna + # check that no nix deps remain + nixdeps=$(${otool} -L $out/bin/echidna | tail -n +2 | { ${grep} /nix/store -c || test $? = 1; }) + if [ ! "$nixdeps" = "0" ]; then + echo "Nix deps remain in redistributable binary!" + exit 255 + fi # re-sign binary CODESIGN_ALLOCATE=${codesign_allocate} ${codesign} -f -s - $out/bin/echidna chmod 555 $out/bin/echidna