From 7fcf9daa2237400a3c73832178b2e4e5acf810af Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Wed, 21 Feb 2024 12:47:42 -0800 Subject: [PATCH] support aarch64 on Windows Adapted from a patch shared by Tomas Kalibera. --- R/tbb.R | 4 ++++ R/zzz.R | 6 +++++- src/Makevars.in | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/R/tbb.R b/R/tbb.R index 00fccd3b..d881fd8f 100644 --- a/R/tbb.R +++ b/R/tbb.R @@ -81,6 +81,10 @@ tbbLdFlags <- function() { return(sprintf(fmt, asBuildPath(tbbLib))) } + # on Aarch64 builds, use the version of TBB provided by Rtools + if (is_windows() && R.version$arch == "aarch64") + return("-ltbb12 -ltbbmalloc") + # on Mac, Windows and Solaris, we need to explicitly link (#206) needsExplicitFlags <- is_mac() || is_windows() || (is_solaris() && !is_sparc()) if (needsExplicitFlags) { diff --git a/R/zzz.R b/R/zzz.R index 31c40a3e..2e284705 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -27,8 +27,12 @@ loadTbbLibrary <- function(name) { .onLoad <- function(libname, pkgname) { + tbbLibraryName <- "tbb" + if (is_windows() && R.version$arch == "aarch64") + tbbLibraryName <- "tbb12" + # load tbb, tbbmalloc - .tbbDllInfo <<- loadTbbLibrary("tbb") + .tbbDllInfo <<- loadTbbLibrary(tbbLibraryName) .tbbMallocDllInfo <<- loadTbbLibrary("tbbmalloc") # load tbbmalloc_proxy, but only if requested diff --git a/src/Makevars.in b/src/Makevars.in index 83e78fb3..af771924 100644 --- a/src/Makevars.in +++ b/src/Makevars.in @@ -88,6 +88,14 @@ ifeq ($(USE_TBB), Windows) # Linker needs access to the tbb dll; otherwise you get errors such as: # "undefined reference to `tbb::task_scheduler_init::terminate()'" PKG_LIBS += -Ltbb/build/lib_release -ltbb -ltbbmalloc + + # override for aarch64 (experimental) to use Rtools TBB + ARCH=$(shell "${R_HOME}/bin/R" --vanilla -s -e 'cat(R.version$$arch)') + ifeq "$(ARCH)" "aarch64" + TBB_LIB = ${R_TOOLS_SOFT} + TBB_INC = ${R_TOOLS_SOFT} + PKG_LIBS = -ltbb12 -ltbbmalloc + endif endif