Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# RcppParallel (development version)

* Fixed bundled oneTBB builds and downstream compilation with Clang and libc++
when targeting macOS 10.12 or earlier, where C++17 aligned allocation is not
available. (#219)


# RcppParallel 6.2.0

Expand Down
3 changes: 2 additions & 1 deletion R/tbb-autodetected.R.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
TBB_ENABLED <- @TBB_ENABLED@
TBB_LIB <- "@TBB_LIB@"
TBB_INC <- "@TBB_INC@"
TBB_CXXFLAGS <- "@TBB_CXXFLAGS@"

TBB_NAME <- "@TBB_NAME@"
TBB_MALLOC_NAME <- "@TBB_MALLOC_NAME@"
TBB_MALLOC_NAME <- "@TBB_MALLOC_NAME@"
3 changes: 3 additions & 0 deletions R/tbb.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ tbbCxxFlags <- function() {

flags <- c("-DRCPP_PARALLEL_USE_TBB=1")

if (nzchar(TBB_CXXFLAGS))
flags <- c(flags, TBB_CXXFLAGS)

# if TBB_INC is set, apply those library paths
tbbInc <- Sys.getenv("TBB_INC", unset = TBB_INC)
if (!file.exists(tbbInc)) {
Expand Down
4 changes: 3 additions & 1 deletion src/Makevars.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ TBB_LIB = @TBB_LIB@
TBB_INC = @TBB_INC@
TBB_NAME = @TBB_NAME@
TBB_MALLOC_NAME = @TBB_MALLOC_NAME@
TBB_CXXFLAGS = @TBB_CXXFLAGS@

PKG_CPPFLAGS = @PKG_CPPFLAGS@
PKG_CXXFLAGS = @PKG_CXXFLAGS@
Expand All @@ -28,7 +29,8 @@ tbb: tbb-clean
@TBB_LIB="$(TBB_LIB)" TBB_INC="$(TBB_INC)" \
TBB_NAME="$(TBB_NAME)" TBB_MALLOC_NAME="$(TBB_MALLOC_NAME)" \
CC="$(CC)" CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" \
CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" \
CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS) $(TBB_CXXFLAGS)" \
LDFLAGS="$(LDFLAGS)" \
CMAKE="$(CMAKE)" "@R@" -s -f install.libs.R --args build

# NOTE: we do not want to clean ../inst/lib or ../inst/libs here,
Expand Down
18 changes: 18 additions & 0 deletions tests/test-cxx-flags.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Unit tests for the compiler flags handed to downstream packages through
# RcppParallel::CxxFlags().

RcppParallel:::test_init()

flags <- tbbCxxFlags()

assert(is.character(flags))
assert(length(flags) == 1L)
assert(!is.na(flags))
assert(grepl("-DRCPP_PARALLEL_USE_TBB=1", flags, fixed = TRUE))

hasNoAlignedAllocation <- grepl(
"-fno-aligned-allocation",
flags,
fixed = TRUE
)
assert(identical(hasNoAlignedAllocation, nzchar(TBB_CXXFLAGS)))
50 changes: 48 additions & 2 deletions tools/config/configure.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@

# make sure we call correct version of R
rExe <- if (.Platform$OS.type == "windows") "R.exe" else "R"
define(R = file.path(R.home("bin"), rExe))
rPath <- file.path(R.home("bin"), rExe)
define(R = rPath)

# Clang enables C++17 aligned allocation based on the deployment target, but
# the corresponding libc++ entry points are unavailable before macOS 10.13.
# Probe through R CMD SHLIB so we see the compiler, standard library, flags,
# launchers, and user Makevars settings that will actually build the package.
tbbNeedsNoAlignedAllocation <- function() {

if (!identical(Sys.info()[["sysname"]], "Darwin"))
return(FALSE)

probeDir <- tempfile("RcppParallel-configure-")
dir.create(probeDir)
on.exit(unlink(probeDir, recursive = TRUE), add = TRUE)

source <- file.path(probeDir, "probe.cpp")
writeLines(c(
"#include <cstddef>",
"#if defined(__clang__) && defined(_LIBCPP_VERSION) && \\",
" defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \\",
" __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101300",
"#pragma message(\"RCPP_PARALLEL_NO_ALIGNED_ALLOCATION\")",
"#endif",
"int rcppParallelConfigureProbe;"
), source)

output <- tryCatch(
suppressWarnings(system2(
rPath,
c("CMD", "SHLIB", shQuote(source)),
stdout = TRUE,
stderr = TRUE
)),
error = function(cnd) character()
)

any(grepl("RCPP_PARALLEL_NO_ALIGNED_ALLOCATION", output, fixed = TRUE))

}

# check whether user has Makevars file that might cause trouble
makevars <- Sys.getenv("R_MAKEVARS_USER", unset = "~/.R/Makevars")
Expand Down Expand Up @@ -237,7 +276,14 @@ if (!is.na(tbbLib)) {
# TBB is always enabled: either one was supplied via TBB_LIB / TBB_ROOT, or we
# built the bundled copy, and failing to do either is fatal above
define(TBB_ENABLED = TRUE)
define(PKG_CXXFLAGS = "-DRCPP_PARALLEL_USE_TBB=1")
tbbCxxFlags <- if (tbbNeedsNoAlignedAllocation()) {
"-fno-aligned-allocation"
} else {
""
}
define(TBB_CXXFLAGS = tbbCxxFlags)
pkgCxxFlags <- c("-DRCPP_PARALLEL_USE_TBB=1", tbbCxxFlags)
define(PKG_CXXFLAGS = paste(pkgCxxFlags[nzchar(pkgCxxFlags)], collapse = " "))

# macOS needs some extra flags set
if (Sys.info()[["sysname"]] == "Darwin") {
Expand Down
Loading