Skip to content

Commit 91e4bf6

Browse files
authored
Add CMDSTANR_USE_RTOOLS envvar to force use of stock RTools (#980)
* Add CMDSTANR_USE_RTOOLS envvar to use stock rtools * CI needs 2.35 RC for stock rtools * Typo * Rtools make needs diff path handling
1 parent 827385f commit 91e4bf6

5 files changed

Lines changed: 23 additions & 5 deletions

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ jobs:
4242
echo "CMDSTAN_PATH=${HOME}/.cmdstan" >> $GITHUB_ENV
4343
shell: bash
4444

45+
- name: Use stock RTools for Windows R-Devel
46+
if: ${{ matrix.config.os == 'windows-latest' && matrix.config.r == 'devel' }}
47+
run: |
48+
echo "CMDSTANR_USE_RTOOLS=TRUE" >> $GITHUB_ENV
49+
shell: bash
50+
4551
- uses: n1hility/cancel-previous-runs@v3
4652
with:
4753
token: ${{ secrets.GITHUB_TOKEN }}
@@ -63,7 +69,11 @@ jobs:
6369
- name: Install cmdstan
6470
run: |
6571
cmdstanr::check_cmdstan_toolchain(fix = TRUE)
66-
cmdstanr::install_cmdstan(cores = 2)
72+
if (Sys.getenv("CMDSTANR_USE_RTOOLS") == "TRUE") {
73+
cmdstanr::install_cmdstan(cores = 2, version = "2.35.0-rc2")
74+
} else {
75+
cmdstanr::install_cmdstan(cores = 2)
76+
}
6777
shell: Rscript {0}
6878

6979
- name: Session info

R/install.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,9 @@ check_rtools4x_windows_toolchain <- function(fix = FALSE, quiet = FALSE) {
635635
call. = FALSE
636636
)
637637
}
638+
if (Sys.getenv("CMDSTANR_USE_RTOOLS") != "") {
639+
return(invisible(NULL))
640+
}
638641
if (!is_toolchain_installed(app = "g++", path = toolchain_path) ||
639642
!is_toolchain_installed(app = "mingw32-make", path = toolchain_path)) {
640643
if (!fix) {
@@ -844,8 +847,11 @@ toolchain_PATH_env_var <- function() {
844847
}
845848

846849
rtools4x_toolchain_path <- function() {
847-
c_runtime <- ifelse(is_ucrt_toolchain(), "ucrt64", "mingw64")
848-
repair_path(file.path(rtools4x_home_path(), c_runtime, "bin"))
850+
toolchain <- ifelse(is_ucrt_toolchain(), "ucrt64", "mingw64")
851+
if (Sys.getenv("CMDSTANR_USE_RTOOLS") != "") {
852+
toolchain <- "x86_64-w64-mingw32.static.posix"
853+
}
854+
repair_path(file.path(rtools4x_home_path(), toolchain, "bin"))
849855
}
850856

851857
rtools4x_version <- function() {

R/model.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ compile <- function(quiet = TRUE,
672672
),
673673
run_log <- wsl_compatible_run(
674674
command = make_cmd(),
675-
args = c(wsl_safe_path(tmp_exe),
675+
args = c(wsl_safe_path(repair_path(tmp_exe)),
676676
cpp_options_to_compile_flags(cpp_options),
677677
stancflags_val),
678678
wd = cmdstan_path(),

R/utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ is_rosetta2 <- function() {
8585

8686
# Returns the type of make command to use to compile depending on the OS
8787
make_cmd <- function() {
88-
if (os_is_windows() && !os_is_wsl()) {
88+
if (os_is_windows() && !os_is_wsl() && (Sys.getenv("CMDSTANR_USE_RTOOLS") == "")) {
8989
"mingw32-make.exe"
9090
} else {
9191
"make"

tests/testthat/test-install.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
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") != "")
24

35
cmdstan_test_tarball_url <- Sys.getenv("CMDSTAN_TEST_TARBALL_URL")
46
if (!nzchar(cmdstan_test_tarball_url)) {

0 commit comments

Comments
 (0)