Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at litex 230 lines 8.0 kB view raw
1{ lib, stdenv, icu, expat, zlib, bzip2, zstd, xz, python ? null, fixDarwinDylibNames, libiconv, libxcrypt 2, boost-build 3, fetchpatch 4, which 5, toolset ? /**/ if stdenv.cc.isClang then "clang" 6 else if stdenv.cc.isGNU then "gcc" 7 else null 8, enableRelease ? true 9, enableDebug ? false 10, enableSingleThreaded ? false 11, enableMultiThreaded ? true 12, enableShared ? !(with stdenv.hostPlatform; isStatic || libc == "msvcrt") # problems for now 13, enableStatic ? !enableShared 14, enablePython ? false 15, enableNumpy ? false 16, enableIcu ? stdenv.hostPlatform == stdenv.buildPlatform 17, taggedLayout ? ((enableRelease && enableDebug) || (enableSingleThreaded && enableMultiThreaded) || (enableShared && enableStatic)) 18, patches ? [] 19, boostBuildPatches ? [] 20, useMpi ? false 21, mpi 22, extraB2Args ? [] 23 24# Attributes inherit from specific versions 25, version, src 26, ... 27}: 28 29# We must build at least one type of libraries 30assert enableShared || enableStatic; 31 32assert enableNumpy -> enablePython; 33 34let 35 36 variant = lib.concatStringsSep "," 37 (lib.optional enableRelease "release" ++ 38 lib.optional enableDebug "debug"); 39 40 threading = lib.concatStringsSep "," 41 (lib.optional enableSingleThreaded "single" ++ 42 lib.optional enableMultiThreaded "multi"); 43 44 link = lib.concatStringsSep "," 45 (lib.optional enableShared "shared" ++ 46 lib.optional enableStatic "static"); 47 48 runtime-link = if enableShared then "shared" else "static"; 49 50 # To avoid library name collisions 51 layout = if taggedLayout then "tagged" else "system"; 52 53 needUserConfig = stdenv.hostPlatform != stdenv.buildPlatform || useMpi || (stdenv.isDarwin && enableShared); 54 55 b2Args = lib.concatStringsSep " " ([ 56 "--includedir=$dev/include" 57 "--libdir=$out/lib" 58 "-j$NIX_BUILD_CORES" 59 "--layout=${layout}" 60 "variant=${variant}" 61 "threading=${threading}" 62 "link=${link}" 63 "-sEXPAT_INCLUDE=${expat.dev}/include" 64 "-sEXPAT_LIBPATH=${expat.out}/lib" 65 66 # TODO: make this unconditional 67 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform || 68 # required on mips; see 61d9f201baeef4c4bb91ad8a8f5f89b747e0dfe4 69 (stdenv.hostPlatform.isMips && lib.versionAtLeast version "1.79")) [ 70 "address-model=${toString stdenv.hostPlatform.parsed.cpu.bits}" 71 "architecture=${if stdenv.hostPlatform.isMips64 72 then if lib.versionOlder version "1.78" then "mips1" else "mips" 73 else if stdenv.hostPlatform.parsed.cpu.name == "s390x" then "s390x" 74 else toString stdenv.hostPlatform.parsed.cpu.family}" 75 "binary-format=${toString stdenv.hostPlatform.parsed.kernel.execFormat.name}" 76 "target-os=${toString stdenv.hostPlatform.parsed.kernel.name}" 77 78 # adapted from table in boost manual 79 # https://www.boost.org/doc/libs/1_66_0/libs/context/doc/html/context/architectures.html 80 "abi=${if stdenv.hostPlatform.parsed.cpu.family == "arm" then "aapcs" 81 else if stdenv.hostPlatform.isWindows then "ms" 82 else if stdenv.hostPlatform.isMips32 then "o32" 83 else if stdenv.hostPlatform.isMips64n64 then "n64" 84 else "sysv"}" 85 ] ++ lib.optional (link != "static") "runtime-link=${runtime-link}" 86 ++ lib.optional (variant == "release") "debug-symbols=off" 87 ++ lib.optional (toolset != null) "toolset=${toolset}" 88 ++ lib.optional (!enablePython) "--without-python" 89 ++ lib.optional needUserConfig "--user-config=user-config.jam" 90 ++ lib.optional (stdenv.buildPlatform.isDarwin && stdenv.hostPlatform.isLinux) "pch=off" 91 ++ lib.optionals (stdenv.hostPlatform.libc == "msvcrt") [ 92 "threadapi=win32" 93 ] ++ extraB2Args 94 ); 95 96in 97 98stdenv.mkDerivation { 99 pname = "boost"; 100 101 inherit src version; 102 103 patchFlags = []; 104 105 patches = patches 106 ++ lib.optional stdenv.isDarwin ./darwin-no-system-python.patch 107 ++ [ ./cmake-paths-173.patch ] 108 ++ lib.optional (version == "1.77.0") (fetchpatch { 109 url = "https://github.com/boostorg/math/commit/7d482f6ebc356e6ec455ccb5f51a23971bf6ce5b.patch"; 110 relative = "include"; 111 sha256 = "sha256-KlmIbixcds6GyKYt1fx5BxDIrU7msrgDdYo9Va/KJR4="; 112 }); 113 114 meta = with lib; { 115 homepage = "http://boost.org/"; 116 description = "Collection of C++ libraries"; 117 license = licenses.boost; 118 platforms = platforms.unix ++ platforms.windows; 119 maintainers = with maintainers; [ hjones2199 ]; 120 121 broken = 122 # boost-context lacks support for the N32 ABI on mips64. The build 123 # will succeed, but packages depending on boost-context will fail with 124 # a very cryptic error message. 125 stdenv.hostPlatform.isMips64n32; 126 }; 127 128 passthru = { 129 inherit boostBuildPatches; 130 }; 131 132 preConfigure = lib.optionalString useMpi '' 133 cat << EOF >> user-config.jam 134 using mpi : ${mpi}/bin/mpiCC ; 135 EOF 136 '' 137 # On darwin we need to add the `$out/lib` to the libraries' rpath explicitly, 138 # otherwise the dynamic linker is unable to resolve the reference to @rpath 139 # when the boost libraries want to load each other at runtime. 140 + lib.optionalString (stdenv.isDarwin && enableShared) '' 141 cat << EOF >> user-config.jam 142 using clang-darwin : : ${stdenv.cc.targetPrefix}c++ 143 : <linkflags>"-rpath $out/lib/" 144 ; 145 EOF 146 '' 147 # b2 has trouble finding the correct compiler and tools for cross compilation 148 # since it apparently ignores $CC, $AR etc. Thus we need to set everything 149 # in user-config.jam. To keep things simple we just set everything in an 150 # uniform way for clang and gcc (which works thanks to our cc-wrapper). 151 # We pass toolset later which will make b2 invoke everything in the right 152 # way -- the other toolset in user-config.jam will be ignored. 153 + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' 154 cat << EOF >> user-config.jam 155 using gcc : cross : ${stdenv.cc.targetPrefix}c++ 156 : <archiver>$AR 157 <ranlib>$RANLIB 158 ; 159 160 using clang : cross : ${stdenv.cc.targetPrefix}c++ 161 : <archiver>$AR 162 <ranlib>$RANLIB 163 ; 164 EOF 165 '' 166 # b2 needs to be explicitly told how to find Python when cross-compiling 167 + lib.optionalString enablePython '' 168 cat << EOF >> user-config.jam 169 using python : : ${python.interpreter} 170 : ${python}/include/python${python.pythonVersion} 171 : ${python}/lib 172 ; 173 EOF 174 ''; 175 176 NIX_CFLAGS_LINK = lib.optionalString stdenv.isDarwin 177 "-headerpad_max_install_names"; 178 179 enableParallelBuilding = true; 180 181 nativeBuildInputs = [ which boost-build ] 182 ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; 183 buildInputs = [ expat zlib bzip2 libiconv ] 184 ++ lib.optional (lib.versionAtLeast version "1.69") zstd 185 ++ [ xz ] 186 ++ lib.optional enableIcu icu 187 ++ lib.optionals enablePython [ libxcrypt python ] 188 ++ lib.optional enableNumpy python.pkgs.numpy; 189 190 configureScript = "./bootstrap.sh"; 191 configurePlatforms = []; 192 dontDisableStatic = true; 193 dontAddStaticConfigureFlags = true; 194 configureFlags = [ 195 "--includedir=$(dev)/include" 196 "--libdir=$(out)/lib" 197 "--with-bjam=b2" # prevent bootstrapping b2 in configurePhase 198 ] ++ lib.optional (toolset != null) "--with-toolset=${toolset}" 199 ++ [ (if enableIcu then "--with-icu=${icu.dev}" else "--without-icu") ]; 200 201 buildPhase = '' 202 runHook preBuild 203 b2 ${b2Args} 204 runHook postBuild 205 ''; 206 207 installPhase = '' 208 runHook preInstall 209 210 # boostbook is needed by some applications 211 mkdir -p $dev/share/boostbook 212 cp -a tools/boostbook/{xsl,dtd} $dev/share/boostbook/ 213 214 # Let boost install everything else 215 b2 ${b2Args} install 216 217 runHook postInstall 218 ''; 219 220 postFixup = '' 221 # Make boost header paths relative so that they are not runtime dependencies 222 cd "$dev" && find include \( -name '*.hpp' -or -name '*.h' -or -name '*.ipp' \) \ 223 -exec sed '1s/^\xef\xbb\xbf//;1i#line 1 "{}"' -i '{}' \; 224 '' + lib.optionalString (stdenv.hostPlatform.libc == "msvcrt") '' 225 $RANLIB "$out/lib/"*.a 226 ''; 227 228 outputs = [ "out" "dev" ]; 229 setOutputFlags = false; 230}