Skip to content

Commit 9d63bbb

Browse files
committed
bundle old version of tbb for now
1 parent c276b03 commit 9d63bbb

File tree

609 files changed

+190086
-189
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

609 files changed

+190086
-189
lines changed

R/aaa.R

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

22
# stubs that get overridden via configure script
33
TBB_ENABLED <- TRUE
4+
TBB_STATIC <- FALSE
45
TBB_LIB <- ""
56
TBB_INC <- ""
67

R/tbb-autodetected.R.in

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

22
TBB_ENABLED <- @TBB_ENABLED@
3+
TBB_STATIC <- @TBB_STATIC@
34
TBB_LIB <- "@TBB_LIB@"
45
TBB_INC <- "@TBB_INC@"
56

R/tbb.R

+8-18
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ tbbCxxFlags <- function() {
5757
if (!TBB_ENABLED)
5858
return("-DRCPP_PARALLEL_USE_TBB=0")
5959

60-
flags <- c("-DRCPP_PARALLEL_USE_TBB=1")
60+
flags <- c(
61+
"-DRCPP_PARALLEL_USE_TBB=1",
62+
"-DTBB_INTERFACE_NEW"
63+
)
6164

6265
# TBB does not have assembly code for Windows ARM64
6366
# so we need to use compiler builtins
64-
if (TBB_ENABLED && is_windows()) {
65-
if (R.version$arch == "aarch64") {
66-
flags <- c(flags, "-DTBB_USE_GCC_BUILTINS")
67-
}
67+
if (is_windows() && R.version$arch == "aarch64") {
68+
flags <- c(flags, "-DTBB_USE_GCC_BUILTINS")
6869
}
6970

7071
# if TBB_INC is set, apply those library paths
@@ -75,16 +76,7 @@ tbbCxxFlags <- function() {
7576

7677
# add include path
7778
if (nzchar(tbbInc) && file.exists(tbbInc)) {
78-
79-
# prefer new interface if version.h exists -- we keep this
80-
# for compatibility with packages like StanHeaders, rstan
81-
versionPath <- file.path(tbbInc, "tbb/version.h")
82-
if (file.exists(versionPath))
83-
flags <- c(flags, "-DTBB_INTERFACE_NEW")
84-
85-
# now add the include path
8679
flags <- c(flags, paste0("-I", asBuildPath(tbbInc)))
87-
8880
}
8981

9082
# return flags as string
@@ -95,16 +87,14 @@ tbbCxxFlags <- function() {
9587
# Return the linker flags required for TBB on this platform
9688
tbbLdFlags <- function() {
9789

98-
# on Windows, we statically link to oneTBB
99-
if (is_windows()) {
100-
90+
# handle static linking
91+
if (TBB_STATIC) {
10192
libPath <- system.file("libs", package = "RcppParallel")
10293
if (nzchar(.Platform$r_arch))
10394
libPath <- file.path(libPath, .Platform$r_arch)
10495

10596
ldFlags <- sprintf("-L%s -lRcppParallel", asBuildPath(libPath))
10697
return(ldFlags)
107-
10898
}
10999

110100
# shortcut if TBB_LIB defined

R/zzz.R

+3-8
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,19 @@ loadTbbLibrary <- function(name) {
2727

2828
.onLoad <- function(libname, pkgname) {
2929

30-
# on Windows, load RcppParallel first
31-
if (.Platform$OS.type == "windows") {
30+
if (TBB_STATIC) {
3231
.dllInfo <<- library.dynam("RcppParallel", pkgname, libname)
32+
return()
3333
}
3434

35-
# load tbb, tbbmalloc
3635
.tbbDllInfo <<- loadTbbLibrary("tbb")
3736
.tbbMallocDllInfo <<- loadTbbLibrary("tbbmalloc")
3837

39-
# load tbbmalloc_proxy, but only if requested
4038
useTbbMallocProxy <- Sys.getenv("RCPP_PARALLEL_USE_TBBMALLOC_PROXY", unset = "FALSE")
4139
if (useTbbMallocProxy %in% c("TRUE", "True", "true", "1"))
4240
.tbbMallocProxyDllInfo <<- loadTbbLibrary("tbbmalloc_proxy")
4341

44-
# load RcppParallel library if available
45-
if (.Platform$OS.type != "windows") {
46-
.dllInfo <<- library.dynam("RcppParallel", pkgname, libname)
47-
}
42+
.dllInfo <<- library.dynam("RcppParallel", pkgname, libname)
4843

4944
}
5045

src/Makevars.in

+21-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
CMAKE = @CMAKE@
33
R = @R@
44

5+
TBB_ENABLED = @TBB_ENABLED@
6+
TBB_STATIC = @TBB_STATIC@
7+
TBB_SRC = @TBB_SRC@
58
TBB_LIB = @TBB_LIB@
69
TBB_INC = @TBB_INC@
10+
711
TBB_NAME = @TBB_NAME@
812
TBB_MALLOC_NAME = @TBB_MALLOC_NAME@
913

1014
PKG_CPPFLAGS = @PKG_CPPFLAGS@
11-
PKG_CXXFLAGS = @PKG_CXXFLAGS@
1215

1316
PKG_LIBS = @PKG_LIBS@ @PKG_LIBS_EXTRA@
1417

@@ -21,11 +24,23 @@ $(OBJECTS): tbb
2124
# NOTE: TBB libraries are installed via install.libs.R.
2225
# However, we need to copy headers here so that they are visible during compilation.
2326
tbb: tbb-clean
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)" \
28-
CMAKE="$(CMAKE)" "@R@" -s -f install.libs.R --args build
27+
@ \
28+
TBB_ENABLED="$(TBB_ENABLED)" \
29+
TBB_STATIC="$(TBB_STATIC)" \
30+
TBB_SRC="$(TBB_SRC)" \
31+
TBB_LIB="$(TBB_LIB)" \
32+
TBB_INC="$(TBB_INC)" \
33+
TBB_NAME="$(TBB_NAME)" \
34+
TBB_MALLOC_NAME="$(TBB_MALLOC_NAME)" \
35+
CC="$(CC)" \
36+
CFLAGS="$(CFLAGS)" \
37+
CPPFLAGS="$(CPPFLAGS)" \
38+
CXX="$(CXX)" \
39+
CXXFLAGS="$(CXXFLAGS)" \
40+
CXXPICFLAGS="$(CXXPICFLAGS)" \
41+
LDFLAGS="$(LDFLAGS)" \
42+
CMAKE="$(CMAKE)" \
43+
"@R@" -s -f install.libs.R --args build
2944

3045
# NOTE: we do not want to clean ../inst/lib or ../inst/libs here,
3146
# as we may be writing to those locations in multiarch builds

src/install.libs.R

+76-3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ useBundledTbb <- function() {
105105
cmake <- Sys.getenv("CMAKE", unset = "cmake")
106106
buildType <- Sys.getenv("CMAKE_BUILD_TYPE", unset = "Release")
107107
verbose <- Sys.getenv("VERBOSE", unset = "0")
108+
109+
cxxFlags <- paste(Sys.getenv("CPPFLAGS", "CXXFLAGS", "CXXPICFLAGS"), collapse = " ")
110+
Sys.setenv(CXXFLAGS = cxxFlags)
108111

109112
cmakeFlags <- c(
110113
sprintf("-DCMAKE_BUILD_TYPE=%s", buildType),
@@ -159,20 +162,90 @@ useBundledTbb <- function() {
159162

160163
}
161164

165+
useOldBundledTbb <- function() {
166+
167+
useTbbPreamble("tbb-2019/include")
168+
owd <- setwd("tbb-2019/src")
169+
on.exit(setwd(owd), add = TRUE)
170+
171+
makeArgs <- "stdver=c++11"
172+
cxxFlags <- c(
173+
"-DTBB_NO_LEGACY=1",
174+
"-DTBB_SUPPRESS_DEPRECATED_MESSAGES=1",
175+
Sys.getenv(c("CPPFLAGS", "CXXFLAGS"))
176+
)
177+
178+
cxxFlags <- paste(cxxFlags, collapse = " ")
179+
Sys.setenv(
180+
CONLY = Sys.getenv("CC", unset = "cc"),
181+
CPLUS = Sys.getenv("CXX", unset = "c++"),
182+
CXXFLAGS = paste(cxxFlags, collapse = " "),
183+
PIC_KEY = Sys.getenv("CXXPICFLAGS", unset = "-fPIC"),
184+
WARNING_SUPPRESS = ""
185+
)
186+
187+
if (.Platform$OS.type == "windows") {
188+
189+
Sys.setenv(
190+
MSYS2_ARG_CONV_EXCL = "*",
191+
CYGWIN = "nodosfilewarning",
192+
WINARM64_CLANG = "$(WINARM64_CLANG)"
193+
)
194+
195+
makeArgs <- "rtools=true compiler=gcc runtime=mingw"
196+
197+
}
198+
199+
writeLines("** configuring tbb")
200+
system("make info")
201+
writeLines("")
202+
203+
writeLines("** building tbb")
204+
makeTargets <- c("tbb_build_prefix=lib", "tbb_release", "tbbmalloc_release")
205+
output <- system2("make", c("-e", makeArgs, makeTargets), stdout = TRUE, stderr = TRUE)
206+
status <- attr(output, "status")
207+
if (!is.null(status) && status != 0) {
208+
writeLines(output, con = stderr())
209+
stop("error building tbb")
210+
}
211+
212+
shlibPattern <- switch(
213+
Sys.info()[["sysname"]],
214+
Windows = "^tbb.*\\.dll$",
215+
Darwin = "^libtbb.*\\.dylib$",
216+
"^libtbb.*\\.so.*$"
217+
)
218+
219+
setwd(owd)
220+
tbbFiles <- list.files(
221+
file.path(getwd(), "tbb-2019/build/lib_release"),
222+
pattern = shlibPattern,
223+
recursive = TRUE,
224+
full.names = TRUE
225+
)
226+
227+
dir.create("tbb/build/lib_release", recursive = TRUE, showWarnings = FALSE)
228+
file.copy(tbbFiles, "tbb/build/lib_release", overwrite = TRUE)
229+
unlink("tbb/build-tbb", recursive = TRUE)
230+
writeLines("** finished building tbb")
231+
232+
}
233+
162234

163235
# Main ----
164236

237+
tbbSrc <- Sys.getenv("TBB_SRC")
165238
tbbLib <- Sys.getenv("TBB_LIB")
166239
tbbInc <- Sys.getenv("TBB_INC")
167240

168241
args <- commandArgs(trailingOnly = TRUE)
169242
if (identical(args, "build")) {
170243
if (nzchar(tbbLib) && nzchar(tbbInc)) {
171244
useSystemTbb(tbbLib, tbbInc)
172-
} else if (.Platform$OS.type == "windows") {
173-
writeLines("** building RcppParallel without tbb backend")
174-
} else {
245+
} else if (tbbSrc == "tbb") {
175246
useBundledTbb()
247+
} else if (tbbSrc == "tbb-2019") {
248+
useOldBundledTbb()
176249
}
177250
} else {
178251
source("../R/tbb-autodetected.R")

0 commit comments

Comments
 (0)