Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 256 lines 8.6 kB view raw
1{ 2 stdenv, 3 lib, 4 autoPatchelfHook, 5 fetchzip, 6 xz, 7 ncurses5, 8 ncurses, 9 readline, 10 gmp, 11 mpfr, 12 expat, 13 libipt, 14 zlib, 15 dejagnu, 16 sourceHighlight, 17 python3, 18 elfutils, 19 guile, 20 glibc, 21 zstd, 22 majorVersion, 23}: 24 25let 26 throwUnsupportedSystem = throw "Unsupported system: ${stdenv.hostPlatform.system}"; 27in 28stdenv.mkDerivation ( 29 finalAttrs: 30 let 31 versionMap = 32 let 33 url = "https://github.com/alire-project/GNAT-FSF-builds/releases/download/gnat-${finalAttrs.version}/gnat-${stdenv.hostPlatform.system}-${finalAttrs.version}.tar.gz"; 34 in 35 { 36 "11" = 37 { 38 gccVersion = "11.2.0"; 39 alireRevision = "4"; 40 } 41 // { 42 x86_64-darwin = { 43 inherit url; 44 hash = "sha256-FmBgD20PPQlX/ddhJliCTb/PRmKxe9z7TFPa2/SK4GY="; 45 upstreamTriplet = "x86_64-apple-darwin19.6.0"; 46 }; 47 x86_64-linux = { 48 inherit url; 49 hash = "sha256-8fMBJp6igH+Md5jE4LMubDmC4GLt4A+bZG/Xcz2LAJQ="; 50 upstreamTriplet = "x86_64-pc-linux-gnu"; 51 }; 52 } 53 .${stdenv.hostPlatform.system} or throwUnsupportedSystem; 54 "12" = 55 { 56 gccVersion = "12.1.0"; 57 alireRevision = "2"; 58 } 59 // { 60 x86_64-darwin = { 61 inherit url; 62 hash = "sha256-zrcVFvFZMlGUtkG0p1wST6kGInRI64Icdsvkcf25yVs="; 63 upstreamTriplet = "x86_64-apple-darwin19.6.0"; 64 }; 65 x86_64-linux = { 66 inherit url; 67 hash = "sha256-EPDPOOjWJnJsUM7GGxj20/PXumjfLoMIEFX1EDtvWVY="; 68 upstreamTriplet = "x86_64-pc-linux-gnu"; 69 }; 70 } 71 .${stdenv.hostPlatform.system} or throwUnsupportedSystem; 72 "13" = 73 { 74 gccVersion = "13.2.0"; 75 alireRevision = "2"; 76 } 77 // { 78 x86_64-darwin = { 79 inherit url; 80 hash = "sha256-DNHcHTIi7pw0rsVtpyGTyLVElq3IoO2YX/OkDbdeQyo="; 81 upstreamTriplet = "x86_64-apple-darwin21.6.0"; 82 }; 83 x86_64-linux = { 84 inherit url; 85 hash = "sha256-DC95udGSzRDE22ON4UpekxTYWOSBeUdJvILbSFj6MFQ="; 86 upstreamTriplet = "x86_64-pc-linux-gnu"; 87 }; 88 } 89 .${stdenv.hostPlatform.system} or throwUnsupportedSystem; 90 "14" = 91 { 92 gccVersion = "14.2.0"; 93 alireRevision = "1"; 94 } 95 // { 96 x86_64-darwin = { 97 inherit url; 98 hash = "sha256-3YOnvuI6Qq7huQcqgFSz/o+ZgY2wNkKDqHIuzNz1MVY="; 99 upstreamTriplet = "x86_64-apple-darwin21.6.0"; 100 }; 101 x86_64-linux = { 102 inherit url; 103 hash = "sha256-pH3IuOpCM9sY/ppTYcxBmgpsUiMrisIjmAa/rmmZXb4="; 104 upstreamTriplet = "x86_64-pc-linux-gnu"; 105 }; 106 aarch64-linux = { 107 inherit url; 108 hash = "sha256-SVW/0yyj6ZH1GAjvD+unII+zSLGd3KGFt1bjjQ3SEFU="; 109 upstreamTriplet = "aarch64-linux-gnu"; 110 }; 111 } 112 .${stdenv.hostPlatform.system} or throwUnsupportedSystem; 113 }; 114 inherit (versionMap.${majorVersion}) gccVersion alireRevision upstreamTriplet; 115 in 116 { 117 pname = "gnat-bootstrap"; 118 inherit (versionMap.${majorVersion}) gccVersion alireRevision; 119 120 version = "${gccVersion}${lib.optionalString (alireRevision != "") "-"}${alireRevision}"; 121 122 src = fetchzip { 123 inherit (versionMap.${majorVersion}) url hash; 124 }; 125 126 nativeBuildInputs = 127 [ 128 dejagnu 129 gmp 130 guile 131 libipt 132 mpfr 133 python3 134 readline 135 sourceHighlight 136 zlib 137 ] 138 ++ lib.optionals stdenv.buildPlatform.isLinux [ 139 autoPatchelfHook 140 glibc 141 ] 142 ++ lib.optionals (lib.meta.availableOn stdenv.buildPlatform elfutils) [ 143 elfutils 144 ]; 145 146 buildInputs = 147 [ 148 expat 149 ] 150 ++ lib.optionals (lib.versionAtLeast majorVersion "13") [ 151 ncurses 152 ] 153 ++ lib.optionals (lib.versionOlder majorVersion "13") [ 154 ncurses5 155 ] 156 ++ [ 157 xz 158 ] 159 ++ 160 lib.optionals 161 ( 162 lib.versionAtLeast majorVersion "14" && stdenv.hostPlatform.isAarch64 && stdenv.hostPlatform.isLinux 163 ) 164 [ 165 # not sure why the bootstrap binaries link to zstd only on this architecture but they do 166 zstd 167 ]; 168 169 strictDeps = true; 170 171 # https://github.com/alire-project/GNAT-FSF-builds/issues/51 172 autoPatchelfIgnoreMissingDeps = 173 if (stdenv.buildPlatform.isLinux && majorVersion == "13") then true else null; 174 175 postPatch = 176 lib.optionalString (stdenv.hostPlatform.isDarwin) '' 177 substituteInPlace lib/gcc/${upstreamTriplet}/${gccVersion}/install-tools/mkheaders.conf \ 178 --replace "SYSTEM_HEADER_DIR=\"/usr/include\"" "SYSTEM_HEADER_DIR=\"/include\"" 179 '' 180 # The included fixincl binary that is called during header fixup has a 181 # hardcoded execvp("/usr/bin/sed", ...) call, but /usr/bin/sed isn't 182 # available in the Nix Darwin stdenv. Fortunately, execvp() will search the 183 # PATH environment variable for the executable if its first argument does not 184 # contain a slash, so we can just change the string to "sed" and zero the 185 # other bytes. 186 + '' 187 sed -i "s,/usr/bin/sed,sed\x00\x00\x00\x00\x00\x00\x00\x00\x00," libexec/gcc/${upstreamTriplet}/${gccVersion}/install-tools/fixincl 188 ''; 189 190 installPhase = 191 '' 192 mkdir -p $out 193 cp -ar * $out/ 194 '' 195 196 # So far with the Darwin gnat-bootstrap binary packages, there have been two 197 # types of dylib path references to other dylibs that need fixups: 198 # 199 # 1. Dylibs in $out/lib with paths starting with 200 # /Users/runner/.../gcc/install that refer to other dylibs in $out/lib 201 # 2. Dylibs in $out/lib/gcc/*/*/adalib with paths starting with 202 # @rpath that refer to other dylibs in $out/lib/gcc/*/*/adalib 203 # 204 # Additionally, per Section 14.4 Fixed Headers in the GCC 12.2.0 manual [2], 205 # we have to update the fixed header files in current Alire GCC package, since it 206 # was built against macOS 10.15 (Darwin 19.6.0), but Nix currently 207 # builds against macOS 10.12, and the two header file structures differ. 208 # For example, the current Alire GCC package has a fixed <stdio.h> 209 # from macOS 10.15 that contains a #include <_stdio.h>, but neither the Alire 210 # GCC package nor macOS 10.12 have such a header (<xlocale/_stdio.h> and 211 # <secure/_stdio.h> in 10.12 are not equivalent; indeed, 10.15 <_stdio.h> 212 # says it contains code shared by <stdio.h> and <xlocale/_stdio.h>). 213 # 214 # [2]: https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Fixed-Headers.html 215 216 + lib.optionalString (stdenv.hostPlatform.isDarwin) '' 217 upstreamBuildPrefix="/Users/runner/work/GNAT-FSF-builds/GNAT-FSF-builds/sbx/x86_64-darwin/gcc/install" 218 for i in "$out"/lib/*.dylib "$out"/lib/gcc/*/*/adalib/*.dylib; do 219 if [[ -f "$i" && ! -h "$i" ]]; then 220 install_name_tool -id "$i" "$i" || true 221 for old_path in $(otool -L "$i" | grep "$upstreamBuildPrefix" | awk '{print $1}'); do 222 new_path=`echo "$old_path" | sed "s,$upstreamBuildPrefix,$out,"` 223 install_name_tool -change "$old_path" "$new_path" "$i" || true 224 done 225 for old_path in $(otool -L "$i" | grep "@rpath" | awk '{print $1}'); do 226 new_path=$(echo "$old_path" | sed "s,@rpath,$(dirname "$i"),") 227 install_name_tool -change "$old_path" "$new_path" "$i" || true 228 done 229 fi 230 done 231 232 "$out"/libexec/gcc/${upstreamTriplet}/${gccVersion}/install-tools/mkheaders -v -v \ 233 "$out" "${stdenv.cc.libc}" 234 ''; 235 236 passthru = { 237 langC = true; # TRICK for gcc-wrapper to wrap it 238 langCC = false; 239 langFortran = false; 240 langAda = true; 241 isGNU = true; 242 }; 243 244 meta = with lib; { 245 description = "GNAT, the GNU Ada Translator"; 246 homepage = "https://www.gnu.org/software/gnat"; 247 license = licenses.gpl3; 248 maintainers = with maintainers; [ ethindp ]; 249 platforms = [ 250 "x86_64-linux" 251 "x86_64-darwin" 252 ] ++ lib.optionals (lib.versionAtLeast majorVersion "14") [ "aarch64-linux" ]; 253 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; 254 }; 255 } 256)