Skip to content

Commit a1fddba

Browse files
committed
use symlinks when building with bundled TBB
1 parent 47bf439 commit a1fddba

File tree

4 files changed

+90
-25
lines changed

4 files changed

+90
-25
lines changed

R/flags.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ tbbLdFlags <- function() {
100100

101101
tbbRoot <- function() {
102102
rArch <- .Platform$r_arch
103-
libDir <- paste(c("lib", if (nzchar(rArch)) rArch), collapse = "/")
103+
parts <- c("libs", if (nzchar(rArch)) rArch, "tbb")
104+
libDir <- paste(parts, collapse = "/")
104105
system.file(libDir, package = "RcppParallel")
105106
}
106107

inst/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
lib/
2+
libs/

src/Makevars.in

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11

22
PKG_CXXFLAGS = @CXX11STD@
33

4+
# If TBB_ROOT is defined, use it.
5+
ifdef TBB_ROOT
6+
7+
ifndef TBB_LIB
8+
TBB_LIB = $(TBB_ROOT)/lib
9+
endif
10+
11+
ifndef TBB_INC
12+
TBB_INC = $(TBB_ROOT)/include
13+
endif
14+
15+
endif
16+
417
# If TBB_LIB is defined by TBB_INC is not, make a guess.
518
ifdef TBB_LIB
619
ifndef TBB_INC
@@ -69,6 +82,7 @@ endif
6982
ifdef USE_TBB
7083

7184
PKG_CXXFLAGS += -DRCPP_PARALLEL_USE_TBB=1
85+
PKG_CXXFLAGS += -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1
7286

7387
MAKE_ARGS := tbb_release tbbmalloc_release tbb_build_prefix=lib
7488

@@ -101,40 +115,38 @@ endif
101115

102116
# Write compilation output to file, and log it if installation fails.
103117
ifneq ($(OS), Windows_NT)
104-
MAKE_ARGS += > tbb.log 2>&1 || cat tbb.log; rm -f tbb.log
118+
MAKE_ARGS += > tbb.log 2>&1 && echo "(tbb) TBB successfully built and installed." || cat tbb.log; rm -f tbb.log
105119
endif
106120

107-
.PHONY: all tbb
121+
.PHONY: all tbb tbb-clean
108122

109123
# Order is important in Windows' case. See PKG_LIBS above
110124
all: tbb $(SHLIB)
111125

112-
tbb:
126+
$(SHLIB): $(OBJECTS) tbb
127+
128+
# NOTE: TBB libraries are installed via install.libs.R.
129+
# However, we need to copy headers here so that they are visible during compilation.
130+
tbb: tbb-clean
113131
ifdef TBB_LIB
114-
echo "Using system (Intel/OneAPI) TBB library ..."; \
115-
mkdir -p ../inst/lib/$(ARCH_DIR); \
116-
ln -nfs $(TBB_LIB)/libtbb.so ../inst/lib/$(ARCH_DIR)/libtbb.so 2>/dev/null || :; \
117-
ln -nfs $(TBB_LIB)/libtbbmalloc.so ../inst/lib/$(ARCH_DIR)/libtbbmalloc.so 2>/dev/null || :; \
118-
rm -Rf ../inst/include/serial/; \
119-
rm -Rf ../inst/include/tbb/; \
120-
rm -Rf ../inst/include/tbb_local/; \
121-
mkdir -p ../inst/include; \
122-
cp -R $(TBB_INC)/serial ../inst/include/ 2>/dev/null || :; \
123-
cp -R $(TBB_INC)/oneapi ../inst/include/ 2>/dev/null || :; \
124-
cp -R $(TBB_INC)/tbb ../inst/include/ 2>/dev/null || :
132+
@echo "(tbb) Using system (Intel/OneAPI) TBB library ..."
133+
@echo "(tbb) TBB_LIB = $(TBB_LIB)"
134+
@echo "(tbb) TBB_INC = $(TBB_INC)"
135+
@mkdir -p ../inst/include
136+
@cp -R $(TBB_INC)/* ../inst/include/
125137
else
126-
echo "Using bundled TBB library ..."; \
127-
rm -Rf ../inst/include/serial/; \
128-
rm -Rf ../inst/include/tbb/; \
129-
rm -Rf ../inst/include/tbb_local/; \
130-
cp -R tbb/include/* ../inst/include/; \
131-
cd tbb/src; \
132-
$(MAKE_CMD) stdver=@STDVER@ $(MAKE_ARGS); \
133-
cd ../..; \
134-
mkdir -p ../inst/lib/$(ARCH_DIR); \
135-
cp tbb/build/lib_release/$(TBB_COPY_PATTERN) ../inst/lib/$(ARCH_DIR)
138+
@echo "(tbb) Using bundled TBB library ..."
139+
@mkdir -p ../inst/include
140+
@cp -R tbb/include/* ../inst/include/
141+
@(cd tbb/src && $(MAKE_CMD) stdver=@STDVER@ $(MAKE_ARGS))
136142
endif
137143

144+
tbb-clean:
145+
@rm -rf ../inst/include/tbb
146+
@rm -rf ../inst/include/oneapi
147+
@rm -rf ../inst/include/tbb_local
148+
@rm -rf ../inst/include/serial
149+
138150
clean:
139151
ifdef TBB_LIB
140152
echo "Nothing to clean for TBB."

src/install.libs.R

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
.install.libs <- function() {
3+
4+
# copy default library
5+
files <- Sys.glob(paste0("*", SHLIB_EXT))
6+
dest <- file.path(R_PACKAGE_DIR, paste0("libs", R_ARCH))
7+
dir.create(dest, recursive = TRUE, showWarnings = FALSE)
8+
file.copy(files, dest, overwrite = TRUE)
9+
if (file.exists("symbols.rds"))
10+
file.copy("symbols.rds", dest, overwrite = TRUE)
11+
12+
# copy tbb
13+
tbbDest <- file.path(dest, "tbb")
14+
dir.create(tbbDest, recursive = TRUE, showWarnings = FALSE)
15+
16+
# check for bundled vs. system tbb
17+
tbbRoot <- Sys.getenv("TBB_ROOT", unset = NA)
18+
19+
tbbLib <- Sys.getenv("TBB_LIB", unset = NA)
20+
if (is.na(tbbLib) && !is.na(tbbRoot))
21+
tbbLib <- file.path(tbbRoot, "lib")
22+
23+
if (is.na(tbbLib)) {
24+
25+
# using bundled TBB
26+
tbbLibs <- list.files(
27+
path = "tbb/build/lib_release",
28+
pattern = "^libtbb",
29+
full.names = TRUE
30+
)
31+
32+
# copy tbb libraries
33+
file.copy(tbbLibs, tbbDest)
34+
35+
} else {
36+
37+
# using system tbb
38+
tbbLibs <- list.files(
39+
path = tbbLib,
40+
pattern = "[.](?:so|dylib|dll)$",
41+
full.names = TRUE
42+
)
43+
44+
# symlink tbb libraries
45+
file.symlink(tbbLibs, tbbDest)
46+
47+
}
48+
49+
}
50+
51+
.install.libs()

0 commit comments

Comments
 (0)