Skip to content

Commit 79d3779

Browse files
authored
Merge pull request #1054 from stan-dev/stock-rtools-default
Use stock Rtools toolchain by default for RTools44+
2 parents 369b93a + 3f09369 commit 79d3779

File tree

7 files changed

+60
-32
lines changed

7 files changed

+60
-32
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ jobs:
4343
echo "CMDSTAN_PATH=${HOME}/.cmdstan" >> $GITHUB_ENV
4444
shell: bash
4545

46-
- name: Use stock RTools for Windows R-Devel
47-
if: ${{ matrix.config.os == 'windows-latest' && matrix.config.r == 'devel' }}
48-
run: |
49-
echo "CMDSTANR_USE_RTOOLS=TRUE" >> $GITHUB_ENV
50-
shell: bash
51-
5246
- uses: n1hility/cancel-previous-runs@v3
5347
with:
5448
token: ${{ secrets.GITHUB_TOKEN }}

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ URL: https://mc-stan.org/cmdstanr/, https://discourse.mc-stan.org
3232
BugReports: https://github.com/stan-dev/cmdstanr/issues
3333
Encoding: UTF-8
3434
LazyData: true
35-
RoxygenNote: 7.3.1
35+
RoxygenNote: 7.3.2
3636
Roxygen: list(markdown = TRUE, r6 = FALSE)
3737
SystemRequirements: CmdStan (https://mc-stan.org/users/interfaces/cmdstan)
3838
Depends:

R/install.R

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,19 @@
2020
#'
2121
#' The `check_cmdstan_toolchain()` function attempts to check for the required
2222
#' C++ toolchain. It is called internally by `install_cmdstan()` but can also
23-
#' be called directly by the user.
23+
#' be called directly by the user. On Windows only, calling the function with
24+
#' the `fix = TRUE` argument will attempt to install the necessary toolchain
25+
#' components if they are not found. For Windows users with RTools44 no additional
26+
#' toolchain configuration is required. For users with older versions of RTools,
27+
#' the function will install `mingw32-make` and `g++` from MSYS using the
28+
#' RTools-provided `pacman` package manager. This can also be manually requested
29+
#' by setting the environment variable `CMDSTANR_USE_MSYS_TOOLCHAIN` to 'true'
2430
#'
31+
#' NOTE: When installing CmdStan on Windows with RTools44 and CmdStan versions
32+
#' prior to 2.35.0, the above additional toolchain configuration
33+
#' is still required. To enable this configuration, set the environment variable
34+
#' `CMDSTANR_USE_MSYS_TOOLCHAIN` to 'true' and call
35+
#' `check_cmdstan_toolchain(fix = TRUE)`.
2536
#'
2637
#' @export
2738
#' @param dir (string) The path to the directory in which to install CmdStan.
@@ -103,6 +114,15 @@ install_cmdstan <- function(dir = NULL,
103114
} else {
104115
.cmdstanr$WSL <- FALSE
105116
}
117+
if (os_is_windows() && !os_is_wsl() && isTRUE(version < "2.35.0")) {
118+
# RTools44 can be used unmodified with CmdStan 2.35+
119+
# For new installs of older versions, users need to install mingw32-make and MSYS gcc
120+
if (Sys.getenv("CMDSTANR_USE_MSYS_TOOLCHAIN") == "" && rtools4x_version() == "44") {
121+
stop("CmdStan versions prior to 2.35.0 require additional toolchain configuration on Windows.\n",
122+
"Please set the environment variable CMDSTANR_USE_MSYS_TOOLCHAIN to 'true' and \n",
123+
"call `check_cmdstan_toolchain(fix = TRUE)` before installing CmdStan.", call. = FALSE)
124+
}
125+
}
106126
if (check_toolchain) {
107127
check_cmdstan_toolchain(fix = FALSE, quiet = quiet)
108128
}
@@ -643,7 +663,8 @@ check_rtools4x_windows_toolchain <- function(fix = FALSE, quiet = FALSE) {
643663
call. = FALSE
644664
)
645665
}
646-
if (Sys.getenv("CMDSTANR_USE_RTOOLS") != "") {
666+
# No additional utilities/toolchains are needed with RTools44
667+
if (rtools4x_version() >= "44" && Sys.getenv("CMDSTANR_USE_MSYS_TOOLCHAIN") == "") {
647668
return(invisible(NULL))
648669
}
649670
if (!is_toolchain_installed(app = "g++", path = toolchain_path) ||
@@ -855,10 +876,12 @@ toolchain_PATH_env_var <- function() {
855876
}
856877

857878
rtools4x_toolchain_path <- function() {
858-
toolchain <- ifelse(is_ucrt_toolchain(), "ucrt64", "mingw64")
859-
if (Sys.getenv("CMDSTANR_USE_RTOOLS") != "") {
860-
if (arch_is_aarch64()) {
861-
toolchain <- "aarch64-w64-mingw32.static.posix"
879+
if (arch_is_aarch64()) {
880+
toolchain <- "aarch64-w64-mingw32.static.posix"
881+
} else {
882+
if (rtools4x_version() < "44" || Sys.getenv("CMDSTANR_USE_MSYS_TOOLCHAIN") != "" ||
883+
isTRUE(cmdstan_version(error_on_NA=FALSE) < "2.35.0")) {
884+
toolchain <- ifelse(is_ucrt_toolchain(), "ucrt64", "mingw64")
862885
} else {
863886
toolchain <- "x86_64-w64-mingw32.static.posix"
864887
}

R/utils.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ arch_is_aarch64 <- function() {
9696
make_cmd <- function() {
9797
if (Sys.getenv("MAKE") != "") {
9898
Sys.getenv("MAKE")
99-
} else if (os_is_windows() && !os_is_wsl() && (Sys.getenv("CMDSTANR_USE_RTOOLS") == "")) {
99+
} else if (os_is_windows() && !os_is_wsl() &&
100+
(rtools4x_version() < "44" || Sys.getenv("CMDSTANR_USE_MSYS_TOOLCHAIN") != "" || isTRUE(cmdstan_version(error_on_NA=FALSE) < "2.35.0"))) {
100101
"mingw32-make.exe"
101102
} else {
102103
"make"

man/fit-method-save_object.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/install_cmdstan.Rd

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-install.R

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
context("install")
2-
# Current tests need CmdStan 2.35 for stock rtools, but is not yet released
3-
skip_if(Sys.getenv("CMDSTANR_USE_RTOOLS") != "")
42

53
cmdstan_test_tarball_url <- Sys.getenv("CMDSTAN_TEST_TARBALL_URL")
64
if (!nzchar(cmdstan_test_tarball_url)) {
@@ -28,13 +26,13 @@ test_that("install_cmdstan() successfully installs cmdstan", {
2826

2927
test_that("install_cmdstan() errors if installation already exists", {
3028
install_dir <- cmdstan_default_install_path()
31-
dir <- file.path(install_dir, "cmdstan-2.23.0")
29+
dir <- file.path(install_dir, "cmdstan-2.35.0")
3230
if (!dir.exists(dir)) {
3331
dir.create(dir, recursive = TRUE)
3432
}
3533
expect_warning(
3634
install_cmdstan(dir = install_dir, overwrite = FALSE,
37-
version = "2.23.0", wsl = FALSE),
35+
version = "2.35.0", wsl = FALSE),
3836
"An installation already exists",
3937
fixed = TRUE
4038
)
@@ -76,13 +74,13 @@ test_that("install_cmdstan() errors if it times out", {
7674

7775
test_that("install_cmdstan() errors if invalid version or URL", {
7876
expect_error(
79-
install_cmdstan(version = "2.23.2", wsl = os_is_wsl()),
80-
"Download of CmdStan failed with error: cannot open URL 'https://github.com/stan-dev/cmdstan/releases/download/v2.23.2/cmdstan-2.23.2.tar.gz'\nPlease check if the supplied version number is valid."
77+
install_cmdstan(version = "2.35.5", wsl = os_is_wsl()),
78+
"Download of CmdStan failed with error: cannot open URL 'https://github.com/stan-dev/cmdstan/releases/download/v2.35.5/cmdstan-2.35.5.tar.gz'\nPlease check if the supplied version number is valid."
8179
)
8280
expect_error(
83-
install_cmdstan(release_url = "https://github.com/stan-dev/cmdstan/releases/download/v2.23.2/cmdstan-2.23.2.tar.gz",
81+
install_cmdstan(release_url = "https://github.com/stan-dev/cmdstan/releases/download/v2.35.5/cmdstan-2.35.5.tar.gz",
8482
wsl = os_is_wsl()),
85-
"Download of CmdStan failed with error: cannot open URL 'https://github.com/stan-dev/cmdstan/releases/download/v2.23.2/cmdstan-2.23.2.tar.gz'\nPlease check if the supplied release URL is valid."
83+
"Download of CmdStan failed with error: cannot open URL 'https://github.com/stan-dev/cmdstan/releases/download/v2.35.5/cmdstan-2.35.5.tar.gz'\nPlease check if the supplied release URL is valid."
8684
)
8785
expect_error(
8886
install_cmdstan(release_url = "https://github.com/stan-dev/cmdstan/releases/tag/v2.24.0", wsl = os_is_wsl()),
@@ -100,9 +98,9 @@ test_that("install_cmdstan() works with version and release_url", {
10098
expect_message(
10199
expect_output(
102100
install_cmdstan(dir = dir, overwrite = TRUE, cores = 4,
103-
release_url = "https://github.com/stan-dev/cmdstan/releases/download/v2.33.0/cmdstan-2.33.0.tar.gz",
101+
release_url = "https://github.com/stan-dev/cmdstan/releases/download/v2.35.0/cmdstan-2.35.0.tar.gz",
104102
wsl = os_is_wsl()),
105-
"Compiling, linking C++ code",
103+
"Compiling C++ code",
106104
fixed = TRUE
107105
),
108106
"Finished installing CmdStan",
@@ -112,11 +110,11 @@ test_that("install_cmdstan() works with version and release_url", {
112110
expect_message(
113111
expect_output(
114112
install_cmdstan(dir = dir, overwrite = TRUE, cores = 4,
115-
version = "2.33.0",
113+
version = "2.35.0",
116114
# the URL is intentionally invalid to test that the version has higher priority
117115
release_url = "https://github.com/stan-dev/cmdstan/releases/download/v2.27.3/cmdstan-2.27.3.tar.gz",
118116
wsl = os_is_wsl()),
119-
"Compiling, linking C++ code",
117+
"Compiling C++ code",
120118
fixed = TRUE
121119
),
122120
"Finished installing CmdStan",
@@ -125,7 +123,7 @@ test_that("install_cmdstan() works with version and release_url", {
125123
"version and release_url shouldn't both be specified",
126124
fixed = TRUE
127125
)
128-
expect_true(dir.exists(file.path(dir, "cmdstan-2.33.0")))
126+
expect_true(dir.exists(file.path(dir, "cmdstan-2.35.0")))
129127
set_cmdstan_path(cmdstan_default_path())
130128
})
131129

@@ -256,18 +254,18 @@ test_that("Install from release file works", {
256254
dir <- tempdir(check = TRUE)
257255
}
258256

259-
destfile = file.path(dir, "cmdstan-2.33.1.tar.gz")
257+
destfile = file.path(dir, "cmdstan-2.35.0.tar.gz")
260258

261259
download_with_retries(
262-
"https://github.com/stan-dev/cmdstan/releases/download/v2.33.1/cmdstan-2.33.1.tar.gz",
260+
"https://github.com/stan-dev/cmdstan/releases/download/v2.35.0/cmdstan-2.35.0.tar.gz",
263261
destfile)
264262

265263
expect_message(
266264
expect_output(
267265
install_cmdstan(dir = dir, cores = 2, quiet = FALSE, overwrite = TRUE,
268266
release_file = destfile,
269267
wsl = os_is_wsl()),
270-
"Compiling, linking C++ code",
268+
"Compiling C++ code",
271269
fixed = TRUE
272270
),
273271
"CmdStan path set",

0 commit comments

Comments
 (0)