Skip to content

Commit a2f9ff5

Browse files
committed
drop StanHeaders:::LdFlags() TBB linking, incompatible with RcppParallel 6.0.0 on Windows
With rstan now loading correctly (previous commit), Windows CI got further and hit a second, distinct failure: our own compiled EpiStrainDynamics.dll failed to load with the identical "LoadLibrary failure" signature, this time for tbb.dll. StanHeaders:::LdFlags() unconditionally returns "-L<TBB_LIB> -Wl,-rpath,<TBB_LIB> -ltbb -ltbbmalloc", assuming RcppParallel ships a dynamic tbb.dll/tbbmalloc.dll. RcppParallel 6.0.0 (installed on this runner) links TBB statically on Windows instead, and -Wl,-rpath is a no-op on Windows in any case (it's an ELF/Unix linker mechanism). rstan's own from-source Windows build, using the same RcppParallel 6.0.0, links only "-lRcppParallel" with no separate TBB flags and loads fine -- confirming RcppParallel::RcppParallelLibs() alone already provides whatever the installed RcppParallel version actually needs. Drop the StanHeaders:::LdFlags() call from PKG_LIBS in Makevars.win to match.
1 parent 5fd7d06 commit a2f9ff5

2 files changed

Lines changed: 36 additions & 12 deletions

File tree

NEWS.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,27 @@
1313
explicitly importing `%||%` from `rlang` instead of relying on base R's
1414
version, which only exists from R 4.4.0 (related to #43).
1515
* Fixed intermittent R CMD check failures on Windows CI. The reported
16-
error ("Build process failed") was misleading: all six bundled Stan
17-
models were actually compiling and linking successfully, but the
18-
package then failed to lazy-load because `rstan`'s own precompiled
19-
Windows binary DLL failed to load ("LoadLibrary failure: The
20-
specified module could not be found"), most likely an ABI mismatch
21-
between the RSPM binary and the runner's Rtools version. Fixed by
22-
reinstalling `rstan` from source on the Windows CI job specifically.
23-
Also added `src/Makevars.win` (lowering optimisation from `-O2` to
24-
`-O1` and suppressing compiler warnings) and enlarged the Windows
25-
runner's pagefile; these weren't the actual fix, but remain in place
26-
as they reduce build time/noise and are otherwise harmless.
16+
error ("Build process failed") was misleading and had two distinct,
17+
unrelated causes hiding behind it, both only visible once compiler
18+
warning noise was suppressed (see below):
19+
- `rstan`'s own precompiled Windows binary DLL failed to load
20+
("LoadLibrary failure"), most likely an ABI mismatch between the
21+
RSPM binary and the runner's Rtools version. Fixed by reinstalling
22+
`rstan` from source on the Windows CI job specifically.
23+
- With that resolved, the package's own compiled DLL then failed to
24+
load the same way, because `StanHeaders:::LdFlags()` unconditionally
25+
links against a *dynamic* `tbb`/`tbbmalloc`, which `RcppParallel`
26+
(from version 6.0.0) no longer reliably provides on Windows (having
27+
moved to static TBB linking), and `-Wl,-rpath` has no effect on
28+
Windows regardless. Fixed by dropping `StanHeaders:::LdFlags()` from
29+
`src/Makevars.win`'s `PKG_LIBS` and relying solely on
30+
`RcppParallel::RcppParallelLibs()`, matching what `rstan`'s own
31+
Windows build does.
32+
Also lowered optimisation from `-O2` to `-O1`, suppressed compiler
33+
warnings, and enlarged the Windows runner's pagefile in
34+
`src/Makevars.win`/CI config; these weren't the actual fix for either
35+
issue above, but remain in place as they reduce build time/noise and
36+
are otherwise harmless.
2737

2838
## Minor improvements
2939

src/Makevars.win

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,21 @@ STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "message()" -e
33
STANC_FLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "cat(ifelse(utils::packageVersion('rstan') >= '2.26', '-DUSE_STANC3',''))")
44
PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error $(STANC_FLAGS) -D_HAS_AUTO_PTR_ETC=0
55
PKG_CXXFLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::CxxFlags()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::CxxFlags()")
6-
PKG_LIBS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::RcppParallelLibs()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::LdFlags()")
6+
7+
# Deliberately omits StanHeaders:::LdFlags() (unlike the Unix Makevars):
8+
# that function unconditionally emits "-L<TBB_LIB> -Wl,-rpath,<TBB_LIB>
9+
# -ltbb -ltbbmalloc", which assumes RcppParallel ships a *dynamic*
10+
# tbb.dll/tbbmalloc.dll -- true for older RcppParallel releases, but
11+
# RcppParallel >= 6.0.0 links TBB statically on Windows and no longer
12+
# reliably provides those at the expected path, and "-Wl,-rpath" has no
13+
# effect on Windows regardless (it's an ELF/Unix mechanism). The result
14+
# was our own compiled EpiStrainDynamics.dll failing to load at runtime
15+
# with "LoadLibrary failure: The specified module could not be found"
16+
# for tbb.dll. RcppParallel::RcppParallelLibs() alone already provides
17+
# whatever linking its own installed version actually needs -- this is
18+
# confirmed by rstan's own from-source Windows build linking only
19+
# -lRcppParallel with no separate TBB flags at all.
20+
PKG_LIBS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::RcppParallelLibs()")
721

822
CXX_STD = CXX17
923

0 commit comments

Comments
 (0)