From 0d03027c887f5245f1130596e01f712caaa4cbfc Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Thu, 23 Jul 2026 10:21:45 -0700 Subject: [PATCH] fix bundled tbb build issues on macos - disable oneTBB's automatic hwloc search, so the optional tbbbind library is no longer built; its link fails on the CRAN macOS machines, where a static hwloc is discoverable via pkg-config but its required frameworks are not on the link line - build the bundled oneTBB with __TBB_RESUMABLE_TASKS_USE_THREADS on macOS, avoiding the deprecated ucontext APIs (getcontext, swapcontext, makecontext) --- NEWS.md | 9 +++++++++ src/install.libs.R | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/NEWS.md b/NEWS.md index a809295a..f315ae5d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,14 @@ # RcppParallel (development version) +* When building the bundled copy of oneTBB, RcppParallel no longer searches + for hwloc, and so no longer tries to build the optional 'tbbbind' library. + This fixes build failures on machines where a static hwloc library is + discoverable via pkg-config, as on the CRAN macOS machines. + +* On macOS, the bundled copy of oneTBB is now built with + `__TBB_RESUMABLE_TASKS_USE_THREADS`, avoiding use of the deprecated + ucontext APIs (`getcontext`, `swapcontext`, `makecontext`). + # RcppParallel 6.0.0 diff --git a/src/install.libs.R b/src/install.libs.R index 4dcbac27..142914c4 100644 --- a/src/install.libs.R +++ b/src/install.libs.R @@ -116,12 +116,23 @@ useBundledTbb <- function() { prependFlags("CPPFLAGS", "CFLAGS") prependFlags("CPPFLAGS", "CXXFLAGS") + # the ucontext APIs (getcontext, swapcontext, ...) are deprecated on macOS, + # so use the threads-based coroutine implementation for resumable tasks + if (Sys.info()[["sysname"]] == "Darwin") { + flags <- c(Sys.getenv("CXXFLAGS"), "-D__TBB_RESUMABLE_TASKS_USE_THREADS=1") + setenv("CXXFLAGS", flags[nzchar(flags)]) + } + cmakeFlags <- c( forwardEnvVar("CC", "CMAKE_C_COMPILER"), forwardEnvVar("CXX", "CMAKE_CXX_COMPILER"), forwardEnvVar("CFLAGS", "CMAKE_C_FLAGS"), forwardEnvVar("CXXFLAGS", "CMAKE_CXX_FLAGS"), forwardEnvVar("CMAKE_BUILD_TYPE", "CMAKE_BUILD_TYPE"), + # tbbbind requires hwloc, and hwloc's pkg-config file doesn't advertise + # the macOS frameworks needed when linking it statically; RcppParallel + # doesn't use TBB's NUMA APIs, so skip tbbbind altogether + "-DTBB_DISABLE_HWLOC_AUTOMATIC_SEARCH=1", "-DTBB_TEST=0", "-DTBB_EXAMPLES=0", "-DTBB_STRICT=0",