Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Windows ARM64 #3051

Merged
merged 4 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/tbb_2020.3/STAN_CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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

6 changes: 5 additions & 1 deletion lib/tbb_2020.3/build/Makefile.tbb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions lib/tbb_2020.3/build/windows.gcc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions make/compiler_flags
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions make/libraries
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down