fix(patches): add rstan entry to skip removed tbb_stddef.h #114

Merged
pat-s merged 1 commit from fix/rstan-tbb-stddef-patch into main 2026-07-14 13:52:18 +00:00
Owner

Motivation

rstan fails to compile when it is pulled in as a transitive dependency (e.g. of ctsem), aborting the dependency install:

/mnt/cache/R-pkgs/StanHeaders/include/stan/math/prim/core/init_threadpool_tbb.hpp:9:10:
  fatal error: tbb/tbb_stddef.h: No such file or directory
    9 | #include <tbb/tbb_stddef.h>

StanHeaders' init_threadpool_tbb.hpp unconditionally includes the legacy <tbb/tbb_stddef.h> to detect the TBB version, but that header was removed in oneTBB 2021+, which is the TBB that StanHeaders now bundles.

Fix

Add an rstan entry to local/patches/registry.json that pre-defines TBB_INTERFACE_NEW via CPPFLAGS.
The header's own guard skips the removed include when that macro is already defined and selects the modern tbb/global_control.h + tbb/task_arena.h path that the bundled oneTBB actually provides:

#ifndef TBB_INTERFACE_NEW
#include <tbb/tbb_stddef.h>          // removed in oneTBB 2021+
#if TBB_VERSION_MAJOR >= 2020
#define TBB_INTERFACE_NEW
#endif
#endif
#ifdef TBB_INTERFACE_NEW
#include <tbb/global_control.h>      // taken when we pre-define the macro
#include <tbb/task_arena.h>

This is a makevars-tier override (no source diff), applied through bincraft's R_MAKEVARS_USER, so CPPFLAGS stays additive and does not clobber rstan's own PKG_CPPFLAGS.
-I/usr/local/include is kept because the override replaces the default CPPFLAGS.

Files changed

  • local/patches/registry.json: add the rstan entry (versions: "*", platforms: ["*"], makevars.CPPFLAGS = "-DTBB_INTERFACE_NEW -I/usr/local/include").

Behaviour change

When bincraft resolves rstan (direct or transitive) it builds a patched binary with TBB_INTERFACE_NEW defined, so rstan (and dependents such as ctsem) compile against the bundled oneTBB.
The scope is ["*"] because the failure is bound to StanHeaders' bundled TBB version, not the OS or toolchain.

## Motivation `rstan` fails to compile when it is pulled in as a transitive dependency (e.g. of `ctsem`), aborting the dependency install: ``` /mnt/cache/R-pkgs/StanHeaders/include/stan/math/prim/core/init_threadpool_tbb.hpp:9:10: fatal error: tbb/tbb_stddef.h: No such file or directory 9 | #include <tbb/tbb_stddef.h> ``` StanHeaders' `init_threadpool_tbb.hpp` unconditionally includes the legacy `<tbb/tbb_stddef.h>` to detect the TBB version, but that header was removed in oneTBB 2021+, which is the TBB that StanHeaders now bundles. ## Fix Add an `rstan` entry to `local/patches/registry.json` that pre-defines `TBB_INTERFACE_NEW` via `CPPFLAGS`. The header's own guard skips the removed include when that macro is already defined and selects the modern `tbb/global_control.h` + `tbb/task_arena.h` path that the bundled oneTBB actually provides: ```cpp #ifndef TBB_INTERFACE_NEW #include <tbb/tbb_stddef.h> // removed in oneTBB 2021+ #if TBB_VERSION_MAJOR >= 2020 #define TBB_INTERFACE_NEW #endif #endif #ifdef TBB_INTERFACE_NEW #include <tbb/global_control.h> // taken when we pre-define the macro #include <tbb/task_arena.h> ``` This is a makevars-tier override (no source diff), applied through bincraft's `R_MAKEVARS_USER`, so `CPPFLAGS` stays additive and does not clobber rstan's own `PKG_CPPFLAGS`. `-I/usr/local/include` is kept because the override replaces the default `CPPFLAGS`. ## Files changed - `local/patches/registry.json`: add the `rstan` entry (`versions: "*"`, `platforms: ["*"]`, `makevars.CPPFLAGS = "-DTBB_INTERFACE_NEW -I/usr/local/include"`). ## Behaviour change When bincraft resolves `rstan` (direct or transitive) it builds a patched binary with `TBB_INTERFACE_NEW` defined, so `rstan` (and dependents such as `ctsem`) compile against the bundled oneTBB. The scope is `["*"]` because the failure is bound to StanHeaders' bundled TBB version, not the OS or toolchain.
StanHeaders' init_threadpool_tbb.hpp unconditionally includes the legacy
<tbb/tbb_stddef.h> for TBB version detection, but that header was removed
in oneTBB 2021+ (the version StanHeaders now bundles), so rstan's Module.cpp
fails to compile when rstan is pulled in as a transitive dependency (e.g. of
ctsem).

Pre-define TBB_INTERFACE_NEW via CPPFLAGS so the header's own guard skips the
removed include and selects the modern tbb/global_control.h + tbb/task_arena.h
path that the bundled TBB provides. Preserve -I/usr/local/include since the
CPPFLAGS override replaces the R default.
pat-s force-pushed fix/rstan-tbb-stddef-patch from 2561bed5e7 to 6373712c70 2026-07-14 13:40:12 +00:00 Compare
pat-s merged commit 04059f20e3 into main 2026-07-14 13:52:18 +00:00
pat-s deleted branch fix/rstan-tbb-stddef-patch 2026-07-14 13:52:18 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
devxy/build-cran-binaries!114
No description provided.