Skip to content

Commit 08d8a22

Browse files
authored
Merge pull request #3051 from stan-dev/tbb-winarm64
Add support for Windows ARM64
2 parents 86a3e83 + df305d6 commit 08d8a22

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

lib/tbb_2020.3/STAN_CHANGES

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ This file documents changes done for the stan-math project
66
- build/windows.inc patches for RTools make:
77
- L15 changed setting to use '?=', allowing override
88
- L25,L113,L114 added additional '/' to each cmd flag
9+
10+
- Support for Windows ARM64 with RTools:
11+
- build/Makefile.tbb
12+
- L94 Wrapped the use of `--version-script` export in conditional on non-WINARM64
13+
- build/windows.gcc.ino
14+
- L84 Wrapped the use of `-flifetime-dse` flag in conditional on non-WINARM64
15+

lib/tbb_2020.3/build/Makefile.tbb

Lines changed: 5 additions & 1 deletion
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

lib/tbb_2020.3/build/windows.gcc.inc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ endif
8080
# gcc 6.0 and later have -flifetime-dse option that controls
8181
# elimination of stores done outside the object lifetime
8282
ifeq (ok,$(call detect_js,/minversion gcc 6.0))
83-
# keep pre-contruction stores for zero initialization
84-
DSE_KEY = -flifetime-dse=1
83+
# Clang does not support -flifetime-dse
84+
ifeq (, $(WINARM64))
85+
# keep pre-contruction stores for zero initialization
86+
DSE_KEY = -flifetime-dse=1
87+
endif
8588
endif
8689

8790
ifeq ($(cfg), release)

make/compiler_flags

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ endif
1717

1818
## Set OS specific library filename extensions
1919
ifeq ($(OS),Windows_NT)
20+
WINARM64 := $(shell echo | $(CXX) -E -dM - | findstr __aarch64__)
2021
LIBRARY_SUFFIX ?= .dll
2122
endif
2223

@@ -271,8 +272,13 @@ CXXFLAGS_TBB ?= -I $(TBB_INC)
271272
else
272273
CXXFLAGS_TBB ?= -I $(TBB)/include
273274
endif
275+
LDFLAGS_TBB ?= -Wl,-L,"$(TBB_LIB)" -Wl,--disable-new-dtags
276+
277+
# Windows LLVM/Clang does not support -rpath, but is not needed on Windows anyway
278+
ifeq ($(WINARM64),)
279+
LDFLAGS_TBB += -Wl,-rpath,"$(TBB_LIB)"
280+
endif
274281

275-
LDFLAGS_TBB ?= -Wl,-L,"$(TBB_LIB)" -Wl,-rpath,"$(TBB_LIB)" -Wl,--disable-new-dtags
276282
LDLIBS_TBB ?= -ltbb
277283

278284
else
@@ -290,7 +296,12 @@ ifeq ($(OS),Linux)
290296
endif
291297

292298
CXXFLAGS_TBB ?= -I $(TBB)/include
293-
LDFLAGS_TBB ?= -Wl,-L,"$(TBB_BIN_ABSOLUTE_PATH)" -Wl,-rpath,"$(TBB_BIN_ABSOLUTE_PATH)" $(LDFLAGS_FLTO_FLTO) $(LDFLAGS_OPTIM_TBB)
299+
LDFLAGS_TBB ?= -Wl,-L,"$(TBB_BIN_ABSOLUTE_PATH)" $(LDFLAGS_FLTO_FLTO) $(LDFLAGS_OPTIM_TBB)
300+
301+
# Windows LLVM/Clang does not support -rpath, but is not needed on Windows anyway
302+
ifeq ($(WINARM64),)
303+
LDFLAGS_TBB += -Wl,-rpath,"$(TBB_BIN_ABSOLUTE_PATH)"
304+
endif
294305
LDLIBS_TBB ?= -ltbb
295306

296307
endif

make/libraries

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ endif
138138
ifeq (Windows_NT, $(OS))
139139
ifeq ($(IS_UCRT),true)
140140
TBB_CXXFLAGS += -D_UCRT
141+
endif
142+
# TBB does not have assembly code for Windows ARM64, so we need to use GCC builtins
143+
ifneq ($(WINARM64),)
144+
TBB_CXXFLAGS += -DTBB_USE_GCC_BUILTINS
145+
CXXFLAGS_TBB += -DTBB_USE_GCC_BUILTINS
141146
endif
142147
SH_CHECK := $(shell command -v sh 2>/dev/null)
143148
ifdef SH_CHECK
@@ -169,11 +174,11 @@ endif
169174
$(TBB_BIN)/tbb.def: $(TBB_BIN)/tbb-make-check
170175
@mkdir -p $(TBB_BIN)
171176
touch $(TBB_BIN)/version_$(notdir $(TBB))
172-
tbb_root="$(TBB_RELATIVE_PATH)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbb" compiler=$(TBB_CXX_TYPE) cfg=release stdver=c++1y CXXFLAGS="$(TBB_CXXFLAGS)"
177+
tbb_root="$(TBB_RELATIVE_PATH)" WINARM64="$(WINARM64)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbb" compiler=$(TBB_CXX_TYPE) cfg=release stdver=c++1y CXXFLAGS="$(TBB_CXXFLAGS)"
173178

174179
$(TBB_BIN)/tbbmalloc.def: $(TBB_BIN)/tbb-make-check
175180
@mkdir -p $(TBB_BIN)
176-
tbb_root="$(TBB_RELATIVE_PATH)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbbmalloc" compiler=$(TBB_CXX_TYPE) cfg=release stdver=c++1y malloc CXXFLAGS="$(TBB_CXXFLAGS)"
181+
tbb_root="$(TBB_RELATIVE_PATH)" WINARM64="$(WINARM64)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbbmalloc" compiler=$(TBB_CXX_TYPE) cfg=release stdver=c++1y malloc CXXFLAGS="$(TBB_CXXFLAGS)"
177182

178183
$(TBB_BIN)/libtbb.dylib: $(TBB_BIN)/tbb.def
179184
$(TBB_BIN)/libtbbmalloc.dylib: $(TBB_BIN)/tbbmalloc.def

0 commit comments

Comments
 (0)