From 64a74184f9f6f8276b3d6fce45081b1d7005af1e Mon Sep 17 00:00:00 2001 From: jgabry Date: Tue, 29 Sep 2026 11:33:09 -0600 Subject: [PATCH 1/2] Add rpath for libtbb in test_stan_functions.R on Linux --- tests/testthat/test_stan_functions.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/testthat/test_stan_functions.R b/tests/testthat/test_stan_functions.R index 108afbca..506b2ba9 100644 --- a/tests/testthat/test_stan_functions.R +++ b/tests/testthat/test_stan_functions.R @@ -60,6 +60,12 @@ functions <- c(unlist(lapply(file.path(MODELS_HOME, "functions", model_code <- paste(c("functions {", functions[grep("CODOLS", functions, invert = TRUE)], "}"), collapse = "\n") stanc_ret <- stanc(model_code = model_code, model_name = "Stan Functions", allow_undefined = TRUE) +# rstan's plugin links to RcppParallel's libtbb without an rpath, so on musl +# (e.g., Alpine) the compiled module can't find libtbb.so at load time (#660) +if (Sys.info()[["sysname"]] == "Linux") { + Sys.setenv(PKG_LIBS = paste(Sys.getenv("PKG_LIBS"), + paste0("-Wl,-rpath,", RcppParallel::tbbLibraryPath()))) +} expose_stan_functions(stanc_ret, rebuild = TRUE, verbose = TRUE) # Rcpp::registerPlugin("rstan", rstan:::rstanplugin) # Rcpp::sourceCpp(file.path(INCLUDE_DIR, "tests.cpp"), rebuild = TRUE, verbose = TRUE) From de234f03879a8a2ca77c4e7f32e72a6bf45b2fee Mon Sep 17 00:00:00 2001 From: jgabry Date: Tue, 29 Sep 2026 11:35:55 -0600 Subject: [PATCH 2/2] Note when the libtbb rpath workaround can be removed --- tests/testthat/test_stan_functions.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test_stan_functions.R b/tests/testthat/test_stan_functions.R index 506b2ba9..bd483802 100644 --- a/tests/testthat/test_stan_functions.R +++ b/tests/testthat/test_stan_functions.R @@ -61,7 +61,9 @@ model_code <- paste(c("functions {", functions[grep("CODOLS", functions, invert stanc_ret <- stanc(model_code = model_code, model_name = "Stan Functions", allow_undefined = TRUE) # rstan's plugin links to RcppParallel's libtbb without an rpath, so on musl -# (e.g., Alpine) the compiled module can't find libtbb.so at load time (#660) +# (e.g., Alpine) the compiled module can't find libtbb.so at load time (#660). +# This can be removed once we require an rstan release that includes the fix +# (stan-dev/rstan#1196). if (Sys.info()[["sysname"]] == "Linux") { Sys.setenv(PKG_LIBS = paste(Sys.getenv("PKG_LIBS"), paste0("-Wl,-rpath,", RcppParallel::tbbLibraryPath())))