|
27 | 27 |
|
28 | 28 | # prefer musl on Linux, static glibc + threading does not work properly |
29 | 29 | # TODO: maybe only override it for echidna-redistributable? |
30 | | - pkgsStatic = if pkgs.stdenv.hostPlatform.isLinux then pkgs.pkgsStatic else pkgs; |
| 30 | + pkgsGHC = if pkgs.stdenv.hostPlatform.isLinux then pkgs.pkgsMusl else pkgs; |
| 31 | + pkgsDeps = if pkgs.stdenv.hostPlatform.isLinux then pkgs.pkgsStatic else pkgs; |
31 | 32 | # this is not perfect for development as it hardcodes solc to 0.5.7, test suite runs fine though |
32 | 33 | # 0.5.7 is not available on aarch64 darwin so alternatively pick 0.8.5 |
33 | 34 | solc = solc-pkgs.mkDefault pkgs (pkgs.solc_0_5_7 or pkgs.solc_0_8_5); |
34 | 35 |
|
35 | | - secp256k1-static = pkgsStatic.secp256k1.overrideAttrs (attrs: { |
| 36 | + secp256k1-static = pkgsDeps.secp256k1.overrideAttrs (attrs: { |
36 | 37 | configureFlags = attrs.configureFlags ++ [ "--enable-static" ]; |
37 | 38 | }); |
38 | 39 |
|
39 | | - ncurses-static = pkgsStatic.ncurses.override { enableStatic = true; }; |
| 40 | + ncurses-static = pkgsDeps.ncurses.override { enableStatic = true; }; |
40 | 41 |
|
41 | | - hsPkgs = ps : |
42 | | - ps.haskellPackages.override { |
43 | | - overrides = hfinal: hprev: { |
44 | | - with-utf8 = |
45 | | - if (with ps.stdenv; hostPlatform.isDarwin && hostPlatform.isx86) |
46 | | - then ps.haskell.lib.compose.overrideCabal (_ : { extraLibraries = [ps.libiconv]; }) hprev.with-utf8 |
47 | | - else hprev.with-utf8; |
48 | | - # TODO: temporary fix for static build which is still on 9.4 |
49 | | - witch = ps.haskell.lib.doJailbreak hprev.witch; |
50 | | - }; |
51 | | - }; |
| 42 | + dependencies-static = with pkgsDeps; [ |
| 43 | + (gmp.override { withStatic = true; }) |
| 44 | + secp256k1-static |
| 45 | + (libff.override { enableStatic = true; }) |
| 46 | + ncurses-static |
| 47 | + ] ++ lib.optionals (!pkgs.stdenv.hostPlatform.isDarwin) [ |
| 48 | + # darwin provides these |
| 49 | + (zlib.override { static = true; shared = false; }) |
| 50 | + (libffi.overrideAttrs (_: { dontDisableStatic = true; })) |
| 51 | + ]; |
52 | 52 |
|
53 | | - hevm = pkgs: pkgs.lib.pipe ((hsPkgs pkgs).callCabal2nix "hevm" (pkgs.fetchFromGitHub { |
54 | | - owner = "ethereum"; |
55 | | - repo = "hevm"; |
56 | | - rev = "7fa6a959bea935f476100037aa84531523cd9d8a"; |
57 | | - sha256 = "sha256-4dTXB/3F3180L5tBhDVky2A6irbGDN4rZHdnDdc+j64="; |
58 | | - }) { secp256k1 = pkgs.secp256k1; }) |
59 | | - ([ |
60 | | - pkgs.haskell.lib.compose.dontCheck |
61 | | - ]); |
| 53 | + hevm = pkgs: pkgs.lib.pipe |
| 54 | + (pkgs.haskellPackages.callCabal2nix "hevm" (pkgs.fetchFromGitHub { |
| 55 | + owner = "ethereum"; |
| 56 | + repo = "hevm"; |
| 57 | + rev = "7fa6a959bea935f476100037aa84531523cd9d8a"; |
| 58 | + sha256 = "sha256-4dTXB/3F3180L5tBhDVky2A6irbGDN4rZHdnDdc+j64="; |
| 59 | + }) { secp256k1 = pkgs.secp256k1; }) |
| 60 | + ([ |
| 61 | + pkgs.haskell.lib.compose.dontCheck |
| 62 | + ]); |
62 | 63 |
|
63 | 64 | echidna = pkgs: with pkgs; lib.pipe |
64 | | - ((hsPkgs pkgs).callCabal2nix "echidna" ./. { hevm = hevm pkgs; }) |
| 65 | + (haskellPackages.callCabal2nix "echidna" ./. { hevm = hevm pkgs; }) |
65 | 66 | ([ |
66 | 67 | # FIXME: figure out solc situation, it conflicts with the one from |
67 | 68 | # solc-select that is installed with slither, disable tests in the meantime |
|
70 | 71 | (haskell.lib.compose.disableCabalFlag "static") |
71 | 72 | ]); |
72 | 73 |
|
73 | | - echidna-static = with pkgsStatic; lib.pipe |
74 | | - (echidna pkgsStatic) |
| 74 | + echidna-static = with pkgsGHC; lib.pipe |
| 75 | + (echidna pkgsGHC) |
75 | 76 | [ |
76 | 77 | (haskell.lib.compose.appendConfigureFlags |
77 | | - [ |
78 | | - "--extra-lib-dirs=${stripDylib (gmp.override { withStatic = true; })}/lib" |
79 | | - "--extra-lib-dirs=${stripDylib secp256k1-static}/lib" |
80 | | - "--extra-lib-dirs=${stripDylib (libff.override { enableStatic = true; })}/lib" |
81 | | - "--extra-lib-dirs=${zlib.override { static = true; shared = false; }}/lib" |
82 | | - "--extra-lib-dirs=${stripDylib (libffi.overrideAttrs (_: { dontDisableStatic = true; }))}/lib" |
83 | | - "--extra-lib-dirs=${stripDylib (ncurses-static)}/lib" |
84 | | - ]) |
| 78 | + (map (drv: "--extra-lib-dirs=${stripDylib drv}/lib") dependencies-static)) |
85 | 79 | (haskell.lib.compose.enableCabalFlag "static") |
86 | 80 | ]; |
87 | 81 |
|
|
100 | 94 | in if pkgs.stdenv.isLinux |
101 | 95 | then pkgs.runCommand "echidna-stripNixRefs" {} '' |
102 | 96 | mkdir -p $out/bin |
103 | | - cp ${pkgsStatic.haskell.lib.dontCheck echidna-static}/bin/echidna $out/bin/ |
| 97 | + cp ${pkgs.haskell.lib.dontCheck echidna-static}/bin/echidna $out/bin/ |
104 | 98 | # fix TERMINFO path in ncurses |
105 | 99 | ${perl} -i -pe 's#(${ncurses-static}/share/terminfo)#"/etc/terminfo:/lib/terminfo:/usr/share/terminfo:/usr/lib/terminfo" . "\x0" x (length($1) - 65)#e' $out/bin/echidna |
106 | 100 | chmod 555 $out/bin/echidna |
107 | 101 | '' else pkgs.runCommand "echidna-stripNixRefs" {} '' |
108 | 102 | mkdir -p $out/bin |
109 | | - cp ${pkgsStatic.haskell.lib.dontCheck echidna-static}/bin/echidna $out/bin/ |
110 | | - # get the list of dynamic libs from otool and tidy the output |
111 | | - libs=$(${otool} -L $out/bin/echidna | tail -n +2 | sed 's/^[[:space:]]*//' | cut -d' ' -f1) |
112 | | - # get the path for libcxx |
113 | | - cxx=$(echo "$libs" | ${grep} '^/nix/store/.*/libc++\.') |
114 | | - cxxabi=$(echo "$libs" | ${grep} '^/nix/store/.*/libc++abi\.') |
115 | | - iconv=$(echo "$libs" | ${grep} '^/nix/store/.*/libiconv\.') |
| 103 | + cp ${pkgs.haskell.lib.dontCheck echidna-static}/bin/echidna $out/bin/ |
116 | 104 | # rewrite /nix/... library paths to point to /usr/lib |
117 | | - chmod 777 $out/bin/echidna |
118 | | - ${install_name_tool} -change "$cxx" /usr/lib/libc++.1.dylib $out/bin/echidna |
119 | | - ${install_name_tool} -change "$cxxabi" /usr/lib/libc++abi.dylib $out/bin/echidna |
120 | | - ${install_name_tool} -change "$iconv" /usr/lib/libiconv.dylib $out/bin/echidna |
| 105 | + exe="$out/bin/echidna" |
| 106 | + chmod 777 "$exe" |
| 107 | + for lib in $(${otool} -L "$exe" | awk '/nix\/store/{ print $1 }'); do |
| 108 | + case "$lib" in |
| 109 | + *libc++.*.dylib) ${install_name_tool} -change "$lib" /usr/lib/libc++.dylib "$exe" ;; |
| 110 | + *libc++abi.*.dylib) ${install_name_tool} -change "$lib" /usr/lib/libc++abi.dylib "$exe" ;; |
| 111 | + *libffi.*.dylib) ${install_name_tool} -change "$lib" /usr/lib/libffi.dylib "$exe" ;; |
| 112 | + *libiconv.2.dylib) ${install_name_tool} -change "$lib" /usr/lib/libiconv.2.dylib "$exe" ;; |
| 113 | + *libz.dylib) ${install_name_tool} -change "$lib" /usr/lib/libz.dylib "$exe" ;; |
| 114 | + esac |
| 115 | + done |
121 | 116 | # fix TERMINFO path in ncurses |
122 | 117 | ${perl} -i -pe 's#(${ncurses-static}/share/terminfo)#"/usr/share/terminfo" . "\x0" x (length($1) - 19)#e' $out/bin/echidna |
123 | 118 | # check that no nix deps remain |
124 | | - nixdeps=$(${otool} -L $out/bin/echidna | tail -n +2 | { ${grep} /nix/store -c || test $? = 1; }) |
| 119 | + nixdeps=$(${otool} -L "$exe" | tail -n +2 | { ${grep} /nix/store -c || test $? = 1; }) |
125 | 120 | if [ ! "$nixdeps" = "0" ]; then |
126 | 121 | echo "Nix deps remain in redistributable binary!" |
127 | 122 | exit 255 |
128 | 123 | fi |
129 | 124 | # re-sign binary |
130 | | - CODESIGN_ALLOCATE=${codesign_allocate} ${codesign} -f -s - $out/bin/echidna |
131 | | - chmod 555 $out/bin/echidna |
| 125 | + CODESIGN_ALLOCATE=${codesign_allocate} ${codesign} -f -s - "$exe" |
| 126 | + chmod 555 "$exe" |
132 | 127 | ''; |
133 | 128 |
|
134 | 129 | # if we pass a library folder to ghc via --extra-lib-dirs that contains |
|
0 commit comments