Repository: apache/arrow
File: r/tools/nixlibs.R (R)

Code before:
    } else if (identical(Sys.info()["machine"], "x86_64") && file.exists(file.path("/opt/R/x86_64/include", header))) {
      openssl_root_dir <- "/opt/R/x86_64"
    } else {
      openssl_root_dir <- "/usr/local"
    }
  }
  openssl_root_dir
}

# (built with newer devtoolset but older glibc (2.17) for broader compatibility, like manylinux2014)
determine_binary_from_stderr <- function(errs) {
  # Check for dealbreakers:
  if (!on_macos && any(grepl("Using libc++", errs, fixed = TRUE))) {
    # Our linux binaries are all built with GNU stdlib so they fail with libc++
    lg("Linux binaries incompatible with libc++")
    return(NULL)
  } else if (header_not_found("curl/curl", errs)) {
    lg("libcurl not found")
    return(NULL)
  } else if (header_not_found("openssl/opensslv", errs)) {
    lg("OpenSSL not found")
    return(NULL)
  } else if (any(grepl("OpenSSL version must be 3.0 or greater", errs))) {
    lg("OpenSSL found but version >= 3.0.0 is required")
    return(NULL)
  } else if (any(grepl("Using OpenSSL version 3", errs)) || is.null(attr(errs, "status"))) {
    # Either explicitly found OpenSSL 3, or no error (assumes OpenSSL 3+)
    lg("Found libcurl and OpenSSL >= 3.0.0")
    return("openssl-3.0")
  }
  NULL
}

header_not_found <- function(header, errs) {
  regex <- sprintf("[Ee]rror.*%s\\.h", header)
  any(grepl(regex, errs))
}

#### start distro ####

distro <- function() {
  # This is not part of distro but needed to enable prebuilt binaries on macos
  if (on_macos) {
    return(list(id = "darwin", arch = tolower(Sys.info()[["machine"]])))
  }

  # The code in this script is a (potentially stale) copy of the distro package
  if (requireNamespace("distro", quietly = TRUE)) {
    # Use the version from the package, which may be updated from this
    return(distro::distro())
  }

Review comment (suggestion):
I think we can remove the "Using OpenSSL version 3" test now (here and in the test program above), right? If the test program is successful, it has found openssl >= 3.

Code after:
  header <- "openssl/opensslv.h"
  if (is.na(openssl_root_dir) || !file.exists(file.path(openssl_root_dir, "include", header))) {
    # try to guess default openssl include dir based on CRAN's build script
    # https://github.com/R-macos/recipes/blob/master/build.sh#L35
    if (identical(Sys.info()["machine"], "arm64") && file.exists(file.path("/opt/R/arm64/include", header))) {
      openssl_root_dir <- "/opt/R/arm64"
    } else if (identical(Sys.info()["machine"], "x86_64") && file.exists(file.path("/opt/R/x86_64/include", header))) {
      openssl_root_dir <- "/opt/R/x86_64"
    } else {
      openssl_root_dir <- "/usr/local"
    }
  }
  openssl_root_dir
}

has_binary_sysreqs <- function(errs) {
  # Check for dealbreakers:
  if (!on_macos && any(grepl("Using libc++", errs, fixed = TRUE))) {
    # Our linux binaries are all built with GNU stdlib so they fail with libc++
    lg("Linux binaries incompatible with libc++")
    return(FALSE)
  } else if (header_not_found("curl/curl", errs)) {
    lg("libcurl not found")
    return(FALSE)
  } else if (header_not_found("openssl/opensslv", errs)) {
    lg("OpenSSL not found")
    return(FALSE)
  } else if (any(grepl("OpenSSL version must be 3.0 or greater", errs))) {
    lg("OpenSSL found but version >= 3.0 is required")
    return(FALSE)
  } else if (is.null(attr(errs, "status"))) {
    # Successful compile = OpenSSL >= 3.0 found
    lg("Found libcurl and OpenSSL >= 3.0")
    return(TRUE)
  }
  FALSE
}

header_not_found <- function(header, errs) {
  regex <- sprintf("[Ee]rror.*%s\\.h", header)
  any(grepl(regex, errs))
}

#### start distro ####

distro <- function() {
  # This is not part of distro but needed to enable prebuilt binaries on macos
  if (on_macos) {
    return(list(id = "darwin", arch = tolower(Sys.info()[["machine"]])))
  }