Skip to content

Commit

Permalink
Merge pull request #2999 from stan-dev/tbb-rtools-make
Browse files Browse the repository at this point in the history
Minor patches to TBB Windows build for compatibility with RTools make
  • Loading branch information
WardBrian committed Jan 31, 2024
2 parents 70f8047 + e5b364b commit babb1ad
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 65 deletions.
46 changes: 5 additions & 41 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,12 @@ jobs:
- name: Set path for Rtools40
if: runner.os == 'Windows'
run: echo "C:/rtools40/usr/bin;C:/rtools40/mingw64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- name: Install mingw32-make and check toolchain path
if: runner.os == 'Windows'
run: |
pacman -Syu mingw-w64-x86_64-make --noconfirm
g++ --version
Get-Command g++ | Select-Object -ExpandProperty Definition
mingw32-make --version
Get-Command mingw32-make | Select-Object -ExpandProperty Definition
shell: powershell

- name: Build Math libs
shell: powershell
run: |
Add-Content make\local "O=1`n"
mingw32-make -f make/standalone math-libs -j2
make -f make/standalone math-libs -j2
- name: Add TBB to PATH
shell: powershell
run: echo "D:/a/math/math/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
Expand Down Expand Up @@ -85,21 +76,12 @@ jobs:
- name: Set path for Rtools40
if: runner.os == 'Windows'
run: echo "C:/rtools40/usr/bin;C:/rtools40/mingw64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- name: Install mingw32-make and check toolchain path
if: runner.os == 'Windows'
run: |
pacman -Syu mingw-w64-x86_64-make --noconfirm
g++ --version
Get-Command g++ | Select-Object -ExpandProperty Definition
mingw32-make --version
Get-Command mingw32-make | Select-Object -ExpandProperty Definition
shell: powershell

- name: Build Math libs
shell: powershell
run: |
Add-Content make\local "O=1`n"
mingw32-make -f make/standalone math-libs -j2
make -f make/standalone math-libs -j2
- name: Add TBB to PATH
shell: powershell
run: echo "D:/a/math/math/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
Expand Down Expand Up @@ -139,21 +121,12 @@ jobs:
- name: Set path for Rtools40
if: runner.os == 'Windows'
run: echo "C:/rtools40/usr/bin;C:/rtools40/mingw64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- name: Install mingw32-make and check toolchain path
if: runner.os == 'Windows'
run: |
pacman -Syu mingw-w64-x86_64-make --noconfirm
g++ --version
Get-Command g++ | Select-Object -ExpandProperty Definition
mingw32-make --version
Get-Command mingw32-make | Select-Object -ExpandProperty Definition
shell: powershell

- name: Build Math libs
shell: powershell
run: |
Add-Content make\local "O=1`n"
mingw32-make -f make/standalone math-libs -j2
make -f make/standalone math-libs -j2
- name: Add TBB to PATH
shell: powershell
run: echo "D:/a/math/math/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
Expand All @@ -171,7 +144,7 @@ jobs:
with:
name: gtest_outputs_xml
path: '**/*_test.xml'

mix-fun-2:
name: mix/fun tests 2
runs-on: windows-latest
Expand All @@ -188,21 +161,12 @@ jobs:
- name: Set path for Rtools40
if: runner.os == 'Windows'
run: echo "C:/rtools40/usr/bin;C:/rtools40/mingw64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- name: Install mingw32-make and check toolchain path
if: runner.os == 'Windows'
run: |
pacman -Syu mingw-w64-x86_64-make --noconfirm
g++ --version
Get-Command g++ | Select-Object -ExpandProperty Definition
mingw32-make --version
Get-Command mingw32-make | Select-Object -ExpandProperty Definition
shell: powershell

- name: Build Math libs
shell: powershell
run: |
Add-Content make\local "O=1`n"
mingw32-make -f make/standalone math-libs -j2
make -f make/standalone math-libs -j2
- name: Add TBB to PATH
shell: powershell
run: echo "D:/a/math/math/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
Expand Down
4 changes: 4 additions & 0 deletions lib/tbb_2020.3/STAN_CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ This file documents changes done for the stan-math project

- drop -g flag from makefiles for release mode builds to decrease size of binaries
- Add `tbb::` to line 252 of `task.h` to fix a build failure with gcc 13. This was done upstream in https://github.com/oneapi-src/oneTBB/pull/833

- build/windows.inc patches for RTools make:
- L15 changed setting to use '?=', allowing override
- L25,L113,L114 added additional '/' to each cmd flag
8 changes: 4 additions & 4 deletions lib/tbb_2020.3/build/windows.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

export SHELL = cmd
SHELL ?= cmd

ifdef tbb_build_dir
test_dir:=$(tbb_build_dir)
Expand All @@ -22,7 +22,7 @@ endif

# A convenience wrapper for calls to detect.js.
# $(1) is the full command line for the script, e.g. /minversion icl 12
detect_js = $(shell cmd /C "cscript /nologo /E:jscript $(tbb_root)/build/detect.js $(1)")
detect_js = $(shell cmd //C "cscript //nologo //E:jscript $(tbb_root)/build/detect.js $(1)")

# TODO give an error if archs doesn't match
ifndef arch
Expand Down Expand Up @@ -110,8 +110,8 @@ ifneq ($(filter vc8 vc9,$(runtime)),)
RML.MANIFEST = tbbmanifest.exe.manifest
endif

MAKE_VERSIONS = cmd /C cscript /nologo /E:jscript $(subst \,/,$(tbb_root))/build/version_info_windows.js $(compiler) $(arch) $(subst \,/,"$(VERSION_FLAGS)") > version_string.ver
MAKE_TBBVARS = cmd /C "$(subst /,\,$(tbb_root))\build\generate_tbbvars.bat"
MAKE_VERSIONS = cmd //C cscript //nologo //E:jscript $(subst \,/,$(tbb_root))/build/version_info_windows.js $(compiler) $(arch) $(subst \,/,"$(VERSION_FLAGS)") > version_string.ver
MAKE_TBBVARS = cmd //C "$(subst /,\,$(tbb_root))\build\generate_tbbvars.bat"

TEST_LAUNCHER = $(subst /,\,$(tbb_root))\build\test_launcher.bat $(largs)

Expand Down
17 changes: 7 additions & 10 deletions make/libraries
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ clean-sundials:
# Note that the tbb targets must not be build in parallel (so no concurrent
# build of tbb and tbbmalloc, for example). This is ensured here with proper
# dependencies.
#
# On windows the mingw32-make (part of RTools, for example) is required to build
# the TBB as this make has proper POSIX extensions needed by the used downstream
# TBB makefiles.

ifndef TBB_LIB

Expand Down Expand Up @@ -143,6 +139,13 @@ ifeq (Windows_NT, $(OS))
ifeq ($(IS_UCRT),true)
TBB_CXXFLAGS += -D_UCRT
endif
SH_CHECK := $(shell command -v sh 2>/dev/null)
ifdef SH_CHECK
WINDOWS_HAS_SH ?= true
endif
ifeq ($(WINDOWS_HAS_SH), true) # Stop TBB makefile changing SHELL on RTools
SHELL = sh.exe
endif
endif

# If brackets or spaces are found in MAKE on Windows
Expand All @@ -157,12 +160,6 @@ $(TBB_BIN)/tbb-make-check:
ifeq ($(OS),Windows_NT)
ifneq ($(MAKE),$(MAKE_ESCAPED))
$(error '$nError:$n$nThe RTools toolchain is installed in a path with spaces or brackets.$nPlease reinstall the toolchain.$n$n')
else
if ! [[ $(MAKE) =~ mingw32 ]]; then \
echo "ERROR: Please use mingw32-make on Windows to build the Intel TBB library."; \
echo "This is packaged with RTools, for example."; \
exit 1; \
fi
endif
endif
@mkdir -p $(TBB_BIN)
Expand Down
12 changes: 3 additions & 9 deletions runTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ def doCommand(command, exit_on_failure=True):

def generateTests(j):
"""Generate all tests and pass along the j parameter to make."""
if isWin():
doCommand("mingw32-make -j%d generate-tests -s" % (j or 1))
else:
doCommand("make -j%d generate-tests -s" % (j or 1))
doCommand("make -j%d generate-tests -s" % (j or 1))


def divide_chunks(l, n):
Expand Down Expand Up @@ -238,10 +235,7 @@ def cleanupJumboTests(paths):

def makeTest(name, j):
"""Run the make command for a given single test."""
if isWin():
doCommand("mingw32-make -j%d %s" % (j or 1, name))
else:
doCommand("make -j%d %s" % (j or 1, name))
doCommand("make -j%d %s" % (j or 1, name))


def commandExists(command):
Expand Down Expand Up @@ -375,7 +369,7 @@ def handleExpressionTests(tests, only_functions, n_test_files):
def checkToolchainPathWindows():
if isWin():
p1 = subprocess.Popen(
"where.exe mingw32-make",
"where.exe make",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
Expand Down
2 changes: 1 addition & 1 deletion test/sig_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys

if os.name == "nt": # Windows
make = "mingw32-make"
make = "make"
exe_extension = ".exe"
else:
make = "make"
Expand Down

0 comments on commit babb1ad

Please sign in to comment.