guard bundled tbb against gcc cpuid.h / mingw intrin.h conflict#248
Merged
Conversation
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
kevinushey
added a commit
that referenced
this pull request
Jul 23, 2026
On Windows, RcppParallel ships the TBB headers provided by Rtools, not the bundled copy of oneTBB -- useTbbPreamble() copies them from TBB_INC at build time. The __cpuid guard added in #248 patched only the bundled sources, so installed packages on Windows never received it, and the cpuid.h/intrin.h include-order conflict persisted. Post-process the copied _machine.h in useTbbPreamble() instead, applying the same guard to whichever headers are actually installed. The patch function is idempotent and bails if the header does not have the expected form.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
GCC's
<cpuid.h>defines a function-like__cpuidmacro. 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'sdetail/_machine.hincludes, and compilation fails:Observed in the wild with the
robscalepackage on r-universe: https://github.com/r-universe/cran/actions/runs/30028399599/job/89335144753Fix
Suppress the macro via
push_macro/pop_macrowhile including<intrin.h>in the bundledoneapi/tbb/detail/_machine.h. Since mingw'sintrin.his include-guarded, its one-time processing typically happens inside this header, where we control the macro environment -- so this protects downstream packages regardless of their include order.pop_macrorestores GCC's macro for any later use in the translation unit.The guard is a no-op except in the exact broken configuration (mingw +
__cpuidmacro active). The change is recorded inpatches/mingw_cpuid.diffso it can be reapplied when the bundled oneTBB is updated (tools/tbb/update-tbb.Rreplacessrc/tbbwholesale).Notes