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