nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 359 lines 12 kB view raw
1/* 2 Build configuration used to build glibc, Info files, and locale 3 information. 4 5 Note that this derivation has multiple outputs and does not respect the 6 standard convention of putting the executables into the first output. The 7 first output is `lib` so that the libraries provided by this derivation 8 can be accessed directly, e.g. 9 10 "${pkgs.glibc}/lib/ld-linux-x86_64.so.2" 11 12 The executables are put into `bin` output and need to be referenced via 13 the `bin` attribute of the main package, e.g. 14 15 "${pkgs.glibc.bin}/bin/ldd". 16 17 The executables provided by glibc typically include `ldd`, `locale`, `iconv` 18 but the exact set depends on the library version and the configuration. 19*/ 20 21# Note: this package is used for bootstrapping fetchurl, and thus 22# cannot use fetchpatch! All mutable patches (generated by GitHub or 23# cgit) that are needed here should be included directly in Nixpkgs as 24# files. 25 26{ 27 stdenv, 28 lib, 29 buildPackages, 30 fetchurl, 31 linuxHeaders ? null, 32 gd ? null, 33 libpng ? null, 34 libidn2, 35 bison, 36 python3Minimal, 37}: 38 39{ 40 pname, 41 withLinuxHeaders ? false, 42 profilingLibraries ? false, 43 withGd ? false, 44 enableCET ? false, 45 enableCETRuntimeDefault ? false, 46 extraBuildInputs ? [ ], 47 extraNativeBuildInputs ? [ ], 48 ... 49}@args: 50 51let 52 version = "2.42"; 53 patchSuffix = "-51"; 54 sha256 = "sha256-0XdeMuRijmTvkw9DW2e7Y691may2viszW58Z8WUJ8X8="; 55in 56 57assert withLinuxHeaders -> linuxHeaders != null; 58assert withGd -> gd != null && libpng != null; 59assert enableCET == false -> !enableCETRuntimeDefault; 60 61stdenv.mkDerivation ( 62 { 63 version = version + patchSuffix; 64 65 enableParallelBuilding = true; 66 67 patches = [ 68 /* 69 No tarballs for stable upstream branch, only https://sourceware.org/git/glibc.git and using git would complicate bootstrapping. 70 $ git fetch --all -p && git checkout origin/release/2.40/master && git describe 71 glibc-2.42-51-gcbf39c26b2 72 $ git show --minimal --reverse glibc-2.42.. ':!ADVISORIES' > 2.42-master.patch 73 74 To compare the archive contents zdiff can be used. 75 $ diff -u 2.42-master.patch ../nixpkgs/pkgs/development/libraries/glibc/2.42-master.patch 76 77 Please note that each commit has changes to the file ADVISORIES excluded since 78 that conflicts with the directory advisories/ making cross-builds from 79 hosts with case-insensitive file-systems impossible. 80 */ 81 ./2.42-master.patch 82 83 # Allow NixOS and Nix to handle the locale-archive. 84 ./nix-locale-archive.patch 85 86 # Don't use /etc/ld.so.cache, for non-NixOS systems. 87 ./dont-use-system-ld-so-cache.patch 88 89 # Don't use /etc/ld.so.preload, but /etc/ld-nix.so.preload. 90 ./dont-use-system-ld-so-preload.patch 91 92 /* 93 The command "getconf CS_PATH" returns the default search path 94 "/bin:/usr/bin", which is inappropriate on NixOS machines. This 95 patch extends the search path by "/run/current-system/sw/bin". 96 */ 97 ./fix_path_attribute_in_getconf.patch 98 99 ./fix-x64-abi.patch 100 101 # https://github.com/NixOS/nixpkgs/pull/137601 102 ./nix-nss-open-files.patch 103 104 ./0001-Revert-Remove-all-usage-of-BASH-or-BASH-in-installed.patch 105 106 /* 107 Patch derived from archlinux, 108 https://gitlab.archlinux.org/archlinux/packaging/packages/glibc/-/blob/e54d98e2d1aae4930ecad9404ef12234922d9dfd/reenable_DT_HASH.patch 109 110 See also https://github.com/ValveSoftware/Proton/issues/6051 111 & https://github.com/NixOS/nixpkgs/pull/188492#issuecomment-1233802991 112 */ 113 ./reenable_DT_HASH.patch 114 115 # enable parallel & reproducible build of glibcLocales 116 ./0001-localedata-allow-reproducible-parallel-install-of-lo.patch 117 ./0002-Makeconfig-make-inst_complocaledir-overridable.patch 118 ] 119 /* 120 NVCC does not support ARM intrinsics. Since <math.h> is pulled in by almost 121 every HPC piece of software, without this patch CUDA compilation on ARM 122 is effectively broken. See 123 https://forums.developer.nvidia.com/t/nvcc-fails-to-build-with-arm-neon-instructions-cpp-vs-cu/248355/2. 124 */ 125 ++ ( 126 let 127 isAarch64 = stdenv.buildPlatform.isAarch64 || stdenv.hostPlatform.isAarch64; 128 isLinux = stdenv.buildPlatform.isLinux || stdenv.hostPlatform.isLinux; 129 in 130 # Remove certain defines when __CUDACC__ is defined (i.e. we're building with a CUDA compiler) 131 lib.optional (isAarch64 && isLinux) ./0001-aarch64-math-vector.h-add-NVCC-include-guard.patch 132 ) 133 # Modify certain defines to be compatible with musl 134 ++ lib.optional stdenv.hostPlatform.isMusl ./fix-rpc-types-musl-conflicts.patch 135 # Enable cross-compilation of glibc on Darwin (build=Darwin, host=Linux) 136 ++ lib.optional stdenv.buildPlatform.isDarwin ./darwin-cross-build.patch 137 # Reverts this patch: https://sourceware.org/git/?p=glibc.git;a=commit;h=55d63e731253de82e96ed4ddca2e294076cd0bc5 138 # This revert enables [CET] (Control-flow Enforcement Technology) by default 139 # [CET]: https://en.wikipedia.org/wiki/Control-flow_integrity#Intel_Control-flow_Enforcement_Technology 140 ++ lib.optional enableCETRuntimeDefault ./2.39-revert-cet-default-disable.patch; 141 142 postPatch = '' 143 # Needed for glibc to build with the gnumake 3.82 144 # http://comments.gmane.org/gmane.linux.lfs.support/31227 145 sed -i 's/ot \$/ot:\n\ttouch $@\n$/' manual/Makefile 146 147 # nscd needs libgcc, and we don't want it dynamically linked 148 # because we don't want it to depend on bootstrap-tools libs. 149 echo "LDFLAGS-nscd += -static-libgcc" >> nscd/Makefile 150 151 # Ensure that `__nss_files_fopen` can still be wrapped by `libredirect`. 152 sed -i -e '/libc_hidden_def (__nss_files_fopen)/d' nss/nss_files_fopen.c 153 sed -i -e '/libc_hidden_proto (__nss_files_fopen)/d' include/nss_files.h 154 '' 155 # FIXME: find a solution for infinite recursion in cross builds. 156 # For now it's hopefully acceptable that IDN from libc doesn't reliably work. 157 + lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) '' 158 159 # Ensure that libidn2 is found. 160 patch -p 1 <<EOF 161 --- a/inet/idna.c 162 +++ b/inet/idna.c 163 @@ -25,1 +25,1 @@ 164 -#define LIBIDN2_SONAME "libidn2.so.0" 165 +#define LIBIDN2_SONAME "${lib.getLib libidn2}/lib/libidn2.so.0" 166 EOF 167 ''; 168 169 configureFlags = [ 170 "-C" 171 "--enable-add-ons" 172 "--sysconfdir=/etc" 173 "--enable-stack-protector=strong" 174 "--enable-bind-now" 175 (lib.withFeatureAs withLinuxHeaders "headers" "${linuxHeaders}/include") 176 (lib.enableFeature profilingLibraries "profile") 177 "--enable-fortify-source" 178 ] 179 ++ lib.optionals (stdenv.hostPlatform.isx86 || stdenv.hostPlatform.isAarch64) [ 180 # This feature is currently supported on 181 # i386, x86_64 and x32 with binutils 2.29 or later, 182 # and on aarch64 with binutils 2.30 or later. 183 # https://sourceware.org/glibc/wiki/PortStatus 184 "--enable-static-pie" 185 ] 186 ++ lib.optionals (enableCET != false) [ 187 # Enable Intel Control-flow Enforcement Technology (CET) support 188 "--enable-cet${if builtins.isString enableCET then "=${enableCET}" else ""}" 189 ] 190 ++ lib.optionals withLinuxHeaders [ 191 "--enable-kernel=3.10.0" # RHEL 7 and derivatives, seems oldest still supported kernel 192 ] 193 ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ 194 (lib.flip lib.withFeature "fp" ( 195 stdenv.hostPlatform.gcc.float or (stdenv.hostPlatform.parsed.abi.float or "hard") == "soft" 196 )) 197 "--with-__thread" 198 ] 199 ++ lib.optionals (stdenv.hostPlatform == stdenv.buildPlatform && stdenv.hostPlatform.isAarch32) [ 200 "--host=arm-linux-gnueabi" 201 "--build=arm-linux-gnueabi" 202 203 # To avoid linking with -lgcc_s (dynamic link) 204 # so the glibc does not depend on its compiler store path 205 "libc_cv_as_needed=no" 206 ] 207 ++ lib.optional withGd "--with-gd"; 208 209 makeFlags = 210 (args.makeFlags or [ ]) 211 ++ [ "OBJCOPY=${stdenv.cc.targetPrefix}objcopy" ] 212 ++ lib.optionals (stdenv.cc.libc != null) [ 213 "BUILD_LDFLAGS=-Wl,-rpath,${stdenv.cc.libc}/lib" 214 "OBJDUMP=${stdenv.cc.bintools.bintools}/bin/objdump" 215 ]; 216 217 postInstall = (args.postInstall or "") + '' 218 moveToOutput bin/getent $getent 219 ''; 220 221 installFlags = [ "sysconfdir=$(out)/etc" ]; 222 223 # out as the first output is an exception exclusive to glibc 224 225 # getent is its own output, not kept in bin, since many things 226 # depend on getent but not on the locale generation tools in the bin 227 # output. This saves a couple of megabytes of closure size in many cases. 228 outputs = [ 229 "out" 230 "bin" 231 "dev" 232 "static" 233 "getent" 234 ]; 235 236 strictDeps = true; 237 depsBuildBuild = [ buildPackages.stdenv.cc ]; 238 nativeBuildInputs = [ 239 bison 240 python3Minimal 241 ] 242 ++ extraNativeBuildInputs; 243 buildInputs = [ 244 linuxHeaders 245 ] 246 ++ lib.optionals withGd [ 247 gd 248 libpng 249 ] 250 ++ extraBuildInputs; 251 252 env = { 253 linuxHeaders = lib.optionalString withLinuxHeaders linuxHeaders; 254 inherit (stdenv.hostPlatform) is64bit; 255 # Needed to install share/zoneinfo/zone.tab. Set to impure /bin/sh to 256 # prevent a retained dependency on the bootstrap tools in the stdenv-linux 257 # bootstrap. 258 BASH_SHELL = "/bin/sh"; 259 }; 260 261 # Used by libgcc, elf-header, and others to determine ABI 262 passthru = { 263 inherit version; 264 minorRelease = version; 265 }; 266 } 267 268 // (removeAttrs args [ 269 "withLinuxHeaders" 270 "linuxHeaders" 271 "withGd" 272 "enableCET" 273 "postInstall" 274 "makeFlags" 275 ]) 276 // 277 278 { 279 src = fetchurl { 280 url = "mirror://gnu/glibc/glibc-${version}.tar.xz"; 281 inherit sha256; 282 }; 283 284 # Remove absolute paths from `configure' & co.; build out-of-tree. 285 preConfigure = '' 286 export PWD_P=$(type -tP pwd) 287 for i in configure io/ftwtest-sh; do 288 # Can't use substituteInPlace here because replace hasn't been 289 # built yet in the bootstrap. 290 sed -i "$i" -e "s^/bin/pwd^$PWD_P^g" 291 done 292 293 mkdir build 294 cd build 295 296 configureScript="`pwd`/../configure" 297 '' 298 + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' 299 sed -i s/-lgcc_eh//g ../Makeconfig 300 301 cat > config.cache << "EOF" 302 libc_cv_forced_unwind=yes 303 libc_cv_c_cleanup=yes 304 libc_cv_gnu89_inline=yes 305 EOF 306 307 # ./configure has logic like 308 # 309 # AR=`$CC -print-prog-name=ar` 310 # 311 # This searches various directories in the gcc and its wrapper. In nixpkgs, 312 # this returns the bare string "ar", which is build ar. This can result as 313 # a build failure with the following message: 314 # 315 # libc_pic.a: error adding symbols: archive has no index; run ranlib to add one 316 # 317 # (Observed cross compiling from aarch64-linux -> armv7l-linux). 318 # 319 # Nixpkgs passes a correct value for AR and friends, so to use the correct 320 # set of tools, we only need to delete this special handling. 321 sed -i \ 322 -e '/^AR=/d' \ 323 -e '/^AS=/d' \ 324 -e '/^LD=/d' \ 325 -e '/^OBJCOPY=/d' \ 326 -e '/^OBJDUMP=/d' \ 327 $configureScript 328 ''; 329 330 preBuild = lib.optionalString withGd "unset NIX_DONT_SET_RPATH"; 331 332 doCheck = false; # fails 333 334 meta = 335 336 { 337 homepage = "https://www.gnu.org/software/libc/"; 338 description = "GNU C Library"; 339 340 longDescription = '' 341 Any Unix-like operating system needs a C library: the library which 342 defines the "system calls" and other basic facilities such as 343 open, malloc, printf, exit... 344 345 The GNU C library is used as the C library in the GNU system and 346 most systems with the Linux kernel. 347 ''; 348 349 license = lib.licenses.lgpl2Plus; 350 351 maintainers = with lib.maintainers; [ 352 ma27 353 connorbaker 354 ]; 355 platforms = lib.platforms.linux; 356 } 357 // (args.meta or { }); 358 } 359)