fix(patches): force RcppParallel to use its bundled oneTBB

The link-order fix alone does not survive a build image that exports
TBB_INC/TBB_LIB. RcppParallel's configure.R then never reaches the
bundled branch at all: it links the image's TBB, install.libs.R fills
RcppParallel/lib with absolute symlinks into the image's library dir,
and the published binary records NEEDED libtbb.so.12 (libtbb.so.2 for
the classic Intel TBB on el8/el9), so it cannot dyn.load on a consumer
machine without that exact library. build-env-images dropped those
variables, but its images are rebuilt only by cron or a manual run, and
R reads ~/.Renviron after the process environment, so nothing on the
pipeline side can override them in the meantime.

Patch the package to ignore an ambient TBB_ROOT/TBB_LIB/TBB_INC instead
of relying on the image being clean, in all four places that read them:
configure.R (branch selection), install.libs.R (which R CMD INSTALL runs
outside the src/Makevars rule that passes the configured values), and
R/tbb.R at run time -- .onLoad() would otherwise dyn.load a second,
unrelated TBB next to the bundled one, which segfaults R on load, and
RcppParallelLibs()/CxxFlags() would hand the system TBB to dependents
such as rstan. BINCRAFT_ALLOW_SYSTEM_TBB=TRUE restores the upstream
behaviour. Keep the link-order hunk: the bundled branch passes its build
dir as '-Wl,-L', which gcc still places after its own search dirs.

Verified on the current (pre-fix) build-env images, which still export
TBB_INC/TBB_LIB -- ubuntu jammy, redhat 9 and alpine 3.24: NEEDED
libtbb.so, rpath $ORIGIN/../lib, real libtbb.so.2 in RcppParallel/lib,
and the package loads with every system libtbb moved away. Without the
patch on jammy the same build yields NEEDED libtbb.so.12 and fails to
load; with the configure-only patch it builds the bundled TBB but
segfaults on the post-install load test.
This commit is contained in:
Patrick Schratz 2026-07-31 09:03:56 +00:00
commit 7aa6db3135
No known key found for this signature in database
GPG key ID: 62050D5BC68AB6DC

View file

@ -6,8 +6,8 @@
"env": {},
"configure_args": [],
"makevars": {},
"patch": "RcppParallel/bundled-tbb-link-order.patch",
"reason": "RcppParallel 6.x bundles oneTBB 2022 and builds it with cmake, which works on musl and g++ 8-15, so the system-TBB workaround needed for 5.x is gone. What remains broken is the link order: configure.R passes the TBB directory as '-Wl,-L', and gcc expands its own search dirs (/usr/lib64, /usr/lib/<triplet>) into '-L' options ahead of anything forwarded with '-Wl,'. On a build host with a distro TBB installed, '-ltbb' therefore resolves to the system library and RcppParallel.so records its SONAME (libtbb.so.12, or libtbb.so.2 for the classic Intel TBB on el8/el9) instead of the bundled 'libtbb.so'. The published binary then loads the system TBB rather than the copy in RcppParallel/lib and fails to dyn.load on a consumer machine without one, the same way fs did with libuv. Passing a plain '-L' puts the bundled build dir ahead of gcc's defaults; verified on alpine 3.24, el8 and ubuntu noble to produce NEEDED libtbb.so + RPATH $ORIGIN/../lib, loading with every system libtbb removed."
"patch": "RcppParallel/force-bundled-tbb.patch",
"reason": "RcppParallel 6.x bundles oneTBB 2022 and builds it with cmake on every platform we ship, so the system-TBB workaround needed for 5.x is gone, but two things still steer the build back to a system TBB. (1) Ambient TBB_ROOT/TBB_LIB/TBB_INC: several build images still export these (build-env-images dropped them, but the images are rebuilt only by cron/manual runs, so a stale image keeps them), and R reads ~/.Renviron *after* the process environment, so no pipeline-side env override can undo it. configure.R then takes the system-TBB branch, install.libs.R symlinks the image's libraries into RcppParallel/lib as absolute paths, and the binary records NEEDED libtbb.so.12 (libtbb.so.2 for the classic Intel TBB on el8/el9) -- it cannot dyn.load on a consumer machine without that exact TBB. Both files are patched to ignore those variables (opt out with BINCRAFT_ALLOW_SYSTEM_TBB=TRUE); install.libs.R needs it separately because R CMD INSTALL runs it outside the src/Makevars rule that passes the configured values. (2) Link order: the bundled branch passes its build dir as '-Wl,-Ltbb/build/lib_release', and gcc expands its own search dirs (/usr/lib64, /usr/lib/<triplet>) into '-L' options ahead of anything forwarded with '-Wl,', so '-ltbb' would still resolve to a distro TBB when one is installed; a plain '-L' puts the bundled dir first. Verified on the current build-env-ubuntu:jammy image (which still exports TBB_INC/TBB_LIB): NEEDED libtbb.so, RUNPATH $ORIGIN/../lib, real libtbb.so.2 in RcppParallel/lib, and the package loads with every system libtbb moved away."
},
{
"package": "fs",