diff --git a/lib/tbb_2020.3/STAN_CHANGES b/lib/tbb_2020.3/STAN_CHANGES index 67193d07e32..bc82dfb5969 100644 --- a/lib/tbb_2020.3/STAN_CHANGES +++ b/lib/tbb_2020.3/STAN_CHANGES @@ -6,3 +6,10 @@ This file documents changes done for the stan-math project - build/windows.inc patches for RTools make: - L15 changed setting to use '?=', allowing override - L25,L113,L114 added additional '/' to each cmd flag + +- Support for Windows ARM64 with RTools: + - build/Makefile.tbb + - L94 Wrapped the use of `--version-script` export in conditional on non-WINARM64 + - build/windows.gcc.ino + - L84 Wrapped the use of `-flifetime-dse` flag in conditional on non-WINARM64 + \ No newline at end of file diff --git a/lib/tbb_2020.3/build/Makefile.tbb b/lib/tbb_2020.3/build/Makefile.tbb index 1556899811a..cf889cc31a2 100644 --- a/lib/tbb_2020.3/build/Makefile.tbb +++ b/lib/tbb_2020.3/build/Makefile.tbb @@ -91,7 +91,11 @@ ifneq (,$(TBB.DEF)) tbb.def: $(TBB.DEF) $(TBB.LST) $(CPLUS) $(PREPROC_ONLY) $< $(CPLUS_FLAGS) $(INCLUDES) > $@ -LIB_LINK_FLAGS += $(EXPORT_KEY)tbb.def +# LLVM on Windows doesn't need --version-script export +# https://reviews.llvm.org/D63743 +ifeq (, $(WINARM64)) + LIB_LINK_FLAGS += $(EXPORT_KEY)tbb.def +endif $(TBB.DLL): tbb.def endif diff --git a/lib/tbb_2020.3/build/windows.gcc.inc b/lib/tbb_2020.3/build/windows.gcc.inc index dc123eedc9c..d882ceb920a 100644 --- a/lib/tbb_2020.3/build/windows.gcc.inc +++ b/lib/tbb_2020.3/build/windows.gcc.inc @@ -80,8 +80,11 @@ endif # gcc 6.0 and later have -flifetime-dse option that controls # elimination of stores done outside the object lifetime ifeq (ok,$(call detect_js,/minversion gcc 6.0)) - # keep pre-contruction stores for zero initialization - DSE_KEY = -flifetime-dse=1 + # Clang does not support -flifetime-dse + ifeq (, $(WINARM64)) + # keep pre-contruction stores for zero initialization + DSE_KEY = -flifetime-dse=1 + endif endif ifeq ($(cfg), release) diff --git a/make/compiler_flags b/make/compiler_flags index c6b9228a82c..0be4905ccee 100644 --- a/make/compiler_flags +++ b/make/compiler_flags @@ -17,6 +17,7 @@ endif ## Set OS specific library filename extensions ifeq ($(OS),Windows_NT) + WINARM64 := $(shell echo | $(CXX) -E -dM - | findstr __aarch64__) LIBRARY_SUFFIX ?= .dll endif @@ -271,8 +272,13 @@ CXXFLAGS_TBB ?= -I $(TBB_INC) else CXXFLAGS_TBB ?= -I $(TBB)/include endif +LDFLAGS_TBB ?= -Wl,-L,"$(TBB_LIB)" -Wl,--disable-new-dtags + +# Windows LLVM/Clang does not support -rpath, but is not needed on Windows anyway +ifeq ($(WINARM64),) + LDFLAGS_TBB += -Wl,-rpath,"$(TBB_LIB)" +endif -LDFLAGS_TBB ?= -Wl,-L,"$(TBB_LIB)" -Wl,-rpath,"$(TBB_LIB)" -Wl,--disable-new-dtags LDLIBS_TBB ?= -ltbb else @@ -290,7 +296,12 @@ ifeq ($(OS),Linux) endif CXXFLAGS_TBB ?= -I $(TBB)/include -LDFLAGS_TBB ?= -Wl,-L,"$(TBB_BIN_ABSOLUTE_PATH)" -Wl,-rpath,"$(TBB_BIN_ABSOLUTE_PATH)" $(LDFLAGS_FLTO_FLTO) $(LDFLAGS_OPTIM_TBB) +LDFLAGS_TBB ?= -Wl,-L,"$(TBB_BIN_ABSOLUTE_PATH)" $(LDFLAGS_FLTO_FLTO) $(LDFLAGS_OPTIM_TBB) + +# Windows LLVM/Clang does not support -rpath, but is not needed on Windows anyway +ifeq ($(WINARM64),) + LDFLAGS_TBB += -Wl,-rpath,"$(TBB_BIN_ABSOLUTE_PATH)" +endif LDLIBS_TBB ?= -ltbb endif diff --git a/make/libraries b/make/libraries index 3e9b1d0d75d..bb5224a9835 100644 --- a/make/libraries +++ b/make/libraries @@ -138,6 +138,11 @@ endif ifeq (Windows_NT, $(OS)) ifeq ($(IS_UCRT),true) TBB_CXXFLAGS += -D_UCRT + endif + # TBB does not have assembly code for Windows ARM64, so we need to use GCC builtins + ifneq ($(WINARM64),) + TBB_CXXFLAGS += -DTBB_USE_GCC_BUILTINS + CXXFLAGS_TBB += -DTBB_USE_GCC_BUILTINS endif SH_CHECK := $(shell command -v sh 2>/dev/null) ifdef SH_CHECK @@ -169,11 +174,11 @@ endif $(TBB_BIN)/tbb.def: $(TBB_BIN)/tbb-make-check @mkdir -p $(TBB_BIN) touch $(TBB_BIN)/version_$(notdir $(TBB)) - 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)" + 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)" $(TBB_BIN)/tbbmalloc.def: $(TBB_BIN)/tbb-make-check @mkdir -p $(TBB_BIN) - 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)" + 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)" $(TBB_BIN)/libtbb.dylib: $(TBB_BIN)/tbb.def $(TBB_BIN)/libtbbmalloc.dylib: $(TBB_BIN)/tbbmalloc.def