Skip to content

Drop pre-2.35 CmdStan support in cmdstanr v1.0#1144

Open
jgabry wants to merge 16 commits intomasterfrom
min-cmdstan-2-35
Open

Drop pre-2.35 CmdStan support in cmdstanr v1.0#1144
jgabry wants to merge 16 commits intomasterfrom
min-cmdstan-2-35

Conversation

@jgabry
Copy link
Member

@jgabry jgabry commented Feb 24, 2026

Submission Checklist

  • Run unit tests
  • Declare copyright holder and agree to license (see below)

Summary

Some of the code was developed with the help of codex. I also had it take a look at the code changes and generate this summary:

In cmdstanr v1.0 we will only support CmdStan >= 2.35.0. Users needing older CmdStan versions can install an older cmdstanr release. This simplifies legacy compatibility code and tightens behavior around version/path handling.

Main changes:

  • Require CmdStan >= 2.35.0.
  • Enforce this minimum in install_cmdstan() for:
    • explicit version,
    • release_url/release_file when the archive name is parseable,
    • and the unpacked archive itself.
  • Reject unsupported existing installations in set_cmdstan_path() and
    cmdstanr_initialize().

Windows/toolchain updates:

  • Deprecate CMDSTANR_USE_MSYS_TOOLCHAIN and ignore it (with warning).
  • Remove legacy MSYS/pacman/Rtools35 code paths.
  • Add ABI-aware Rtools fallback resolution.
  • Add/extend Windows CI diagnostics for toolchain candidate selection.
  • In CI debug checks, use cmdstanr:::is_rtools4x_toolchain_usable() for consistency
    with package logic.

WSL/path state handling:

  • Reset cached .cmdstanr$WSL state when path/version state is explicitly cleared.
  • Scope cmdstan_default_path(dir=...) to the supplied directory (do not fall back to
    unrelated WSL CmdStan installs when an explicit dir is provided).

Compatibility/docs/tests/CI:

  • Bump minimum R version to >= 4.0.0.
  • Remove obsolete pre-R-3.5 tempdir branches.
  • Update NEWS + install docs (and regenerate Rd).
  • Add/extend tests for version parsing/rejection, env-var init behavior, Windows
    fallback behavior, and WSL state reset behavior.
  • Keep a pinned windows-2022 (R 4.1) CI job for legacy toolchain coverage; skip
    posterior::pareto_smooth-dependent init tests only on that configuration.
  • Harden recursive make test subprocess env (R_HOME/R_LIBS/R_LIBS_USER) and Makefile quoting.

Copyright and Licensing

Please list the copyright holder for the work you are submitting
(this will be you or your assignee, such as a university or company):
Jonah Gabry

By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses:

Raise cmdstanr support floors and remove legacy Windows toolchain compatibility paths tied to older CmdStan versions.

Core behavior updates:

- Require CmdStan >= 2.35.0 across installation and path initialization flows.

- Enforce version floor for install_cmdstan() inputs (version, release_url/release_file when parseable) and after archive unpack.

- Reject unsupported existing installations in set_cmdstan_path()/cmdstanr_initialize().

- Keep CMDSTANR_USE_MSYS_TOOLCHAIN as deprecated/ignored with a once-per-session warning and migration guidance.

Windows/toolchain cleanup:

- Remove legacy MSYS/pacman/mingw32-make toolchain-install code paths.

- Remove Rtools35/R3.x-specific branching and simplify toolchain path selection for current Rtools flows.

R floor + compatibility cleanup:

- Bump package Depends: R to >= 4.0.0.

- Remove obsolete tempdir branches for R < 3.5 in code/tests.

Docs and tests:

- Update NEWS and install documentation, including note about using older cmdstanr releases for older CmdStan/MSYS workflows.

- Add tests for archive version extraction, unsupported version rejection (including release_file and RC boundary), unsupported CMDSTAN env initialization, and ignored MSYS env warning behavior.
@jgabry jgabry marked this pull request as draft February 25, 2026 00:19
@codecov-commenter
Copy link

codecov-commenter commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 86.15385% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.92%. Comparing base (f429f12) to head (37d2e8d).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
R/install.R 86.41% 11 Missing ⚠️
R/path.R 83.33% 5 Missing ⚠️
R/zzz.R 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1144      +/-   ##
==========================================
+ Coverage   87.95%   89.92%   +1.96%     
==========================================
  Files          14       14              
  Lines        5935     5913      -22     
==========================================
+ Hits         5220     5317      +97     
+ Misses        715      596     -119     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Avoid backend-specific assumptions that caused failures on WSL

- The test had expected cmdstanr_initialize() to leave PATH/VERSION NULL after rejecting an unsupported CmdStan version

- On WSL CI, initialization can apparently fall back to an existing supported installation, so NULL is not guaranteed.
@jgabry jgabry requested a review from SteveBronder February 25, 2026 17:09
@jgabry
Copy link
Member Author

jgabry commented Feb 25, 2026

@SteveBronder @WardBrian If we require CmdStan 2.35 in cmdstanr v1.0 then I think we can simplify a lot of the Windows toolchain stuff. But I don't fully trust myself with Windows, so would be great to get your feedback if you have time. (You don't necessarily need to look at every line of code if you don't have time, but at least at a high level do these changes make sense?).

@jgabry jgabry marked this pull request as ready for review February 25, 2026 17:15
@jgabry jgabry marked this pull request as draft February 25, 2026 23:44
- Scope cmdstan_default_path(dir=...) to the provided directory and avoid unrelated WSL fallback.\n- Keep Windows toolchain debug validation aligned with is_rtools4x_toolchain_usable().\n- Add a windows-2022 (R 4.1) CI-only skip flag for pareto_smooth-dependent init tests.\n- Centralize that skip logic in a shared test helper and apply it to all affected tests.\n- Harden recursive make test subprocess env and Makefile quoting for Windows reliability.
we need `posterior::pareto_smooth()`
@jgabry jgabry marked this pull request as ready for review February 27, 2026 18:11
@WardBrian
Copy link
Member

This is similar to what cmdstanpy is doing in v2.0.0 (stan-dev/cmdstanpy#834)

I think the simplifications you're suggesting make sense -- the main thing is just that make works instead of needing mingw32-make, right?

@jgabry
Copy link
Member Author

jgabry commented Mar 2, 2026

I think the simplifications you're suggesting make sense -- the main thing is just that make works instead of needing mingw32-make, right?

Yeah. But I did also add a fallback on the Rtools side: rtools4x_toolchain_candidates() now tries an ordered list

cmdstanr/R/install.R

Lines 748 to 763 in 9c579c3

rtools4x_toolchain_candidates <- function() {
rtools_home <- rtools4x_home_path()
if (!nzchar(rtools_home)) {
return(character())
}
# Prefer the modern static toolchain first, then ABI-compatible legacy
# fallbacks for older Rtools layouts
toolchains <- if (arch_is_aarch64()) {
"aarch64-w64-mingw32.static.posix"
} else if (is_ucrt_toolchain()) {
c("x86_64-w64-mingw32.static.posix", "ucrt64", "mingw64")
} else {
c("x86_64-w64-mingw32.static.posix", "mingw64", "ucrt64")
}
repair_path(file.path(rtools_home, toolchains, "bin"))
}

and rtools4x_toolchain_path() then picks the first usable one. What do you think about this? I'm not sure if this necessary. To test it I added windows-2022 (R 4.1) to our CI matrix and it does use the fallback logic and select a different toolchain than the windows-latest (with new R) runs.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates cmdstanr v1.0 compatibility and initialization/toolchain logic by dropping support for CmdStan < 2.35.0 (and raising the minimum supported R version), simplifying legacy Windows/MSYS paths, and tightening path/version handling across installs and initialization.

Changes:

  • Enforce CmdStan >= 2.35.0 in install_cmdstan(), set_cmdstan_path(), and cmdstanr_initialize(); add version parsing helpers and tests.
  • Remove pre-R-4.0 and pre-2.35 legacy branches (tempdir handling, MSYS/Rtools35 paths) and add ABI-aware Rtools toolchain candidate selection.
  • Update docs/NEWS/DESCRIPTION and extend CI and tests for the new behavior (Windows toolchain diagnostics, WSL/path state reset, recursive make test).

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/testthat/testdata/Makefile Removes old recursive-make test Makefile (moved to resources).
tests/testthat/test-utils.R Points recursive make test at new resource file; improves failure diagnostics.
tests/testthat/test-path.R Adds tests for rejecting unsupported CmdStan installs and resetting cached WSL/path/version state.
tests/testthat/test-model-output_dir.R Drops pre-3.5 tempdir branch; uses tempdir(check=TRUE).
tests/testthat/test-install.R Removes legacy Windows/Rtools35 tests; adds tests for version parsing/floor checks and Rtools candidate selection.
tests/testthat/test-fit-init.R Minor cleanup (removes stray blank line).
tests/testthat/resources/recursive-cmdstan-flags.mk New makefile resource for recursive get_cmdstan_flags() test.
man/install_cmdstan.Rd Updates docs to reflect new minimum CmdStan support and toolchain notes.
R/zzz.R Resets cached PATH/VERSION/WSL state on invalid CMDSTAN env handling; removes pre-3.5 tempdir branch.
R/utils.R Deprecates/ignores CMDSTANR_USE_MSYS_TOOLCHAIN (warn-once); simplifies make_cmd().
R/path.R Rejects unsupported CmdStan versions in set_cmdstan_path(); adds min-version helpers; resets cached WSL on unset.
R/install.R Enforces minimum version for requested/latest/archive CmdStan; removes legacy MSYS toolchain paths; adds Rtools candidate logic.
R/args.R Drops pre-3.5 tempdir branch; uses tempdir(check=TRUE).
NEWS.md Announces CmdStan <2.35 unsupported, minimum R bump, Windows toolchain changes, env-var deprecation.
DESCRIPTION Bumps minimum R to 4.0.0 and raises posterior minimum.
.github/workflows/R-CMD-check.yaml Adds Windows-2022 (R 4.1) job and Windows toolchain resolution diagnostics.
Comments suppressed due to low confidence (3)

man/install_cmdstan.Rd:73

  • The generated Rd example for release_file contains an extra double-quote at the start (shows release_file=""./cmdstan-...). This should be corrected at the roxygen source so the rendered documentation shows a valid example (release_file="./cmdstan-...").
\item{release_file}{(string) A file path to a CmdStan release tar.gz file
downloaded from the releases page: \url{https://github.com/stan-dev/cmdstan/releases}.
For example: \verb{release_file=""./cmdstan-2.35.0.tar.gz"}. If \code{release_file} is
specified then both \code{release_url} and \code{version} will be ignored.}

R/install.R:601

  • This comment is now inaccurate: the code checks version-specific env vars like RTOOLS<ver>_HOME (via rtools4x_home_path()) and supports multiple Rtools versions, not just “RTOOLS4X_HOME” / “RTools 40”. Updating the comment will prevent confusion when debugging toolchain detection.
  # If RTOOLS4X_HOME is not set (the env. variable gets set on install)
  # we assume that RTools 40 is not installed.
  if (!nzchar(rtools_path)) {

R/install.R:60

  • The example release_file value has an extra double-quote at the beginning (release_file=""./cmdstan-...). This renders incorrectly and is not a valid example expression; it should be release_file="./cmdstan-...".
#'   downloaded from the releases page: <https://github.com/stan-dev/cmdstan/releases>.
#'   For example: `release_file=""./cmdstan-2.35.0.tar.gz"`. If `release_file` is
#'   specified then both `release_url` and `version` will be ignored.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jgabry
Copy link
Member Author

jgabry commented Mar 5, 2026

@florence-bockting, when you have a chance can you test that you can use the cmdstanr from this branch on your windows computer? If possible test that install_cmdstan() works and that you can compile and run a model. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants