Skip to content

Commit

Permalink
apacheGH-33807: [R] Add a message if we detect running under emulation (
Browse files Browse the repository at this point in the history
apache#37777)

Resolves apache#33807 and apache#37034

### Rationale for this change

If someone is running R under emulation, arrow segfaults without error. We can detect this when we load so can also warn people that this is not recommended. Though the version of R being run is not directly an arrow issue, arrow fails very quickly in this configuration.

### What changes are included in this PR?

Detect when running under rosetta (on macOS only) and warn when the library is attached

### Are these changes tested?

No, given the paucity of ARM-based mac CI, testing this organically would be difficult. But the logic is straightforward.

### Are there any user-facing changes?

Yes, a warning when someone loads arrow under emulation.
* Closes: apache#33807

Authored-by: Jonathan Keane <jkeane@gmail.com>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
  • Loading branch information
jonkeane authored and loicalleyne committed Nov 13, 2023
1 parent 0e2e863 commit 5651627
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
21 changes: 21 additions & 0 deletions r/R/arrow-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ configure_tzdb <- function() {
# Just to be extra safe, let's wrap this in a try();
# we don't want a failed startup message to prevent the package from loading
try({
# On MacOS only, Check if we are running in under emulation, and warn this will not work
if (on_rosetta()) {
packageStartupMessage(
paste(
"Warning:",
" It appears that you are running R and Arrow in emulation (i.e. you're",
" running an Intel version of R on a non-Intel mac). This configuration is",
" not supported by arrow, you should install a native (arm64) build of R",
" and use arrow with that. See https://cran.r-project.org/bin/macosx/",
"",
sep = "\n"
)
)
}


features <- arrow_info()$capabilities
# That has all of the #ifdef features, plus the compression libs and the
# string libraries (but not the memory allocators, they're added elsewhere)
Expand Down Expand Up @@ -225,6 +241,11 @@ on_macos_10_13_or_lower <- function() {
package_version(unname(Sys.info()["release"])) < "18.0.0"
}

on_rosetta <- function() {
identical(tolower(Sys.info()[["sysname"]]), "darwin") &&
identical(system("sysctl -n sysctl.proc_translated", intern = TRUE), "1")
}

option_use_threads <- function() {
!is_false(getOption("arrow.use_threads"))
}
Expand Down
4 changes: 1 addition & 3 deletions r/R/install-arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ install_arrow <- function(nightly = FALSE,
verbose = Sys.getenv("ARROW_R_DEV", FALSE),
repos = getOption("repos"),
...) {
sysname <- tolower(Sys.info()[["sysname"]])
conda <- isTRUE(grepl("conda", R.Version()$platform))

if (conda) {
Expand All @@ -80,8 +79,7 @@ install_arrow <- function(nightly = FALSE,
# On the M1, we can't use the usual autobrew, which pulls Intel dependencies
apple_m1 <- grepl("arm-apple|aarch64.*darwin", R.Version()$platform)
# On Rosetta, we have to build without JEMALLOC, so we also can't autobrew
rosetta <- identical(sysname, "darwin") && identical(system("sysctl -n sysctl.proc_translated", intern = TRUE), "1")
if (rosetta) {
if (on_rosetta()) {
Sys.setenv(ARROW_JEMALLOC = "OFF")
}
if (apple_m1 || rosetta) {
Expand Down
2 changes: 2 additions & 0 deletions r/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ additional steps should be required.

There are some special cases to note:

- On macOS, the R you use with Arrow should match the architecture of the machine you are using. If you're using an ARM (aka M1, M2, etc.) processor use R compiled for arm64. If you're using an Intel based mac, use R compiled for x86. Using R and Arrow compiled for Intel based macs on an ARM based mac will result in segfaults and crashes.

- On Linux the installation process can sometimes be more involved because
CRAN does not host binaries for Linux. For more information please see the [installation guide](https://arrow.apache.org/docs/r/articles/install.html).

Expand Down

0 comments on commit 5651627

Please sign in to comment.