Skip to content

Commit

Permalink
Alternate windows approach
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed Jan 23, 2024
1 parent a4750aa commit 733e052
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -740,25 +740,30 @@ with_cmdstan_flags <- function(expr) {

libs <- c("LDLIBS", "LIBSUNDIALS", "TBB_TARGETS", "LDFLAGS_TBB")
libs <- paste(sapply(libs, get_cmdstan_flags), collapse = " ")
if (.Platform$OS.type == "windows") {
if (os_is_windows()) {
libs <- paste(libs, "-fopenmp -lstdc++")
}
lib_paths <- c("/stan/lib/stan_math/lib/tbb/",
"/stan/lib/stan_math/lib/sundials_6.1.1/lib/")
new_makevars <- c(
PKG_CPPFLAGS = ifelse(cmdstan_version() <= "2.30.1", "-DCMDSTAN_JSON", ""),
PKG_CXXFLAGS = paste(cxxflags, cmdstanr_includes, r_includes, collapse = " "),
PKG_LIBS = libs
)
if (os_is_windows()) {
new_makevars <- c(
new_makevars,
SHLIB_LD = paste0(rtools4x_toolchain_path(),"/gcc"),
LOCAL_CPPFLAGS = paste0("-L'",rtools4x_toolchain_path(),"/../include'"),
LOCAL_LIBS = paste0("-L'",rtools4x_toolchain_path(),"/../lib'")
)
}
withr::with_path(
c(
paste0(cmdstan_path(), lib_paths),
toolchain_PATH_env_var()
),
withr::with_makevars(
c(
USE_CXX14 = 1,
PKG_CPPFLAGS = ifelse(cmdstan_version() <= "2.30.1", "-DCMDSTAN_JSON", ""),
PKG_CXXFLAGS = paste(cxxflags, cmdstanr_includes, r_includes, collapse = " "),
PKG_LIBS = libs
),
expr
)
withr::with_makevars(new_makevars, expr)
)
}

Expand Down Expand Up @@ -818,11 +823,16 @@ expose_model_methods <- function(env, force_recompile = FALSE, verbose = FALSE)
}

methods_dll <- tempfile(fileext = .Platform$dynlib.ext)
envvar <- c("current")
if (os_is_windows()) {
envvar <- c(envvar, "BINPREF" = paste0(rtools4x_toolchain_path(), "/"))
}
with_cmdstan_flags(
processx::run(
command = file.path(R.home(component = "bin"), "R"),
args = c("CMD", "SHLIB", repair_path(model_obj_file), repair_path(precomp_methods_file),
"-o", repair_path(methods_dll)),
env = envvar,
echo = verbose || is_verbose_mode(),
echo_cmd = is_verbose_mode(),
error_on_status = FALSE
Expand Down

0 comments on commit 733e052

Please sign in to comment.