Skip to content

Commit 0950041

Browse files
committed
try to support older R + Windows
1 parent c328085 commit 0950041

File tree

5 files changed

+44
-21
lines changed

5 files changed

+44
-21
lines changed

R/aaa.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
TBB_ENABLED <- TRUE
44
TBB_LIB <- ""
55
TBB_INC <- ""
6-
TBB_NAME <- "tbb"
6+
7+
TBB_NAME <- "tbb"
8+
TBB_MALLOC_NAME <- "tbbmalloc"

R/tbb-autodetected.R.in

+2
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
TBB_ENABLED <- @TBB_ENABLED@
33
TBB_LIB <- "@TBB_LIB@"
44
TBB_INC <- "@TBB_INC@"
5+
56
TBB_NAME <- "@TBB_NAME@"
7+
TBB_MALLOC_NAME <- "@TBBMALLOC_NAME@"

R/tbb.R

+8-4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ tbbCxxFlags <- function() {
6161

6262
# if TBB_INC is set, apply those library paths
6363
tbbInc <- Sys.getenv("TBB_INC", unset = TBB_INC)
64+
if (!file.exists(tbbInc)) {
65+
tbbInc <- system.file("include", package = "Rcpp")
66+
}
67+
6468
if (nzchar(tbbInc)) {
6569

6670
# add include path
@@ -96,15 +100,15 @@ tbbLdFlags <- function() {
96100
# shortcut if TBB_LIB defined
97101
tbbLib <- Sys.getenv("TBB_LINK_LIB", Sys.getenv("TBB_LIB", unset = TBB_LIB))
98102
if (nzchar(tbbLib)) {
99-
fmt <- "-L%1$s -Wl,-rpath,%1$s -l%2$s -ltbbmalloc"
100-
return(sprintf(fmt, asBuildPath(tbbLib), TBB_NAME))
103+
fmt <- "-L%1$s -Wl,-rpath,%1$s -l%2$s -l%3$s"
104+
return(sprintf(fmt, asBuildPath(tbbLib), TBB_NAME, TBB_MALLOC_NAME))
101105
}
102106

103107
# explicitly link on macOS
104108
# https://github.com/RcppCore/RcppParallel/issues/206
105109
if (is_mac()) {
106-
fmt <- "-L%s -l%s -ltbbmalloc"
107-
return(sprintf(fmt, asBuildPath(tbbLibraryPath()), TBB_NAME))
110+
fmt <- "-L%s -l%s -l%s"
111+
return(sprintf(fmt, asBuildPath(tbbLibraryPath()), TBB_NAME, TBB_MALLOC_NAME))
108112
}
109113

110114
# nothing required on other platforms

src/Makevars.in

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
CMAKE = @CMAKE@
33
R = @R@
44

5-
TBB_LIB = @TBB_LIB@
6-
TBB_INC = @TBB_INC@
7-
TBB_NAME = @TBB_NAME@
5+
TBB_LIB = @TBB_LIB@
6+
TBB_INC = @TBB_INC@
7+
TBB_NAME = @TBB_NAME@
8+
TBB_MALLOC_NAME = @TBB_MALLOC_NAME@
89

910
PKG_CPPFLAGS = @PKG_CPPFLAGS@
1011
PKG_CXXFLAGS = @PKG_CXXFLAGS@
@@ -20,9 +21,10 @@ $(OBJECTS): tbb
2021
# NOTE: TBB libraries are installed via install.libs.R.
2122
# However, we need to copy headers here so that they are visible during compilation.
2223
tbb: tbb-clean
23-
TBB_LIB="$(TBB_LIB)" TBB_INC="$(TBB_INC)" TBB_NAME="$(TBB_NAME)" \
24-
CC="$(CC)" CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" \
25-
CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" \
24+
TBB_LIB="$(TBB_LIB)" TBB_INC="$(TBB_INC)" \
25+
TBB_NAME="$(TBB_NAME)" TBB_MALLOC_NAME="$(TBB_MALLOC_NAME)" \
26+
CC="$(CC)" CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" \
27+
CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" \
2628
CMAKE="$(CMAKE)" "@R@" -s -f install.libs.R --args build
2729

2830
# NOTE: we do not want to clean ../inst/lib or ../inst/libs here,

tools/config/configure.R

+23-10
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ 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$"
111110
gccPath <- normalizePath(Sys.which("gcc"), winslash = "/")
112111

113112
tbbLib <- Sys.getenv("TBB_LIB", unset = NA)
@@ -118,22 +117,35 @@ if (.Platform$OS.type == "windows") {
118117
if (is.na(tbbInc))
119118
tbbInc <- normalizePath(file.path(gccPath, "../../include"), winslash = "/")
120119

121-
tbbLibs <- list.files(tbbLib, pattern = tbbPattern)
122-
if (length(tbbLibs)) {
123-
tbbName <- gsub(tbbPattern, "\\1", tbbLibs[[1L]])
120+
tbbFiles <- list.files(tbbLib, pattern = "^libtbb")
121+
if (length(tbbFiles)) {
122+
123+
tbbPattern <- "^lib(tbb\\d*(?:_static)?)\\.a$"
124+
tbbName <- grep(tbbPattern, tbbFiles, perl = TRUE, value = TRUE)
125+
tbbName <- gsub(tbbPattern, "\\1", tbbName, perl = TRUE)
126+
127+
tbbMallocPattern <- "^lib(tbbmalloc\\d*(?:_static)?)\\.a$"
128+
tbbMallocName <- grep(tbbMallocPattern, tbbFiles, perl = TRUE, value = TRUE)
129+
tbbMallocName <- gsub(tbbMallocPattern, "\\1", tbbMallocName, perl = TRUE)
130+
124131
Sys.setenv(
125132
TBB_LIB = tbbLib,
126133
TBB_INC = tbbInc,
127-
TBB_NAME = tbbName
134+
TBB_NAME = tbbName,
135+
TBB_MALLOC_NAME = tbbMallocName
128136
)
137+
129138
}
139+
130140
}
131141

132142
# try and figure out path to TBB
133143
tbbRoot <- Sys.getenv("TBB_ROOT", unset = NA)
134144
tbbLib <- Sys.getenv("TBB_LIB", unset = NA)
135145
tbbInc <- Sys.getenv("TBB_INC", unset = NA)
146+
136147
tbbName <- Sys.getenv("TBB_NAME", unset = "tbb")
148+
tbbMallocName <- Sys.getenv("TBB_MALLOC_NAME", unset = "tbbmalloc")
137149

138150
# check TBB_ROOT first if defined
139151
if (!is.na(tbbRoot)) {
@@ -205,9 +217,10 @@ if (tryAutoDetect) {
205217

206218
# now, define TBB_LIB and TBB_INC as appropriate
207219
define(
208-
TBB_LIB = if (!is.na(tbbLib)) tbbLib else "",
209-
TBB_INC = if (!is.na(tbbInc)) tbbInc else "",
210-
TBB_NAME = tbbName
220+
TBB_LIB = if (!is.na(tbbLib)) tbbLib else "",
221+
TBB_INC = if (!is.na(tbbInc)) tbbInc else "",
222+
TBB_NAME = tbbName,
223+
TBB_MALLOC_NAME = tbbMallocName
211224
)
212225

213226
# set PKG_LIBS
@@ -217,7 +230,7 @@ pkgLibs <- if (!is.na(tbbLib)) {
217230
"-Wl,-L\"$(TBB_LIB)\"",
218231
sprintf("-Wl,-rpath,%s", shQuote(tbbLib)),
219232
"-l$(TBB_NAME)",
220-
"-ltbbmalloc"
233+
"-l$(TBB_MALLOC_NAME)"
221234
)
222235

223236
} else if (.Platform$OS.type == "windows") {
@@ -229,7 +242,7 @@ pkgLibs <- if (!is.na(tbbLib)) {
229242
c(
230243
"-Wl,-Ltbb/build/lib_release",
231244
"-l$(TBB_NAME)",
232-
"-ltbbmalloc"
245+
"-l$(TBB_MALLOC_NAME)"
233246
)
234247

235248
}

0 commit comments

Comments
 (0)