Skip to content

Commit

Permalink
Revert "bundle old version of tbb for now"
Browse files Browse the repository at this point in the history
This reverts commit 9d63bbb.
  • Loading branch information
kevinushey committed Jan 19, 2025
1 parent 9d63bbb commit 0b136ce
Show file tree
Hide file tree
Showing 609 changed files with 189 additions and 190,086 deletions.
1 change: 0 additions & 1 deletion R/aaa.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

# stubs that get overridden via configure script
TBB_ENABLED <- TRUE
TBB_STATIC <- FALSE
TBB_LIB <- ""
TBB_INC <- ""

Expand Down
1 change: 0 additions & 1 deletion R/tbb-autodetected.R.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

TBB_ENABLED <- @TBB_ENABLED@
TBB_STATIC <- @TBB_STATIC@
TBB_LIB <- "@TBB_LIB@"
TBB_INC <- "@TBB_INC@"

Expand Down
26 changes: 18 additions & 8 deletions R/tbb.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ tbbCxxFlags <- function() {
if (!TBB_ENABLED)
return("-DRCPP_PARALLEL_USE_TBB=0")

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

# TBB does not have assembly code for Windows ARM64
# so we need to use compiler builtins
if (is_windows() && R.version$arch == "aarch64") {
flags <- c(flags, "-DTBB_USE_GCC_BUILTINS")
if (TBB_ENABLED && is_windows()) {
if (R.version$arch == "aarch64") {
flags <- c(flags, "-DTBB_USE_GCC_BUILTINS")
}
}

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

# add include path
if (nzchar(tbbInc) && file.exists(tbbInc)) {

# prefer new interface if version.h exists -- we keep this
# for compatibility with packages like StanHeaders, rstan
versionPath <- file.path(tbbInc, "tbb/version.h")
if (file.exists(versionPath))
flags <- c(flags, "-DTBB_INTERFACE_NEW")

# now add the include path
flags <- c(flags, paste0("-I", asBuildPath(tbbInc)))

}

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

# handle static linking
if (TBB_STATIC) {
# on Windows, we statically link to oneTBB
if (is_windows()) {

libPath <- system.file("libs", package = "RcppParallel")
if (nzchar(.Platform$r_arch))
libPath <- file.path(libPath, .Platform$r_arch)

ldFlags <- sprintf("-L%s -lRcppParallel", asBuildPath(libPath))
return(ldFlags)

}

# shortcut if TBB_LIB defined
Expand Down
11 changes: 8 additions & 3 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,24 @@ loadTbbLibrary <- function(name) {

.onLoad <- function(libname, pkgname) {

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

# load tbb, tbbmalloc
.tbbDllInfo <<- loadTbbLibrary("tbb")
.tbbMallocDllInfo <<- loadTbbLibrary("tbbmalloc")

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

.dllInfo <<- library.dynam("RcppParallel", pkgname, libname)
# load RcppParallel library if available
if (.Platform$OS.type != "windows") {
.dllInfo <<- library.dynam("RcppParallel", pkgname, libname)
}

}

Expand Down
27 changes: 6 additions & 21 deletions src/Makevars.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
CMAKE = @CMAKE@
R = @R@

TBB_ENABLED = @TBB_ENABLED@
TBB_STATIC = @TBB_STATIC@
TBB_SRC = @TBB_SRC@
TBB_LIB = @TBB_LIB@
TBB_INC = @TBB_INC@

TBB_NAME = @TBB_NAME@
TBB_MALLOC_NAME = @TBB_MALLOC_NAME@

PKG_CPPFLAGS = @PKG_CPPFLAGS@
PKG_CXXFLAGS = @PKG_CXXFLAGS@

PKG_LIBS = @PKG_LIBS@ @PKG_LIBS_EXTRA@

Expand All @@ -24,23 +21,11 @@ $(OBJECTS): tbb
# NOTE: TBB libraries are installed via install.libs.R.
# However, we need to copy headers here so that they are visible during compilation.
tbb: tbb-clean
@ \
TBB_ENABLED="$(TBB_ENABLED)" \
TBB_STATIC="$(TBB_STATIC)" \
TBB_SRC="$(TBB_SRC)" \
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)" \
CXXPICFLAGS="$(CXXPICFLAGS)" \
LDFLAGS="$(LDFLAGS)" \
CMAKE="$(CMAKE)" \
"@R@" -s -f install.libs.R --args build
@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)" \
CMAKE="$(CMAKE)" "@R@" -s -f install.libs.R --args build

# NOTE: we do not want to clean ../inst/lib or ../inst/libs here,
# as we may be writing to those locations in multiarch builds
Expand Down
79 changes: 3 additions & 76 deletions src/install.libs.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ useBundledTbb <- function() {
cmake <- Sys.getenv("CMAKE", unset = "cmake")
buildType <- Sys.getenv("CMAKE_BUILD_TYPE", unset = "Release")
verbose <- Sys.getenv("VERBOSE", unset = "0")

cxxFlags <- paste(Sys.getenv("CPPFLAGS", "CXXFLAGS", "CXXPICFLAGS"), collapse = " ")
Sys.setenv(CXXFLAGS = cxxFlags)

cmakeFlags <- c(
sprintf("-DCMAKE_BUILD_TYPE=%s", buildType),
Expand Down Expand Up @@ -162,90 +159,20 @@ useBundledTbb <- function() {

}

useOldBundledTbb <- function() {

useTbbPreamble("tbb-2019/include")
owd <- setwd("tbb-2019/src")
on.exit(setwd(owd), add = TRUE)

makeArgs <- "stdver=c++11"
cxxFlags <- c(
"-DTBB_NO_LEGACY=1",
"-DTBB_SUPPRESS_DEPRECATED_MESSAGES=1",
Sys.getenv(c("CPPFLAGS", "CXXFLAGS"))
)

cxxFlags <- paste(cxxFlags, collapse = " ")
Sys.setenv(
CONLY = Sys.getenv("CC", unset = "cc"),
CPLUS = Sys.getenv("CXX", unset = "c++"),
CXXFLAGS = paste(cxxFlags, collapse = " "),
PIC_KEY = Sys.getenv("CXXPICFLAGS", unset = "-fPIC"),
WARNING_SUPPRESS = ""
)

if (.Platform$OS.type == "windows") {

Sys.setenv(
MSYS2_ARG_CONV_EXCL = "*",
CYGWIN = "nodosfilewarning",
WINARM64_CLANG = "$(WINARM64_CLANG)"
)

makeArgs <- "rtools=true compiler=gcc runtime=mingw"

}

writeLines("** configuring tbb")
system("make info")
writeLines("")

writeLines("** building tbb")
makeTargets <- c("tbb_build_prefix=lib", "tbb_release", "tbbmalloc_release")
output <- system2("make", c("-e", makeArgs, makeTargets), stdout = TRUE, stderr = TRUE)
status <- attr(output, "status")
if (!is.null(status) && status != 0) {
writeLines(output, con = stderr())
stop("error building tbb")
}

shlibPattern <- switch(
Sys.info()[["sysname"]],
Windows = "^tbb.*\\.dll$",
Darwin = "^libtbb.*\\.dylib$",
"^libtbb.*\\.so.*$"
)

setwd(owd)
tbbFiles <- list.files(
file.path(getwd(), "tbb-2019/build/lib_release"),
pattern = shlibPattern,
recursive = TRUE,
full.names = TRUE
)

dir.create("tbb/build/lib_release", recursive = TRUE, showWarnings = FALSE)
file.copy(tbbFiles, "tbb/build/lib_release", overwrite = TRUE)
unlink("tbb/build-tbb", recursive = TRUE)
writeLines("** finished building tbb")

}


# Main ----

tbbSrc <- Sys.getenv("TBB_SRC")
tbbLib <- Sys.getenv("TBB_LIB")
tbbInc <- Sys.getenv("TBB_INC")

args <- commandArgs(trailingOnly = TRUE)
if (identical(args, "build")) {
if (nzchar(tbbLib) && nzchar(tbbInc)) {
useSystemTbb(tbbLib, tbbInc)
} else if (tbbSrc == "tbb") {
} else if (.Platform$OS.type == "windows") {
writeLines("** building RcppParallel without tbb backend")
} else {
useBundledTbb()
} else if (tbbSrc == "tbb-2019") {
useOldBundledTbb()
}
} else {
source("../R/tbb-autodetected.R")
Expand Down
Loading

0 comments on commit 0b136ce

Please sign in to comment.