Skip to content

Commit 17e9ff9

Browse files
committed
Update linux/wsl detection for install arch
1 parent 17678d5 commit 17e9ff9

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

R/install.R

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,16 @@ install_cmdstan <- function(dir = NULL,
136136
download_url <- release_url
137137
split_url <- strsplit(release_url, "/")
138138
tar_name <- utils::tail(split_url[[1]], n = 1)
139+
tar_name <- gsub("-linux-(.*).tar.gz", ".tar.gz", tar_name)
139140
cmdstan_ver <- substr(tar_name, 0, nchar(tar_name) - 7)
140141
tar_gz_file <- paste0(cmdstan_ver, ".tar.gz")
141142
dir_cmdstan <- file.path(dir, cmdstan_ver)
142143
dest_file <- file.path(dir, tar_gz_file)
143144
} else {
144145
ver <- latest_released_version(quiet = quiet)
145146
message("* Latest CmdStan release is v", ver)
146-
cmdstan_ver <- paste0("cmdstan-", ver, cmdstan_arch_suffix(ver))
147-
tar_gz_file <- paste0(cmdstan_ver, ".tar.gz")
147+
cmdstan_ver <- paste0("cmdstan-", ver)
148+
tar_gz_file <- paste0(cmdstan_ver, cmdstan_arch_suffix(ver), ".tar.gz")
148149
dir_cmdstan <- file.path(dir, cmdstan_ver)
149150
message("* Installing CmdStan v", ver, " in ", dir_cmdstan)
150151
message("* Downloading ", tar_gz_file, " from GitHub...")
@@ -748,15 +749,36 @@ check_unix_cpp_compiler <- function() {
748749
}
749750

750751
cmdstan_arch_suffix <- function(version = NULL) {
752+
os_needs_arch <- os_is_linux() || os_is_wsl()
753+
if ((!is.null(version) && version < "2.26") || !os_needs_arch) {
754+
# pre-CmdStan 2.26, only the x86 tarball was provided
755+
return(NULL)
756+
}
757+
751758
arch <- NULL
752-
if (grepl("linux", R.version$os) && grepl("aarch64", R.version$arch)) {
753-
arch <- "-linux-arm64"
759+
if (os_is_wsl()) {
760+
arch <- wsl_compatible_run(command = "uname", args = "-m")$stdout
761+
arch <- gsub("\n", "", arch, fixed = TRUE)
762+
} else {
763+
arch <- R.version$arch
754764
}
755-
if (!is.null(version) && version < "2.26") {
756-
# pre-CmdStan 2.26, only the x86 tarball was provided
757-
arch <- NULL
765+
766+
if (any(grepl(arch, c("x86_64", "i686")))) {
767+
return(NULL)
768+
}
769+
770+
arch <- gsub("aarch64", "arm64", arch)
771+
arch <- gsub("armv7l", "armel", arch)
772+
available_archs <- c("arm64", "armel", "armhf", "mips64el", "ppc64el", "s390x")
773+
selected_arch <- grep(arch, available_archs, value = TRUE)
774+
775+
if (length(selected_arch) == 0) {
776+
stop("Your CPU architecture: ", arch, " is not compatible!", "\n",
777+
"Supported architectures are: ", paste0(available_archs, collapse = ", "),
778+
call. = FALSE)
758779
}
759-
arch
780+
781+
paste0("-linux-", selected_arch)
760782
}
761783

762784
is_toolchain_installed <- function(app, path) {

R/utils.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ os_is_macos <- function() {
5050
isTRUE(Sys.info()[["sysname"]] == "Darwin")
5151
}
5252

53+
os_is_linux <- function() {
54+
isTRUE(Sys.info()[["sysname"]] == "Linux")
55+
}
56+
5357
is_rtools43_toolchain <- function() {
5458
os_is_windows() && R.version$major == "4" && R.version$minor >= "3.0"
5559
}

0 commit comments

Comments
 (0)