|
88 | 88 | } |
89 | 89 |
|
90 | 90 | useTbbPreamble <- function(tbbInc) { |
| 91 | + |
91 | 92 | dir.create("../inst/include", recursive = TRUE, showWarnings = FALSE) |
92 | 93 | for (suffix in c("oneapi", "serial", "tbb")) { |
93 | 94 | tbbPath <- file.path(tbbInc, suffix) |
94 | 95 | if (file.exists(tbbPath)) { |
95 | 96 | file.copy(tbbPath, "../inst/include", recursive = TRUE) |
96 | 97 | } |
97 | 98 | } |
| 99 | + |
| 100 | + patchTbbMachineHeader("../inst/include/oneapi/tbb/detail/_machine.h") |
| 101 | + |
| 102 | +} |
| 103 | + |
| 104 | +# Guard the '#include <intrin.h>' in TBB's _machine.h against GCC's |
| 105 | +# <cpuid.h> macro on mingw. The headers we ship may come from Rtools |
| 106 | +# rather than from the bundled copy of oneTBB, so the guard must be |
| 107 | +# applied to the copied headers, not just the bundled sources. |
| 108 | +patchTbbMachineHeader <- function(path) { |
| 109 | + |
| 110 | + if (!file.exists(path)) |
| 111 | + return() |
| 112 | + |
| 113 | + contents <- readLines(path) |
| 114 | + if (any(grepl("push_macro", contents, fixed = TRUE))) |
| 115 | + return() |
| 116 | + |
| 117 | + index <- which(contents == "#include <intrin.h>") |
| 118 | + if (length(index) != 1L) |
| 119 | + return() |
| 120 | + |
| 121 | + replacement <- c( |
| 122 | + "// GCC's <cpuid.h> defines a function-like '__cpuid' macro that mangles the", |
| 123 | + "// __cpuid() declarations in mingw's <intrin.h>. Hide the macro while", |
| 124 | + "// including <intrin.h> so the two headers can coexist in any order.", |
| 125 | + "#if defined(__MINGW32__) && defined(__cpuid)", |
| 126 | + "#pragma push_macro(\"__cpuid\")", |
| 127 | + "#undef __cpuid", |
| 128 | + "#include <intrin.h>", |
| 129 | + "#pragma pop_macro(\"__cpuid\")", |
| 130 | + "#else", |
| 131 | + "#include <intrin.h>", |
| 132 | + "#endif" |
| 133 | + ) |
| 134 | + |
| 135 | + contents <- append(contents[-index], replacement, after = index - 1L) |
| 136 | + writeLines(contents, path) |
| 137 | + |
98 | 138 | } |
99 | 139 |
|
100 | 140 | useSystemTbb <- function(tbbLib, tbbInc) { |
|
0 commit comments