From 4d51c38af4700e73129e29380adc493b14a7e9be Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Thu, 23 Jul 2026 14:48:51 -0700 Subject: [PATCH] guard bundled tbb against gcc cpuid.h / mingw intrin.h conflict GCC's defines a function-like '__cpuid' macro. If a downstream package includes before any TBB header on Windows (mingw), the macro mangles the __cpuid() declarations in mingw's , which oneTBB's detail/_machine.h includes, and compilation fails, e.g.: intrin-impl.h:2013:42: error: macro "__cpuid" requires 5 arguments, but only 2 given Suppress the macro via push_macro/pop_macro while including , so the two headers can coexist in any include order. Record the change in patches/mingw_cpuid.diff so it can be reapplied on oneTBB updates. This was observed in the wild with the 'robscale' package on r-universe: https://github.com/r-universe/cran/actions/runs/30028399599/job/89335144753 --- NEWS.md | 6 +++++ patches/mingw_cpuid.diff | 24 ++++++++++++++++++++ src/tbb/include/oneapi/tbb/detail/_machine.h | 12 ++++++++++ 3 files changed, 42 insertions(+) create mode 100644 patches/mingw_cpuid.diff diff --git a/NEWS.md b/NEWS.md index 3b535328..600139ab 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,11 @@ # RcppParallel (development version) +* The bundled oneTBB headers now guard against GCC's `` being + included before `` on Windows (mingw). Previously, translation + units including `` before any TBB header would fail to compile, + as the `__cpuid` macro from `` conflicts with the `__cpuid()` + function declared by mingw's ``. + * 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 diff --git a/patches/mingw_cpuid.diff b/patches/mingw_cpuid.diff new file mode 100644 index 00000000..2f16bdf8 --- /dev/null +++ b/patches/mingw_cpuid.diff @@ -0,0 +1,24 @@ +diff --git a/src/tbb/include/oneapi/tbb/detail/_machine.h b/src/tbb/include/oneapi/tbb/detail/_machine.h +index ca481380..8174f3d3 100644 +--- a/src/tbb/include/oneapi/tbb/detail/_machine.h ++++ b/src/tbb/include/oneapi/tbb/detail/_machine.h +@@ -26,7 +26,19 @@ + #include + + #ifdef _WIN32 ++ ++// GCC's defines a function-like '__cpuid' macro that mangles the ++// __cpuid() declarations in mingw's . Hide the macro while ++// including so the two headers can coexist in any order. ++#if defined(__MINGW32__) && defined(__cpuid) ++#pragma push_macro("__cpuid") ++#undef __cpuid ++#include ++#pragma pop_macro("__cpuid") ++#else + #include ++#endif ++ + #ifdef __TBBMALLOC_BUILD + #define WIN32_LEAN_AND_MEAN + #ifndef NOMINMAX diff --git a/src/tbb/include/oneapi/tbb/detail/_machine.h b/src/tbb/include/oneapi/tbb/detail/_machine.h index ca481380..8174f3d3 100644 --- a/src/tbb/include/oneapi/tbb/detail/_machine.h +++ b/src/tbb/include/oneapi/tbb/detail/_machine.h @@ -26,7 +26,19 @@ #include #ifdef _WIN32 + +// GCC's defines a function-like '__cpuid' macro that mangles the +// __cpuid() declarations in mingw's . Hide the macro while +// including so the two headers can coexist in any order. +#if defined(__MINGW32__) && defined(__cpuid) +#pragma push_macro("__cpuid") +#undef __cpuid +#include +#pragma pop_macro("__cpuid") +#else #include +#endif + #ifdef __TBBMALLOC_BUILD #define WIN32_LEAN_AND_MEAN #ifndef NOMINMAX