Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update expose_stan_functions flags for c++17 #1097

Merged
merged 3 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions rstan/rstan/R/cxxfunplus.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,12 @@ cxxfunctionplus <- function(sig = character(), body = character(),
..., verbose = FALSE) {
R_version <- with(R.version, paste(major, minor, sep = "."))
WINDOWS <- .Platform$OS.type == "windows"
if (WINDOWS && R_version < "3.7.0") {
has_USE_CXX11 <- Sys.getenv("USE_CXX11") != ""
Sys.setenv(USE_CXX11 = 1) # -std=c++1y gets added anyways
if (!has_USE_CXX11) on.exit(Sys.unsetenv("USE_CXX11"))
if (WINDOWS && R.version$major < 4) {
stop("cxxfunctionplus requires R >= 4.0 on Windows to use C++17")
} else {
has_USE_CXX14 <- Sys.getenv("USE_CXX14") != ""
Sys.setenv(USE_CXX14 = 1)
if (!has_USE_CXX14) on.exit(Sys.unsetenv("USE_CXX14"))
has_USE_CXX17 <- Sys.getenv("USE_CXX17") != ""
Sys.setenv(USE_CXX17 = 1)
if (!has_USE_CXX17) on.exit(Sys.unsetenv("USE_CXX17"))
}
if (rstan_options("required"))
pkgbuild::has_build_tools(debug = FALSE) ||
Expand Down Expand Up @@ -183,11 +181,6 @@ cxxfunctionplus <- function(sig = character(), body = character(),
close(zz)
try(file.remove(tf), silent = TRUE)
on.exit(NULL)
if (WINDOWS && R_version < "3.7.0") {
if (!has_USE_CXX11) on.exit(Sys.unsetenv("USE_CXX11"), add = TRUE)
} else {
if (!has_USE_CXX14) on.exit(Sys.unsetenv("USE_CXX14"), add = TRUE)
}
}
dso_last_path <- dso_path(fx)
if (grepl("^darwin", R.version$os) && grepl("clang", get_CXX(FALSE))) {
Expand Down
18 changes: 5 additions & 13 deletions rstan/rstan/R/expose_stan_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,12 @@ expose_stan_functions <- function(stanmodel, includes = NULL,
code <- expose_stan_functions_hacks(r$cppcode, includes)

WINDOWS <- .Platform$OS.type == "windows"
R_version <- with(R.version, paste(major, minor, sep = "."))
if (WINDOWS && R_version < "3.7.0") {
has_USE_CXX11 <- Sys.getenv("USE_CXX11") != ""
Sys.setenv(USE_CXX11 = 1) # -std=c++1y gets added anyways
if (!has_USE_CXX11) on.exit(Sys.unsetenv("USE_CXX11"))
if (WINDOWS && R.version$major < 4) {
stop("expose_stan_functions requires R >= 4.0 on Windows to use C++17")
} else {
has_USE_CXX14 <- Sys.getenv("USE_CXX14") != ""
Sys.setenv(USE_CXX14 = 1)
if (!has_USE_CXX14) on.exit(Sys.unsetenv("USE_CXX14"))
has_USE_CXX17 <- Sys.getenv("USE_CXX17") != ""
Sys.setenv(USE_CXX17 = 1)
if (!has_USE_CXX17) on.exit(Sys.unsetenv("USE_CXX17"))
}

if (rstan_options("required"))
Expand Down Expand Up @@ -109,11 +106,6 @@ expose_stan_functions <- function(stanmodel, includes = NULL,
close(zz)
try(file.remove(tf), silent = TRUE)
on.exit(NULL)
if (WINDOWS && R_version < "3.7.0") {
if (!has_USE_CXX11) on.exit(Sys.unsetenv("USE_CXX11"), add = TRUE)
} else {
if (!has_USE_CXX14) on.exit(Sys.unsetenv("USE_CXX14"), add = TRUE)
}
}
DOTS <- list(...)
if (isTRUE(DOTS$dryRun)) return(code)
Expand Down
16 changes: 7 additions & 9 deletions rstan/rstan/R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -1650,19 +1650,17 @@ create_progress_html_file <- function(htmlfname, textfname) {
cat(src2, file = htmlfname)
}

get_CXX <- function(CXX14 = TRUE) {
get_CXX <- function(...) {
if (.Platform$OS.type != "windows")
return (system2(file.path(R.home(component = "bin"), "R"),
args = paste("CMD config", ifelse(CXX14, "CXX14", "CXX11")),
stdout = TRUE, stderr = FALSE))
args = "CMD config CXX17", stdout = TRUE, stderr = FALSE))

ls_path <- Sys.which("ls")
if (ls_path == "")
return(NULL)
ls_path <- Sys.which("ls")
if (ls_path == "") return(NULL)

install_path <- dirname(dirname(ls_path))
file.path(install_path,
paste0('mingw_', Sys.getenv('WIN')), 'bin', 'g++')
install_path <- dirname(dirname(ls_path))
file.path(install_path,
paste0('mingw_', Sys.getenv('WIN')), 'bin', 'g++')
}

is.sparc <- function() {
Expand Down
7 changes: 3 additions & 4 deletions rstan/rstan/R/plugin.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ boost_path_fun2 <- function() {
}

PKG_CPPFLAGS_env_fun <- function() {
Eigen <- dir(system.file("include", "stan", "math", "prim",
package = "StanHeaders", mustWork = TRUE),
Eigen <- dir(system.file("include", "stan", "math", "prim",
package = "StanHeaders", mustWork = TRUE),
pattern = "Eigen.hpp$", full.names = TRUE, recursive = TRUE)[1]
paste(' -I"', file.path(inc_path_fun("Rcpp"), '" '),
' -I"', file.path(eigen_path_fun(), '" '),
Expand All @@ -58,7 +58,7 @@ PKG_CPPFLAGS_env_fun <- function() {
' -DUSE_STANC3',
' -DSTRICT_R_HEADERS ',
' -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION ',
' -DBOOST_NO_AUTO_PTR ',
' -D_HAS_AUTO_PTR_ETC=0 ',
' -include ', shQuote(Eigen), ' ',
ifelse (.Platform$OS.type == "windows", ' -std=c++1y',
' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 '),
Expand Down Expand Up @@ -145,4 +145,3 @@ inlineCxxPlugin <- function(...) {
settings <- rstanplugin()
settings
}

1 change: 1 addition & 0 deletions rstan/rstan/R/stan_plot_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ color_vector_chain <- function(n) {
mdf <- cbind(mdf_td, div = mdf_nd$value)
plot_data <- if (divergent == "All") mdf else mdf[mdf$div == divergent, , drop = FALSE]
if (nrow(plot_data) == 0) return(NULL)
count <- NaN

graph <- ggplot2::ggplot(
data = plot_data,
Expand Down
1 change: 0 additions & 1 deletion rstan/rstan/src/Makevars
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
CXX_STD = CXX17
CXX14STD = -std=c++1y
STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))" | tail -n 1)
PKG_CPPFLAGS = -I"../inst/include" -I"../inst/include/boost_not_in_BH" -I"${STANHEADERS_SRC}" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_REENTRANT -DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS -D_HAS_AUTO_PTR_ETC=0
PKG_CPPFLAGS += $(shell "${R_HOME}/bin/Rscript" -e "RcppParallel::CxxFlags()" | tail -n 1)
Expand Down
1 change: 0 additions & 1 deletion rstan/rstan/src/Makevars.win
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
CXX_STD = CXX17
CXX14STD = -std=c++1y
STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))" | tail -n 1)
PKG_CPPFLAGS = -I"../inst/include" -I"../inst/include/boost_not_in_BH" -I"${STANHEADERS_SRC}" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_REENTRANT -DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS -D_HAS_AUTO_PTR_ETC=0
PKG_CPPFLAGS += $(shell "${R_HOME}/bin/Rscript" -e "RcppParallel::CxxFlags()" | tail -n 1)
Expand Down
Loading