|
1 | 1 |
|
2 | 2 | # make sure we call correct version of R |
3 | 3 | rExe <- if (.Platform$OS.type == "windows") "R.exe" else "R" |
4 | | -define(R = file.path(R.home("bin"), rExe)) |
| 4 | +rPath <- file.path(R.home("bin"), rExe) |
| 5 | +define(R = rPath) |
| 6 | + |
| 7 | +# Clang enables C++17 aligned allocation based on the deployment target, but |
| 8 | +# the corresponding libc++ entry points are unavailable before macOS 10.13. |
| 9 | +# Probe through R CMD SHLIB so we see the compiler, standard library, flags, |
| 10 | +# launchers, and user Makevars settings that will actually build the package. |
| 11 | +tbbNeedsNoAlignedAllocation <- function() { |
| 12 | + |
| 13 | + if (!identical(Sys.info()[["sysname"]], "Darwin")) |
| 14 | + return(FALSE) |
| 15 | + |
| 16 | + probeDir <- tempfile("RcppParallel-configure-") |
| 17 | + dir.create(probeDir) |
| 18 | + on.exit(unlink(probeDir, recursive = TRUE), add = TRUE) |
| 19 | + |
| 20 | + source <- file.path(probeDir, "probe.cpp") |
| 21 | + writeLines(c( |
| 22 | + "#include <cstddef>", |
| 23 | + "#if defined(__clang__) && defined(_LIBCPP_VERSION) && \\", |
| 24 | + " defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \\", |
| 25 | + " __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101300", |
| 26 | + "#pragma message(\"RCPP_PARALLEL_NO_ALIGNED_ALLOCATION\")", |
| 27 | + "#endif", |
| 28 | + "int rcppParallelConfigureProbe;" |
| 29 | + ), source) |
| 30 | + |
| 31 | + output <- tryCatch( |
| 32 | + suppressWarnings(system2( |
| 33 | + rPath, |
| 34 | + c("CMD", "SHLIB", shQuote(source)), |
| 35 | + stdout = TRUE, |
| 36 | + stderr = TRUE |
| 37 | + )), |
| 38 | + error = function(cnd) character() |
| 39 | + ) |
| 40 | + |
| 41 | + any(grepl("RCPP_PARALLEL_NO_ALIGNED_ALLOCATION", output, fixed = TRUE)) |
| 42 | + |
| 43 | +} |
5 | 44 |
|
6 | 45 | # check whether user has Makevars file that might cause trouble |
7 | 46 | makevars <- Sys.getenv("R_MAKEVARS_USER", unset = "~/.R/Makevars") |
@@ -237,7 +276,14 @@ if (!is.na(tbbLib)) { |
237 | 276 | # TBB is always enabled: either one was supplied via TBB_LIB / TBB_ROOT, or we |
238 | 277 | # built the bundled copy, and failing to do either is fatal above |
239 | 278 | define(TBB_ENABLED = TRUE) |
240 | | -define(PKG_CXXFLAGS = "-DRCPP_PARALLEL_USE_TBB=1") |
| 279 | +tbbCxxFlags <- if (tbbNeedsNoAlignedAllocation()) { |
| 280 | + "-fno-aligned-allocation" |
| 281 | +} else { |
| 282 | + "" |
| 283 | +} |
| 284 | +define(TBB_CXXFLAGS = tbbCxxFlags) |
| 285 | +pkgCxxFlags <- c("-DRCPP_PARALLEL_USE_TBB=1", tbbCxxFlags) |
| 286 | +define(PKG_CXXFLAGS = paste(pkgCxxFlags[nzchar(pkgCxxFlags)], collapse = " ")) |
241 | 287 |
|
242 | 288 | # macOS needs some extra flags set |
243 | 289 | if (Sys.info()[["sysname"]] == "Darwin") { |
|
0 commit comments