Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fadf3ca
Add CMake test builds with shared objects and precompiled headers
SteveBronder Oct 14, 2026
53da082
Simplify CMake testing and reuse Jenkins build directories
SteveBronder Oct 14, 2026
679221f
Merge commit 'd12f488749a92899e8b9a473bd59e6cfbb13eb79' into HEAD
yashikno Oct 14, 2026
48ab621
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Oct 14, 2026
c550c5b
Fix CMake CI and consolidate test runner commands
SteveBronder Oct 15, 2026
865d800
Fix OpenCL warnings with Clang 10
SteveBronder Oct 15, 2026
ddc7cca
Replace tuple callback captures with direct value captures
SteveBronder Oct 15, 2026
e2c91d6
Fix remaining CI platform, solver, and MPI failures
SteveBronder Oct 16, 2026
f1a0dc7
Fix remaining threading and Windows ARM numerical tests
SteveBronder Oct 16, 2026
cf12429
Read Jenkins parallelism from the active container
SteveBronder Oct 16, 2026
ae42a39
Rename the shared empty CMake source to empty.cpp
SteveBronder Oct 16, 2026
a809ff3
Fix Jenkins compilation and parallel CMake test builds
SteveBronder Oct 22, 2026
b191ccc
Allow time for optimized Laplace test suites
SteveBronder Oct 22, 2026
a93eccf
Identify exceptions in individual ODE gradient checks
SteveBronder Oct 22, 2026
d655047
Initialize CVODES adjoint quadrature derivative buffers
SteveBronder Oct 22, 2026
ddc1c9a
Use cleanup fixture for adjoint quadrature regression
SteveBronder Oct 22, 2026
f86a525
Run grouped directory test executables in Jenkins
SteveBronder Oct 22, 2026
521d18a
Fix OpenCL state cleanup in grouped test executables
SteveBronder Oct 27, 2026
b2fff32
Share test target setup and build directory executables in Jenkins
SteveBronder Oct 28, 2026
4077c27
Migrate develop's Jenkinsfile from make to CMake
SteveBronder Oct 28, 2026
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
12 changes: 7 additions & 5 deletions .github/workflows/header_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ jobs:
Get-Command mingw32-make | Select-Object -ExpandProperty Definition
shell: powershell

- name: Build Math libs
shell: powershell
run: mingw32-make -f make/standalone math-libs -j2
- name: Install Ninja
run: python -m pip install ninja

- name: Run header tests
shell: powershell
run: make -j2 test-headers
run: |
cmake -S . -B build -G Ninja -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DSTAN_BUILD_PROB_TESTS=OFF
cmake --build build --parallel 2 --target test-headers

opencl:
name: OpenCL
Expand All @@ -57,7 +58,8 @@ jobs:
- name: Run header tests
run: |
echo "STAN_OPENCL=true" > make/local
make -j2 test-headers
cmake -S . -B build -DSTAN_OPENCL=ON -DSTAN_BUILD_PROB_TESTS=OFF
cmake --build build --parallel 2 --target test-headers
no_range_checks:
name: NoRange
runs-on: ubuntu-latest
Expand Down
18 changes: 8 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,24 @@ jobs:
with:
r-version: 'release'

- name: Build Math libs
- name: Configure test tools
shell: pwsh
run: |
echo "$(pwd)/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
python -m pip install ninja
Add-Content make\local "CPPFLAGS=-w -Wno-psabi -Wno-misleading-indentation`n"
Add-Content make\local "STAN_THREADS=true`n"
make -f make/standalone math-libs -j2

- name: Run ${{ matrix.config.label }} unit tests
shell: pwsh
run: |
python runTests.py -j4 ${{ matrix.config.tests }}
python runTests.py --cmake-arg=-GNinja --cmake-arg=-DCMAKE_C_COMPILER=gcc --cmake-arg=-DCMAKE_CXX_COMPILER=g++ -j4 ${{ matrix.config.tests }}

- name: Upload gtest_output xml
uses: actions/upload-artifact@v7
if: failure()
with:
name: gtest_outputs_xml
path: '**/*_test.xml'
path: 'build/test-results/*.xml'

mix-fun:
name: mix fun and prob tests ${{ matrix.group }} (${{ matrix.os }})
Expand All @@ -91,13 +90,12 @@ jobs:
r-version: 'release'


- name: Build Math libs
- name: Configure test tools
shell: pwsh
run: |
echo "$(pwd)/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
python -m pip install ninja
Add-Content make\local "CPPFLAGS=-w -Wno-psabi -Wno-misleading-indentation`n"
Add-Content make\local "STAN_THREADS=true`n"
make -f make/standalone math-libs -j2

- name: Run mix/fun unit tests
shell: pwsh
Expand All @@ -114,11 +112,11 @@ jobs:
$MixFunProbTests[(4 * $FifthNumberTests)..($NumberTests - 1)] `
)

python runTests.py -j2 $MixFunProbTestsArray[(${{ matrix.group }} - 1)]
python runTests.py --cmake-arg=-GNinja --cmake-arg=-DCMAKE_C_COMPILER=gcc --cmake-arg=-DCMAKE_CXX_COMPILER=g++ -j2 $MixFunProbTestsArray[(${{ matrix.group }} - 1)]

- name: Upload gtest_output xml
uses: actions/upload-artifact@v7
if: failure()
with:
name: gtest_outputs_xml
path: '**/*_test.xml'
path: 'build/test-results/*.xml'
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ lib/tbb/**

# gdb debug history
.gdb_history

# CMake build trees
/build/
/build-*/
/.build/
/.build-*/
176 changes: 176 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
cmake_minimum_required(VERSION 3.16.3)
include(cmake/MakeLocal.cmake)
project(stanmath LANGUAGES C CXX)
stan_apply_make_local_flags()

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "Use an out-of-source build: cmake -S . -B build")
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
stan_cache_default(CMAKE_POSITION_INDEPENDENT_CODE ON BOOL
"Compile position-independent code and link executables as PIE")
# Link executables as PIE to match their position-independent objects.
include(CheckPIESupported)
check_pie_supported()

option(STAN_BUILD_DOCS "Build the Stan Math library documentation" OFF)
option(STAN_TEST_HEADERS "Create targets that check standalone headers" ON)
option(STAN_TEST_PCH "Reuse precompiled headers when building tests" ON)
option(STAN_BUILD_PROB_TESTS "Generate and build distribution tests" ON)
option(STAN_BUILD_EXPRESSION_TESTS "Build pre-generated expression tests" OFF)
option(STAN_TEST_ROW_VECTORS "Include row vectors in distribution tests" OFF)
option(STAN_PROB_TEST_ALL "Test all distribution autodiff modes" OFF)
option(STAN_NO_RANGE_CHECKS "Disable range checks within the Stan library" OFF)
option(STAN_MPI "Enable MPI support" OFF)
option(STAN_OPENCL "Enable OpenCL support" OFF)
option(STAN_THREADS "Enable multi-threading support" OFF)
option(STAN_SANITIZE_ADDRESS "Compile C++ sources and link with AddressSanitizer" OFF)
stan_cache_default(STAN_OPENCL_DEVICE_ID "0" STRING "OpenCL device ID")
stan_cache_default(STAN_OPENCL_PLATFORM_ID "0" STRING "OpenCL platform ID")
stan_cache_default(STAN_INTEGRATED_OPENCL "0" STRING "Enable integrated OpenCL features")
set(STAN_TEST_NAME_FILTERS "" CACHE STRING "Required substrings in selected test source paths")
set(STAN_SELECTED_TEST_REGEX "" CACHE STRING
"Tests whose source paths match this regex are built by stan_selected_tests")
include(CTest)
stan_cache_default(STAN_TEST_OPTIMIZATION "1" STRING "Optimization level for tests and solver libraries")
if(DEFINED CACHE{STAN_TEST_OPTIMIZATION})
set_property(CACHE STAN_TEST_OPTIMIZATION PROPERTY STRINGS 0 1 2 3)
endif()
if(NOT STAN_TEST_OPTIMIZATION MATCHES "^[0-3]$")
message(FATAL_ERROR "STAN_TEST_OPTIMIZATION must be 0, 1, 2, or 3")
endif()
# Keep solver libraries at the same optimization level as the C++ tests.
if(MSVC)
if(STAN_TEST_OPTIMIZATION STREQUAL "0")
set(STAN_TEST_OPTIMIZATION_FLAGS /Od)
elseif(STAN_TEST_OPTIMIZATION STREQUAL "1")
set(STAN_TEST_OPTIMIZATION_FLAGS /O1)
else()
set(STAN_TEST_OPTIMIZATION_FLAGS /O2)
endif()
else()
set(STAN_TEST_OPTIMIZATION_FLAGS -O${STAN_TEST_OPTIMIZATION})
endif()
# Like Make's CXXFLAGS, reach every C++ compile and link, but not the
# vendored TBB build, which takes its own flags.
if(STAN_SANITIZE_ADDRESS)
if(MSVC)
add_compile_options(/fsanitize=address)
else()
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fsanitize=address>)
add_link_options(-fsanitize=address)
endif()
endif()

add_library(stanmath INTERFACE)
add_library(stanmath::stanmath ALIAS stanmath)
target_compile_features(stanmath INTERFACE cxx_std_17)
target_include_directories(stanmath INTERFACE "${PROJECT_SOURCE_DIR}")
target_compile_definitions(stanmath INTERFACE BOOST_DISABLE_ASSERTS TBB_INTERFACE_NEW _REENTRANT)
foreach(feature STAN_NO_RANGE_CHECKS STAN_THREADS STAN_MPI)
if(${feature})
target_compile_definitions(stanmath INTERFACE ${feature})
endif()
endforeach()
add_subdirectory(cmake)

if(STAN_OPENCL)
# Configuration and object-only header checks need headers, not a loader.
# Respect explicit FindOpenCL overrides while defaulting to vendored headers.
if(NOT DEFINED OpenCL_INCLUDE_DIR)
set(OpenCL_INCLUDE_DIR "${STAN_OPENCL_ROOT}")
endif()
find_package(OpenCL QUIET)
target_include_directories(stanmath SYSTEM INTERFACE "${OpenCL_INCLUDE_DIR}")
if(TARGET OpenCL::OpenCL)
target_link_libraries(stanmath INTERFACE OpenCL::OpenCL)
elseif(APPLE)
target_link_libraries(stanmath INTERFACE "-framework OpenCL")
else()
# Keep the ordinary platform link requirement even without a found loader.
target_link_libraries(stanmath INTERFACE OpenCL)
endif()
target_compile_definitions(stanmath INTERFACE
STAN_OPENCL OPENCL_DEVICE_ID=${STAN_OPENCL_DEVICE_ID}
OPENCL_PLATFORM_ID=${STAN_OPENCL_PLATFORM_ID}
CL_HPP_TARGET_OPENCL_VERSION=120 CL_HPP_MINIMUM_OPENCL_VERSION=120
CL_HPP_ENABLE_EXCEPTIONS INTEGRATED_OPENCL=${STAN_INTEGRATED_OPENCL})
endif()
if(STAN_MPI)
find_package(MPI REQUIRED COMPONENTS CXX)
if(STAN_USE_SYSTEM_BOOST)
find_package(Boost REQUIRED COMPONENTS mpi serialization)
else()
# Build the MPI libraries against the same headers used by Stan; mixing
# vendored headers with an older system Boost can change serialization ABI.
file(GLOB serialization_sources CONFIGURE_DEPENDS
"${STAN_BOOST_ROOT}/libs/serialization/src/*.cpp")
add_library(stan_boost_serialization STATIC ${serialization_sources})
add_library(Boost::serialization ALIAS stan_boost_serialization)
target_include_directories(stan_boost_serialization SYSTEM PUBLIC "${STAN_BOOST_ROOT}")
file(GLOB mpi_sources CONFIGURE_DEPENDS "${STAN_BOOST_ROOT}/libs/mpi/src/*.cpp")
add_library(stan_boost_mpi STATIC ${mpi_sources})
add_library(Boost::mpi ALIAS stan_boost_mpi)
target_compile_definitions(stan_boost_mpi PRIVATE BOOST_MPI_SOURCE=1)
target_compile_definitions(stan_boost_mpi INTERFACE BOOST_MPI_NO_LIB=1)
target_link_libraries(stan_boost_mpi PUBLIC Boost::serialization MPI::MPI_CXX)
endif()
target_link_libraries(stanmath INTERFACE Boost::mpi Boost::serialization MPI::MPI_CXX)
add_library(stan_mpi OBJECT stan/math/prim/functor/mpi_cluster_inst.cpp)
target_link_libraries(stan_mpi PRIVATE stanmath)
endif()

message(STATUS "Stan Math: compiler=${CMAKE_CXX_COMPILER} "
"(${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}), "
"build type=${CMAKE_BUILD_TYPE}, test optimization=${STAN_TEST_OPTIMIZATION}")
message(STATUS "Stan Math: CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}, "
"CMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}")
message(STATUS "Stan Math: threads=${STAN_THREADS}, OpenCL=${STAN_OPENCL}, MPI=${STAN_MPI}, "
"AddressSanitizer=${STAN_SANITIZE_ADDRESS}")
set(STAN_EFFECTIVE_MPI "${STAN_MPI}" CACHE INTERNAL "MPI setting used by test executables")
include(cmake/StanTest.cmake)
if(BUILD_TESTING)
add_subdirectory(test)
endif()
if(STAN_BUILD_DOCS)
find_package(Doxygen REQUIRED)
add_custom_target(doxygen
COMMAND ${CMAKE_COMMAND} -E make_directory doc/api
COMMAND ${DOXYGEN_EXECUTABLE} doxygen/doxygen.cfg
COMMAND ${CMAKE_COMMAND} -E copy doxygen/pretty_stuff/eigen_navtree_hacks.js
doc/api/html/eigen_navtree_hacks.js
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
endif()

find_package(Python3 COMPONENTS Interpreter)
if(Python3_FOUND)
# The same checks as make/cpplint and Make's test-math-dependencies.
set(cpplint_command "${Python3_EXECUTABLE}" lib/cpplint_2.0.2/cpplint.py
--output=vs7 --counting=detailed --root=stan --extensions=hpp,cpp --recursive
"--filter=-runtime/indentation_namespace,-build/c++11,-readability/namespace,-legal/copyright,-whitespace/indent,-build/header_guard,-build/include_order,-build/include_what_you_use,-runtime/string,-build/namespaces")
add_custom_target(cpplint
COMMAND ${cpplint_command} stan
COMMAND ${cpplint_command} test/unit
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
VERBATIM)
add_custom_target(test-math-dependencies
COMMAND "${Python3_EXECUTABLE}" runChecks.py
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
VERBATIM)
endif()

set(STAN_COMPILE_TEST_SOURCE "" CACHE FILEPATH "Source file for compile-only compatibility checks")
if(STAN_COMPILE_TEST_SOURCE)
# Only GoogleTest's headers are needed; its targets exist only with tests.
add_library(stan_compile_test_options INTERFACE)
target_link_libraries(stan_compile_test_options INTERFACE stan_test_flags)
target_include_directories(stan_compile_test_options SYSTEM INTERFACE
"${STAN_BENCHMARK_ROOT}/googletest/googletest/include")
stan_add_pch(stan_compile_test_pch stan_compile_test_options <stan/math/mix.hpp> <gtest/gtest.h>)
add_library(stan_compile_test OBJECT EXCLUDE_FROM_ALL "${STAN_COMPILE_TEST_SOURCE}")
stan_configure_test(stan_compile_test stan_compile_test_options stan_compile_test_pch)
endif()
Loading
Loading