Skip to content

Generalise RTools config/support #777

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

Merged
merged 10 commits into from
Jun 26, 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
78 changes: 44 additions & 34 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ install_cmdstan <- function(dir = NULL,
stanc_makefile)
writeLines(stanc_makefile, con = file.path(dir_cmdstan, "make", "stanc"))

if ((is_rtools42_toolchain() || is_rtools43_toolchain()) && !wsl) {
if (is_ucrt_toolchain() && !wsl) {
cmdstan_make_local(
dir = dir_cmdstan,
cpp_options = list(
"CXXFLAGS += -Wno-nonnull",
"TBB_CXXFLAGS= -U__MSVCRT_VERSION__ -D__MSVCRT_VERSION__=0x0E00"
"CXXFLAGS += -Wno-nonnull -D_UCRT",
"TBB_CXXFLAGS= -D_UCRT"
),
append = TRUE
)
Expand Down Expand Up @@ -534,13 +534,13 @@ build_status_ok <- function(process_log, quiet = FALSE) {

install_toolchain <- function(quiet = FALSE) {
rtools_usr_bin <- file.path(rtools4x_home_path(), "usr", "bin")
if (R.version$minor < "2.0") {
install_pkgs <- "mingw-w64-x86_64-make"
if (!quiet) message("Installing mingw32-make with Rtools40.")
} else {
ver <- ifelse(is_rtools43_toolchain(), "Rtools43", "Rtools42")
rtools_version <- paste0("Rtools", rtools4x_version())
if (is_ucrt_toolchain()) {
install_pkgs <- c("mingw-w64-ucrt-x86_64-make", "mingw-w64-ucrt-x86_64-gcc")
if (!quiet) message("Installing mingw32-make and g++ with ", ver, ".")
if (!quiet) message(paste0("Installing mingw32-make and g++ with ", rtools_version))
} else {
install_pkgs <- "mingw-w64-x86_64-make"
if (!quiet) message(paste0("Installing mingw32-make with ", rtools_version))
}
if (!checkmate::test_directory(rtools_usr_bin, access = "w")) {
warning("No write permissions in the RTools folder. This might prevent installing the toolchain.",
Expand Down Expand Up @@ -595,8 +595,8 @@ check_wsl_toolchain <- function() {
}

check_rtools4x_windows_toolchain <- function(fix = FALSE, quiet = FALSE) {
rtools_path <- rtools4x_home_path()
rtools_version <- if (is_rtools43_toolchain()) "Rtools43" else if (is_rtools42_toolchain()) "Rtools42" else "Rtools40"
rtools_path <- rtools_home_path()
rtools_version <- paste0("Rtools", rtools4x_version())
toolchain_path <- rtools4x_toolchain_path()
# If RTOOLS4X_HOME is not set (the env. variable gets set on install)
# we assume that RTools 40 is not installed.
Expand Down Expand Up @@ -794,7 +794,7 @@ is_toolchain_installed <- function(app, path) {

toolchain_PATH_env_var <- function() {
path <- NULL
if (is_rtools43_toolchain() || is_rtools42_toolchain() || is_rtools40_toolchain()) {
if (R.version$major == "4") {
rtools_home <- rtools4x_home_path()
path <- paste0(
repair_path(file.path(rtools_home, "usr", "bin")), ";",
Expand All @@ -805,34 +805,44 @@ toolchain_PATH_env_var <- function() {
}

rtools4x_toolchain_path <- function() {
if (is_rtools43_toolchain() || is_rtools42_toolchain()) {
path <- repair_path(file.path(rtools4x_home_path(), "ucrt64", "bin"))
c_runtime <- ifelse(is_ucrt_toolchain(), "ucrt64", "mingw64")
repair_path(file.path(rtools4x_home_path(), c_runtime, "bin"))
}

rtools4x_version <- function() {
rtools_ver <- NULL

if (R.version$minor < "2.0") {
rtools_ver <- "40"
} else if (R.version$minor < "3.0") {
rtools_ver <- "42"
} else {
path <- repair_path(file.path(rtools4x_home_path(), "mingw64", "bin"))
rtools_ver <- "43"
}
path
rtools_ver
}

rtools4x_home_path <- function() {
path <- NULL
if (is_rtools43_toolchain()) {
path <- Sys.getenv("RTOOLS43_HOME")
if (!nzchar(path)) {
default_path <- repair_path(file.path("C:/rtools43"))
if (dir.exists(default_path)) {
path <- default_path
}
}
} else if (is_rtools42_toolchain()) {
path <- Sys.getenv("RTOOLS42_HOME")
if (!nzchar(path)) {
default_path <- repair_path(file.path("C:/rtools42"))
if (dir.exists(default_path)) {
path <- default_path
}
rtools_ver <- rtools4x_version()
path <- Sys.getenv(paste0("RTOOLS", rtools_ver, "_HOME"))

if (!nzchar(path)) {
default_path <- repair_path(file.path(paste0("C:/rtools", rtools_ver)))
if (dir.exists(default_path)) {
path <- default_path
}
} else {
path <- Sys.getenv("RTOOLS40_HOME")
}

path
}

rtools_home_path <- function() {
path <- NULL
if (R.version$major == "3") {
path <- Sys.getenv("RTOOLS_HOME")
}
if (R.version$major == "4") {
path <- rtools4x_home_path()
}
path
}
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ is_rtools40_toolchain <- function() {
os_is_windows() && R.version$major == "4" && R.version$minor < "2.0"
}

is_ucrt_toolchain <- function() {
os_is_windows() && R.version$major == "4" && R.version$minor >= "2.0"
}

# Check if running R in Rosetta 2 translation environment, which is an
# Intel-to-ARM translation layer.
is_rosetta2 <- function() {
Expand Down