1 { lib, stdenv, icu, expat, zlib, bzip2, python, fixDarwinDylibNames, libiconv
5 , toolset ? /**/ if stdenv.cc.isClang then "clang"
9 , enableSingleThreaded ? false
10 , enableMultiThreaded ? true
11 , enableShared ? !(with stdenv.hostPlatform; isStatic || libc == "msvcrt") # problems for now
12 , enableStatic ? !enableShared
13 , enablePython ? false
15 , taggedLayout ? ((enableRelease && enableDebug) || (enableSingleThreaded && enableMultiThreaded) || (enableShared && enableStatic))
21 # Attributes inherit from specific versions
26 # We must build at least one type of libraries
27 assert enableShared || enableStatic;
29 # Python isn't supported when cross-compiling
30 assert enablePython -> stdenv.hostPlatform == stdenv.buildPlatform;
31 assert enableNumpy -> enablePython;
33 # Boost <1.69 can't be build with clang >8, because pth was removed
34 assert with lib; ((toolset == "clang" && !(versionOlder stdenv.cc.version "8.0.0")) -> !(versionOlder version "1.69"));
39 variant = concatStringsSep ","
40 (optional enableRelease "release" ++
41 optional enableDebug "debug");
43 threading = concatStringsSep ","
44 (optional enableSingleThreaded "single" ++
45 optional enableMultiThreaded "multi");
47 link = concatStringsSep ","
48 (optional enableShared "shared" ++
49 optional enableStatic "static");
51 runtime-link = if enableShared then "shared" else "static";
53 # To avoid library name collisions
54 layout = if taggedLayout then "tagged" else "system";
56 # Versions of b2 before 1.65 have job limits; specifically:
57 # - Versions before 1.58 support up to 64 jobs[0]
58 # - Versions before 1.65 support up to 256 jobs[1]
60 # [0]: https://github.com/boostorg/build/commit/0ef40cb86728f1cd804830fef89a6d39153ff632
61 # [1]: https://github.com/boostorg/build/commit/316e26ca718afc65d6170029284521392524e4f8
63 if versionOlder version "1.58" then
64 "$(($NIX_BUILD_CORES<=64 ? $NIX_BUILD_CORES : 64))"
65 else if versionOlder version "1.65" then
66 "$(($NIX_BUILD_CORES<=256 ? $NIX_BUILD_CORES : 256))"
70 b2Args = concatStringsSep " " ([
71 "--includedir=$dev/include"
76 "threading=${threading}"
78 "-sEXPAT_INCLUDE=${expat.dev}/include"
79 "-sEXPAT_LIBPATH=${expat.out}/lib"
81 # TODO: make this unconditional
82 ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
83 "address-model=${toString stdenv.hostPlatform.parsed.cpu.bits}"
84 "architecture=${toString stdenv.hostPlatform.parsed.cpu.family}"
85 "binary-format=${toString stdenv.hostPlatform.parsed.kernel.execFormat.name}"
86 "target-os=${toString stdenv.hostPlatform.parsed.kernel.name}"
88 # adapted from table in boost manual
89 # https://www.boost.org/doc/libs/1_66_0/libs/context/doc/html/context/architectures.html
90 "abi=${if stdenv.hostPlatform.parsed.cpu.family == "arm" then "aapcs"
91 else if stdenv.hostPlatform.isWindows then "ms"
92 else if stdenv.hostPlatform.isMips then "o32"
94 ] ++ optional (link != "static") "runtime-link=${runtime-link}"
95 ++ optional (variant == "release") "debug-symbols=off"
96 ++ optional (toolset != null) "toolset=${toolset}"
97 ++ optional (!enablePython) "--without-python"
98 ++ optional (useMpi || stdenv.hostPlatform != stdenv.buildPlatform) "--user-config=user-config.jam"
99 ++ optionals (stdenv.hostPlatform.libc == "msvcrt") [
106 stdenv.mkDerivation {
114 ++ optional stdenv.isDarwin (
115 if version == "1.55.0"
116 then ./darwin-1.55-no-system-python.patch
117 else ./darwin-no-system-python.patch)
118 # Fix boost-context segmentation faults on ppc64 due to ABI violation
119 ++ optional (versionAtLeast version "1.61" &&
120 versionOlder version "1.71") (fetchpatch {
121 url = "https://github.com/boostorg/context/commit/2354eca9b776a6739112833f64754108cc0d1dc5.patch";
122 sha256 = "067m4bjpmcanqvg28djax9a10avmdwhlpfx6gn73kbqqq70dnz29";
124 extraPrefix = "libs/context/";
126 ++ optional (and (versionAtLeast version "1.70") (!versionAtLeast version "1.73")) ./cmake-paths.patch
127 ++ optional (versionAtLeast version "1.73") ./cmake-paths-173.patch;
130 homepage = "http://boost.org/";
131 description = "Collection of C++ libraries";
132 license = licenses.boost;
133 platforms = platforms.unix ++ platforms.windows;
134 badPlatforms = optional (versionOlder version "1.59") "aarch64-linux"
135 ++ optional ((versionOlder version "1.57") || version == "1.58") "x86_64-darwin"
136 ++ optionals (versionOlder version "1.73") lib.platforms.riscv;
137 maintainers = with maintainers; [ peti ];
141 if test -f tools/build/src/tools/clang-darwin.jam ; then
142 substituteInPlace tools/build/src/tools/clang-darwin.jam \
143 --replace '@rpath/$(<[1]:D=)' "$out/lib/\$(<[1]:D=)";
145 '' + optionalString useMpi ''
146 cat << EOF >> user-config.jam
147 using mpi : ${mpi}/bin/mpiCC ;
149 '' + optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
150 cat << EOF >> user-config.jam
151 using gcc : cross : ${stdenv.cc.targetPrefix}c++ ;
153 # Build b2 with buildPlatform CC/CXX.
154 sed '2i export CC=$CC_FOR_BUILD; export CXX=$CXX_FOR_BUILD' \
155 -i ./tools/build/src/engine/build.sh
158 NIX_CFLAGS_LINK = lib.optionalString stdenv.isDarwin
159 "-headerpad_max_install_names";
161 enableParallelBuilding = true;
163 nativeBuildInputs = [ which ]
164 ++ optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
165 depsBuildBuild = [ buildPackages.stdenv.cc ];
166 buildInputs = [ expat zlib bzip2 libiconv ]
167 ++ optional (stdenv.hostPlatform == stdenv.buildPlatform) icu
168 ++ optional enablePython python
169 ++ optional enableNumpy python.pkgs.numpy;
171 configureScript = "./bootstrap.sh";
172 configurePlatforms = [];
174 "--includedir=$(dev)/include"
175 "--libdir=$(out)/lib"
176 ] ++ optional enablePython "--with-python=${python.interpreter}"
177 ++ [ (if stdenv.hostPlatform == stdenv.buildPlatform then "--with-icu=${icu.dev}" else "--without-icu") ]
178 ++ optional (toolset != null) "--with-toolset=${toolset}";
189 # boostbook is needed by some applications
190 mkdir -p $dev/share/boostbook
191 cp -a tools/boostbook/{xsl,dtd} $dev/share/boostbook/
193 # Let boost install everything else
194 ./b2 ${b2Args} install
200 # Make boost header paths relative so that they are not runtime dependencies
201 cd "$dev" && find include \( -name '*.hpp' -or -name '*.h' -or -name '*.ipp' \) \
202 -exec sed '1s/^\xef\xbb\xbf//;1i#line 1 "{}"' -i '{}' \;
203 '' + optionalString (stdenv.hostPlatform.libc == "msvcrt") ''
204 $RANLIB "$out/lib/"*.a
207 outputs = [ "out" "dev" ];
208 setOutputFlags = false;