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