From 700cb62fa1d48d1d35547bb7690f8e6de6c2b93e Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 22 May 2024 21:06:33 +0300 Subject: [PATCH 1/4] Add CMDSTANR_USE_RTOOLS envvar to use stock rtools --- .github/workflows/R-CMD-check.yaml | 6 ++++++ R/install.R | 10 ++++++++-- R/utils.R | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index c43b91e6..37000a84 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -42,6 +42,12 @@ jobs: echo "CMDSTAN_PATH=${HOME}/.cmdstan" >> $GITHUB_ENV shell: bash + - name: Use stock RTools for Windows R-Devel + if: ${{ matrix.config.os == 'windows-latest' && matrix.config.r == 'devel' }} + run: | + echo "CMDSTANR_USE_RTOOLS=TRUE" >> $GITHUB_ENV + shell: bash + - uses: n1hility/cancel-previous-runs@v3 with: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/R/install.R b/R/install.R index 942bf77c..3a430a4e 100644 --- a/R/install.R +++ b/R/install.R @@ -635,6 +635,9 @@ check_rtools4x_windows_toolchain <- function(fix = FALSE, quiet = FALSE) { call. = FALSE ) } + if (Sys.getenv("CMDSTANR_USE_RTOOLS") != "") { + return(invisible(NULL)) + } if (!is_toolchain_installed(app = "g++", path = toolchain_path) || !is_toolchain_installed(app = "mingw32-make", path = toolchain_path)) { if (!fix) { @@ -844,8 +847,11 @@ toolchain_PATH_env_var <- function() { } rtools4x_toolchain_path <- function() { - c_runtime <- ifelse(is_ucrt_toolchain(), "ucrt64", "mingw64") - repair_path(file.path(rtools4x_home_path(), c_runtime, "bin")) + toolchain <- ifelse(is_ucrt_toolchain(), "ucrt64", "mingw64") + if (Sys.getenv("CMDSTANR_USE_RTOOLS") != "") { + toolchain <- "x86_64-w64-mingw32.static.posix" + } + repair_path(file.path(rtools4x_home_path(), toolchain, "bin")) } rtools4x_version <- function() { diff --git a/R/utils.R b/R/utils.R index b41287ee..d03184ab 100644 --- a/R/utils.R +++ b/R/utils.R @@ -85,7 +85,7 @@ is_rosetta2 <- function() { # Returns the type of make command to use to compile depending on the OS make_cmd <- function() { - if (os_is_windows() && !os_is_wsl()) { + if (os_is_windows() && !os_is_wsl() && (Sys.getenv("CMDSTANR_USE_RTOOLS") == "")) { "mingw32-make.exe" } else { "make" From 2ab63d8b32744b0fa1cbfd663c86af3fe132b736 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 22 May 2024 21:18:15 +0300 Subject: [PATCH 2/4] CI needs 2.35 RC for stock rtools --- .github/workflows/R-CMD-check.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 37000a84..e2fe66f5 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -69,6 +69,11 @@ jobs: - name: Install cmdstan run: | cmdstanr::check_cmdstan_toolchain(fix = TRUE) + if (Sys.getenv("CMDSTANR_USE_RTOOLS") == "TRUE") { + cmdstanr::install_cmdstan(cores = 2, version = "2.35.0-rc2") + } else { + cmdstanr::install_cmdstan(cores = 2) + } cmdstanr::install_cmdstan(cores = 2) shell: Rscript {0} From 0c2cc823d064567728e2b6024f1fb80869c7bf38 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 22 May 2024 21:27:57 +0300 Subject: [PATCH 3/4] Typo --- .github/workflows/R-CMD-check.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index e2fe66f5..5b2db711 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -74,7 +74,6 @@ jobs: } else { cmdstanr::install_cmdstan(cores = 2) } - cmdstanr::install_cmdstan(cores = 2) shell: Rscript {0} - name: Session info From 884ea8522d0579fe3aa2154499af2d084bb556bf Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 22 May 2024 23:03:21 +0300 Subject: [PATCH 4/4] Rtools make needs diff path handling --- R/model.R | 2 +- tests/testthat/test-install.R | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/R/model.R b/R/model.R index 8db71a17..c3ef104c 100644 --- a/R/model.R +++ b/R/model.R @@ -672,7 +672,7 @@ compile <- function(quiet = TRUE, ), run_log <- wsl_compatible_run( command = make_cmd(), - args = c(wsl_safe_path(tmp_exe), + args = c(wsl_safe_path(repair_path(tmp_exe)), cpp_options_to_compile_flags(cpp_options), stancflags_val), wd = cmdstan_path(), diff --git a/tests/testthat/test-install.R b/tests/testthat/test-install.R index 211a19c3..5d415543 100644 --- a/tests/testthat/test-install.R +++ b/tests/testthat/test-install.R @@ -1,4 +1,6 @@ context("install") +# Current tests need CmdStan 2.35 for stock rtools, but is not yet released +skip_if(Sys.getenv("CMDSTANR_USE_RTOOLS") != "") cmdstan_test_tarball_url <- Sys.getenv("CMDSTAN_TEST_TARBALL_URL") if (!nzchar(cmdstan_test_tarball_url)) {