Skip to content

build: support Eigen 5#6036

Open
e-kwsm wants to merge 1 commit intopybind:masterfrom
e-kwsm:eigen5
Open

build: support Eigen 5#6036
e-kwsm wants to merge 1 commit intopybind:masterfrom
e-kwsm:eigen5

Conversation

@e-kwsm
Copy link
Copy Markdown

@e-kwsm e-kwsm commented Apr 13, 2026

Description

fix #6034

  • CONFIG mode can find the system eigen, but the version specifier 3.2.7 matches 3.2.7 to <3.3
  • CONFIG mode defines Eigen3_FOUND but not EIGEN3_FOUND
  • MODULE mode cannot detect eigen 5 version since the macros are removed

Suggested changelog entry:

@e-kwsm e-kwsm requested a review from henryiii as a code owner April 13, 2026 15:17

else()
find_package(Eigen3 3.2.7 QUIET CONFIG)
find_package(Eigen3 3.2.7...5 QUIET CONFIG)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a lot of help from Cursor GPT-5.4 Extra High Fast:


One small suggestion: I think this would be a bit clearer and more robust as a two-step CONFIG probe instead of 3.2.7...5.

I checked this locally, and 3.2.7...5 is not a wildcard for “any 5.x” in standard CMake version semantics. It is a bounded range whose upper endpoint is effectively 5.0.0. The reason this still passed with Eigen 5.0.1 in CI seems to be that the particular package version file accepted it, but that is package-specific behavior rather than something I would want to rely on.

Something like this seems safer and more explicit:

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
@@
-    find_package(Eigen3 3.2.7...5 QUIET CONFIG)
-    set(EIGEN3_FOUND ${Eigen3_FOUND})
-    set(EIGEN3_VERSION ${Eigen3_VERSION})
+    find_package(Eigen3 3.2.7 QUIET CONFIG)
+    if(NOT Eigen3_FOUND)
+      find_package(Eigen3 5 QUIET CONFIG)
+    endif()
+    set(EIGEN3_FOUND ${Eigen3_FOUND})
+    set(EIGEN3_VERSION ${Eigen3_VERSION})
 
     if(NOT EIGEN3_FOUND)
       # Couldn't load via target, so fall back to allowing module mode finding, which will pick up
       # tools/FindEigen3.cmake
       # XXX: MODULE mode does not work with Eigen 5
       find_package(Eigen3 3.2.7 QUIET)

Also, please add something like the following to the PR description:

This intentionally fixes the CONFIG-mode path and normalizes the legacy EIGEN3_* variables after the CONFIG probe. It does not touch the old tools/FindEigen3.cmake logic, which is more invasive and easier to get wrong. In other words, this is a targeted compatibility fix for environments that provide an Eigen3Config.cmake, while leaving the legacy MODULE-mode finder as a fallback for older setups.

I think that extra explanation would help reviewers understand why this “band-aid” approach is actually a good first step here.

@rwgk
Copy link
Copy Markdown
Collaborator

rwgk commented Apr 13, 2026

Dumping this here JIC it's useful later:

$ cd /wrk/logs_24351313720 && grep 'Building tests with Eigen ' *.txt
Manylinux_on_ЁЯРН_3.13t__quay.io_pypa_manylinux_2_28_x86_64latest_.txt:2026-04-13T15:45:09.7474372Z -- Building tests with Eigen v3.4.0
Manylinux_on_ЁЯРН_3.13t__quay.io_pypa_musllinux_1_2_x86_64latest_.txt:2026-04-13T15:31:57.7239852Z -- Building tests with Eigen v3.4.0
Manylinux_on_ЁЯРН_3.14t__quay.io_pypa_manylinux_2_28_x86_64latest_.txt:2026-04-13T15:43:25.9684270Z -- Building tests with Eigen v3.4.0
Manylinux_on_ЁЯРН_3.14t__quay.io_pypa_musllinux_1_2_x86_64latest_.txt:2026-04-13T15:18:19.4452939Z -- Building tests with Eigen v3.4.0
windows-11-arm_тАв_clang-msys2.txt:2026-04-13T15:21:08.4490132Z -- Building tests with Eigen v3.4.0
ЁЯРН_3.10_тАв_MSVC_2022_тАв_x86_-DCMAKE_CXX_STANDARD=20.txt:2026-04-13T15:18:29.0587237Z -- Building tests with Eigen v3.4.0
ЁЯРН_3.10_тАв_windows-latest_тАв_clang-latest.txt:2026-04-13T15:29:44.4324218Z -- Building tests with Eigen v3.4.0
ЁЯРН_3.11__deadsnakes__тАв_x64.txt:2026-04-13T15:40:01.8675733Z -- Building tests with Eigen v3.4.0
ЁЯРН_3.11_тАв_windows-latest_тАв_x64_inplace_C++14.txt:2026-04-13T15:27:11.6902348Z -- Building tests with Eigen v3.4.0
ЁЯРН_3.12_тАв_macos-latest_тАв_x64_inplace_C++14.txt:2026-04-13T15:23:04.8725960Z -- Building tests with Eigen v3.4.0
ЁЯРН_3.12_тАв_macos-latest_тАв_x64_inplace_C++14.txt:2026-04-13T15:23:07.5210840Z -- Building tests with Eigen v3.4.0
ЁЯРН_3.13_тАв_MSVC_2022_тАв_x86.txt:2026-04-13T15:27:08.8347871Z -- Building tests with Eigen v3.4.0
ЁЯРН_3.13_тАв_windows-11-arm_тАв_clang-msvc.txt:2026-04-13T15:18:08.1777943Z -- Building tests with Eigen v3.4.0
ЁЯРН_3.8_тАв_MSVC_2022__Debug__тАв_x86_-DCMAKE_CXX_STANDARD=17.txt:2026-04-13T15:18:57.2200220Z -- Building tests with Eigen v3.4.0
ЁЯРН_3.8_тАв_MSVC_2022_тАв_x86_-DCMAKE_CXX_STANDARD=17.txt:2026-04-13T15:35:33.9571642Z -- Building tests with Eigen v3.4.0
ЁЯРН_3.9_тАв_Debian_тАв_x86_тАв__Install.txt:2026-04-13T15:31:26.6303513Z -- Building tests with Eigen v3.3.9
ЁЯРН_3.9_тАв_MSVC_2022_C++20_тАв_x64.txt:2026-04-13T15:19:03.7649122Z -- Building tests with Eigen v3.4.0
ЁЯРН_3.9_тАв_MSVC_2022__Debug__тАв_x86_-DCMAKE_CXX_STANDARD=20.txt:2026-04-13T15:19:14.5917572Z -- Building tests with Eigen v3.4.0
ЁЯРН_3.9_тАв_ubuntu-latest_тАв_x64_inplace_C++14.txt:2026-04-13T15:25:02.0112582Z -- Building tests with Eigen v3.4.0
ЁЯРН_3.9_тАв_ubuntu-latest_тАв_x64_inplace_C++14.txt:2026-04-13T15:25:02.7123248Z -- Building tests with Eigen v3.4.0
ЁЯРН_3_тАв_almalinux8_тАв_x64.txt:2026-04-13T15:29:46.8762575Z -- Building tests with Eigen v3.4.0
ЁЯРН_3_тАв_almalinux9_тАв_x64.txt:2026-04-13T15:42:59.2142831Z -- Building tests with Eigen v3.4.0
ЁЯРН_3_тАв_Clang_11_тАв_C++20_тАв_x64.txt:2026-04-13T15:18:06.5394732Z -- Building tests with Eigen v3.3.9
ЁЯРН_3_тАв_Clang_14_тАв_C++20_тАв_x64.txt:2026-04-13T15:27:30.9043079Z -- Building tests with Eigen v3.3.9
ЁЯРН_3_тАв_Clang_16_тАв_C++20_тАв_x64.txt:2026-04-13T15:45:04.7429434Z -- Building tests with Eigen v3.3.9
ЁЯРН_3_тАв_Clang_18_тАв_C++20_тАв_x64_тАв_cxx_flags.txt:2026-04-13T15:33:50.8555289Z -- Building tests with Eigen v3.4.0
ЁЯРН_3_тАв_Clang_5_тАв_C++14_тАв_x64.txt:2026-04-13T15:45:27.2940515Z -- Building tests with Eigen v3.3.9
ЁЯРН_3_тАв_GCC_10_тАв_C++17_тАв_x64.txt:2026-04-13T15:36:38.6160904Z -- Building tests with Eigen v3.3.9
ЁЯРН_3_тАв_GCC_10_тАв_C++20_тАв_x64.txt:2026-04-13T15:37:19.5454112Z -- Building tests with Eigen v3.3.9
ЁЯРН_3_тАв_GCC_13_тАв_C++20_тАв_x64_тАв_cxx_flags.txt:2026-04-13T15:35:43.9052191Z -- Building tests with Eigen v3.4.0
ЁЯРН_3_тАв_GCC_9_тАв_C++20_тАв_x64.txt:2026-04-13T15:36:36.1282816Z -- Building tests with Eigen v3.3.9
ЁЯРН_3_тАв_windows-latest_тАв_mingw64.txt:2026-04-13T15:31:09.8594338Z -- Building tests with Eigen v5.0.1
ЁЯРН_3_тАв_windows-latest_тАв_mingw64.txt:2026-04-13T15:40:17.7723933Z -- Building tests with Eigen v5.0.1
ЁЯРН_3_тАв_windows-latest_тАв_mingw64.txt:2026-04-13T15:49:10.6210954Z -- Building tests with Eigen v5.0.1
ЁЯРН__macos-15-intel__3.11__-DPYBIND11_TEST_SMART_HOLDER=ON____ЁЯзк.txt:2026-04-13T15:43:30.4458490Z -- Building tests with Eigen v3.4.0
ЁЯРН__macos-15-intel__3.13__-DCMAKE_CXX_STANDARD=11____ЁЯзк.txt:2026-04-13T15:31:05.5212480Z -- Building tests with Eigen v3.4.0
ЁЯРН__macos-15-intel__3.8__-DCMAKE_CXX_STANDARD=14____ЁЯзк.txt:2026-04-13T15:43:14.7538210Z -- Building tests with Eigen v3.4.0
ЁЯРН__macos-15-intel__pypy-3.10__-DCMAKE_CXX_STANDARD=17____ЁЯзк.txt:2026-04-13T15:39:25.5136610Z -- Building tests with Eigen v3.4.0
ЁЯРН__macos-latest__3.12__-DCMAKE_CXX_STANDARD=17_-DPYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMP...___ЁЯзк.txt:2026-04-13T15:43:23.2161650Z -- Building tests with Eigen v3.4.0
ЁЯРН__macos-latest__3.14__-DCMAKE_CXX_STANDARD=14____ЁЯзк.txt:2026-04-13T15:24:30.2178710Z -- Building tests with Eigen v3.4.0
ЁЯРН__macos-latest__3.14t__-DCMAKE_CXX_STANDARD=20____ЁЯзк.txt:2026-04-13T15:28:53.7653790Z -- Building tests with Eigen v3.4.0
ЁЯРН__macos-latest__graalpy-24.2____ЁЯзк.txt:2026-04-13T15:31:16.0608680Z -- Building tests with Eigen v3.4.0
ЁЯРН__macos-latest__pypy-3.11____ЁЯзк.txt:2026-04-13T15:27:17.9590140Z -- Building tests with Eigen v3.4.0
ЁЯРН__ubuntu-22.04__3.8__-DPYBIND11_FINDPYTHON=OFF_-DPYBIND11_NUMPY_1_ONLY=ON____ЁЯзк.txt:2026-04-13T15:22:49.6631519Z -- Building tests with Eigen v3.4.0
ЁЯРН__ubuntu-latest__3.10__-DCMAKE_CXX_STANDARD=20____ЁЯзк.txt:2026-04-13T15:44:05.4961417Z -- Building tests with Eigen v3.4.0
ЁЯРН__ubuntu-latest__3.11__-DPYBIND11_TEST_SMART_HOLDER=ON_-DCMAKE_CXX_STANDARD=17____ЁЯзк.txt:2026-04-13T15:40:07.1723481Z -- Building tests with Eigen v3.4.0
ЁЯРН__ubuntu-latest__3.12__-DPYBIND11_TEST_SMART_HOLDER=ON_-DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON____ЁЯзк.txt:2026-04-13T15:40:29.0561729Z -- Building tests with Eigen v3.4.0
ЁЯРН__ubuntu-latest__3.13__-DCMAKE_CXX_STANDARD=23_-DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON____ЁЯзк.txt:2026-04-13T15:20:00.3995707Z -- Building tests with Eigen v3.4.0
ЁЯРН__ubuntu-latest__3.14__-DCMAKE_CXX_STANDARD=14____ЁЯзк.txt:2026-04-13T15:38:43.4016812Z -- Building tests with Eigen v3.4.0
ЁЯРН__ubuntu-latest__3.14t__-DCMAKE_CXX_STANDARD=17_-DPYBIND11_TEST_SMART_HOLDER=ON____ЁЯзк.txt:2026-04-13T15:36:28.1893352Z -- Building tests with Eigen v3.4.0
ЁЯРН__ubuntu-latest__3.14t__-DCMAKE_CXX_STANDARD=20_-DPYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_I...___ЁЯзк.txt:2026-04-13T15:36:25.6712370Z -- Building tests with Eigen v3.4.0
ЁЯРН__ubuntu-latest__3.8__-DPYBIND11_FINDPYTHON=ON_-DCMAKE_CXX_STANDARD=17____ЁЯзк.txt:2026-04-13T15:25:30.2587583Z -- Building tests with Eigen v3.4.0
ЁЯРН__ubuntu-latest__graalpy-24.1____ЁЯзк.txt:2026-04-13T15:45:45.3532574Z -- Building tests with Eigen v3.4.0
ЁЯРН__ubuntu-latest__graalpy-24.2__-DCMAKE_CXX_STANDARD=20____ЁЯзк.txt:2026-04-13T15:28:00.7083007Z -- Building tests with Eigen v3.4.0
ЁЯРН__ubuntu-latest__pypy-3.10__-DCMAKE_CXX_STANDARD=14____ЁЯзк.txt:2026-04-13T15:45:49.4636700Z -- Building tests with Eigen v3.4.0
ЁЯРН__ubuntu-latest__pypy3.11__-DCMAKE_CXX_STANDARD=17____ЁЯзк.txt:2026-04-13T15:29:05.4379127Z -- Building tests with Eigen v3.4.0
ЁЯРН__windows-2022__3.10__-DPYBIND11_TEST_SMART_HOLDER=ON_-DCMAKE_CXX_FLAGS=_GR__EHsc____ЁЯзк.txt:2026-04-13T15:26:28.0246806Z -- Building tests with Eigen v3.4.0
ЁЯРН__windows-2022__3.13__-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL____ЁЯзк.txt:2026-04-13T15:27:05.7961997Z -- Building tests with Eigen v3.4.0
ЁЯРН__windows-2022__3.8__-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded_-DPYBIND11_NUMPY_1_ONLY=ON____ЁЯзк.txt:2026-04-13T15:38:09.7176495Z -- Building tests with Eigen v3.4.0
ЁЯРН__windows-2022__3.8__-DPYBIND11_FINDPYTHON=OFF____ЁЯзк.txt:2026-04-13T15:19:03.7729353Z -- Building tests with Eigen v3.4.0
ЁЯРН__windows-2022__3.9__-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL_-DCMAKE_CXX_STANDARD=14____ЁЯзк.txt:2026-04-13T15:37:11.4132891Z -- Building tests with Eigen v3.4.0
ЁЯРН__windows-latest__3.14__-DCMAKE_CXX_STANDARD=20____ЁЯзк.txt:2026-04-13T15:35:51.6861433Z -- Building tests with Eigen v3.4.0
ЁЯРН__windows-latest__3.14t__-DCMAKE_CXX_STANDARD=23____ЁЯзк.txt:2026-04-13T15:49:11.3968002Z -- Building tests with Eigen v3.4.0
ЁЯРН__windows-latest__3.9__-DPYBIND11_TEST_SMART_HOLDER=ON____ЁЯзк.txt:2026-04-13T15:43:21.1358271Z -- Building tests with Eigen v3.4.0
ЁЯРН__windows-latest__pypy-3.10__-DCMAKE_CXX_STANDARD=17____ЁЯзк.txt:2026-04-13T15:45:27.2473575Z -- Building tests with Eigen v3.4.0
ЁЯРН__windows-latest__pypy3.11__-DCMAKE_CXX_STANDARD=20____ЁЯзк.txt:2026-04-13T15:47:35.3283292Z -- Building tests with Eigen v3.4.0

@rwgk
Copy link
Copy Markdown
Collaborator

rwgk commented Apr 13, 2026

Also dumping this here JIC it's useful later:

Cursor GPT-5.4 Extra High Fast


1. What determines which Eigen version a job uses now, and will that float?

Jobs fall into two buckets.

Jobs that pass -DDOWNLOAD_EIGEN=ON use the pinned git hash from tests/CMakeLists.txt, so those are stable until pybind11 changes the pin. That is why a lot of the archive shows v3.4.0.

      - name: Configure
        run: >
          cmake -S. -Bbuild -Werror=dev
          -DPYBIND11_WERROR=ON
          -DPYBIND11_PYTEST_ARGS=-v
          -DDOWNLOAD_CATCH=ON
          -DDOWNLOAD_EIGEN=ON
          ${{ inputs.cmake-args }}
set(PYBIND11_EIGEN_VERSION_AND_HASH
    "3.4.0;929bc0e191d0927b1735b9a1ddc0e8b77e3a25ec"
    CACHE STRING "Eigen version to use for tests, format: VERSION;HASH")

Jobs that do not pass DOWNLOAD_EIGEN=ON use whatever system/package-manager Eigen is installed in that environment, so those do float over time. In the current archive:

  • the GCC/Clang container jobs and the Debian x86 install job are on v3.3.9
  • most pinned-download jobs are on v3.4.0
  • the mingw64 MSYS2 job is on v5.0.1
    - uses: actions/checkout@v6

    - name: Add Python 3
      run: apt-get update; apt-get install -y python3-dev python3-numpy python3-pytest python3-pip libeigen3-dev

    - name: Update pip
      run: python3 -m pip install --upgrade pip

    - name: Update CMake
      uses: jwlawson/actions-setup-cmake@v2.2

    - name: Configure
      shell: bash
      run: >
        cmake -S . -B build
        -DPYBIND11_WERROR=ON
        -DDOWNLOAD_CATCH=ON
        -DCMAKE_CXX_STANDARD=${{ matrix.std }}
        -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}"
        -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
          - sys: mingw64
            env: x86_64
            extra_install: |
              mingw-w64-x86_64-python-numpy
              mingw-w64-x86_64-python-scipy
              mingw-w64-x86_64-eigen3

So the practical answer is:

  • DOWNLOAD_EIGEN=ON jobs: no float
  • system-package jobs: yes, they float
  • Eigen 5 coverage in current CI is real, but opportunistic, because it is coming from the current MSYS2 mingw64 package set

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: does not work with Eigen 5

2 participants