Skip to content

Commit c328085

Browse files
committed
make sure RcppParallel still builds with older R
1 parent f3fcdfd commit c328085

File tree

7 files changed

+75
-18
lines changed

7 files changed

+75
-18
lines changed

NEWS.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
## RcppParallel 5.1.10 (UNRELEASED)
33

44
* RcppParallel now bundles oneTBB 2022.0.0.
5+
6+
* On Windows, RcppParallel now uses the copy of TBB provided by Rtools, if any.
7+
If TBB is not available, RcppParallel will use only the fallback 'tinythread'
8+
implementation. In practice, this implies that RcppParallel will now only
9+
provide a TBB backend with R (>= 4.2.0).
510

611
## RcppParallel 5.1.9
712

R/aaa.R

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
# stubs that get overridden via configure script
3+
TBB_ENABLED <- TRUE
34
TBB_LIB <- ""
45
TBB_INC <- ""
56
TBB_NAME <- "tbb"

R/tbb-autodetected.R.in

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
TBB_ENABLED <- @TBB_ENABLED@
23
TBB_LIB <- "@TBB_LIB@"
34
TBB_INC <- "@TBB_INC@"
45
TBB_NAME <- "@TBB_NAME@"

R/tbb.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ tbbCxxFlags <- function() {
5050

5151
# opt-in to TBB on Windows
5252
if (is_windows()) {
53-
flags <- c(flags, "-DRCPP_PARALLEL_USE_TBB=1")
53+
enabled <- if (TBB_ENABLED) "1" else "0"
54+
flags <- c(flags, sprintf("-DRCPP_PARALLEL_USE_TBB=%s", enabled))
5455
if (R.version$arch == "aarch64") {
5556
# TBB does not have assembly code for Windows ARM64
5657
# so we need to use compiler builtins

src/Makevars.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ TBB_INC = @TBB_INC@
77
TBB_NAME = @TBB_NAME@
88

99
PKG_CPPFLAGS = @PKG_CPPFLAGS@
10-
PKG_CXXFLAGS = @CXX11STD@ -DRCPP_PARALLEL_USE_TBB=1
10+
PKG_CXXFLAGS = @PKG_CXXFLAGS@
1111

1212
PKG_LIBS = @PKG_LIBS@ @PKG_LIBS_EXTRA@
1313

src/install.libs.R

+44-7
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,56 @@ useBundledTbb <- function() {
8989
useTbbPreamble("tbb/include")
9090
dir.create("tbb/build-tbb", showWarnings = FALSE)
9191

92+
cmake <- Sys.getenv("CMAKE", unset = "cmake")
93+
buildType <- Sys.getenv("CMAKE_BUILD_TYPE", unset = "Release")
94+
verbose <- Sys.getenv("VERBOSE", unset = "0")
95+
96+
cmakeFlags <- c(
97+
sprintf("-DCMAKE_BUILD_TYPE=%s", buildType),
98+
"-DTBB_TEST=0",
99+
"-DTBB_EXAMPLES=0",
100+
"-DTBB_STRICT=0",
101+
".."
102+
)
103+
92104
writeLines("*** configuring tbb")
93-
status <- system("cd tbb/build-tbb; cmake -DTBB_TEST=0 -DTBB_EXAMPLES=0 -DTBB_STRICT=0 .. > build.log 2>&1")
94-
if (status != 0L) {
95-
system("cat build.log")
105+
owd <- setwd("tbb/build-tbb")
106+
output <- system2(cmake, shQuote(cmakeFlags), stdout = TRUE, stderr = TRUE)
107+
status <- attr(output, "status")
108+
if (is.numeric(status) && status != 0L) {
109+
writeLines(output)
96110
stop("error configuring tbb (status code ", status, ")")
111+
} else if (!identical(verbose, "0")) {
112+
writeLines(output)
97113
}
114+
setwd(owd)
98115

99116
writeLines("*** building tbb")
100-
status <- system("cd tbb/build-tbb; cmake --build . > build.log 2>&1")
101-
if (status != 0L) {
102-
system("cat build.log")
117+
owd <- setwd("tbb/build-tbb")
118+
output <- system2(cmake, c("--build", ".", "--config", "release"), stdout = TRUE, stderr = TRUE)
119+
status <- attr(output, "status")
120+
if (is.numeric(status) && status != 0L) {
121+
writeLines(output)
103122
stop("error building tbb (status code ", status, ")")
123+
} else if (!identical(verbose, "0")) {
124+
writeLines(output)
104125
}
126+
setwd(owd)
127+
128+
shlibPattern <- switch(
129+
Sys.info()[["sysname"]],
130+
Windows = "^tbb.*\\.dll$",
131+
Darwin = "^libtbb.*\\.dylib$",
132+
"^libtbb.*\\.so.*$"
133+
)
134+
135+
tbbFiles <- list.files(
136+
"tbb/build-tbb",
137+
pattern = shlibPattern,
138+
recursive = TRUE,
139+
full.names = TRUE
140+
)
105141

106-
tbbFiles <- list.files(pattern = "^libtbb\\.(so|dylib)", recursive = TRUE)
107142
tbbDir <- dirname(tbbFiles[[1L]])
108143

109144
dir.create("tbb/build", showWarnings = FALSE)
@@ -123,6 +158,8 @@ args <- commandArgs(trailingOnly = TRUE)
123158
if (identical(args, "build")) {
124159
if (nzchar(tbbLib) && nzchar(tbbInc)) {
125160
useSystemTbb(tbbLib, tbbInc)
161+
} else if (.Platform$OS.type == "windows") {
162+
writeLines("** building RcppParallel without tbb backend")
126163
} else {
127164
useBundledTbb()
128165
}

tools/config/configure.R

+21-9
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,26 @@ switch(
107107
# on Windows, check for Rtools; if it exists, and we have tbb, use it
108108
if (.Platform$OS.type == "windows") {
109109

110+
tbbPattern <- "lib(tbb[^[:alpha:]]*)\\.a$"
110111
gccPath <- normalizePath(Sys.which("gcc"), winslash = "/")
111112

112113
tbbLib <- Sys.getenv("TBB_LIB", unset = NA)
113-
if (is.na(tbbLib)) {
114+
if (is.na(tbbLib))
114115
tbbLib <- normalizePath(file.path(gccPath, "../../lib"), winslash = "/")
115-
Sys.setenv(TBB_LIB = tbbLib)
116-
}
117116

118117
tbbInc <- Sys.getenv("TBB_INC", unset = NA)
119-
if (is.na(tbbInc)) {
118+
if (is.na(tbbInc))
120119
tbbInc <- normalizePath(file.path(gccPath, "../../include"), winslash = "/")
121-
Sys.setenv(TBB_INC = tbbInc)
122-
}
123120

124-
tbbPattern <- "lib(tbb[^[:alpha:]]*)\\.a$"
125121
tbbLibs <- list.files(tbbLib, pattern = tbbPattern)
126122
if (length(tbbLibs)) {
127123
tbbName <- gsub(tbbPattern, "\\1", tbbLibs[[1L]])
128-
Sys.setenv(TBB_NAME = tbbName)
124+
Sys.setenv(
125+
TBB_LIB = tbbLib,
126+
TBB_INC = tbbInc,
127+
TBB_NAME = tbbName
128+
)
129129
}
130-
131130
}
132131

133132
# try and figure out path to TBB
@@ -220,6 +219,11 @@ pkgLibs <- if (!is.na(tbbLib)) {
220219
"-l$(TBB_NAME)",
221220
"-ltbbmalloc"
222221
)
222+
223+
} else if (.Platform$OS.type == "windows") {
224+
225+
NULL
226+
223227
} else {
224228

225229
c(
@@ -283,6 +287,14 @@ if (!is.na(tbbLib)) {
283287
define(PKG_CPPFLAGS = "-I../inst/include")
284288
}
285289

290+
# PKG_CXXFLAGS
291+
if (.Platform$OS.type == "windows" && is.na(tbbLib)) {
292+
define(TBB_ENABLED = FALSE)
293+
define(PKG_CXXFLAGS = "-DRCPP_PARALLEL_USE_TBB=0")
294+
} else {
295+
define(TBB_ENABLED = TRUE)
296+
define(PKG_CXXFLAGS = "-DRCPP_PARALLEL_USE_TBB=1")
297+
}
286298

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

0 commit comments

Comments
 (0)