From 17e9ff9ad34c692ad660b45ca9c4d6e7450b444d Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 25 Sep 2023 10:39:03 +0300 Subject: [PATCH] Update linux/wsl detection for install arch --- R/install.R | 38 ++++++++++++++++++++++++++++++-------- R/utils.R | 4 ++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/R/install.R b/R/install.R index ceb141c52..25497763a 100644 --- a/R/install.R +++ b/R/install.R @@ -136,6 +136,7 @@ install_cmdstan <- function(dir = NULL, download_url <- release_url split_url <- strsplit(release_url, "/") tar_name <- utils::tail(split_url[[1]], n = 1) + tar_name <- gsub("-linux-(.*).tar.gz", ".tar.gz", tar_name) cmdstan_ver <- substr(tar_name, 0, nchar(tar_name) - 7) tar_gz_file <- paste0(cmdstan_ver, ".tar.gz") dir_cmdstan <- file.path(dir, cmdstan_ver) @@ -143,8 +144,8 @@ install_cmdstan <- function(dir = NULL, } else { ver <- latest_released_version(quiet = quiet) message("* Latest CmdStan release is v", ver) - cmdstan_ver <- paste0("cmdstan-", ver, cmdstan_arch_suffix(ver)) - tar_gz_file <- paste0(cmdstan_ver, ".tar.gz") + cmdstan_ver <- paste0("cmdstan-", ver) + tar_gz_file <- paste0(cmdstan_ver, cmdstan_arch_suffix(ver), ".tar.gz") dir_cmdstan <- file.path(dir, cmdstan_ver) message("* Installing CmdStan v", ver, " in ", dir_cmdstan) message("* Downloading ", tar_gz_file, " from GitHub...") @@ -748,15 +749,36 @@ check_unix_cpp_compiler <- function() { } cmdstan_arch_suffix <- function(version = NULL) { + os_needs_arch <- os_is_linux() || os_is_wsl() + if ((!is.null(version) && version < "2.26") || !os_needs_arch) { + # pre-CmdStan 2.26, only the x86 tarball was provided + return(NULL) + } + arch <- NULL - if (grepl("linux", R.version$os) && grepl("aarch64", R.version$arch)) { - arch <- "-linux-arm64" + if (os_is_wsl()) { + arch <- wsl_compatible_run(command = "uname", args = "-m")$stdout + arch <- gsub("\n", "", arch, fixed = TRUE) + } else { + arch <- R.version$arch } - if (!is.null(version) && version < "2.26") { - # pre-CmdStan 2.26, only the x86 tarball was provided - arch <- NULL + + if (any(grepl(arch, c("x86_64", "i686")))) { + return(NULL) + } + + arch <- gsub("aarch64", "arm64", arch) + arch <- gsub("armv7l", "armel", arch) + available_archs <- c("arm64", "armel", "armhf", "mips64el", "ppc64el", "s390x") + selected_arch <- grep(arch, available_archs, value = TRUE) + + if (length(selected_arch) == 0) { + stop("Your CPU architecture: ", arch, " is not compatible!", "\n", + "Supported architectures are: ", paste0(available_archs, collapse = ", "), + call. = FALSE) } - arch + + paste0("-linux-", selected_arch) } is_toolchain_installed <- function(app, path) { diff --git a/R/utils.R b/R/utils.R index 519a21f8b..ec8189411 100644 --- a/R/utils.R +++ b/R/utils.R @@ -50,6 +50,10 @@ os_is_macos <- function() { isTRUE(Sys.info()[["sysname"]] == "Darwin") } +os_is_linux <- function() { + isTRUE(Sys.info()[["sysname"]] == "Linux") +} + is_rtools43_toolchain <- function() { os_is_windows() && R.version$major == "4" && R.version$minor >= "3.0" }