Skip to content

Commit 4d51c38

Browse files
committed
guard bundled tbb against gcc cpuid.h / mingw intrin.h conflict
GCC's <cpuid.h> defines a function-like '__cpuid' macro. If a downstream package includes <cpuid.h> before any TBB header on Windows (mingw), the macro mangles the __cpuid() declarations in mingw's <intrin.h>, 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 <intrin.h>, 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
1 parent fbaeabb commit 4d51c38

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# RcppParallel (development version)
22

3+
* The bundled oneTBB headers now guard against GCC's `<cpuid.h>` being
4+
included before `<intrin.h>` on Windows (mingw). Previously, translation
5+
units including `<cpuid.h>` before any TBB header would fail to compile,
6+
as the `__cpuid` macro from `<cpuid.h>` conflicts with the `__cpuid()`
7+
function declared by mingw's `<intrin.h>`.
8+
39
* When building the bundled copy of oneTBB, RcppParallel no longer searches
410
for hwloc, and so no longer tries to build the optional 'tbbbind' library.
511
This fixes build failures on machines where a static hwloc library is

patches/mingw_cpuid.diff

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/src/tbb/include/oneapi/tbb/detail/_machine.h b/src/tbb/include/oneapi/tbb/detail/_machine.h
2+
index ca481380..8174f3d3 100644
3+
--- a/src/tbb/include/oneapi/tbb/detail/_machine.h
4+
+++ b/src/tbb/include/oneapi/tbb/detail/_machine.h
5+
@@ -26,7 +26,19 @@
6+
#include <cstddef>
7+
8+
#ifdef _WIN32
9+
+
10+
+// GCC's <cpuid.h> defines a function-like '__cpuid' macro that mangles the
11+
+// __cpuid() declarations in mingw's <intrin.h>. Hide the macro while
12+
+// including <intrin.h> so the two headers can coexist in any order.
13+
+#if defined(__MINGW32__) && defined(__cpuid)
14+
+#pragma push_macro("__cpuid")
15+
+#undef __cpuid
16+
+#include <intrin.h>
17+
+#pragma pop_macro("__cpuid")
18+
+#else
19+
#include <intrin.h>
20+
+#endif
21+
+
22+
#ifdef __TBBMALLOC_BUILD
23+
#define WIN32_LEAN_AND_MEAN
24+
#ifndef NOMINMAX

src/tbb/include/oneapi/tbb/detail/_machine.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,19 @@
2626
#include <cstddef>
2727

2828
#ifdef _WIN32
29+
30+
// GCC's <cpuid.h> defines a function-like '__cpuid' macro that mangles the
31+
// __cpuid() declarations in mingw's <intrin.h>. Hide the macro while
32+
// including <intrin.h> so the two headers can coexist in any order.
33+
#if defined(__MINGW32__) && defined(__cpuid)
34+
#pragma push_macro("__cpuid")
35+
#undef __cpuid
36+
#include <intrin.h>
37+
#pragma pop_macro("__cpuid")
38+
#else
2939
#include <intrin.h>
40+
#endif
41+
3042
#ifdef __TBBMALLOC_BUILD
3143
#define WIN32_LEAN_AND_MEAN
3244
#ifndef NOMINMAX

0 commit comments

Comments
 (0)