Skip to content

apply cpuid guard to tbb headers copied at install time#253

Merged
kevinushey merged 1 commit into
masterfrom
bugfix/patch-copied-tbb-headers
Jul 23, 2026
Merged

apply cpuid guard to tbb headers copied at install time#253
kevinushey merged 1 commit into
masterfrom
bugfix/patch-copied-tbb-headers

Conversation

@kevinushey

Copy link
Copy Markdown
Contributor

Follow-up to #248, which turned out to be incomplete: on Windows, RcppParallel ships the TBB headers provided by Rtools, not the bundled oneTBB copy -- useTbbPreamble() copies them from TBB_INC at build time. So the __cpuid guard patched into the bundled sources never reached installed packages on Windows, and the cpuid.h/intrin.h include-order conflict persisted. Confirmed on a real Rtools45 setup: the sourceCpp repro (#include <cpuid.h> before <tbb/parallel_sort.h>) still failed against a patched build, with the installed _machine.h showing the unpatched line.

This applies the same guard by post-processing the copied _machine.h in useTbbPreamble(), covering both the Rtools and bundled header sources. The patch function is idempotent (skips if push_macro already present) and bails unless the header contains exactly one bare #include <intrin.h> line, so unexpected header layouts are left untouched.

Tested: patching a pristine v6.0.0 _machine.h produces output identical (modulo blank lines) to the source-patched bundled header; re-running is a no-op; files without the expected include are left unmodified. _flow_graph_trace_impl.h is the only other TBB header including <intrin.h>, and only under _MSC_VER, so _machine.h remains the single mingw chokepoint.

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.
@kevinushey
kevinushey merged commit a269874 into master Jul 23, 2026
5 checks passed
@kevinushey
kevinushey deleted the bugfix/patch-copied-tbb-headers branch July 23, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant