Skip to content

Commit 4fe07af

Browse files
committed
Support building TBB on Windows arm64
1 parent 5aa08f8 commit 4fe07af

File tree

6 files changed

+30
-28
lines changed

6 files changed

+30
-28
lines changed

R/tbb.R

-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ tbbLdFlags <- function() {
8181
return(sprintf(fmt, asBuildPath(tbbLib)))
8282
}
8383

84-
# on Aarch64 builds, use the version of TBB provided by Rtools
85-
if (is_windows() &&R.version$arch=="aarch64")
86-
return("-ltbb12 -ltbbmalloc")
87-
8884
# on Mac, Windows and Solaris, we need to explicitly link (#206)
8985
needsExplicitFlags<- is_mac() || is_windows() || (is_solaris() &&!is_sparc())
9086
if (needsExplicitFlags) {

R/zzz.R

+1-5
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,8 @@ loadTbbLibrary <- function(name) {
2727

2828
.onLoad<-function(libname, pkgname) {
2929

30-
tbbLibraryName<-"tbb"
31-
if (is_windows() &&R.version$arch=="aarch64")
32-
tbbLibraryName<-"tbb12"
33-
3430
# load tbb, tbbmalloc
35-
.tbbDllInfo<<- loadTbbLibrary(tbbLibraryName)
31+
.tbbDllInfo<<- loadTbbLibrary("tbb")
3632
.tbbMallocDllInfo<<- loadTbbLibrary("tbbmalloc")
3733

3834
# load tbbmalloc_proxy, but only if requested

src/Makevars.in

+18-16
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,25 @@ ifeq ($(OS), Windows_NT)
2121
USE_TBB=Windows
2222
TBB_COPY_PATTERN=tbb*.dll
2323

24+
ARCH=$(shell "${R_HOME}/bin/R" --vanilla -s -e 'cat(R.version$$arch)')
25+
TBB_CXXFLAGS = @CXX11FLAGS@ -DTBB_NO_LEGACY=1
26+
ifeq "$(ARCH)" "aarch64"
27+
WINARM64=true
28+
PKG_CPPFLAGS += -DTBB_USE_GCC_BUILTINS
29+
TBB_CXXFLAGS += -DTBB_USE_GCC_BUILTINS
30+
endif
31+
2432
MAKE = make
2533
MAKEFLAGS = -e -j1
2634
MAKE_CMD = \
2735
MSYS2_ARG_CONV_EXCL="*" \
2836
CYGWIN=nodosfilewarning \
2937
CONLY="@WINDOWS_CC@" \
3038
CPLUS="@WINDOWS_CXX11@" \
31-
CXXFLAGS="@CXX11FLAGS@ -DTBB_NO_LEGACY=1" \
39+
CXXFLAGS="$(TBB_CXXFLAGS)" \
3240
PIC_KEY="@CXX11PICFLAGS@" \
3341
WARNING_SUPPRESS="" \
42+
WINARM64="$(WINARM64)" \
3443
$(MAKE)
3544

3645
else
@@ -77,26 +86,19 @@ ifeq ($(USE_TBB), Windows)
7786
# rtools: turn on hacks to compensate for make and shell differences rtools<=>MinGW
7887
# compiler: overwrite default (which is cl = MS compiler)
7988
MAKE_ARGS += rtools=true compiler=gcc
80-
ifeq ($(WIN), 64)
81-
MAKE_ARGS += arch=intel64 runtime=mingw
82-
ARCH_DIR=x64/
83-
else
84-
MAKE_ARGS += arch=ia32 runtime=mingw
85-
ARCH_DIR=i386/
89+
ifneq ($(WINARM64), true)
90+
ifeq ($(WIN), 64)
91+
MAKE_ARGS += arch=intel64 runtime=mingw
92+
ARCH_DIR=x64/
93+
else
94+
MAKE_ARGS += arch=ia32 runtime=mingw
95+
ARCH_DIR=i386/
96+
endif
8697
endif
8798

8899
# Linker needs access to the tbb dll; otherwise you get errors such as:
89100
# "undefined reference to `tbb::task_scheduler_init::terminate()'"
90101
PKG_LIBS += -Ltbb/build/lib_release -ltbb -ltbbmalloc
91-
92-
# override for aarch64 (experimental) to use Rtools TBB
93-
ARCH=$(shell "${R_HOME}/bin/R" --vanilla -s -e 'cat(R.version$$arch)')
94-
ifeq "$(ARCH)" "aarch64"
95-
TBB_LIB = ${R_TOOLS_SOFT}
96-
TBB_INC = ${R_TOOLS_SOFT}
97-
PKG_LIBS = -ltbb12 -ltbbmalloc
98-
endif
99-
100102
endif
101103

102104
# write compiler if set

src/tbb/build/Makefile.tbb

+5-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ ifneq (,$(TBB.DEF))
9191
tbb.def: $(TBB.DEF) $(TBB.LST)
9292
$(CPLUS) $(PREPROC_ONLY) $< $(CPLUS_FLAGS) $(INCLUDES) > $@
9393

94-
LIB_LINK_FLAGS += $(EXPORT_KEY)tbb.def
94+
# LLVM on Windows doesn't need --version-script export
95+
# https://reviews.llvm.org/D63743
96+
ifeq (, $(WINARM64))
97+
LIB_LINK_FLAGS += $(EXPORT_KEY)tbb.def
98+
endif
9599
$(TBB.DLL): tbb.def
96100
endif
97101

src/tbb/build/Makefile.tbbmalloc

+5-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ ifneq (,$(MALLOC.DEF))
7474
tbbmalloc.def: $(MALLOC.DEF)
7575
$(CPLUS) $(PREPROC_ONLY) $< $(M_CPLUS_FLAGS) $(WARNING_SUPPRESS) $(INCLUDES) > $@
7676

77-
MALLOC_LINK_FLAGS += $(EXPORT_KEY)tbbmalloc.def
77+
# LLVM on Windows doesn't need --version-script export
78+
# https://reviews.llvm.org/D63743
79+
ifeq (, $(WINARM64))
80+
MALLOC_LINK_FLAGS += $(EXPORT_KEY)tbbmalloc.def
81+
endif
7882
$(MALLOC.DLL): tbbmalloc.def
7983
endif
8084

src/tbb/src/tbbmalloc/TypeDefinitions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# define__ARCH_ipf 1
2626
# elif defined(_M_IX86)||defined(__i386__) // the latter for MinGW support
2727
# define__ARCH_x86_32 1
28-
# elif defined(_M_ARM)
28+
# elif defined(_M_ARM)|| defined(__aarch64__)
2929
# define__ARCH_other 1
3030
# else
3131
# error Unknown processor architecture for Windows

0 commit comments

Comments
 (0)
close