wlandau / instantiate

Pre-compiled CmdStan models in R packages
https://wlandau.github.io/instantiate/
Other
22 stars 2 forks source link

Robust compiler settings #1

Closed wlandau closed 10 months ago

wlandau commented 1 year ago

Every compilation in instantiate happens inside install.packages(), which messes with compiler settings like CXXFLAGS. https://github.com/stan-dev/cmdstanr/issues/787 is just one instance of this. It would be great to reliably configure the toolchain.

wlandau commented 1 year ago

@jgabry, are there environment variables I can set up front in a platform-independent way to ensure Stan models compile inside install.packages() the same way they would ordinarily compile outside package installation?

jgabry commented 1 year ago

To be honest, I'm not sure I fully understand why there's currently a difference inside vs outside install.packages. @rok-cesnovar @andrjohns any thoughts on CmdStan environment variables that could help here?

andrjohns commented 1 year ago

Try using withr::with_makevars() to control the makeflags being used (example here)

wlandau commented 1 year ago

with_makevars() could definitely help with stan_package_compile() and internal CmdStan installation if I know what environment variables to set and the values to supply. Is there a safe/universal configuration I can use? I see the with_makevars() call you shared sets USE_CXX14 = 1, PKG_CPPFLAGS = "" for sufficiently recent CmdStan, and some custom stuff for PKG_CXXFLAGS and PKG_LIBS. Are those the only envvars I would need? Would it be reasonable to emulate rcpp_source_stan() and get_cmdstan_flags()?