Skip to content

Commit

Permalink
Update linux/wsl detection for install arch
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed Sep 25, 2023
1 parent 17678d5 commit 17e9ff9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
38 changes: 30 additions & 8 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,16 @@ 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)
dest_file <- file.path(dir, tar_gz_file)
} 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...")
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down

0 comments on commit 17e9ff9

Please sign in to comment.