Skip to content

Commit d3deeb3

Browse files
committed
keep the legacy observe definition out of the bundled tbb on windows
The bundled oneTBB carries a local (non-upstream) definition of tbb::internal::task_scheduler_observer_v3::observe in observer_proxy.cpp, alongside the declarations in task_scheduler_observer.h. Once the bundled copy is actually built on Windows, libtbb12.a and tbb-compat.o both define it and the stub fails to link: libtbb12.a(observer_proxy.cpp.obj): multiple definition of 'tbb::internal::task_scheduler_observer_v3::observe(bool)' The stub has to own that definition on Windows, because R CMD SHLIB builds the DLL's export list from the objects it compiles -- a definition sitting in the archive would never make it into tmp.def. So leave it out of the library there; other platforms keep it, where it serves binaries built against RcppParallel 5.x. Also stop trusting R CMD SHLIB's exit code: it reported success through the link failure above, so the install completed and shipped a package with no tbb.dll -- precisely the failure mode that packages linking '-ltbb' only hit at load time. Check for the artifact, and for the copy, instead.
1 parent 3138398 commit d3deeb3

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/install.libs.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,15 @@ buildTbbStub <- function(tbbDest) {
152152

153153
}
154154

155-
file.copy("tbb-compat/tbb.dll", file.path(tbbDest, "tbb.dll"))
155+
# 'R CMD SHLIB' has been seen to report success on Windows even when the
156+
# link failed, which would otherwise leave us shipping a package with no
157+
# stub at all -- and packages linking '-ltbb' only discover that when they
158+
# fail to load. Check for the artifact rather than trusting the exit code.
159+
if (!file.exists("tbb-compat/tbb.dll"))
160+
stop("tbb.dll stub was not produced")
161+
162+
if (!file.copy("tbb-compat/tbb.dll", file.path(tbbDest, "tbb.dll")))
163+
stop("couldn't copy tbb.dll stub to '", tbbDest, "'")
156164

157165
}
158166

src/tbb/src/tbb/observer_proxy.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@ void __TBB_EXPORTED_FUNC observe(d1::task_scheduler_observer &tso, bool enable)
318318
} // namespace detail
319319
} // namespace tbb
320320

321+
// Not on Windows: there the old ABI is published by the tbb.dll stub built
322+
// from src/tbb-compat/tbb-compat.cpp, which has to define this itself in
323+
// order for R CMD SHLIB to pick it up when generating the export list.
324+
// Defining it here as well makes the stub fail to link with "multiple
325+
// definition of tbb::internal::task_scheduler_observer_v3::observe".
326+
#ifndef _WIN32
327+
321328
namespace tbb {
322329
namespace internal {
323330

@@ -327,4 +334,6 @@ void __TBB_EXPORTED_FUNC task_scheduler_observer_v3::observe( bool enable ) {
327334
}
328335

329336
} // namespace internal
330-
} // namespace tbb
337+
} // namespace tbb
338+
339+
#endif /* _WIN32 */

0 commit comments

Comments
 (0)