resolve the tbb library path against the installed package on windows - #273
Merged
Conversation
tbbLibraryPath() returned NULL on Windows (#270). The cause is the set of filenames it looks for: the static archives 'libtbb12.a' and 'libtbb.a'. Neither is ever installed with the package. TBB is linked statically into RcppParallel.dll on Windows, and the only TBB library installed alongside it is the tbb.dll stub, so look for that first. The archives are kept as later candidates, for a TBB_LIB pointed at an Rtools tree at runtime. Note this is not the TBB_LIB problem the report proposed, though the report is right that TBB_LIB is also wrong here. The archive lookup fails even when the search directory is correct: a bundled-oneTBB build records no TBB_LIB, so tbbRoot() already answered with the package's own lib directory, and tbbLibraryPath("tbb") still returned NULL. The lookup only ever succeeded when the package happened to run on the machine that built it against an Rtools TBB -- and then answered with a path into Rtools, a build dependency, rather than with anything the installed package uses. Separately, tbbLibraryPath(NULL) and tbbRoot() return the search directory itself, with no existence check, so there the configure-time TBB_LIB really was the defect: for a pre-built binary it names a directory on the build machine ('D:/rtools45/...' in the report). Answer with our own library directory on Windows instead. This is already how tbbLdFlags() and loadTbbLibrary() behave; tbbRoot() was the last place trusting TBB_LIB. Scoped to Windows deliberately. Off Windows a configured TBB_LIB names where the libraries genuinely are -- the package symlinks them into its own lib directory rather than copying -- and tbbLdFlags() emits it as an -rpath. tbbLibraryPath("tbbmalloc") now returns NULL on Windows, which is honest: no separate tbbmalloc library is installed there.
kevinushey
force-pushed
the
bugfix/windows-tbb-library-path
branch
from
July 28, 2026 07:02
98fd12f to
38e83da
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #270.
tbbLibraryPath()returnedNULLon Windows when called from a pre-builtbinary, and the internal
tbbRoot()reported a directory that need not existon the machine running it.
Cause
Both consulted
TBB_LIB, the library directory recorded inR/tbb-autodetected.Rwhen configure ran. On Windows that names the Rtoolstree of whichever machine built the package --
D:/rtools45/...in the report-- which says nothing about where the installed package's TBB actually is.
This is already understood elsewhere in the package:
tbbLdFlags()resolvespurely at runtime via
archSystemFile(), andloadTbbLibrary()carries acomment explaining that it deliberately avoids
tbbRoot()because "tbbRoot()would prefer
TBB_LIB, which on Windows points at Rtools and holds only staticlibraries."
tbbRoot()was the last place still trusting the configure-timevalue.
Fix
On Windows,
tbbRoot()now always reports the package's own library directory.TBB is linked statically into
RcppParallel.dllthere, so thetbb.dllstubinstalled beside it is the only TBB library there is.
That alone was not enough:
tbbLibraryPath()'s Windows candidates were thestatic archives
libtbb12.a/libtbb.a, which are never installed into thepackage. With
tbbRoot()corrected it would have searched the right directoryand still found nothing. It now looks for the stub first, keeping the archives
afterwards for a
TBB_LIBpointed at an Rtools tree at runtime.Consequences
tbbLibraryPath("tbbmalloc")returnsNULLon Windows. That is honest ratherthan a regression -- no separate tbbmalloc library is installed there, as an
install log confirms:
Source and binary installs now agree, where previously a source install
reported a path to a build dependency in Rtools that happened to exist only
on the build machine.
Verification
Simulating a Windows install against both the old and new code, with a fake
package tree containing
lib/x64/tbb.dll:TBB_LIBabsent at runtimetbbRoot()=D:/rtools45/...(does not exist),tbbLibraryPath("tbb")=NULL.../lib/x64,.../lib/x64/tbb.dllTBB_LIBpresenttbbLibraryPath("tbb")=NULL.../lib/x64/tbb.dllTBB_LIBemptytbbLibraryPath("tbb")=NULL.../lib/x64/tbb.dllTBB_LIBoverridetbbLibraryPath("tbb")=NULL.../lib/x64/tbb.dllWorth noting the bug was broader than reported:
tbbLibraryPath("tbb")returned
NULLfor every Windows configuration, including a bundled-oneTBBbuild, not only the binary case.
Also verified: a full macOS install with unchanged behaviour
(
tbbLibraryPath("tbb")still resolves to the installedlibtbb.dylib), andall 10 test files pass.
Test
tests/test-tbb-library-path.Rpins the invariant that both functions mustdescribe the installation actually in use -- whatever they return has to exist.
That is the bug class here, and it is checkable on every platform. The
stronger "must be found" assertion is scoped to Windows, where the installed
layout is known exactly (
install.libs.Ralways builds the stub when TBB isenabled, and fails the install if it cannot); off Windows a system TBB may
legitimately be unresolvable, e.g. a distro package shipping no unversioned
libtbb.sodevelopment symlink.Not done here
The roxygen block for
tbbLibraryPath()could usefully document what itreturns on Windows, but the installed roxygen2 (8.0.0.9000) is newer than
RoxygenNote: 7.3.3, so regenerating would bump the version and churn all six.Rdfiles. Left for a separate docs pass; the user-visible behaviour isdescribed in
NEWS.md.