build-cran-binaries/local/patches/RcppParallel/force-bundled-tbb-6.1.x.patch
pat-s 40a0a6e02d
Some checks failed
ci/crow/cron/process-updates/12 Pipeline failed
ci/crow/cron/process-updates/11 Pipeline was successful
ci/crow/cron/process-updates/9 Pipeline was successful
ci/crow/cron/process-updates/2 Pipeline was successful
ci/crow/cron/process-updates/13 Pipeline was successful
ci/crow/cron/process-updates/8 Pipeline was successful
ci/crow/cron/process-updates/16 Pipeline was successful
ci/crow/cron/process-updates/15 Pipeline was successful
ci/crow/cron/process-updates/10 Pipeline was successful
ci/crow/cron/process-updates/14 Pipeline was successful
ci/crow/cron/process-updates/3 Pipeline was successful
ci/crow/cron/process-updates/4 Pipeline was successful
ci/crow/cron/auto-apply-patches Pipeline was successful
ci/crow/cron/process-updates/7 Pipeline failed
ci/crow/cron/process-updates/5 Pipeline was successful
ci/crow/cron/process-updates/1 Pipeline failed
ci/crow/cron/process-updates/6 Pipeline was successful
fix(patches): cover every RcppParallel 6.x release with the bundled-TBB patch (#228)
2026-10-04 07:35:01 +00:00

157 lines
6.3 KiB
Diff

diff --git a/R/aaa.R b/R/aaa.R
index 568a2aa..2744059 100644
--- a/R/aaa.R
+++ b/R/aaa.R
@@ -5,4 +5,21 @@ TBB_LIB <- ""
TBB_INC <- ""
TBB_NAME <- "tbb"
-TBB_MALLOC_NAME <- "tbbmalloc"
\ No newline at end of file
+TBB_MALLOC_NAME <- "tbbmalloc"
+
+# bincraft patch: build images (ours did until build-env-images c51ed09) and
+# plenty of user environments export TBB_ROOT / TBB_LIB / TBB_INC. A binary we
+# publish always carries its own oneTBB in RcppParallel/lib -- see the
+# companion changes in tools/config/configure.R and src/install.libs.R -- so
+# honouring those variables at run time is actively harmful: .onLoad() would
+# dyn.load() a second, unrelated TBB into the process next to the bundled one
+# (two copies of the same symbols in the global scope, which segfaults R on
+# load), and RcppParallelLibs() / CxxFlags() would hand that system TBB to
+# dependents such as rstan, putting NEEDED libtbb.so.12 back into their
+# binaries. Read the variables only when explicitly opted back in.
+bincraftGetenv <- function(name, unset = "") {
+ if (Sys.getenv("BINCRAFT_ALLOW_SYSTEM_TBB", unset = "FALSE") == "TRUE")
+ Sys.getenv(name, unset = unset)
+ else
+ unset
+}
\ No newline at end of file
diff --git a/R/tbb.R b/R/tbb.R
index 152fd16..4b06aa5 100644
--- a/R/tbb.R
+++ b/R/tbb.R
@@ -17,7 +17,7 @@ tbbLibraryPath <- function(name = NULL) {
sysname <- Sys.info()[["sysname"]]
# find root for TBB install
- tbbRoot <- Sys.getenv("TBB_LIB", unset = tbbRoot())
+ tbbRoot <- bincraftGetenv("TBB_LIB", unset = tbbRoot())
if (is.null(name))
return(tbbRoot)
@@ -58,7 +58,7 @@ tbbCxxFlags <- function() {
flags <- c("-DRCPP_PARALLEL_USE_TBB=1")
# if TBB_INC is set, apply those library paths
- tbbInc <- Sys.getenv("TBB_INC", unset = TBB_INC)
+ tbbInc <- bincraftGetenv("TBB_INC", unset = TBB_INC)
if (!file.exists(tbbInc)) {
tbbInc <- system.file("include", package = "RcppParallel")
}
@@ -96,7 +96,7 @@ tbbLdFlags <- function() {
}
# shortcut if TBB_LIB defined
- tbbLib <- Sys.getenv("TBB_LINK_LIB", Sys.getenv("TBB_LIB", unset = TBB_LIB))
+ tbbLib <- bincraftGetenv("TBB_LINK_LIB", bincraftGetenv("TBB_LIB", unset = TBB_LIB))
if (nzchar(tbbLib)) {
if (R.version$os == "emscripten") {
fmt <- "-L%1$s -l%2$s"
diff --git a/src/install.libs.R b/src/install.libs.R
index e770838..1dd2fc7 100644
--- a/src/install.libs.R
+++ b/src/install.libs.R
@@ -492,6 +492,18 @@ prependFlags <- function(prependFlags, toFlags) {
tbbLib <- Sys.getenv("TBB_LIB")
tbbInc <- Sys.getenv("TBB_INC")
+# bincraft patch: the companion change in tools/config/configure.R stops an
+# ambient TBB_LIB / TBB_INC from selecting a system TBB, but this script is
+# also run directly by `R CMD INSTALL` (not only through the `tbb` rule in
+# src/Makevars, which passes the configured values), so at install time it
+# still sees the image's environment and would symlink the system libraries
+# into RcppParallel/lib. Drop them here for the same reason, under the same
+# opt-out.
+if (Sys.getenv("BINCRAFT_ALLOW_SYSTEM_TBB", unset = "FALSE") != "TRUE") {
+ tbbLib <- ""
+ tbbInc <- ""
+}
+
args <- commandArgs(trailingOnly = TRUE)
if (identical(args, "build")) {
if (nzchar(tbbLib) && nzchar(tbbInc)) {
diff --git a/tools/config/configure.R b/tools/config/configure.R
index c3842f9..adf7876 100644
--- a/tools/config/configure.R
+++ b/tools/config/configure.R
@@ -66,6 +66,24 @@ tbbRoot <- Sys.getenv("TBB_ROOT", unset = NA)
tbbLib <- Sys.getenv("TBB_LIB", unset = NA)
tbbInc <- Sys.getenv("TBB_INC", unset = NA)
+# bincraft patch: ignore an ambient TBB_ROOT / TBB_LIB / TBB_INC. Our build
+# images exported these until build-env-images c51ed09 (a leftover from
+# RcppParallel 5.x, whose bundled Intel TBB would not build on musl or with
+# modern g++), and any of them switches the branches below to a system TBB.
+# The published binary then records NEEDED libtbb.so.12 (or libtbb.so.2 for
+# the classic Intel TBB) and gets a RcppParallel/lib full of absolute symlinks
+# into the image's library dir, so it cannot dyn.load on a consumer machine
+# without that exact TBB. 6.x bundles oneTBB 2022 and builds it with cmake on
+# every platform we ship, so the bundled copy is always the right choice here;
+# forcing it in the package rather than relying on the image environment keeps
+# the binary correct whichever image version CI happens to pull. Set
+# BINCRAFT_ALLOW_SYSTEM_TBB=TRUE to restore the upstream behaviour.
+if (Sys.getenv("BINCRAFT_ALLOW_SYSTEM_TBB", unset = "FALSE") != "TRUE") {
+ tbbRoot <- NA
+ tbbLib <- NA
+ tbbInc <- NA
+}
+
tbbName <- Sys.getenv("TBB_NAME", unset = "tbb")
tbbMallocName <- Sys.getenv("TBB_MALLOC_NAME", unset = "tbbmalloc")
@@ -146,6 +164,18 @@ define(
)
# set PKG_LIBS
+#
+# bincraft patch: the non-Windows library directories below are passed as
+# plain '-L', not '-Wl,-L'. gcc expands its own search dirs (/usr/lib64,
+# /usr/lib/<triplet>) into explicit '-L' options ahead of anything forwarded
+# verbatim with '-Wl,', so with '-Wl,-L' a system libtbb.so wins over the one
+# named here: on a build host with a distro TBB installed, '-ltbb' resolves to
+# that library and RcppParallel.so records its SONAME (libtbb.so.12, or
+# libtbb.so.2 for the classic Intel TBB) instead of the bundled 'libtbb.so'.
+# The binary then loads the system TBB rather than the copy shipped in
+# RcppParallel/lib, and fails outright on a machine that has no system TBB.
+# gcc places a plain '-L' before its built-in dirs, so the intended library is
+# found first.
pkgLibs <- if (.Platform$OS.type == "windows") {
if (!is.na(tbbLib) && file.exists(file.path(tbbInc, "oneapi"))) {
@@ -183,7 +213,7 @@ pkgLibs <- if (.Platform$OS.type == "windows") {
} else if (!is.na(tbbLib)) {
c(
- "-Wl,-L\"$(TBB_LIB)\"",
+ "-L\"$(TBB_LIB)\"",
sprintf("-Wl,-rpath,%s", shQuote(tbbLib)),
"-l$(TBB_NAME)",
"-l$(TBB_MALLOC_NAME)"
@@ -192,14 +222,14 @@ pkgLibs <- if (.Platform$OS.type == "windows") {
} else if (R.version$os == "emscripten") {
c(
- "-Wl,-Ltbb/build/lib_release",
+ "-Ltbb/build/lib_release",
"-l$(TBB_NAME)"
)
} else {
c(
- "-Wl,-Ltbb/build/lib_release",
+ "-Ltbb/build/lib_release",
"-l$(TBB_NAME)",
"-l$(TBB_MALLOC_NAME)"
)