Skip to content

Commit 733e052

Browse files
committed
Alternate windows approach
1 parent a4750aa commit 733e052

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

R/utils.R

+20-10
Original file line numberDiff line numberDiff line change
@@ -740,25 +740,30 @@ with_cmdstan_flags <- function(expr) {
740740

741741
libs <- c("LDLIBS", "LIBSUNDIALS", "TBB_TARGETS", "LDFLAGS_TBB")
742742
libs <- paste(sapply(libs, get_cmdstan_flags), collapse = " ")
743-
if (.Platform$OS.type == "windows") {
743+
if (os_is_windows()) {
744744
libs <- paste(libs, "-fopenmp -lstdc++")
745745
}
746746
lib_paths <- c("/stan/lib/stan_math/lib/tbb/",
747747
"/stan/lib/stan_math/lib/sundials_6.1.1/lib/")
748+
new_makevars <- c(
749+
PKG_CPPFLAGS = ifelse(cmdstan_version() <= "2.30.1", "-DCMDSTAN_JSON", ""),
750+
PKG_CXXFLAGS = paste(cxxflags, cmdstanr_includes, r_includes, collapse = " "),
751+
PKG_LIBS = libs
752+
)
753+
if (os_is_windows()) {
754+
new_makevars <- c(
755+
new_makevars,
756+
SHLIB_LD = paste0(rtools4x_toolchain_path(),"/gcc"),
757+
LOCAL_CPPFLAGS = paste0("-L'",rtools4x_toolchain_path(),"/../include'"),
758+
LOCAL_LIBS = paste0("-L'",rtools4x_toolchain_path(),"/../lib'")
759+
)
760+
}
748761
withr::with_path(
749762
c(
750763
paste0(cmdstan_path(), lib_paths),
751764
toolchain_PATH_env_var()
752765
),
753-
withr::with_makevars(
754-
c(
755-
USE_CXX14 = 1,
756-
PKG_CPPFLAGS = ifelse(cmdstan_version() <= "2.30.1", "-DCMDSTAN_JSON", ""),
757-
PKG_CXXFLAGS = paste(cxxflags, cmdstanr_includes, r_includes, collapse = " "),
758-
PKG_LIBS = libs
759-
),
760-
expr
761-
)
766+
withr::with_makevars(new_makevars, expr)
762767
)
763768
}
764769

@@ -818,11 +823,16 @@ expose_model_methods <- function(env, force_recompile = FALSE, verbose = FALSE)
818823
}
819824

820825
methods_dll <- tempfile(fileext = .Platform$dynlib.ext)
826+
envvar <- c("current")
827+
if (os_is_windows()) {
828+
envvar <- c(envvar, "BINPREF" = paste0(rtools4x_toolchain_path(), "/"))
829+
}
821830
with_cmdstan_flags(
822831
processx::run(
823832
command = file.path(R.home(component = "bin"), "R"),
824833
args = c("CMD", "SHLIB", repair_path(model_obj_file), repair_path(precomp_methods_file),
825834
"-o", repair_path(methods_dll)),
835+
env = envvar,
826836
echo = verbose || is_verbose_mode(),
827837
echo_cmd = is_verbose_mode(),
828838
error_on_status = FALSE

0 commit comments

Comments
 (0)