add dev-libs/boost with static-libs support via an additional ebuild
[nodoc-overlay.git] / dev-libs / boost / boost-1.90.0-r2.ebuild
1 # Copyright 1999-2026 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=8
5
6 # Keep an eye on releases: https://www.boost.org/releases/
7
8 PYTHON_COMPAT=( python3_{11..14} )
9
10 inherit dot-a edo flag-o-matic multiprocessing python-r1 toolchain-funcs multilib-minimal
11
12 MY_PV="$(ver_rs 1- _)"
13
14 DESCRIPTION="Boost Libraries for C++"
15 HOMEPAGE="https://www.boost.org/"
16 SRC_URI="https://archives.boost.io/release/${PV}/source/boost_${MY_PV}.tar.bz2"
17 S="${WORKDIR}/${PN}_${MY_PV}"
18
19 LICENSE="Boost-1.0"
20 SLOT="0/${PV}"
21 KEYWORDS="~alpha amd64 arm arm64 ~hppa ~loong ~m68k ~mips ppc ppc64 ~riscv ~s390 ~sparc x86 ~arm64-macos ~x64-macos ~x64-solaris"
22 IUSE="bzip2 +context debug doc icu lzma +nls mpi numpy python +stacktrace static-libs test test-full tools zlib zstd"
23 REQUIRED_USE="
24 python? ( ${PYTHON_REQUIRED_USE} )
25 test-full? ( test )
26 "
27 RESTRICT="!test? ( test )"
28
29 RDEPEND="
30 bzip2? ( app-arch/bzip2:=[${MULTILIB_USEDEP}] )
31 icu? ( dev-libs/icu:=[${MULTILIB_USEDEP}] )
32 !icu? ( virtual/libiconv[${MULTILIB_USEDEP}] )
33 lzma? ( app-arch/xz-utils:=[${MULTILIB_USEDEP}] )
34 mpi? ( virtual/mpi[${MULTILIB_USEDEP},threads] )
35 python? (
36 ${PYTHON_DEPS}
37 numpy? ( dev-python/numpy:=[${PYTHON_USEDEP}] )
38 )
39 zlib? ( virtual/zlib:=[${MULTILIB_USEDEP}] )
40 zstd? ( app-arch/zstd:=[${MULTILIB_USEDEP}] )"
41 DEPEND="
42 ${RDEPEND}
43 static-libs? ( dev-libs/boost-static )"
44 BDEPEND=">=dev-build/b2-5.1.0"
45
46 PATCHES=(
47 "${FILESDIR}"/${PN}-1.88.0-disable_icu_rpath.patch
48 "${FILESDIR}"/${PN}-1.88.0-build-auto_index-tool.patch
49 "${FILESDIR}"/${PN}-1.88.0-algorithm-reverse_copy.patch
50 "${FILESDIR}"/${PN}-1.88.0-beast-network-sandbox.patch
51 "${FILESDIR}"/${PN}-1.88.0-bind-no-Werror.patch
52 "${FILESDIR}"/${PN}-1.88.0-range-any_iterator.patch
53 "${FILESDIR}"/${PN}-1.88.0-system-crashing-test.patch
54 "${FILESDIR}"/${PN}-1.88.0-yap-cstdint.patch
55 # https://github.com/boostorg/dll/issues/108
56 "${FILESDIR}"/${PN}-1.89.0-dll-no-lto.patch
57 "${FILESDIR}"/${PN}-1.89.0-graph-remove-system-dependency.patch
58 "${FILESDIR}"/${PN}-1.89.0-predef-include-path.patch
59 "${FILESDIR}"/${PN}-1.89.0-python-exclude-broken-tests.patch
60 "${FILESDIR}"/${PN}-1.89.0-unordered-no-tbb.patch
61 "${FILESDIR}"/${PN}-1.90.0-cobalt.patch
62 "${FILESDIR}"/${PN}-1.90.0-msm-std.patch
63 "${FILESDIR}"/${PN}-1.90.0-unsigned-char-EOF.patch
64 )
65
66 create_user-config.jam() {
67 local user_config_jam="${BUILD_DIR}"/user-config.jam
68 if [[ -s ${user_config_jam} ]]; then
69 einfo "${user_config_jam} already exists, skipping configuration"
70 return
71 else
72 einfo "Creating configuration in ${user_config_jam}"
73 fi
74
75 local compiler compiler_version compiler_executable="$(tc-getCXX)"
76 compiler="gcc"
77 compiler_version="$(gcc-version)"
78
79 if use mpi; then
80 local mpi_configuration="using mpi ;"
81 fi
82
83 cat > "${user_config_jam}" <<- __EOF__ || die
84 using ${compiler} : ${compiler_version} : ${compiler_executable} : <cflags>"${CPPFLAGS} ${CFLAGS}" <cxxflags>"${CPPFLAGS} ${CXXFLAGS}" <linkflags>"${LDFLAGS}" <archiver>"$(tc-getAR)" <ranlib>"$(tc-getRANLIB)" ;
85 ${mpi_configuration}
86 __EOF__
87
88 if multilib_native_use python; then
89 append_to_user_config() {
90 local py_config
91 if tc-is-cross-compiler; then
92 py_config="using python : ${EPYTHON#python} : : ${ESYSROOT}/usr/include/${EPYTHON} : ${ESYSROOT}/usr/$(get_libdir) ;"
93 else
94 py_config="using python : ${EPYTHON#python} : ${PYTHON} : $(python_get_includedir) ;"
95 fi
96 echo "${py_config}" >> "${user_config_jam}" || die
97 }
98 python_foreach_impl append_to_user_config
99 fi
100
101 if multilib_native_use python && use numpy; then
102 einfo "Enabling support for NumPy extensions in Boost.Python"
103 else
104 einfo "Disabling support for NumPy extensions in Boost.Python"
105
106 # Boost.Build does not allow for disabling of numpy
107 # extensions, thereby leading to automagic numpy
108 # https://github.com/boostorg/python/issues/111#issuecomment-280447482
109 sed \
110 -e 's/\[ unless \[ python\.numpy \] : <build>no \]/<build>no/g' \
111 -i "${BUILD_DIR}"/libs/python/build/Jamfile || die
112 fi
113 }
114
115 pkg_setup() {
116 # Bail out on unsupported build configuration, bug #456792
117 if [[ -f "${EROOT}"/etc/site-config.jam ]]; then
118 if ! grep -q 'gentoo\(debug\|release\)' "${EROOT}"/etc/site-config.jam; then
119 eerror "You are using custom ${EROOT}/etc/site-config.jam without defined gentoorelease/gentoodebug targets."
120 eerror "Boost can not be built in such configuration."
121 eerror "Please, either remove this file or add targets from ${EROOT}/usr/share/boost-build/site-config.jam to it."
122 die "Unsupported target in ${EROOT}/etc/site-config.jam"
123 fi
124 fi
125 }
126
127 src_prepare() {
128 default
129 multilib_copy_sources
130 }
131
132 ejam() {
133 create_user-config.jam
134
135 local b2_opts=( "--user-config=${BUILD_DIR}/user-config.jam" )
136 if multilib_native_use python; then
137 append_to_b2_opts() {
138 b2_opts+=( python="${EPYTHON#python}" )
139 }
140 python_foreach_impl append_to_b2_opts
141 else
142 b2_opts+=( --without-python )
143 fi
144 b2_opts+=( "$@" )
145
146 echo b2 "${b2_opts[@]}" >&2
147 b2 "${b2_opts[@]}"
148 }
149
150 src_configure() {
151 # -Werror=odr
152 # https://bugs.gentoo.org/943975
153 # https://github.com/boostorg/quickbook/issues/27
154 # https://github.com/boostorg/spirit/issues/800
155 #
156 # Tests also fail:
157 # https://bugs.gentoo.org/956660
158 # https://github.com/boostorg/smart_ptr/issues/121
159 # https://github.com/boostorg/thread/issues/415
160 filter-lto
161
162 lto-guarantee-fat
163
164 # Workaround for too many parallel processes requested, bug #506064
165 [[ "$(makeopts_jobs)" -gt 64 ]] && MAKEOPTS="${MAKEOPTS} -j64"
166
167 # We don't want to end up with -L/usr/lib on our linker lines
168 # which then gives us lots of
169 # skipping incompatible /usr/lib/libc.a when searching for -lc
170 # warnings
171 [[ -n ${ESYSROOT} ]] && local icuarg="-sICU_PATH=${ESYSROOT}/usr"
172
173 OPTIONS=(
174 $(usex debug gentoodebug gentoorelease)
175 "-j$(makeopts_jobs)"
176 -q
177 -d+2
178 pch=off
179 $(usex icu "${icuarg}" '--disable-icu boost.locale.icu=off')
180 $(usev !mpi --without-mpi)
181 $(usev !nls --without-locale)
182 $(usev !context '--without-context --without-coroutine --without-fiber')
183 $(usev !stacktrace --without-stacktrace)
184 --boost-build="${BROOT}"/usr/share/b2/src
185 --layout=system
186 # building with threading=single is currently not possible
187 # https://svn.boost.org/trac/boost/ticket/7105
188 threading=multi
189 link=shared
190 # this seems to be the only way to disable compression algorithms
191 # https://www.boost.org/doc/libs/1_70_0/libs/iostreams/doc/installation.html#boost-build
192 -sNO_BZIP2=$(usex bzip2 0 1)
193 -sNO_LZMA=$(usex lzma 0 1)
194 -sNO_ZLIB=$(usex zlib 0 1)
195 -sNO_ZSTD=$(usex zstd 0 1)
196 boost.stacktrace.from_exception=off
197 )
198
199 if [[ ${CHOST} == *-darwin* ]]; then
200 # We need to add the prefix, and in two cases this exceeds, so prepare
201 # for the largest possible space allocation.
202 append-ldflags -Wl,-headerpad_max_install_names
203 fi
204
205 # Use C++17 globally as of 1.80
206 append-cxxflags -std=c++17
207
208 if [[ ${CHOST} != *-darwin* ]]; then
209 # On modern macOS, file I/O is already 64-bit by default,
210 # there's no support for special options like O_LARGEFILE.
211 # Thus, LFS must be disabled.
212 #
213 # On other systems, we need to enable LFS explicitly for 64-bit
214 # offsets on 32-bit hosts (#894564)
215 append-lfs-flags
216 fi
217 }
218
219 multilib_src_compile() {
220 ejam \
221 --prefix="${EPREFIX}"/usr \
222 "${OPTIONS[@]}" || die
223
224 if multilib_native_use tools; then
225 pushd tools >/dev/null || die
226 ejam \
227 --prefix="${EPREFIX}"/usr \
228 "${OPTIONS[@]}" \
229 || die "Building of Boost tools failed"
230 popd >/dev/null || die
231 fi
232 }
233
234 multilib_src_test() {
235 ##
236 ## Test exclusions
237 ##
238
239 # The following libraries do not compile or fail their tests:
240 local libs_excluded=(
241 # it seems tests are no longer built
242 "callable_traits"
243 # test output comparison failure
244 "config"
245 # undefined reference to `boost::math::concepts::real_concept boost::math::bernoulli_b2n<boost::math::concepts::real_concept>(int)
246 "math"
247 # In function 'PyObject* boost::parameter::python::aux::unspecified_type()':
248 # /usr/include/python3.13/object.h:339:30: error: lvalue required as left operand of assignment
249 # #define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
250 # ~~~~~~~^~~~~~~~~~~~~~~~~~~~
251 "parameter_python"
252 # scope/lambda_tests22.cpp(27): test 'x == 1' failed in function 'int main()'
253 "phoenix"
254 # vec_access.hpp:95:223: error: static assertion failed: Boost QVM static assertion failure
255 "qvm"
256 # Processing file ../boost_1_89_0/libs/regex/example/../include/boost/regex/v5/regex_iterator.hpp
257 # terminate called after throwing an instance of 'std::length_error'
258 # what(): basic_string::_M_create
259 "regex"
260 # in function `boost::archive::tmpnam(char*)': test_array.cpp:(.text+0x108):
261 # undefined reference to `boost::filesystem::detail::unique_path(...)'
262 "serialization"
263 # TuTestMain.cpp(22) fatal error: in "test_main_caller( argc_ argv )":
264 # std::runtime_error: Event was not consumed!
265 "statechart"
266 # t_5_007.cpp(22): error: could not find include file: boost/version.hpp
267 "wave"
268 )
269
270 if ! use mpi; then
271 # graph_parallel tries to use MPI even with use=-mpi
272 local no_mpi=( "mpi" "graph_parallel" )
273 einfo "Disabling tests due to USE=-mpi: ${no_mpi[@]}"
274 libs_excluded+=( ${no_mpi[@]} )
275 fi
276
277 if ! use test-full; then
278 # passes its tests but takes a very long time to build
279 local no_full=( "geometry" "multiprecision" )
280 einfo "Disabling expensive tests due to USE=-test-full: ${no_full[@]}"
281 libs_excluded+=( ${no_full[@]} )
282 fi
283
284 einfo "Skipping the following tests: ${libs_excluded[@]}"
285
286 ##
287 ## Find and run tests
288 ##
289
290 # Prepare to find libraries but without exclusions
291 local excluded findlibs="find ${BUILD_DIR}/libs -maxdepth 1 -mindepth 1 -type d "
292 for excluded in ${libs_excluded[@]}; do
293 findlibs+="-not -name ${excluded} "
294 done
295
296 # Must come as last argument
297 findlibs+="-print0"
298
299 # Collect libraries to test, with full path.
300 # The list is then sorted to provide predictable execution order,
301 # which would otherwise depend on the file system.
302 local libs
303 readarray -td '' libs < <(${findlibs})
304 readarray -td '' libs < <(printf '%s\0' "${libs[@]}" | sort -z)
305
306 # Build the list of test names we are about to run
307 local lib_names
308 for lib in ${libs[@]}; do
309 lib_names+=("${lib##*/}")
310 done
311
312 # Create custom options for tests based on the build settings
313 TEST_OPTIONS=("${OPTIONS[@]}")
314
315 # Dial down log output - the full b2 command used to compile & run
316 # a test suite will be printed by ejam and can be used to build
317 # and run the tests in a test suite's directory.
318 TEST_OPTIONS=("${TEST_OPTIONS[@]/-d+2/-d0}")
319
320 # Finally build & run all test suites
321 einfo "Running the following tests: ${lib_names[*]}"
322
323 local failed_tests=()
324 for lib in "${libs[@]}"; do
325 # Skip libraries without test directory
326 [[ ! -d "${lib}/test" ]] && continue
327
328 # Move into library test dir & run all tests
329 pushd "${lib}/test" >/dev/null || die
330 nonfatal edob -m "Running tests in: $(pwd)" ejam --prefix="${EPREFIX}"/usr "${TEST_OPTIONS[@]}" || failed_tests+=( "${lib}" )
331 popd >/dev/null || die
332 done
333
334 if (( ${#failed_tests[@]} )); then
335 eerror "Failed tests. Printing summary."
336 local failed_test
337 for failed_test in "${failed_tests[@]}" ; do
338 eerror "Failed test: ${failed_test}"
339 done
340 die "Tests failed."
341 fi
342 }
343
344 multilib_src_install() {
345 ejam \
346 --prefix="${ED}"/usr \
347 --includedir="${ED}"/usr/include \
348 --libdir="${ED}"/usr/$(get_libdir) \
349 "${OPTIONS[@]}" install || die "Installation of Boost libraries failed"
350
351 if multilib_native_use tools; then
352 dobin dist/bin/*
353
354 insinto /usr/share
355 doins -r dist/share/boostbook
356 fi
357
358 # boost's build system truely sucks for not having a destdir. Because for
359 # this reason we are forced to build with a prefix that includes the
360 # DESTROOT, dynamic libraries on Darwin end messed up, referencing the
361 # DESTROOT instread of the actual EPREFIX. There is no way out of here
362 # but to do it the dirty way of manually setting the right install_names.
363 if [[ ${CHOST} == *-darwin* ]]; then
364 einfo "Working around completely broken build-system(tm)"
365 local d
366 for d in "${ED}"/usr/lib/*.dylib; do
367 if [[ -f ${d} ]]; then
368 # fix the "soname"
369 ebegin " correcting install_name of ${d#${ED}}"
370 install_name_tool -id "/${d#${D}}" "${d}"
371 eend $?
372 # fix references to other libs
373 # these paths look like this:
374 # bin.v2/libs/thread/build/gcc-12.1/gentoorelease/pch-off/
375 # threadapi-pthread/threading-multi/visibility-hidden/
376 # libboost_thread.dylib
377 refs=$(otool -XL "${d}" | \
378 sed -e '1d' -e 's/^\t//' | \
379 grep "libboost_" | \
380 cut -f1 -d' ')
381 local r
382 for r in ${refs}; do
383 # strip path prefix from references, so we obtain
384 # something like libboost_thread.dylib.
385 local r_basename=${r##*/}
386
387 ebegin " correcting reference to ${r_basename}"
388 install_name_tool -change \
389 "${r}" \
390 "${EPREFIX}/usr/lib/${r_basename}" \
391 "${d}"
392 eend $?
393 done
394 fi
395 done
396 fi
397 }
398
399 multilib_src_install_all() {
400 if ! use numpy; then
401 rm -r "${ED}"/usr/include/boost/python/numpy* || die
402 fi
403
404 if use python; then
405 if use mpi; then
406 move_mpi_py_into_sitedir() {
407 python_moduleinto boost
408
409 python_domodule "${ED}"/usr/$(get_libdir)/boost-${EPYTHON}/mpi.so
410 rm -r "${ED}"/usr/$(get_libdir)/boost-${EPYTHON} || die
411
412 python_optimize
413 }
414 python_foreach_impl move_mpi_py_into_sitedir
415 else
416 rm -r "${ED}"/usr/include/boost/mpi/python* || die
417 fi
418 else
419 rm -r "${ED}"/usr/include/boost/{python*,mpi/python*,parameter/aux_/python,parameter/python*} || die
420 fi
421
422 if ! use nls; then
423 rm -r "${ED}"/usr/include/boost/locale || die
424 fi
425
426 if ! use context; then
427 rm -r "${ED}"/usr/include/boost/context || die
428 rm -r "${ED}"/usr/include/boost/coroutine{,2} || die
429 rm "${ED}"/usr/include/boost/asio/spawn.hpp || die
430 fi
431
432 if use doc; then
433 # find extraneous files that shouldn't be installed
434 # as part of the documentation and remove them.
435 find libs/*/* \( -iname 'test' -o -iname 'src' \) -exec rm -rf '{}' + || die
436 find doc \( -name 'Jamfile.v2' -o -name 'build' -o -name '*.manifest' \) -exec rm -rf '{}' + || die
437 find tools \( -name 'Jamfile.v2' -o -name 'src' -o -name '*.cpp' -o -name '*.hpp' \) -exec rm -rf '{}' + || die
438
439 docinto html
440 dodoc *.{htm,html,png,css}
441 dodoc -r doc libs more tools
442
443 # To avoid broken links
444 dodoc LICENSE_1_0.txt
445
446 dosym ../../../../include/boost /usr/share/doc/${PF}/html/boost
447 fi
448
449 strip-lto-bytecode
450 }
451
452 pkg_preinst() {
453 # Yay for having symlinks that are nigh-impossible to remove without
454 # resorting to dirty hacks like these. Removes lingering symlinks
455 # from the slotted versions.
456 local symlink
457 for symlink in "${EROOT}"/usr/include/boost "${EROOT}"/usr/share/boostbook; do
458 if [[ -L ${symlink} ]]; then
459 rm -f "${symlink}" || die
460 fi
461 done
462
463 # some ancient installs still have boost cruft lying around
464 # for unknown reasons, causing havoc for reverse dependencies
465 # Bug: 607734
466 rm -rf "${EROOT}"/usr/include/boost-1_[3-5]? || die
467 }
468
469 pkg_postinst() {
470 elog "Boost.Regex is *extremely* ABI sensitive. If you get errors such as"
471 elog
472 elog " undefined reference to \`boost::re_detail_$(ver_cut 1)0$(ver_cut 2)00::cpp_regex_traits_implementation"
473 elog " <char>::transform_primary[abi:cxx11](char const*, char const*) const'"
474 elog
475 elog "Then you need to recompile Boost and all its reverse dependencies"
476 elog "using the same toolchain. In general, *every* change of the C++ toolchain"
477 elog "requires a complete rebuild of the Boost-dependent ecosystem."
478 elog
479 elog "See for instance https://bugs.gentoo.org/638138"
480 }