Skip to content

Commit 434e2b9

Browse files
committed
log tbb header and library provenance during install
Stale or unexpected TBB libraries swept into the installed package have been a subtle source of downstream load failures, and were invisible in installation logs. Report which headers and libraries are installed and from where, and note when the tbb stub build is skipped because a tbb.dll is already present. Additionally, when the VERBOSE environment variable is set (as already used by the bundled TBB build), report how TBB libraries are resolved and loaded at package load time; this would have surfaced the lookup bug fixed in #250 immediately.
1 parent c3d0825 commit 434e2b9

4 files changed

Lines changed: 46 additions & 6 deletions

File tree

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# RcppParallel (development version)
22

3+
* RcppParallel now reports which TBB headers and libraries are installed
4+
with the package, and from where, during package installation. In
5+
addition, setting the `VERBOSE` environment variable to a value other
6+
than `0` enables diagnostics describing how TBB libraries are resolved
7+
and loaded when the package is loaded.
8+
39
* On Windows, RcppParallel once again loads its compatibility stub library
410
(`tbb.dll`) when the package is loaded. Packages linking with `-ltbb`
511
(e.g. via StanHeaders) record a load-time dependency on `tbb.dll`, which

R/utils.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11

2+
# opt-in diagnostics, primarily useful when debugging issues with
3+
# TBB library resolution and loading during package load; uses the
4+
# same VERBOSE environment variable as the TBB build in install.libs.R
5+
verboseMessage <- function(fmt, ...) {
6+
verbose <- Sys.getenv("VERBOSE", unset = "0")
7+
if (!identical(verbose, "0"))
8+
message(sprintf(fmt, ...))
9+
}
10+
211
# like system.file(), but injects the architecture-specific subdirectory
312
# used on Windows when set; e.g. archSystemFile("lib") resolves 'lib/x64'
413
archSystemFile <- function(dir, name = NULL) {

R/zzz.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@ loadTbbLibrary <- function(name) {
2424
# install.libs.R places the stub; tbbRoot() would prefer TBB_LIB,
2525
# which on Windows points at Rtools and holds only static libraries
2626
path <- archSystemFile("lib", paste0(name, ".dll"))
27-
if (!file.exists(path))
27+
if (!file.exists(path)) {
28+
verboseMessage("TBB library '%s' not found in package 'lib' folder; skipping", name)
2829
return(NULL)
30+
}
2931

32+
verboseMessage("loading TBB library '%s'", path)
3033
return(dyn.load(path, local = FALSE, now = TRUE))
3134

3235
}
3336

3437
path <- tbbLibraryPath(name)
35-
if (is.null(path))
38+
if (is.null(path)) {
39+
verboseMessage("TBB library '%s' could not be resolved; skipping", name)
3640
return(NULL)
37-
41+
}
42+
3843
if (!file.exists(path)) {
3944
warning("TBB library ", shQuote(name), " not found.")
4045
return(NULL)
4146
}
42-
47+
48+
verboseMessage("loading TBB library '%s'", path)
4349
dyn.load(path, local = FALSE, now = TRUE)
4450

4551
}

src/install.libs.R

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@
3838
if (!nzchar(tbbLib)) {
3939

4040
# using bundled TBB
41+
tbbSrc <- "tbb/build/lib_release"
4142
tbbLibs <- list.files(
42-
path = "tbb/build/lib_release",
43+
path = tbbSrc,
4344
pattern = shlibPattern,
4445
full.names = TRUE
4546
)
4647

48+
logTbbLibraries(tbbLibs, tbbSrc)
4749
for (tbbLib in tbbLibs) {
4850
system2("cp", c("-P", shQuote(tbbLib), shQuote(tbbDest)))
4951
}
@@ -61,6 +63,7 @@
6163
tbbLibs <- tbbLibs[!nzchar(Sys.readlink(tbbLibs))]
6264

6365
# copy / link the libraries
66+
logTbbLibraries(tbbLibs, tbbLib)
6467
useSymlinks <- Sys.getenv("TBB_USE_SYMLINKS", unset = .Platform$OS.type != "windows")
6568
if (useSymlinks) {
6669
file.symlink(tbbLibs, tbbDest)
@@ -76,7 +79,9 @@
7679
# older binaries (like rstan) can still load
7780
if (.Platform$OS.type == "windows") {
7881
tbbDll <- file.path(tbbDest, "tbb.dll")
79-
if (!file.exists(tbbDll)) {
82+
if (file.exists(tbbDll)) {
83+
writeLines("** tbb.dll already exists; skipping tbb stub library")
84+
} else {
8085
writeLines("** creating tbb stub library")
8186
status <- system("R CMD SHLIB -o tbb-compat/tbb.dll tbb-compat/tbb-compat.cpp")
8287
if (status != 0)
@@ -87,8 +92,22 @@
8792

8893
}
8994

95+
# Report which TBB libraries are about to be installed, and from where.
96+
# Stale or unexpected libraries copied here have historically been a
97+
# subtle source of load failures in downstream packages, so make the
98+
# provenance easy to spot in installation logs.
99+
logTbbLibraries <- function(tbbLibs, source) {
100+
if (length(tbbLibs)) {
101+
fmt <- "** copying TBB libraries from '%s' [%s]"
102+
writeLines(sprintf(fmt, source, paste(basename(tbbLibs), collapse = ", ")))
103+
} else {
104+
writeLines(sprintf("** no TBB libraries found in '%s'", source))
105+
}
106+
}
107+
90108
useTbbPreamble <- function(tbbInc) {
91109

110+
writeLines(sprintf("** copying TBB headers from '%s'", tbbInc))
92111
dir.create("../inst/include", recursive = TRUE, showWarnings = FALSE)
93112
for (suffix in c("oneapi", "serial", "tbb")) {
94113
tbbPath <- file.path(tbbInc, suffix)

0 commit comments

Comments
 (0)