From 1581cd5684ceb4878c224d5ac677e10122fb842b Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 24 May 2024 15:46:58 +1200 Subject: [PATCH 01/11] pybind11: upgraded from version 2.11.1 to version 2.12.0. --- extern/pybind11/.github/CONTRIBUTING.md | 2 +- extern/pybind11/.github/dependabot.yml | 10 +- extern/pybind11/.github/workflows/ci.yml | 185 +++++++++++------- .../pybind11/.github/workflows/configure.yml | 6 +- extern/pybind11/.github/workflows/format.yml | 8 +- extern/pybind11/.github/workflows/labeler.yml | 2 +- extern/pybind11/.github/workflows/pip.yml | 16 +- .../pybind11/.github/workflows/upstream.yml | 14 +- extern/pybind11/.pre-commit-config.yaml | 40 ++-- extern/pybind11/.readthedocs.yml | 21 +- extern/pybind11/CMakeLists.txt | 63 +++++- extern/pybind11/README.rst | 9 +- extern/pybind11/docs/advanced/embedding.rst | 2 +- extern/pybind11/docs/advanced/exceptions.rst | 22 +-- extern/pybind11/docs/advanced/functions.rst | 2 +- extern/pybind11/docs/advanced/misc.rst | 29 +++ extern/pybind11/docs/benchmark.py | 2 +- extern/pybind11/docs/changelog.rst | 184 ++++++++++++++++- extern/pybind11/docs/compiling.rst | 16 +- extern/pybind11/docs/release.rst | 128 ++++++++---- extern/pybind11/docs/upgrade.rst | 28 +++ extern/pybind11/include/pybind11/cast.h | 151 +++++++++++++- .../pybind11/include/pybind11/detail/class.h | 31 +-- .../pybind11/include/pybind11/detail/common.h | 20 +- .../pybind11/include/pybind11/detail/init.h | 2 +- .../include/pybind11/detail/internals.h | 21 +- .../pybind11/detail/type_caster_base.h | 61 +++++- .../pybind11/include/pybind11/eigen/tensor.h | 5 +- extern/pybind11/include/pybind11/functional.h | 3 +- extern/pybind11/include/pybind11/gil.h | 10 +- .../include/pybind11/gil_safe_call_once.h | 91 +++++++++ extern/pybind11/include/pybind11/numpy.h | 179 ++++++++++++++--- extern/pybind11/include/pybind11/pybind11.h | 169 +++++++++++----- extern/pybind11/include/pybind11/pytypes.h | 27 ++- extern/pybind11/include/pybind11/stl.h | 15 +- extern/pybind11/include/pybind11/stl_bind.h | 84 +++----- extern/pybind11/include/pybind11/typing.h | 125 ++++++++++++ extern/pybind11/noxfile.py | 2 +- extern/pybind11/pybind11/_version.py | 2 +- extern/pybind11/pybind11/setup_helpers.py | 4 +- extern/pybind11/pyproject.toml | 19 +- extern/pybind11/tests/CMakeLists.txt | 13 +- extern/pybind11/tests/conftest.py | 1 + ...s_module_interleaved_error_already_set.cpp | 4 +- .../tests/extra_python_package/test_files.py | 2 + .../tests/pybind11_cross_module_tests.cpp | 8 +- extern/pybind11/tests/pybind11_tests.cpp | 12 +- extern/pybind11/tests/requirements.txt | 22 ++- extern/pybind11/tests/test_buffers.py | 7 + extern/pybind11/tests/test_builtin_casters.py | 4 +- extern/pybind11/tests/test_callbacks.py | 7 + extern/pybind11/tests/test_class.py | 14 ++ .../tests/test_cmake_build/CMakeLists.txt | 3 +- .../installed_embed/CMakeLists.txt | 6 +- .../installed_function/CMakeLists.txt | 6 +- .../installed_target/CMakeLists.txt | 6 +- .../subdirectory_embed/CMakeLists.txt | 12 +- .../subdirectory_function/CMakeLists.txt | 12 +- .../subdirectory_target/CMakeLists.txt | 12 +- .../tests/test_constants_and_functions.cpp | 4 + .../tests/test_custom_type_casters.cpp | 12 ++ extern/pybind11/tests/test_eigen_matrix.cpp | 17 ++ extern/pybind11/tests/test_eigen_matrix.py | 9 +- extern/pybind11/tests/test_enum.py | 9 +- extern/pybind11/tests/test_exceptions.cpp | 67 +++++-- extern/pybind11/tests/test_exceptions.h | 2 +- extern/pybind11/tests/test_exceptions.py | 23 ++- .../tests/test_factory_constructors.py | 4 +- .../tests/test_kwargs_and_defaults.cpp | 46 +++++ .../tests/test_kwargs_and_defaults.py | 38 +++- .../tests/test_methods_and_attributes.py | 34 ++-- extern/pybind11/tests/test_numpy_array.py | 12 +- extern/pybind11/tests/test_numpy_dtypes.cpp | 33 +++- extern/pybind11/tests/test_numpy_dtypes.py | 14 +- .../test_python_multiple_inheritance.cpp | 45 +++++ .../tests/test_python_multiple_inheritance.py | 35 ++++ extern/pybind11/tests/test_pytypes.cpp | 29 ++- extern/pybind11/tests/test_pytypes.py | 58 +++++- .../tests/test_sequences_and_iterators.cpp | 19 ++ .../tests/test_sequences_and_iterators.py | 13 ++ extern/pybind11/tests/test_smart_ptr.cpp | 27 +-- extern/pybind11/tests/test_stl.py | 24 +-- extern/pybind11/tests/test_stl_binders.cpp | 80 ++++++++ extern/pybind11/tests/test_stl_binders.py | 50 ++++- .../tests/test_type_caster_pyobject_ptr.cpp | 4 +- extern/pybind11/tools/FindPythonLibsNew.cmake | 29 ++- extern/pybind11/tools/make_changelog.py | 30 ++- extern/pybind11/tools/pybind11Common.cmake | 46 +++-- extern/pybind11/tools/pybind11Config.cmake.in | 2 +- extern/pybind11/tools/pybind11NewTools.cmake | 99 +++++++--- extern/pybind11/tools/pybind11Tools.cmake | 20 +- 91 files changed, 2325 insertions(+), 570 deletions(-) create mode 100644 extern/pybind11/include/pybind11/gil_safe_call_once.h create mode 100644 extern/pybind11/include/pybind11/typing.h create mode 100644 extern/pybind11/tests/test_python_multiple_inheritance.cpp create mode 100644 extern/pybind11/tests/test_python_multiple_inheritance.py diff --git a/extern/pybind11/.github/CONTRIBUTING.md b/extern/pybind11/.github/CONTRIBUTING.md index ad7974395..f5a08e2d7 100644 --- a/extern/pybind11/.github/CONTRIBUTING.md +++ b/extern/pybind11/.github/CONTRIBUTING.md @@ -135,7 +135,7 @@ The valid options are: * Use `-G` and the name of a generator to use something different. `cmake --help` lists the generators available. - On Unix, setting `CMAKE_GENERATER=Ninja` in your environment will give - you automatic mulithreading on all your CMake projects! + you automatic multithreading on all your CMake projects! * Open the `CMakeLists.txt` with QtCreator to generate for that IDE. * You can use `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON` to generate the `.json` file that some tools expect. diff --git a/extern/pybind11/.github/dependabot.yml b/extern/pybind11/.github/dependabot.yml index 2c7d17083..22c34bd74 100644 --- a/extern/pybind11/.github/dependabot.yml +++ b/extern/pybind11/.github/dependabot.yml @@ -4,4 +4,12 @@ updates: - package-ecosystem: "github-actions" directory: "/" schedule: - interval: "daily" + interval: "weekly" + groups: + actions: + patterns: + - "*" + ignore: + - dependency-name: actions/checkout + versions: + - "<5" diff --git a/extern/pybind11/.github/workflows/ci.yml b/extern/pybind11/.github/workflows/ci.yml index 48f7c5e93..5cc6c3515 100644 --- a/extern/pybind11/.github/workflows/ci.yml +++ b/extern/pybind11/.github/workflows/ci.yml @@ -69,13 +69,12 @@ jobs: runs-on: ${{ matrix.runs-on }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} - allow-prereleases: true - name: Setup Boost (Linux) # Can't use boost + define _ @@ -87,11 +86,11 @@ jobs: run: brew install boost - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.14 + uses: jwlawson/actions-setup-cmake@v2.0 - name: Cache wheels if: runner.os == 'macOS' - uses: actions/cache@v3 + uses: actions/cache@v4 with: # This path is specific to macOS - we really only need it for PyPy NumPy wheels # See https://github.com/actions/cache/blob/master/examples.md#python---pip @@ -109,12 +108,15 @@ jobs: run: python -m pip install pytest-github-actions-annotate-failures # First build - C++11 mode and inplace - # More-or-less randomly adding -DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON here. + # More-or-less randomly adding -DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON here + # (same for PYBIND11_NUMPY_1_ONLY, but requires a NumPy 1.x at runtime). - name: Configure C++11 ${{ matrix.args }} run: > cmake -S . -B . -DPYBIND11_WERROR=ON + -DPYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION=ON -DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON + -DPYBIND11_NUMPY_1_ONLY=ON -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_STANDARD=11 @@ -139,11 +141,13 @@ jobs: # Second build - C++17 mode and in a build directory # More-or-less randomly adding -DPYBIND11_SIMPLE_GIL_MANAGEMENT=OFF here. + # (same for PYBIND11_NUMPY_1_ONLY, but requires a NumPy 1.x at runtime). - name: Configure C++17 run: > cmake -S . -B build2 -DPYBIND11_WERROR=ON -DPYBIND11_SIMPLE_GIL_MANAGEMENT=OFF + -DPYBIND11_NUMPY_1_ONLY=ON -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_STANDARD=17 @@ -195,9 +199,10 @@ jobs: matrix: include: # TODO: Fails on 3.10, investigate - - python-version: "3.9" - python-debug: true - valgrind: true + # JOB DISABLED (NEEDS WORK): https://github.com/pybind/pybind11/issues/4889 + # - python-version: "3.9" + # python-debug: true + # valgrind: true - python-version: "3.11" python-debug: false @@ -205,20 +210,20 @@ jobs: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python ${{ matrix.python-version }} (deadsnakes) - uses: deadsnakes/action@v3.0.1 + uses: deadsnakes/action@v3.1.0 with: python-version: ${{ matrix.python-version }} debug: ${{ matrix.python-debug }} - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.14 + uses: jwlawson/actions-setup-cmake@v2.0 - name: Valgrind cache if: matrix.valgrind - uses: actions/cache@v3 + uses: actions/cache@v4 id: cache-valgrind with: path: valgrind @@ -302,12 +307,15 @@ jobs: - clang: 15 std: 20 container_suffix: "-bullseye" + - clang: 16 + std: 20 + container_suffix: "-bullseye" name: "🐍 3 • Clang ${{ matrix.clang }} • C++${{ matrix.std }} • x64" container: "silkeh/clang:${{ matrix.clang }}${{ matrix.container_suffix }}" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Add wget and python3 run: apt-get update && apt-get install -y python3-dev python3-numpy python3-pytest libeigen3-dev @@ -341,7 +349,7 @@ jobs: container: nvidia/cuda:12.2.0-devel-ubuntu22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # tzdata will try to ask for the timezone, so set the DEBIAN_FRONTEND - name: Install 🐍 3 @@ -365,7 +373,7 @@ jobs: # container: centos:8 # # steps: -# - uses: actions/checkout@v3 +# - uses: actions/checkout@v4 # # - name: Add Python 3 and a few requirements # run: yum update -y && yum install -y git python3-devel python3-numpy python3-pytest make environment-modules @@ -401,54 +409,55 @@ jobs: # run: cmake --build build --target test_cmake_build - # Testing on CentOS 7 + PGI compilers, which seems to require more workarounds - centos-nvhpc7: - if: ${{ false }} # JOB DISABLED (NEEDS WORK): https://github.com/pybind/pybind11/issues/4690 - runs-on: ubuntu-latest - name: "🐍 3 • CentOS7 / PGI 22.9 • x64" - container: centos:7 + # Testing on Ubuntu + NVHPC (previous PGI) compilers, which seems to require more workarounds + ubuntu-nvhpc7: + runs-on: ubuntu-20.04 + name: "🐍 3 • NVHPC 23.5 • C++17 • x64" + env: + # tzdata will try to ask for the timezone, so set the DEBIAN_FRONTEND + DEBIAN_FRONTEND: 'noninteractive' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - name: Add Python 3 and a few requirements - run: yum update -y && yum install -y epel-release && yum install -y git python3-devel make environment-modules cmake3 yum-utils + - name: Add NVHPC Repo + run: | + echo 'deb [trusted=yes] https://developer.download.nvidia.com/hpc-sdk/ubuntu/amd64 /' | \ + sudo tee /etc/apt/sources.list.d/nvhpc.list - - name: Install NVidia HPC SDK - run: yum-config-manager --add-repo https://developer.download.nvidia.com/hpc-sdk/rhel/nvhpc.repo && yum -y install nvhpc-22.9 + - name: Install 🐍 3 & NVHPC + run: | + sudo apt-get update -y && \ + sudo apt-get install -y cmake environment-modules git python3-dev python3-pip python3-numpy && \ + sudo apt-get install -y --no-install-recommends nvhpc-23-5 && \ + sudo rm -rf /var/lib/apt/lists/* + python3 -m pip install --upgrade pip + python3 -m pip install --upgrade pytest - # On CentOS 7, we have to filter a few tests (compiler internal error) - # and allow deeper template recursion (not needed on CentOS 8 with a newer - # standard library). On some systems, you many need further workarounds: + # On some systems, you many need further workarounds: # https://github.com/pybind/pybind11/pull/2475 - name: Configure shell: bash run: | source /etc/profile.d/modules.sh - module load /opt/nvidia/hpc_sdk/modulefiles/nvhpc/22.9 - cmake3 -S . -B build -DDOWNLOAD_CATCH=ON \ - -DCMAKE_CXX_STANDARD=11 \ + module load /opt/nvidia/hpc_sdk/modulefiles/nvhpc/23.5 + cmake -S . -B build -DDOWNLOAD_CATCH=ON \ + -DCMAKE_CXX_STANDARD=17 \ -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") \ -DCMAKE_CXX_FLAGS="-Wc,--pending_instantiations=0" \ -DPYBIND11_TEST_FILTER="test_smart_ptr.cpp" - # Building before installing Pip should produce a warning but not an error - name: Build - run: cmake3 --build build -j 2 --verbose - - - name: Install CMake with pip - run: | - python3 -m pip install --upgrade pip - python3 -m pip install pytest + run: cmake --build build -j 2 --verbose - name: Python tests - run: cmake3 --build build --target pytest + run: cmake --build build --target pytest - name: C++ tests - run: cmake3 --build build --target cpptest + run: cmake --build build --target cpptest - name: Interface test - run: cmake3 --build build --target test_cmake_build + run: cmake --build build --target test_cmake_build # Testing on GCC using the GCC docker images (only recent images supported) @@ -465,12 +474,13 @@ jobs: - { gcc: 10, std: 17 } - { gcc: 11, std: 20 } - { gcc: 12, std: 20 } + - { gcc: 13, std: 20 } name: "🐍 3 • GCC ${{ matrix.gcc }} • C++${{ matrix.std }}• x64" container: "gcc:${{ matrix.gcc }}" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Add Python 3 run: apt-get update; apt-get install -y python3-dev python3-numpy python3-pytest python3-pip libeigen3-dev @@ -479,7 +489,7 @@ jobs: run: python3 -m pip install --upgrade pip - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.14 + uses: jwlawson/actions-setup-cmake@v2.0 - name: Configure shell: bash @@ -524,13 +534,11 @@ jobs: # Testing on ICC using the oneAPI apt repo icc: runs-on: ubuntu-20.04 - strategy: - fail-fast: false name: "🐍 3 • ICC latest • x64" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Add apt repo run: | @@ -634,7 +642,13 @@ jobs: container: "${{ matrix.container }}" steps: - - uses: actions/checkout@v3 + - name: Latest actions/checkout + uses: actions/checkout@v4 + if: matrix.container != 'centos:7' + + - name: Pin actions/checkout as required for centos:7 + uses: actions/checkout@v3 + if: matrix.container == 'centos:7' - name: Add Python 3 (RHEL 7) if: matrix.container == 'centos:7' @@ -651,6 +665,11 @@ jobs: run: | python3 -m pip install cmake -r tests/requirements.txt + - name: Ensure NumPy 2 is used (required Python >= 3.9) + if: matrix.container == 'almalinux:9' + run: | + python3 -m pip install 'numpy>=2.0.0b1' 'scipy>=1.13.0rc1' + - name: Configure shell: bash run: > @@ -682,7 +701,7 @@ jobs: container: i386/debian:buster steps: - - uses: actions/checkout@v1 # Required to run inside docker + - uses: actions/checkout@v1 # v1 is required to run inside docker - name: Install requirements run: | @@ -725,9 +744,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: "3.x" @@ -777,19 +796,19 @@ jobs: runs-on: windows-2019 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} architecture: x86 - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.14 + uses: jwlawson/actions-setup-cmake@v2.0 - name: Prepare MSVC - uses: ilammy/msvc-dev-cmd@v1.12.1 + uses: ilammy/msvc-dev-cmd@v1.13.0 with: arch: x86 @@ -830,19 +849,19 @@ jobs: runs-on: windows-2019 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} architecture: x86 - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.14 + uses: jwlawson/actions-setup-cmake@v2.0 - name: Prepare MSVC - uses: ilammy/msvc-dev-cmd@v1.12.1 + uses: ilammy/msvc-dev-cmd@v1.13.0 with: arch: x86 @@ -878,19 +897,21 @@ jobs: runs-on: windows-2022 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} - name: Prepare env + # Ensure use of NumPy 2 (via NumPy nightlies but can be changed soon) run: | python3 -m pip install -r tests/requirements.txt + python3 -m pip install 'numpy>=2.0.0b1' 'scipy>=1.13.0rc1' - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.14 + uses: jwlawson/actions-setup-cmake@v2.0 - name: Configure C++20 run: > @@ -948,7 +969,6 @@ jobs: mingw-w64-${{matrix.env}}-gcc mingw-w64-${{matrix.env}}-python-pip mingw-w64-${{matrix.env}}-python-numpy - mingw-w64-${{matrix.env}}-python-scipy mingw-w64-${{matrix.env}}-cmake mingw-w64-${{matrix.env}}-make mingw-w64-${{matrix.env}}-python-pytest @@ -956,12 +976,23 @@ jobs: mingw-w64-${{matrix.env}}-boost mingw-w64-${{matrix.env}}-catch - - uses: actions/checkout@v3 + - uses: msys2/setup-msys2@v2 + if: matrix.sys == 'mingw64' + with: + msystem: ${{matrix.sys}} + install: >- + git + mingw-w64-${{matrix.env}}-python-scipy + + - uses: actions/checkout@v4 - name: Configure C++11 # LTO leads to many undefined reference like # `pybind11::detail::function_call::function_call(pybind11::detail::function_call&&) - run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build + run: >- + cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON + -DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)") + -S . -B build - name: Build C++11 run: cmake --build build -j 2 @@ -979,7 +1010,10 @@ jobs: run: git clean -fdx - name: Configure C++14 - run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build2 + run: >- + cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON + -DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)") + -S . -B build2 - name: Build C++14 run: cmake --build build2 -j 2 @@ -997,7 +1031,10 @@ jobs: run: git clean -fdx - name: Configure C++17 - run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build3 + run: >- + cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON + -DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)") + -S . -B build3 - name: Build C++17 run: cmake --build build3 -j 2 @@ -1027,21 +1064,21 @@ jobs: run: env - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Clang uses: egor-tensin/setup-clang@v1 - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.14 + uses: jwlawson/actions-setup-cmake@v2.0 - name: Install ninja-build tool - uses: seanmiddleditch/gha-setup-ninja@v3 + uses: seanmiddleditch/gha-setup-ninja@v4 - name: Run pip installs run: | @@ -1096,7 +1133,7 @@ jobs: run: env - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Show Clang++ version before brew install llvm run: clang++ --version @@ -1108,7 +1145,7 @@ jobs: run: clang++ --version - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.14 + uses: jwlawson/actions-setup-cmake@v2.0 - name: Run pip installs run: | diff --git a/extern/pybind11/.github/workflows/configure.yml b/extern/pybind11/.github/workflows/configure.yml index ec7cd612d..dca37864c 100644 --- a/extern/pybind11/.github/workflows/configure.yml +++ b/extern/pybind11/.github/workflows/configure.yml @@ -49,10 +49,10 @@ jobs: runs-on: ${{ matrix.runs-on }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python 3.7 - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: 3.7 architecture: ${{ matrix.arch }} @@ -63,7 +63,7 @@ jobs: # An action for adding a specific version of CMake: # https://github.com/jwlawson/actions-setup-cmake - name: Setup CMake ${{ matrix.cmake }} - uses: jwlawson/actions-setup-cmake@v1.14 + uses: jwlawson/actions-setup-cmake@v2.0 with: cmake-version: ${{ matrix.cmake }} diff --git a/extern/pybind11/.github/workflows/format.yml b/extern/pybind11/.github/workflows/format.yml index b8242ee52..1eaa56e1c 100644 --- a/extern/pybind11/.github/workflows/format.yml +++ b/extern/pybind11/.github/workflows/format.yml @@ -25,13 +25,13 @@ jobs: name: Format runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: "3.x" - name: Add matchers run: echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json" - - uses: pre-commit/action@v3.0.0 + - uses: pre-commit/action@v3.0.1 with: # Slow hooks are marked with manual - slow is okay here, run them too extra_args: --hook-stage manual --all-files @@ -43,7 +43,7 @@ jobs: runs-on: ubuntu-latest container: silkeh/clang:15-bullseye steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install requirements run: apt-get update && apt-get install -y git python3-dev python3-pytest diff --git a/extern/pybind11/.github/workflows/labeler.yml b/extern/pybind11/.github/workflows/labeler.yml index 858a4a0e2..dd7105662 100644 --- a/extern/pybind11/.github/workflows/labeler.yml +++ b/extern/pybind11/.github/workflows/labeler.yml @@ -14,7 +14,7 @@ jobs: pull-requests: write steps: - - uses: actions/labeler@main + - uses: actions/labeler@v4 if: > github.event.pull_request.merged == true && !startsWith(github.event.pull_request.title, 'chore(deps):') && diff --git a/extern/pybind11/.github/workflows/pip.yml b/extern/pybind11/.github/workflows/pip.yml index d6687b441..19baf57d9 100644 --- a/extern/pybind11/.github/workflows/pip.yml +++ b/extern/pybind11/.github/workflows/pip.yml @@ -28,10 +28,10 @@ jobs: runs-on: windows-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup 🐍 3.6 - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: 3.6 @@ -50,10 +50,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup 🐍 3.8 - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: 3.8 @@ -73,13 +73,13 @@ jobs: run: twine check dist/* - name: Save standard package - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: standard path: dist/pybind11-* - name: Save global package - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: global path: dist/pybind11_global-* @@ -94,12 +94,12 @@ jobs: needs: [packaging] steps: - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: "3.x" # Downloads all to directories matching the artifact names - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 - name: Publish standard package uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/extern/pybind11/.github/workflows/upstream.yml b/extern/pybind11/.github/workflows/upstream.yml index dd8a1c960..389260038 100644 --- a/extern/pybind11/.github/workflows/upstream.yml +++ b/extern/pybind11/.github/workflows/upstream.yml @@ -13,30 +13,30 @@ concurrency: env: PIP_BREAK_SYSTEM_PACKAGES: 1 - PIP_ONLY_BINARY: ":all:" # For cmake: VERBOSE: 1 jobs: standard: - name: "🐍 3.12 latest • ubuntu-latest • x64" + name: "🐍 3.13 latest • ubuntu-latest • x64" runs-on: ubuntu-latest # Only runs when the 'python dev' label is selected if: "contains(github.event.pull_request.labels.*.name, 'python dev')" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - name: Setup Python 3.12 - uses: actions/setup-python@v4 + - name: Setup Python 3.13 + uses: actions/setup-python@v5 with: - python-version: "3.12-dev" + python-version: "3.13" + allow-prereleases: true - name: Setup Boost run: sudo apt-get install libboost-dev - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.14 + uses: jwlawson/actions-setup-cmake@v2.0 - name: Run pip installs run: | diff --git a/extern/pybind11/.pre-commit-config.yaml b/extern/pybind11/.pre-commit-config.yaml index 86ac965d9..2bb47b21c 100644 --- a/extern/pybind11/.pre-commit-config.yaml +++ b/extern/pybind11/.pre-commit-config.yaml @@ -25,27 +25,22 @@ repos: # Clang format the codebase automatically - repo: https://github.com/pre-commit/mirrors-clang-format - rev: "v16.0.6" + rev: "v17.0.6" hooks: - id: clang-format types_or: [c++, c, cuda] -# Black, the code formatter, natively supports pre-commit -- repo: https://github.com/psf/black - rev: "23.3.0" # Keep in sync with blacken-docs - hooks: - - id: black - -# Ruff, the Python auto-correcting linter written in Rust +# Ruff, the Python auto-correcting linter/formatter written in Rust - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.276 + rev: v0.2.0 hooks: - id: ruff args: ["--fix", "--show-fixes"] + - id: ruff-format # Check static types with mypy - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.4.1" + rev: "v1.8.0" hooks: - id: mypy args: [] @@ -67,7 +62,7 @@ repos: # Standard hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: "v4.4.0" + rev: "v4.5.0" hooks: - id: check-added-large-files - id: check-case-conflict @@ -84,21 +79,21 @@ repos: # Also code format the docs - repo: https://github.com/asottile/blacken-docs - rev: "1.14.0" + rev: "1.16.0" hooks: - id: blacken-docs additional_dependencies: - - black==23.3.0 # keep in sync with black hook + - black==23.* # Changes tabs to spaces - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: "v1.5.1" + rev: "v1.5.4" hooks: - id: remove-tabs # Avoid directional quotes - repo: https://github.com/sirosen/texthooks - rev: "0.5.0" + rev: "0.6.4" hooks: - id: fix-ligatures - id: fix-smartquotes @@ -124,7 +119,7 @@ repos: # Use tools/codespell_ignore_lines_from_errors.py # to rebuild .codespell-ignore-lines - repo: https://github.com/codespell-project/codespell - rev: "v2.2.5" + rev: "v2.2.6" hooks: - id: codespell exclude: ".supp$" @@ -132,7 +127,7 @@ repos: # Check for common shell mistakes - repo: https://github.com/shellcheck-py/shellcheck-py - rev: "v0.9.0.5" + rev: "v0.9.0.6" hooks: - id: shellcheck @@ -142,12 +137,19 @@ repos: - id: disallow-caps name: Disallow improper capitalization language: pygrep - entry: PyBind|Numpy|Cmake|CCache|PyTest + entry: PyBind|\bNumpy\b|Cmake|CCache|PyTest exclude: ^\.pre-commit-config.yaml$ # PyLint has native support - not always usable, but works for us - repo: https://github.com/PyCQA/pylint - rev: "v3.0.0a6" + rev: "v3.0.3" hooks: - id: pylint files: ^pybind11 + +- repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.28.0 + hooks: + - id: check-readthedocs + - id: check-github-workflows + - id: check-dependabot diff --git a/extern/pybind11/.readthedocs.yml b/extern/pybind11/.readthedocs.yml index c9c61617c..a2b802f73 100644 --- a/extern/pybind11/.readthedocs.yml +++ b/extern/pybind11/.readthedocs.yml @@ -1,3 +1,20 @@ +# https://blog.readthedocs.com/migrate-configuration-v2/ + +version: 2 + +build: + os: ubuntu-22.04 + apt_packages: + - librsvg2-bin + tools: + python: "3.11" + +sphinx: + configuration: docs/conf.py + python: - version: 3 -requirements_file: docs/requirements.txt + install: + - requirements: docs/requirements.txt + +formats: + - pdf diff --git a/extern/pybind11/CMakeLists.txt b/extern/pybind11/CMakeLists.txt index 87ec10346..7db1bf668 100644 --- a/extern/pybind11/CMakeLists.txt +++ b/extern/pybind11/CMakeLists.txt @@ -5,15 +5,25 @@ # All rights reserved. Use of this source code is governed by a # BSD-style license that can be found in the LICENSE file. +# Propagate this policy (FindPythonInterp removal) so it can be detected later +if(NOT CMAKE_VERSION VERSION_LESS "3.27") + cmake_policy(GET CMP0148 _pybind11_cmp0148) +endif() + cmake_minimum_required(VERSION 3.5) -# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with +# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with # some versions of VS that have a patched CMake 3.11. This forces us to emulate # the behavior using the following workaround: -if(${CMAKE_VERSION} VERSION_LESS 3.26) +if(${CMAKE_VERSION} VERSION_LESS 3.27) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) else() - cmake_policy(VERSION 3.26) + cmake_policy(VERSION 3.27) +endif() + +if(_pybind11_cmp0148) + cmake_policy(SET CMP0148 ${_pybind11_cmp0148}) + unset(_pybind11_cmp0148) endif() # Avoid infinite recursion if tests include this as a subdirectory @@ -82,33 +92,58 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) set(pybind11_system "") set_property(GLOBAL PROPERTY USE_FOLDERS ON) + if(CMAKE_VERSION VERSION_LESS "3.18") + set(_pybind11_findpython_default OFF) + else() + set(_pybind11_findpython_default ON) + endif() else() set(PYBIND11_MASTER_PROJECT OFF) set(pybind11_system SYSTEM) + set(_pybind11_findpython_default OFF) endif() # Options option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT}) option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT}) option(PYBIND11_NOPYTHON "Disable search for Python" OFF) +option(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION + "To enforce that a handle_type_name<> specialization exists" OFF) option(PYBIND11_SIMPLE_GIL_MANAGEMENT "Use simpler GIL management logic that does not support disassociation" OFF) +option(PYBIND11_NUMPY_1_ONLY + "Disable NumPy 2 support to avoid changes to previous pybind11 versions." OFF) set(PYBIND11_INTERNALS_VERSION "" CACHE STRING "Override the ABI version, may be used to enable the unstable ABI.") +if(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION) + add_compile_definitions(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION) +endif() if(PYBIND11_SIMPLE_GIL_MANAGEMENT) add_compile_definitions(PYBIND11_SIMPLE_GIL_MANAGEMENT) endif() +if(PYBIND11_NUMPY_1_ONLY) + add_compile_definitions(PYBIND11_NUMPY_1_ONLY) +endif() cmake_dependent_option( USE_PYTHON_INCLUDE_DIR "Install pybind11 headers in Python include directory instead of default installation prefix" OFF "PYBIND11_INSTALL" OFF) -cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" OFF +cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" ${_pybind11_findpython_default} "NOT CMAKE_VERSION VERSION_LESS 3.12" OFF) +# Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests +# (makes transition easier while we support both modes). +if(PYBIND11_MASTER_PROJECT + AND PYBIND11_FINDPYTHON + AND DEFINED PYTHON_EXECUTABLE + AND NOT DEFINED Python_EXECUTABLE) + set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}") +endif() + # NB: when adding a header don't forget to also add it to setup.py set(PYBIND11_HEADERS include/pybind11/detail/class.h @@ -132,6 +167,7 @@ set(PYBIND11_HEADERS include/pybind11/embed.h include/pybind11/eval.h include/pybind11/gil.h + include/pybind11/gil_safe_call_once.h include/pybind11/iostream.h include/pybind11/functional.h include/pybind11/numpy.h @@ -141,7 +177,8 @@ set(PYBIND11_HEADERS include/pybind11/stl.h include/pybind11/stl_bind.h include/pybind11/stl/filesystem.h - include/pybind11/type_caster_pyobject_ptr.h) + include/pybind11/type_caster_pyobject_ptr.h + include/pybind11/typing.h) # Compare with grep and warn if mismatched if(PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12) @@ -277,7 +314,21 @@ if(PYBIND11_INSTALL) # pkg-config support if(NOT prefix_for_pc_file) - set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}") + if(IS_ABSOLUTE "${CMAKE_INSTALL_DATAROOTDIR}") + set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}") + else() + set(pc_datarootdir "${CMAKE_INSTALL_DATAROOTDIR}") + if(CMAKE_VERSION VERSION_LESS 3.20) + set(prefix_for_pc_file "\${pcfiledir}/..") + while(pc_datarootdir) + get_filename_component(pc_datarootdir "${pc_datarootdir}" DIRECTORY) + string(APPEND prefix_for_pc_file "/..") + endwhile() + else() + cmake_path(RELATIVE_PATH CMAKE_INSTALL_PREFIX BASE_DIRECTORY CMAKE_INSTALL_DATAROOTDIR + OUTPUT_VARIABLE prefix_for_pc_file) + endif() + endif() endif() join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11.pc.in" diff --git a/extern/pybind11/README.rst b/extern/pybind11/README.rst index 80213a406..4032f97a5 100644 --- a/extern/pybind11/README.rst +++ b/extern/pybind11/README.rst @@ -36,10 +36,10 @@ with everything stripped away that isn't relevant for binding generation. Without comments, the core header files only require ~4K lines of code and depend on Python (3.6+, or PyPy) and the C++ standard library. This compact implementation was possible thanks to -some of the new C++11 language features (specifically: tuples, lambda -functions and variadic templates). Since its creation, this library has -grown beyond Boost.Python in many ways, leading to dramatically simpler -binding code in many common situations. +some C++11 language features (specifically: tuples, lambda functions and +variadic templates). Since its creation, this library has grown beyond +Boost.Python in many ways, leading to dramatically simpler binding code in many +common situations. Tutorial and reference documentation is provided at `pybind11.readthedocs.io `_. @@ -71,6 +71,7 @@ pybind11 can map the following core C++ features to Python: - Internal references with correct reference counting - C++ classes with virtual (and pure virtual) methods can be extended in Python +- Integrated NumPy support (NumPy 2 requires pybind11 2.12+) Goodies ------- diff --git a/extern/pybind11/docs/advanced/embedding.rst b/extern/pybind11/docs/advanced/embedding.rst index e6a1686f8..4cb6ebc68 100644 --- a/extern/pybind11/docs/advanced/embedding.rst +++ b/extern/pybind11/docs/advanced/embedding.rst @@ -18,7 +18,7 @@ information, see :doc:`/compiling`. .. code-block:: cmake - cmake_minimum_required(VERSION 3.5...3.26) + cmake_minimum_required(VERSION 3.5...3.27) project(example) find_package(pybind11 REQUIRED) # or `add_subdirectory(pybind11)` diff --git a/extern/pybind11/docs/advanced/exceptions.rst b/extern/pybind11/docs/advanced/exceptions.rst index 53981dc08..e20f42b5f 100644 --- a/extern/pybind11/docs/advanced/exceptions.rst +++ b/extern/pybind11/docs/advanced/exceptions.rst @@ -127,8 +127,7 @@ before a global translator is tried. Inside the translator, ``std::rethrow_exception`` should be used within a try block to re-throw the exception. One or more catch clauses to catch the appropriate exceptions should then be used with each clause using -``PyErr_SetString`` to set a Python exception or ``ex(string)`` to set -the python exception to a custom exception type (see below). +``py::set_error()`` (see below). To declare a custom Python exception type, declare a ``py::exception`` variable and use this in the associated exception translator (note: it is often useful @@ -142,14 +141,16 @@ standard python RuntimeError: .. code-block:: cpp - static py::exception exc(m, "MyCustomError"); + PYBIND11_CONSTINIT static py::gil_safe_call_once_and_store exc_storage; + exc_storage.call_once_and_store_result( + [&]() { return py::exception(m, "MyCustomError"); }); py::register_exception_translator([](std::exception_ptr p) { try { if (p) std::rethrow_exception(p); } catch (const MyCustomException &e) { - exc(e.what()); + py::set_error(exc_storage.get_stored(), e.what()); } catch (const OtherException &e) { - PyErr_SetString(PyExc_RuntimeError, e.what()); + py::set_error(PyExc_RuntimeError, e.what()); } }); @@ -168,8 +169,7 @@ section. .. note:: - Call either ``PyErr_SetString`` or a custom exception's call - operator (``exc(string)``) for every exception caught in a custom exception + Call ``py::set_error()`` for every exception caught in a custom exception translator. Failure to do so will cause Python to crash with ``SystemError: error return without exception set``. @@ -200,7 +200,7 @@ If module1 has the following translator: try { if (p) std::rethrow_exception(p); } catch (const std::invalid_argument &e) { - PyErr_SetString("module1 handled this") + py::set_error(PyExc_ArgumentError, "module1 handled this"); } } @@ -212,7 +212,7 @@ and module2 has the following similar translator: try { if (p) std::rethrow_exception(p); } catch (const std::invalid_argument &e) { - PyErr_SetString("module2 handled this") + py::set_error(PyExc_ArgumentError, "module2 handled this"); } } @@ -312,11 +312,11 @@ error protocol, which is outlined here. After calling the Python C API, if Python returns an error, ``throw py::error_already_set();``, which allows pybind11 to deal with the exception and pass it back to the Python interpreter. This includes calls to -the error setting functions such as ``PyErr_SetString``. +the error setting functions such as ``py::set_error()``. .. code-block:: cpp - PyErr_SetString(PyExc_TypeError, "C API type error demo"); + py::set_error(PyExc_TypeError, "C API type error demo"); throw py::error_already_set(); // But it would be easier to simply... diff --git a/extern/pybind11/docs/advanced/functions.rst b/extern/pybind11/docs/advanced/functions.rst index 69e3d8a1d..372934b09 100644 --- a/extern/pybind11/docs/advanced/functions.rst +++ b/extern/pybind11/docs/advanced/functions.rst @@ -16,7 +16,7 @@ lifetime of objects managed by them. This can lead to issues when creating bindings for functions that return a non-trivial type. Just by looking at the type information, it is not clear whether Python should take charge of the returned value and eventually free its resources, or if this is handled on the -C++ side. For this reason, pybind11 provides a several *return value policy* +C++ side. For this reason, pybind11 provides several *return value policy* annotations that can be passed to the :func:`module_::def` and :func:`class_::def` functions. The default policy is :enum:`return_value_policy::automatic`. diff --git a/extern/pybind11/docs/advanced/misc.rst b/extern/pybind11/docs/advanced/misc.rst index 805ec838f..ddd7f3937 100644 --- a/extern/pybind11/docs/advanced/misc.rst +++ b/extern/pybind11/docs/advanced/misc.rst @@ -398,3 +398,32 @@ before they are used as a parameter or return type of a function: pyFoo.def(py::init()); pyBar.def(py::init()); } + +Setting inner type hints in docstrings +====================================== + +When you use pybind11 wrappers for ``list``, ``dict``, and other generic python +types, the docstring will just display the generic type. You can convey the +inner types in the docstring by using a special 'typed' version of the generic +type. + +.. code-block:: cpp + + PYBIND11_MODULE(example, m) { + m.def("pass_list_of_str", [](py::typing::List arg) { + // arg can be used just like py::list + )); + } + +The resulting docstring will be ``pass_list_of_str(arg0: list[str]) -> None``. + +The following special types are available in ``pybind11/typing.h``: + +* ``py::Tuple`` +* ``py::Dict`` +* ``py::List`` +* ``py::Set`` +* ``py::Callable`` + +.. warning:: Just like in python, these are merely hints. They don't actually + enforce the types of their contents at runtime or compile time. diff --git a/extern/pybind11/docs/benchmark.py b/extern/pybind11/docs/benchmark.py index 2150b6ca7..fb49fd048 100644 --- a/extern/pybind11/docs/benchmark.py +++ b/extern/pybind11/docs/benchmark.py @@ -70,7 +70,7 @@ def generate_dummy_code_boost(nclasses=10): for codegen in [generate_dummy_code_pybind11, generate_dummy_code_boost]: print("{") - for i in range(0, 10): + for i in range(10): nclasses = 2**i with open("test.cpp", "w") as f: f.write(codegen(nclasses)) diff --git a/extern/pybind11/docs/changelog.rst b/extern/pybind11/docs/changelog.rst index add3fd66b..d2285f237 100644 --- a/extern/pybind11/docs/changelog.rst +++ b/extern/pybind11/docs/changelog.rst @@ -10,8 +10,188 @@ Changes will be added here periodically from the "Suggested changelog entry" block in pull request descriptions. +IN DEVELOPMENT +-------------- + +Changes will be summarized here periodically. + +Version 2.12.0 (March 27, 2025) +------------------------------- + +New Features: + +* ``pybind11`` now supports compiling for + `NumPy 2 `_. Most + code shouldn't change (see :ref:`upgrade-guide-2.12` for details). However, + if you experience issues you can define ``PYBIND11_NUMPY_1_ONLY`` to disable + the new support for now, but this will be removed in the future. + `#5050 `_ + +* ``pybind11/gil_safe_call_once.h`` was added (it needs to be included + explicitly). The primary use case is GIL-safe initialization of C++ + ``static`` variables. + `#4877 `_ + +* Support move-only iterators in ``py::make_iterator``, + ``py::make_key_iterator``, ``py::make_value_iterator``. + `#4834 `_ + +* Two simple ``py::set_error()`` functions were added and the documentation was + updated accordingly. In particular, ``py::exception<>::operator()`` was + deprecated (use one of the new functions instead). The documentation for + ``py::exception<>`` was further updated to not suggest code that may result + in undefined behavior. + `#4772 `_ + +Bug fixes: + +* Removes potential for Undefined Behavior during process teardown. + `#4897 `_ + +* Improve compatibility with the nvcc compiler (especially CUDA 12.1/12.2). + `#4893 `_ + +* ``pybind11/numpy.h`` now imports NumPy's ``multiarray`` and ``_internal`` + submodules with paths depending on the installed version of NumPy (for + compatibility with NumPy 2). + `#4857 `_ + +* Builtins collections names in docstrings are now consistently rendered in + lowercase (list, set, dict, tuple), in accordance with PEP 585. + `#4833 `_ + +* Added ``py::typing::Iterator``, ``py::typing::Iterable``. + `#4832 `_ + +* Render ``py::function`` as ``Callable`` in docstring. + `#4829 `_ + +* Also bump ``PYBIND11_INTERNALS_VERSION`` for MSVC, which unlocks two new + features without creating additional incompatibilities. + `#4819 `_ + +* Guard against crashes/corruptions caused by modules built with different MSVC + versions. + `#4779 `_ + +* A long-standing bug in the handling of Python multiple inheritance was fixed. + See PR #4762 for the rather complex details. + `#4762 `_ + +* Fix ``bind_map`` with ``using`` declarations. + `#4952 `_ + +* Qualify ``py::detail::concat`` usage to avoid ADL selecting one from + somewhere else, such as modernjson's concat. + `#4955 `_ + +* Use new PyCode API on Python 3.12+. + `#4916 `_ + +* Minor cleanup from warnings reported by Clazy. + `#4988 `_ + +* Remove typing and duplicate ``class_`` for ``KeysView``/``ValuesView``/``ItemsView``. + `#4985 `_ + +* Use ``PyObject_VisitManagedDict()`` and ``PyObject_ClearManagedDict()`` on Python 3.13 and newer. + `#4973 `_ + +* Update ``make_static_property_type()`` to make it compatible with Python 3.13. + `#4971 `_ + +.. fix(types) + +* Render typed iterators for ``make_iterator``, ``make_key_iterator``, + ``make_value_iterator``. + `#4876 `_ + +* Add several missing type name specializations. + `#5073 `_ + +* Change docstring render for ``py::buffer``, ``py::sequence`` and + ``py::handle`` (to ``Buffer``, ``Sequence``, ``Any``). + `#4831 `_ + +* Fixed ``base_enum.__str__`` docstring. + `#4827 `_ + +* Enforce single line docstring signatures. + `#4735 `_ + +* Special 'typed' wrappers now available in ``typing.h`` to annotate tuple, dict, + list, set, and function. + `#4259 `_ + +* Create ``handle_type_name`` specialization to type-hint variable length tuples. + `#5051 `_ + +.. fix(build) + +* Setting ``PYBIND11_FINDPYTHON`` to OFF will force the old FindPythonLibs mechanism to be used. + `#5042 `_ + +* Skip empty ``PYBIND11_PYTHON_EXECUTABLE_LAST`` for the first cmake run. + `#4856 `_ + +* Fix FindPython mode exports & avoid ``pkg_resources`` if + ``importlib.metadata`` available. + `#4941 `_ + +* ``Python_ADDITIONAL_VERSIONS`` (classic search) now includes 3.12. + `#4909 `_ + +* ``pybind11.pc`` is now relocatable by default as long as install destinations + are not absolute paths. + `#4830 `_ + +* Correctly detect CMake FindPython removal when used as a subdirectory. + `#4806 `_ + +* Don't require the libs component on CMake 3.18+ when using + PYBIND11_FINDPYTHON (fixes manylinux builds). + `#4805 `_ + +* ``pybind11_strip`` is no longer automatically applied when + ``CMAKE_BUILD_TYPE`` is unset. + `#4780 `_ + +* Support ``DEBUG_POSFIX`` correctly for debug builds. + `#4761 `_ + +* Hardcode lto/thin lto for Emscripten cross-compiles. + `#4642 `_ + +* Upgrade maximum supported CMake version to 3.27 to fix CMP0148 warnings. + `#4786 `_ + +Documentation: + +* Small fix to grammar in ``functions.rst``. + `#4791 `_ + +* Remove upper bound in example pyproject.toml for setuptools. + `#4774 `_ + +CI: + +* CI: Update NVHPC to 23.5 and Ubuntu 20.04. + `#4764 `_ + +* Test on PyPy 3.10. + `#4714 `_ + +Other: + +* Use Ruff formatter instead of Black. + `#4912 `_ + +* An ``assert()`` was added to help Coverty avoid generating a false positive. + `#4817 `_ + + Version 2.11.1 (July 17, 2023) ------------------------------ +------------------------------ Changes: @@ -26,7 +206,7 @@ Changes: Version 2.11.0 (July 14, 2023) ------------------------------ +------------------------------ New features: diff --git a/extern/pybind11/docs/compiling.rst b/extern/pybind11/docs/compiling.rst index 1fd098bec..3be84ba7d 100644 --- a/extern/pybind11/docs/compiling.rst +++ b/extern/pybind11/docs/compiling.rst @@ -143,7 +143,7 @@ Your ``pyproject.toml`` file will likely look something like this: .. code-block:: toml [build-system] - requires = ["setuptools>=42", "wheel", "pybind11~=2.6.1"] + requires = ["setuptools>=42", "pybind11>=2.6.1"] build-backend = "setuptools.build_meta" .. note:: @@ -241,7 +241,7 @@ extension module can be created with just a few lines of code: .. code-block:: cmake - cmake_minimum_required(VERSION 3.5...3.26) + cmake_minimum_required(VERSION 3.5...3.27) project(example LANGUAGES CXX) add_subdirectory(pybind11) @@ -498,7 +498,7 @@ You can use these targets to build complex applications. For example, the .. code-block:: cmake - cmake_minimum_required(VERSION 3.5...3.26) + cmake_minimum_required(VERSION 3.5...3.27) project(example LANGUAGES CXX) find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11) @@ -556,7 +556,7 @@ information about usage in C++, see :doc:`/advanced/embedding`. .. code-block:: cmake - cmake_minimum_required(VERSION 3.5...3.26) + cmake_minimum_required(VERSION 3.5...3.27) project(example LANGUAGES CXX) find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11) @@ -639,3 +639,11 @@ cross-project dependency management. Additionally, it is able to autogenerate customizable pybind11-based wrappers by parsing C++ header files. .. [robotpy-build] https://robotpy-build.readthedocs.io + +[litgen]_ is an automatic python bindings generator with a focus on generating +documented and discoverable bindings: bindings will nicely reproduce the documentation +found in headers. It is is based on srcML (srcml.org), a highly scalable, multi-language +parsing tool with a developer centric approach. The API that you want to expose to python +must be C++14 compatible (but your implementation can use more modern constructs). + +.. [litgen] https://pthom.github.io/litgen diff --git a/extern/pybind11/docs/release.rst b/extern/pybind11/docs/release.rst index 4950c3b88..47b5717ca 100644 --- a/extern/pybind11/docs/release.rst +++ b/extern/pybind11/docs/release.rst @@ -15,8 +15,8 @@ For example: For beta, ``PYBIND11_VERSION_PATCH`` should be ``Z.b1``. RC's can be ``Z.rc1``. Always include the dot (even though PEP 440 allows it to be dropped). For a -final release, this must be a simple integer. There is also a HEX version of -the version just below. +final release, this must be a simple integer. There is also +``PYBIND11_VERSION_HEX`` just below that needs to be updated. To release a new version of pybind11: @@ -26,53 +26,93 @@ If you don't have nox, you should either use ``pipx run nox`` instead, or use ``pipx install nox`` or ``brew install nox`` (Unix). - Update the version number - - Update ``PYBIND11_VERSION_MAJOR`` etc. in - ``include/pybind11/detail/common.h``. PATCH should be a simple integer. - - Update the version HEX just below, as well. - - Update ``pybind11/_version.py`` (match above) - - Run ``nox -s tests_packaging`` to ensure this was done correctly. - - Ensure that all the information in ``setup.cfg`` is up-to-date, like - supported Python versions. - - Add release date in ``docs/changelog.rst`` and integrate the output of - ``nox -s make_changelog``. - - Note that the ``make_changelog`` command inspects - `needs changelog `_. - - Manually clear the ``needs changelog`` labels using the GitHub web - interface (very easy: start by clicking the link above). - - ``git add`` and ``git commit``, ``git push``. **Ensure CI passes**. (If it - fails due to a known flake issue, either ignore or restart CI.) -- Add a release branch if this is a new minor version, or update the existing release branch if it is a patch version - - New branch: ``git checkout -b vX.Y``, ``git push -u origin vX.Y`` - - Update branch: ``git checkout vX.Y``, ``git merge ``, ``git push`` + + - Update ``PYBIND11_VERSION_MAJOR`` etc. in + ``include/pybind11/detail/common.h``. PATCH should be a simple integer. + + - Update ``PYBIND11_VERSION_HEX`` just below as well. + + - Update ``pybind11/_version.py`` (match above). + + - Run ``nox -s tests_packaging`` to ensure this was done correctly. + +- Ensure that all the information in ``setup.cfg`` is up-to-date, like + supported Python versions. + +- Add release date in ``docs/changelog.rst`` and integrate the output of + ``nox -s make_changelog``. + + - Note that the ``nox -s make_changelog`` command inspects + `needs changelog `_. + + - Manually clear the ``needs changelog`` labels using the GitHub web + interface (very easy: start by clicking the link above). + +- ``git add`` and ``git commit``, ``git push``. **Ensure CI passes**. (If it + fails due to a known flake issue, either ignore or restart CI.) + +- Add a release branch if this is a new MINOR version, or update the existing + release branch if it is a patch version + + - New branch: ``git checkout -b vX.Y``, ``git push -u origin vX.Y`` + + - Update branch: ``git checkout vX.Y``, ``git merge ``, ``git push`` + - Update tags (optional; if you skip this, the GitHub release makes a - non-annotated tag for you) - - ``git tag -a vX.Y.Z -m 'vX.Y.Z release'``. - - ``git push --tags``. + non-annotated tag for you) + + - ``git tag -a vX.Y.Z -m 'vX.Y.Z release'`` + + - ``grep ^__version__ pybind11/_version.py`` + + - Last-minute consistency check: same as tag? + + - ``git push --tags`` + - Update stable - - ``git checkout stable`` - - ``git merge master`` - - ``git push`` + + - ``git checkout stable`` + + - ``git merge -X theirs vX.Y.Z`` + + - ``git diff vX.Y.Z`` + + - Carefully review and reconcile any diffs. There should be none. + + - ``git push`` + - Make a GitHub release (this shows up in the UI, sends new release notifications to users watching releases, and also uploads PyPI packages). (Note: if you do not use an existing tag, this creates a new lightweight tag for you, so you could skip the above step.) - - GUI method: Under `releases `_ - click "Draft a new release" on the far right, fill in the tag name - (if you didn't tag above, it will be made here), fill in a release name - like "Version X.Y.Z", and copy-and-paste the markdown-formatted (!) changelog - into the description (usually ``cat docs/changelog.rst | pandoc -f rst -t gfm``). - Check "pre-release" if this is a beta/RC. - - CLI method: with ``gh`` installed, run ``gh release create vX.Y.Z -t "Version X.Y.Z"`` - If this is a pre-release, add ``-p``. + + - GUI method: Under `releases `_ + click "Draft a new release" on the far right, fill in the tag name + (if you didn't tag above, it will be made here), fill in a release name + like "Version X.Y.Z", and copy-and-paste the markdown-formatted (!) changelog + into the description. You can use ``cat docs/changelog.rst | pandoc -f rst -t gfm``, + then manually remove line breaks and strip links to PRs and issues, + e.g. to a bare ``#1234``, without the surrounding ``<...>_`` hyperlink markup. + Check "pre-release" if this is a beta/RC. + + - CLI method: with ``gh`` installed, run ``gh release create vX.Y.Z -t "Version X.Y.Z"`` + If this is a pre-release, add ``-p``. - Get back to work - - Make sure you are on master, not somewhere else: ``git checkout master`` - - Update version macros in ``include/pybind11/detail/common.h`` (set PATCH to - ``0.dev1`` and increment MINOR). - - Update ``_version.py`` to match - - Run ``nox -s tests_packaging`` to ensure this was done correctly. - - Add a spot for in-development updates in ``docs/changelog.rst``. - - ``git add``, ``git commit``, ``git push`` + + - Make sure you are on master, not somewhere else: ``git checkout master`` + + - Update version macros in ``include/pybind11/detail/common.h`` (set PATCH to + ``0.dev1`` and increment MINOR). + + - Update ``pybind11/_version.py`` to match. + + - Run ``nox -s tests_packaging`` to ensure this was done correctly. + + - If the release was a new MINOR version, add a new ``IN DEVELOPMENT`` + section in ``docs/changelog.rst``. + + - ``git add``, ``git commit``, ``git push`` If a version branch is updated, remember to set PATCH to ``1.dev1``. @@ -89,7 +129,11 @@ merge it if there are no issues. Manual packaging ^^^^^^^^^^^^^^^^ -If you need to manually upload releases, you can download the releases from the job artifacts and upload them with twine. You can also make the files locally (not recommended in general, as your local directory is more likely to be "dirty" and SDists love picking up random unrelated/hidden files); this is the procedure: +If you need to manually upload releases, you can download the releases from +the job artifacts and upload them with twine. You can also make the files +locally (not recommended in general, as your local directory is more likely +to be "dirty" and SDists love picking up random unrelated/hidden files); +this is the procedure: .. code-block:: bash diff --git a/extern/pybind11/docs/upgrade.rst b/extern/pybind11/docs/upgrade.rst index b13d21f5e..17c26aaa9 100644 --- a/extern/pybind11/docs/upgrade.rst +++ b/extern/pybind11/docs/upgrade.rst @@ -8,6 +8,34 @@ to a new version. But it goes into more detail. This includes things like deprecated APIs and their replacements, build system changes, general code modernization and other useful information. +.. _upgrade-guide-2.12: + +v2.12 +===== + +NumPy support has been upgraded to support the 2.x series too. The two relevant +changes are that: + +* ``dtype.flags()`` is now a ``uint64`` and ``dtype.alignment()`` an + ``ssize_t`` (and NumPy may return an larger than integer value for + ``itemsize()`` in NumPy 2.x). + +* The long deprecated NumPy function ``PyArray_GetArrayParamsFromObject`` + function is not available anymore. + +Due to NumPy changes, you may experience difficulties updating to NumPy 2. +Please see the [NumPy 2 migration guide](https://numpy.org/devdocs/numpy_2_0_migration_guide.html) for details. +For example, a more direct change could be that the default integer ``"int_"`` +(and ``"uint"``) is now ``ssize_t`` and not ``long`` (affects 64bit windows). + +If you want to only support NumPy 1.x for now and are having problems due to +the two internal changes listed above, you can define +``PYBIND11_NUMPY_1_ONLY`` to disable the new support for now. Make sure you +define this on all pybind11 compile units, since it could be a source of ODR +violations if used inconsistently. This option will be removed in the future, +so adapting your code is highly recommended. + + .. _upgrade-guide-2.11: v2.11 diff --git a/extern/pybind11/include/pybind11/cast.h b/extern/pybind11/include/pybind11/cast.h index db3934118..02d9488da 100644 --- a/extern/pybind11/include/pybind11/cast.h +++ b/extern/pybind11/include/pybind11/cast.h @@ -42,13 +42,15 @@ using make_caster = type_caster>; // Shortcut for calling a caster's `cast_op_type` cast operator for casting a type_caster to a T template typename make_caster::template cast_op_type cast_op(make_caster &caster) { - return caster.operator typename make_caster::template cast_op_type(); + using result_t = typename make_caster::template cast_op_type; // See PR #4893 + return caster.operator result_t(); } template typename make_caster::template cast_op_type::type> cast_op(make_caster &&caster) { - return std::move(caster).operator typename make_caster:: - template cast_op_type::type>(); + using result_t = typename make_caster::template cast_op_type< + typename std::add_rvalue_reference::type>; // See PR #4893 + return std::move(caster).operator result_t(); } template @@ -325,8 +327,9 @@ class type_caster { value = false; return true; } - if (convert || (std::strcmp("numpy.bool_", Py_TYPE(src.ptr())->tp_name) == 0)) { - // (allow non-implicit conversion for numpy booleans) + if (convert || is_numpy_bool(src)) { + // (allow non-implicit conversion for numpy booleans), use strncmp + // since NumPy 1.x had an additional trailing underscore. Py_ssize_t res = -1; if (src.is_none()) { @@ -358,6 +361,15 @@ class type_caster { return handle(src ? Py_True : Py_False).inc_ref(); } PYBIND11_TYPE_CASTER(bool, const_name("bool")); + +private: + // Test if an object is a NumPy boolean (without fetching the type). + static inline bool is_numpy_bool(handle object) { + const char *type_name = Py_TYPE(object.ptr())->tp_name; + // Name changed to `numpy.bool` in NumPy 2, `numpy.bool_` is needed for 1.x support + return std::strcmp("numpy.bool", type_name) == 0 + || std::strcmp("numpy.bool_", type_name) == 0; + } }; // Helper class for UTF-{8,16,32} C++ stl strings: @@ -660,8 +672,9 @@ class tuple_caster { return cast(*src, policy, parent); } - static constexpr auto name - = const_name("Tuple[") + concat(make_caster::name...) + const_name("]"); + static constexpr auto name = const_name("tuple[") + + ::pybind11::detail::concat(make_caster::name...) + + const_name("]"); template using cast_op_type = type; @@ -869,10 +882,53 @@ struct is_holder_type template struct is_holder_type> : std::true_type {}; +#ifdef PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION // See PR #4888 + +// This leads to compilation errors if a specialization is missing. +template +struct handle_type_name; + +#else + template struct handle_type_name { static constexpr auto name = const_name(); }; + +#endif + +template <> +struct handle_type_name { + static constexpr auto name = const_name("object"); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name("list"); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name("dict"); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name("Union[set, frozenset]"); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name("set"); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name("frozenset"); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name("str"); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name("tuple"); +}; template <> struct handle_type_name { static constexpr auto name = const_name("bool"); @@ -882,6 +938,10 @@ struct handle_type_name { static constexpr auto name = const_name(PYBIND11_BYTES_NAME); }; template <> +struct handle_type_name { + static constexpr auto name = const_name("Buffer"); +}; +template <> struct handle_type_name { static constexpr auto name = const_name("int"); }; @@ -898,10 +958,50 @@ struct handle_type_name { static constexpr auto name = const_name("float"); }; template <> +struct handle_type_name { + static constexpr auto name = const_name("Callable"); +}; +template <> +struct handle_type_name { + static constexpr auto name = handle_type_name::name; +}; +template <> struct handle_type_name { static constexpr auto name = const_name("None"); }; template <> +struct handle_type_name { + static constexpr auto name = const_name("Sequence"); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name("bytearray"); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name("memoryview"); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name("slice"); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name("type"); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name("capsule"); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name("ellipsis"); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name("weakref"); +}; +template <> struct handle_type_name { static constexpr auto name = const_name("*args"); }; @@ -909,6 +1009,30 @@ template <> struct handle_type_name { static constexpr auto name = const_name("**kwargs"); }; +template <> +struct handle_type_name { + static constexpr auto name = const_name(); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name(); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name(); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name(); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name(); +}; +template <> +struct handle_type_name { + static constexpr auto name = const_name(); +}; template struct pyobject_caster { @@ -1377,7 +1501,15 @@ inline namespace literals { /** \rst String literal version of `arg` \endrst */ -constexpr arg operator"" _a(const char *name, size_t) { return arg(name); } +constexpr arg +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 5 +operator"" _a // gcc 4.8.5 insists on having a space (hard error). +#else +operator""_a // clang 17 generates a deprecation warning if there is a space. +#endif + (const char *name, size_t) { + return arg(name); +} } // namespace literals PYBIND11_NAMESPACE_BEGIN(detail) @@ -1438,7 +1570,8 @@ class argument_loader { static_assert(args_pos == -1 || args_pos == constexpr_first(), "py::args cannot be specified more than once"); - static constexpr auto arg_names = concat(type_descr(make_caster::name)...); + static constexpr auto arg_names + = ::pybind11::detail::concat(type_descr(make_caster::name)...); bool load_args(function_call &call) { return load_impl_sequence(call, indices{}); } diff --git a/extern/pybind11/include/pybind11/detail/class.h b/extern/pybind11/include/pybind11/detail/class.h index bc2b40c50..0b9ea42db 100644 --- a/extern/pybind11/include/pybind11/detail/class.h +++ b/extern/pybind11/include/pybind11/detail/class.h @@ -86,17 +86,16 @@ inline PyTypeObject *make_static_property_type() { type->tp_descr_get = pybind11_static_get; type->tp_descr_set = pybind11_static_set; - if (PyType_Ready(type) < 0) { - pybind11_fail("make_static_property_type(): failure in PyType_Ready()!"); - } - # if PY_VERSION_HEX >= 0x030C0000 - // PRE 3.12 FEATURE FREEZE. PLEASE REVIEW AFTER FREEZE. // Since Python-3.12 property-derived types are required to // have dynamic attributes (to set `__doc__`) enable_dynamic_attributes(heap_type); # endif + if (PyType_Ready(type) < 0) { + pybind11_fail("make_static_property_type(): failure in PyType_Ready()!"); + } + setattr((PyObject *) type, "__module__", str("pybind11_builtins")); PYBIND11_SET_OLDPY_QUALNAME(type, name_obj); @@ -189,12 +188,10 @@ extern "C" inline PyObject *pybind11_meta_call(PyObject *type, PyObject *args, P return nullptr; } - // This must be a pybind11 instance - auto *instance = reinterpret_cast(self); - // Ensure that the base __init__ function(s) were called - for (const auto &vh : values_and_holders(instance)) { - if (!vh.holder_constructed()) { + values_and_holders vhs(self); + for (const auto &vh : vhs) { + if (!vh.holder_constructed() && !vhs.is_redundant_value_and_holder(vh)) { PyErr_Format(PyExc_TypeError, "%.200s.__init__() must be called when overriding __init__", get_fully_qualified_tp_name(vh.type->type).c_str()); @@ -375,7 +372,7 @@ extern "C" inline PyObject *pybind11_object_new(PyTypeObject *type, PyObject *, extern "C" inline int pybind11_object_init(PyObject *self, PyObject *, PyObject *) { PyTypeObject *type = Py_TYPE(self); std::string msg = get_fully_qualified_tp_name(type) + ": No constructor defined!"; - PyErr_SetString(PyExc_TypeError, msg.c_str()); + set_error(PyExc_TypeError, msg.c_str()); return -1; } @@ -522,8 +519,12 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) { /// dynamic_attr: Allow the garbage collector to traverse the internal instance `__dict__`. extern "C" inline int pybind11_traverse(PyObject *self, visitproc visit, void *arg) { +#if PY_VERSION_HEX >= 0x030D0000 + PyObject_VisitManagedDict(self, visit, arg); +#else PyObject *&dict = *_PyObject_GetDictPtr(self); Py_VISIT(dict); +#endif // https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_traverse #if PY_VERSION_HEX >= 0x03090000 Py_VISIT(Py_TYPE(self)); @@ -533,8 +534,12 @@ extern "C" inline int pybind11_traverse(PyObject *self, visitproc visit, void *a /// dynamic_attr: Allow the GC to clear the dictionary. extern "C" inline int pybind11_clear(PyObject *self) { +#if PY_VERSION_HEX >= 0x030D0000 + PyObject_ClearManagedDict(self); +#else PyObject *&dict = *_PyObject_GetDictPtr(self); Py_CLEAR(dict); +#endif return 0; } @@ -579,7 +584,7 @@ extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int fla if (view) { view->obj = nullptr; } - PyErr_SetString(PyExc_BufferError, "pybind11_getbuffer(): Internal error"); + set_error(PyExc_BufferError, "pybind11_getbuffer(): Internal error"); return -1; } std::memset(view, 0, sizeof(Py_buffer)); @@ -587,7 +592,7 @@ extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int fla if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE && info->readonly) { delete info; // view->obj = nullptr; // Was just memset to 0, so not necessary - PyErr_SetString(PyExc_BufferError, "Writable buffer requested for readonly storage"); + set_error(PyExc_BufferError, "Writable buffer requested for readonly storage"); return -1; } view->obj = obj; diff --git a/extern/pybind11/include/pybind11/detail/common.h b/extern/pybind11/include/pybind11/detail/common.h index 31a54c773..454e6061b 100644 --- a/extern/pybind11/include/pybind11/detail/common.h +++ b/extern/pybind11/include/pybind11/detail/common.h @@ -10,12 +10,12 @@ #pragma once #define PYBIND11_VERSION_MAJOR 2 -#define PYBIND11_VERSION_MINOR 11 -#define PYBIND11_VERSION_PATCH 1 +#define PYBIND11_VERSION_MINOR 12 +#define PYBIND11_VERSION_PATCH 0 // Similar to Python's convention: https://docs.python.org/3/c-api/apiabiversion.html // Additional convention: 0xD = dev -#define PYBIND11_VERSION_HEX 0x020B0100 +#define PYBIND11_VERSION_HEX 0x020C0000 // Define some generic pybind11 helper macros for warning management. // @@ -118,6 +118,14 @@ # endif #endif +#if defined(PYBIND11_CPP20) +# define PYBIND11_CONSTINIT constinit +# define PYBIND11_DTOR_CONSTEXPR constexpr +#else +# define PYBIND11_CONSTINIT +# define PYBIND11_DTOR_CONSTEXPR +#endif + // Compiler version assertions #if defined(__INTEL_COMPILER) # if __INTEL_COMPILER < 1800 @@ -288,6 +296,10 @@ PYBIND11_WARNING_DISABLE_MSVC(4505) # undef copysign #endif +#if defined(PYBIND11_NUMPY_1_ONLY) +# define PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED +#endif + #if defined(PYPY_VERSION) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT) # define PYBIND11_SIMPLE_GIL_MANAGEMENT #endif @@ -399,7 +411,7 @@ PYBIND11_WARNING_POP return nullptr; \ } \ catch (const std::exception &e) { \ - PyErr_SetString(PyExc_ImportError, e.what()); \ + ::pybind11::set_error(PyExc_ImportError, e.what()); \ return nullptr; \ } diff --git a/extern/pybind11/include/pybind11/detail/init.h b/extern/pybind11/include/pybind11/detail/init.h index e21171688..4509bd131 100644 --- a/extern/pybind11/include/pybind11/detail/init.h +++ b/extern/pybind11/include/pybind11/detail/init.h @@ -65,7 +65,7 @@ constexpr bool is_alias(void *) { } // Constructs and returns a new object; if the given arguments don't map to a constructor, we fall -// back to brace aggregate initiailization so that for aggregate initialization can be used with +// back to brace aggregate initialization so that for aggregate initialization can be used with // py::init, e.g. `py::init` to initialize a `struct T { int a; int b; }`. For // non-aggregate types, we need to use an ordinary T(...) constructor (invoking as `T{...}` usually // works, but will not do the expected thing when `T` has an `initializer_list` constructor). diff --git a/extern/pybind11/include/pybind11/detail/internals.h b/extern/pybind11/include/pybind11/detail/internals.h index aaa7f8686..c1047e4a0 100644 --- a/extern/pybind11/include/pybind11/detail/internals.h +++ b/extern/pybind11/include/pybind11/detail/internals.h @@ -34,8 +34,9 @@ /// further ABI-incompatible changes may be made before the ABI is officially /// changed to the new version. #ifndef PYBIND11_INTERNALS_VERSION -# if PY_VERSION_HEX >= 0x030C0000 +# if PY_VERSION_HEX >= 0x030C0000 || defined(_MSC_VER) // Version bump for Python 3.12+, before first 3.12 beta release. +// Version bump for MSVC piggy-backed on PR #4779. See comments there. # define PYBIND11_INTERNALS_VERSION 5 # else # define PYBIND11_INTERNALS_VERSION 4 @@ -66,9 +67,14 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass); // `Py_LIMITED_API` anyway. # if PYBIND11_INTERNALS_VERSION > 4 # define PYBIND11_TLS_KEY_REF Py_tss_t & -# if defined(__GNUC__) && !defined(__INTEL_COMPILER) -// Clang on macOS warns due to `Py_tss_NEEDS_INIT` not specifying an initializer -// for every field. +# if defined(__clang__) +# define PYBIND11_TLS_KEY_INIT(var) \ + _Pragma("clang diagnostic push") /**/ \ + _Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"") /**/ \ + Py_tss_t var \ + = Py_tss_NEEDS_INIT; \ + _Pragma("clang diagnostic pop") +# elif defined(__GNUC__) && !defined(__INTEL_COMPILER) # define PYBIND11_TLS_KEY_INIT(var) \ _Pragma("GCC diagnostic push") /**/ \ _Pragma("GCC diagnostic ignored \"-Wmissing-field-initializers\"") /**/ \ @@ -291,9 +297,12 @@ struct type_info { #endif /// On Linux/OSX, changes in __GXX_ABI_VERSION__ indicate ABI incompatibility. +/// On MSVC, changes in _MSC_VER may indicate ABI incompatibility (#2898). #ifndef PYBIND11_BUILD_ABI # if defined(__GXX_ABI_VERSION) # define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION) +# elif defined(_MSC_VER) +# define PYBIND11_BUILD_ABI "_mscver" PYBIND11_TOSTRING(_MSC_VER) # else # define PYBIND11_BUILD_ABI "" # endif @@ -352,7 +361,7 @@ inline bool raise_err(PyObject *exc_type, const char *msg) { raise_from(exc_type, msg); return true; } - PyErr_SetString(exc_type, msg); + set_error(exc_type, msg); return false; } @@ -447,6 +456,7 @@ inline object get_python_state_dict() { #endif if (!state_dict) { raise_from(PyExc_SystemError, "pybind11::detail::get_python_state_dict() FAILED"); + throw error_already_set(); } return state_dict; } @@ -459,6 +469,7 @@ inline internals **get_internals_pp_from_capsule(handle obj) { void *raw_ptr = PyCapsule_GetPointer(obj.ptr(), /*name=*/nullptr); if (raw_ptr == nullptr) { raise_from(PyExc_SystemError, "pybind11::detail::get_internals_pp_from_capsule() FAILED"); + throw error_already_set(); } return static_cast(raw_ptr); } diff --git a/extern/pybind11/include/pybind11/detail/type_caster_base.h b/extern/pybind11/include/pybind11/detail/type_caster_base.h index 16387506c..518d3107b 100644 --- a/extern/pybind11/include/pybind11/detail/type_caster_base.h +++ b/extern/pybind11/include/pybind11/detail/type_caster_base.h @@ -102,8 +102,22 @@ class loader_life_support { inline std::pair all_type_info_get_cache(PyTypeObject *type); +// Band-aid workaround to fix a subtle but serious bug in a minimalistic fashion. See PR #4762. +inline void all_type_info_add_base_most_derived_first(std::vector &bases, + type_info *addl_base) { + for (auto it = bases.begin(); it != bases.end(); it++) { + type_info *existing_base = *it; + if (PyType_IsSubtype(addl_base->type, existing_base->type) != 0) { + bases.insert(it, addl_base); + return; + } + } + bases.push_back(addl_base); +} + // Populates a just-created cache entry. PYBIND11_NOINLINE void all_type_info_populate(PyTypeObject *t, std::vector &bases) { + assert(bases.empty()); std::vector check; for (handle parent : reinterpret_borrow(t->tp_bases)) { check.push_back((PyTypeObject *) parent.ptr()); @@ -136,7 +150,7 @@ PYBIND11_NOINLINE void all_type_info_populate(PyTypeObject *t, std::vectortp_bases) { @@ -322,18 +336,29 @@ struct values_and_holders { explicit values_and_holders(instance *inst) : inst{inst}, tinfo(all_type_info(Py_TYPE(inst))) {} + explicit values_and_holders(PyObject *obj) + : inst{nullptr}, tinfo(all_type_info(Py_TYPE(obj))) { + if (!tinfo.empty()) { + inst = reinterpret_cast(obj); + } + } + struct iterator { private: instance *inst = nullptr; const type_vec *types = nullptr; value_and_holder curr; friend struct values_and_holders; - iterator(instance *inst, const type_vec *tinfo) - : inst{inst}, types{tinfo}, - curr(inst /* instance */, - types->empty() ? nullptr : (*types)[0] /* type info */, - 0, /* vpos: (non-simple types only): the first vptr comes first */ - 0 /* index */) {} + iterator(instance *inst, const type_vec *tinfo) : inst{inst}, types{tinfo} { + if (inst != nullptr) { + assert(!types->empty()); + curr = value_and_holder( + inst /* instance */, + (*types)[0] /* type info */, + 0, /* vpos: (non-simple types only): the first vptr comes first */ + 0 /* index */); + } + } // Past-the-end iterator: explicit iterator(size_t end) : curr(end) {} @@ -364,6 +389,16 @@ struct values_and_holders { } size_t size() { return tinfo.size(); } + + // Band-aid workaround to fix a subtle but serious bug in a minimalistic fashion. See PR #4762. + bool is_redundant_value_and_holder(const value_and_holder &vh) { + for (size_t i = 0; i < vh.index; i++) { + if (PyType_IsSubtype(tinfo[i]->type, tinfo[vh.index]->type) != 0) { + return true; + } + } + return false; + } }; /** @@ -486,8 +521,10 @@ PYBIND11_NOINLINE handle get_object_handle(const void *ptr, const detail::type_i inline PyThreadState *get_thread_state_unchecked() { #if defined(PYPY_VERSION) return PyThreadState_GET(); -#else +#elif PY_VERSION_HEX < 0x030D0000 return _PyThreadState_UncheckedGet(); +#else + return PyThreadState_GetUnchecked(); #endif } @@ -786,7 +823,7 @@ class type_caster_generic { std::string tname = rtti_type ? rtti_type->name() : cast_type.name(); detail::clean_type_id(tname); std::string msg = "Unregistered type : " + tname; - PyErr_SetString(PyExc_TypeError, msg.c_str()); + set_error(PyExc_TypeError, msg.c_str()); return {nullptr, nullptr}; } @@ -1164,13 +1201,17 @@ class type_caster_base : public type_caster_generic { static Constructor make_move_constructor(...) { return nullptr; } }; +inline std::string quote_cpp_type_name(const std::string &cpp_type_name) { + return cpp_type_name; // No-op for now. See PR #4888 +} + PYBIND11_NOINLINE std::string type_info_description(const std::type_info &ti) { if (auto *type_data = get_type_info(ti)) { handle th((PyObject *) type_data->type); return th.attr("__module__").cast() + '.' + th.attr("__qualname__").cast(); } - return clean_type_id(ti.name()); + return quote_cpp_type_name(clean_type_id(ti.name())); } PYBIND11_NAMESPACE_END(detail) diff --git a/extern/pybind11/include/pybind11/eigen/tensor.h b/extern/pybind11/include/pybind11/eigen/tensor.h index 25d12baca..d4ed6c0ca 100644 --- a/extern/pybind11/include/pybind11/eigen/tensor.h +++ b/extern/pybind11/include/pybind11/eigen/tensor.h @@ -70,7 +70,7 @@ struct eigen_tensor_helper struct helper> { - static constexpr auto value = concat(const_name(((void) Is, "?"))...); + static constexpr auto value = ::pybind11::detail::concat(const_name(((void) Is, "?"))...); }; static constexpr auto dimensions_descriptor @@ -104,7 +104,8 @@ struct eigen_tensor_helper< return get_shape() == shape; } - static constexpr auto dimensions_descriptor = concat(const_name()...); + static constexpr auto dimensions_descriptor + = ::pybind11::detail::concat(const_name()...); template static Type *alloc(Args &&...args) { diff --git a/extern/pybind11/include/pybind11/functional.h b/extern/pybind11/include/pybind11/functional.h index 87ec4d10c..6856119cd 100644 --- a/extern/pybind11/include/pybind11/functional.h +++ b/extern/pybind11/include/pybind11/functional.h @@ -128,7 +128,8 @@ struct type_caster> { } PYBIND11_TYPE_CASTER(type, - const_name("Callable[[") + concat(make_caster::name...) + const_name("Callable[[") + + ::pybind11::detail::concat(make_caster::name...) + const_name("], ") + make_caster::name + const_name("]")); }; diff --git a/extern/pybind11/include/pybind11/gil.h b/extern/pybind11/include/pybind11/gil.h index 570a5581d..da22f48d7 100644 --- a/extern/pybind11/include/pybind11/gil.h +++ b/extern/pybind11/include/pybind11/gil.h @@ -11,6 +11,8 @@ #include "detail/common.h" +#include + #if defined(WITH_THREAD) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT) # include "detail/internals.h" #endif @@ -137,7 +139,9 @@ class gil_scoped_acquire { class gil_scoped_release { public: + // PRECONDITION: The GIL must be held when this constructor is called. explicit gil_scoped_release(bool disassoc = false) : disassoc(disassoc) { + assert(PyGILState_Check()); // `get_internals()` must be called here unconditionally in order to initialize // `internals.tstate` for subsequent `gil_scoped_acquire` calls. Otherwise, an // initialization race could occur as multiple threads try `gil_scoped_acquire`. @@ -201,7 +205,11 @@ class gil_scoped_release { PyThreadState *state; public: - gil_scoped_release() : state{PyEval_SaveThread()} {} + // PRECONDITION: The GIL must be held when this constructor is called. + gil_scoped_release() { + assert(PyGILState_Check()); + state = PyEval_SaveThread(); + } gil_scoped_release(const gil_scoped_release &) = delete; gil_scoped_release &operator=(const gil_scoped_release &) = delete; ~gil_scoped_release() { PyEval_RestoreThread(state); } diff --git a/extern/pybind11/include/pybind11/gil_safe_call_once.h b/extern/pybind11/include/pybind11/gil_safe_call_once.h new file mode 100644 index 000000000..eaf84d16e --- /dev/null +++ b/extern/pybind11/include/pybind11/gil_safe_call_once.h @@ -0,0 +1,91 @@ +// Copyright (c) 2023 The pybind Community. + +#pragma once + +#include "detail/common.h" +#include "gil.h" + +#include +#include + +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) + +// Use the `gil_safe_call_once_and_store` class below instead of the naive +// +// static auto imported_obj = py::module_::import("module_name"); // BAD, DO NOT USE! +// +// which has two serious issues: +// +// 1. Py_DECREF() calls potentially after the Python interpreter was finalized already, and +// 2. deadlocks in multi-threaded processes (because of missing lock ordering). +// +// The following alternative avoids both problems: +// +// PYBIND11_CONSTINIT static py::gil_safe_call_once_and_store storage; +// auto &imported_obj = storage // Do NOT make this `static`! +// .call_once_and_store_result([]() { +// return py::module_::import("module_name"); +// }) +// .get_stored(); +// +// The parameter of `call_once_and_store_result()` must be callable. It can make +// CPython API calls, and in particular, it can temporarily release the GIL. +// +// `T` can be any C++ type, it does not have to involve CPython API types. +// +// The behavior with regard to signals, e.g. `SIGINT` (`KeyboardInterrupt`), +// is not ideal. If the main thread is the one to actually run the `Callable`, +// then a `KeyboardInterrupt` will interrupt it if it is running normal Python +// code. The situation is different if a non-main thread runs the +// `Callable`, and then the main thread starts waiting for it to complete: +// a `KeyboardInterrupt` will not interrupt the non-main thread, but it will +// get processed only when it is the main thread's turn again and it is running +// normal Python code. However, this will be unnoticeable for quick call-once +// functions, which is usually the case. +template +class gil_safe_call_once_and_store { +public: + // PRECONDITION: The GIL must be held when `call_once_and_store_result()` is called. + template + gil_safe_call_once_and_store &call_once_and_store_result(Callable &&fn) { + if (!is_initialized_) { // This read is guarded by the GIL. + // Multiple threads may enter here, because the GIL is released in the next line and + // CPython API calls in the `fn()` call below may release and reacquire the GIL. + gil_scoped_release gil_rel; // Needed to establish lock ordering. + std::call_once(once_flag_, [&] { + // Only one thread will ever enter here. + gil_scoped_acquire gil_acq; + ::new (storage_) T(fn()); // fn may release, but will reacquire, the GIL. + is_initialized_ = true; // This write is guarded by the GIL. + }); + // All threads will observe `is_initialized_` as true here. + } + // Intentionally not returning `T &` to ensure the calling code is self-documenting. + return *this; + } + + // This must only be called after `call_once_and_store_result()` was called. + T &get_stored() { + assert(is_initialized_); + PYBIND11_WARNING_PUSH +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 5 + // Needed for gcc 4.8.5 + PYBIND11_WARNING_DISABLE_GCC("-Wstrict-aliasing") +#endif + return *reinterpret_cast(storage_); + PYBIND11_WARNING_POP + } + + constexpr gil_safe_call_once_and_store() = default; + PYBIND11_DTOR_CONSTEXPR ~gil_safe_call_once_and_store() = default; + +private: + alignas(T) char storage_[sizeof(T)] = {}; + std::once_flag once_flag_ = {}; + bool is_initialized_ = false; + // The `is_initialized_`-`storage_` pair is very similar to `std::optional`, + // but the latter does not have the triviality properties of former, + // therefore `std::optional` is not a viable alternative here. +}; + +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/extern/pybind11/include/pybind11/numpy.h b/extern/pybind11/include/pybind11/numpy.h index 36077ec04..03abc8e77 100644 --- a/extern/pybind11/include/pybind11/numpy.h +++ b/extern/pybind11/include/pybind11/numpy.h @@ -10,7 +10,10 @@ #pragma once #include "pybind11.h" +#include "detail/common.h" #include "complex.h" +#include "gil_safe_call_once.h" +#include "pytypes.h" #include #include @@ -26,10 +29,15 @@ #include #include +#if defined(PYBIND11_NUMPY_1_ONLY) && !defined(PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED) +# error PYBIND11_NUMPY_1_ONLY must be defined before any pybind11 header is included. +#endif + /* This will be true on all flat address space platforms and allows us to reduce the whole npy_intp / ssize_t / Py_intptr_t business down to just ssize_t for all size and dimension types (e.g. shape, strides, indexing), instead of inflicting this - upon the library user. */ + upon the library user. + Note that NumPy 2 now uses ssize_t for `npy_intp` to simplify this. */ static_assert(sizeof(::pybind11::ssize_t) == sizeof(Py_intptr_t), "ssize_t != Py_intptr_t"); static_assert(std::is_signed::value, "Py_intptr_t must be signed"); // We now can reinterpret_cast between py::ssize_t and Py_intptr_t (MSVC + PyPy cares) @@ -38,10 +46,16 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_WARNING_DISABLE_MSVC(4127) +class dtype; // Forward declaration class array; // Forward declaration PYBIND11_NAMESPACE_BEGIN(detail) +template <> +struct handle_type_name { + static constexpr auto name = const_name("numpy.dtype"); +}; + template <> struct handle_type_name { static constexpr auto name = const_name("numpy.ndarray"); @@ -50,7 +64,8 @@ struct handle_type_name { template struct npy_format_descriptor; -struct PyArrayDescr_Proxy { +/* NumPy 1 proxy (always includes legacy fields) */ +struct PyArrayDescr1_Proxy { PyObject_HEAD PyObject *typeobj; char kind; @@ -65,6 +80,43 @@ struct PyArrayDescr_Proxy { PyObject *names; }; +#ifndef PYBIND11_NUMPY_1_ONLY +struct PyArrayDescr_Proxy { + PyObject_HEAD + PyObject *typeobj; + char kind; + char type; + char byteorder; + char _former_flags; + int type_num; + /* Additional fields are NumPy version specific. */ +}; +#else +/* NumPy 1.x only, we can expose all fields */ +using PyArrayDescr_Proxy = PyArrayDescr1_Proxy; +#endif + +/* NumPy 2 proxy, including legacy fields */ +struct PyArrayDescr2_Proxy { + PyObject_HEAD + PyObject *typeobj; + char kind; + char type; + char byteorder; + char _former_flags; + int type_num; + std::uint64_t flags; + ssize_t elsize; + ssize_t alignment; + PyObject *metadata; + Py_hash_t hash; + void *reserved_null[2]; + /* The following fields only exist if 0 <= type_num < 2056 */ + char *subarray; + PyObject *fields; + PyObject *names; +}; + struct PyArray_Proxy { PyObject_HEAD char *data; @@ -120,6 +172,28 @@ inline numpy_internals &get_numpy_internals() { return *ptr; } +PYBIND11_NOINLINE module_ import_numpy_core_submodule(const char *submodule_name) { + module_ numpy = module_::import("numpy"); + str version_string = numpy.attr("__version__"); + + module_ numpy_lib = module_::import("numpy.lib"); + object numpy_version = numpy_lib.attr("NumpyVersion")(version_string); + int major_version = numpy_version.attr("major").cast(); + +#ifdef PYBIND11_NUMPY_1_ONLY + if (major_version >= 2) { + throw std::runtime_error( + "This extension was built with PYBIND11_NUMPY_1_ONLY defined, " + "but NumPy 2 is used in this process. For NumPy2 compatibility, " + "this extension needs to be rebuilt without the PYBIND11_NUMPY_1_ONLY define."); + } +#endif + /* `numpy.core` was renamed to `numpy._core` in NumPy 2.0 as it officially + became a private module. */ + std::string numpy_core_path = major_version >= 2 ? "numpy._core" : "numpy.core"; + return module_::import((numpy_core_path + "." + submodule_name).c_str()); +} + template struct same_size { template @@ -186,14 +260,16 @@ struct npy_api { NPY_ULONG_, NPY_ULONGLONG_, NPY_UINT_), }; + unsigned int PyArray_RUNTIME_VERSION_; + struct PyArray_Dims { Py_intptr_t *ptr; int len; }; static npy_api &get() { - static npy_api api = lookup(); - return api; + PYBIND11_CONSTINIT static gil_safe_call_once_and_store storage; + return storage.call_once_and_store_result(lookup).get_stored(); } bool PyArray_Check_(PyObject *obj) const { @@ -224,6 +300,7 @@ struct npy_api { PyObject *(*PyArray_FromAny_)(PyObject *, PyObject *, int, int, int, PyObject *); int (*PyArray_DescrConverter_)(PyObject *, PyObject **); bool (*PyArray_EquivTypes_)(PyObject *, PyObject *); +#ifdef PYBIND11_NUMPY_1_ONLY int (*PyArray_GetArrayParamsFromObject_)(PyObject *, PyObject *, unsigned char, @@ -232,6 +309,7 @@ struct npy_api { Py_intptr_t *, PyObject **, PyObject *); +#endif PyObject *(*PyArray_Squeeze_)(PyObject *); // Unused. Not removed because that affects ABI of the class. int (*PyArray_SetBaseObject_)(PyObject *, PyObject *); @@ -249,7 +327,8 @@ struct npy_api { API_PyArray_DescrFromScalar = 57, API_PyArray_FromAny = 69, API_PyArray_Resize = 80, - API_PyArray_CopyInto = 82, + // CopyInto was slot 82 and 50 was effectively an alias. NumPy 2 removed 82. + API_PyArray_CopyInto = 50, API_PyArray_NewCopy = 85, API_PyArray_NewFromDescr = 94, API_PyArray_DescrNewFromType = 96, @@ -258,18 +337,25 @@ struct npy_api { API_PyArray_View = 137, API_PyArray_DescrConverter = 174, API_PyArray_EquivTypes = 182, +#ifdef PYBIND11_NUMPY_1_ONLY API_PyArray_GetArrayParamsFromObject = 278, +#endif API_PyArray_SetBaseObject = 282 }; static npy_api lookup() { - module_ m = module_::import("numpy.core.multiarray"); + module_ m = detail::import_numpy_core_submodule("multiarray"); auto c = m.attr("_ARRAY_API"); void **api_ptr = (void **) PyCapsule_GetPointer(c.ptr(), nullptr); + if (api_ptr == nullptr) { + raise_from(PyExc_SystemError, "FAILURE obtaining numpy _ARRAY_API pointer."); + throw error_already_set(); + } npy_api api; #define DECL_NPY_API(Func) api.Func##_ = (decltype(api.Func##_)) api_ptr[API_##Func]; DECL_NPY_API(PyArray_GetNDArrayCFeatureVersion); - if (api.PyArray_GetNDArrayCFeatureVersion_() < 0x7) { + api.PyArray_RUNTIME_VERSION_ = api.PyArray_GetNDArrayCFeatureVersion_(); + if (api.PyArray_RUNTIME_VERSION_ < 0x7) { pybind11_fail("pybind11 numpy support requires numpy >= 1.7.0"); } DECL_NPY_API(PyArray_Type); @@ -288,7 +374,9 @@ struct npy_api { DECL_NPY_API(PyArray_View); DECL_NPY_API(PyArray_DescrConverter); DECL_NPY_API(PyArray_EquivTypes); +#ifdef PYBIND11_NUMPY_1_ONLY DECL_NPY_API(PyArray_GetArrayParamsFromObject); +#endif DECL_NPY_API(PyArray_SetBaseObject); #undef DECL_NPY_API @@ -310,6 +398,14 @@ inline const PyArrayDescr_Proxy *array_descriptor_proxy(const PyObject *ptr) { return reinterpret_cast(ptr); } +inline const PyArrayDescr1_Proxy *array_descriptor1_proxy(const PyObject *ptr) { + return reinterpret_cast(ptr); +} + +inline const PyArrayDescr2_Proxy *array_descriptor2_proxy(const PyObject *ptr) { + return reinterpret_cast(ptr); +} + inline bool check_flags(const void *ptr, int flag) { return (flag == (array_proxy(ptr)->flags & flag)); } @@ -350,7 +446,7 @@ struct array_info> { } static constexpr auto extents = const_name::is_array>( - concat(const_name(), array_info::extents), const_name()); + ::pybind11::detail::concat(const_name(), array_info::extents), const_name()); }; // For numpy we have special handling for arrays of characters, so we don't include // the size in the array extents. @@ -589,10 +685,32 @@ class dtype : public object { } /// Size of the data type in bytes. +#ifdef PYBIND11_NUMPY_1_ONLY ssize_t itemsize() const { return detail::array_descriptor_proxy(m_ptr)->elsize; } +#else + ssize_t itemsize() const { + if (detail::npy_api::get().PyArray_RUNTIME_VERSION_ < 0x12) { + return detail::array_descriptor1_proxy(m_ptr)->elsize; + } + return detail::array_descriptor2_proxy(m_ptr)->elsize; + } +#endif /// Returns true for structured data types. +#ifdef PYBIND11_NUMPY_1_ONLY bool has_fields() const { return detail::array_descriptor_proxy(m_ptr)->names != nullptr; } +#else + bool has_fields() const { + if (detail::npy_api::get().PyArray_RUNTIME_VERSION_ < 0x12) { + return detail::array_descriptor1_proxy(m_ptr)->names != nullptr; + } + const auto *proxy = detail::array_descriptor2_proxy(m_ptr); + if (proxy->type_num < 0 || proxy->type_num >= 2056) { + return false; + } + return proxy->names != nullptr; + } +#endif /// Single-character code for dtype's kind. /// For example, floating point types are 'f' and integral types are 'i'. @@ -618,20 +736,39 @@ class dtype : public object { /// Single character for byteorder char byteorder() const { return detail::array_descriptor_proxy(m_ptr)->byteorder; } - /// Alignment of the data type +/// Alignment of the data type +#ifdef PYBIND11_NUMPY_1_ONLY int alignment() const { return detail::array_descriptor_proxy(m_ptr)->alignment; } +#else + ssize_t alignment() const { + if (detail::npy_api::get().PyArray_RUNTIME_VERSION_ < 0x12) { + return detail::array_descriptor1_proxy(m_ptr)->alignment; + } + return detail::array_descriptor2_proxy(m_ptr)->alignment; + } +#endif - /// Flags for the array descriptor +/// Flags for the array descriptor +#ifdef PYBIND11_NUMPY_1_ONLY char flags() const { return detail::array_descriptor_proxy(m_ptr)->flags; } +#else + std::uint64_t flags() const { + if (detail::npy_api::get().PyArray_RUNTIME_VERSION_ < 0x12) { + return (unsigned char) detail::array_descriptor1_proxy(m_ptr)->flags; + } + return detail::array_descriptor2_proxy(m_ptr)->flags; + } +#endif private: - static object _dtype_from_pep3118() { - static PyObject *obj = module_::import("numpy.core._internal") - .attr("_dtype_from_pep3118") - .cast() - .release() - .ptr(); - return reinterpret_borrow(obj); + static object &_dtype_from_pep3118() { + PYBIND11_CONSTINIT static gil_safe_call_once_and_store storage; + return storage + .call_once_and_store_result([]() { + return detail::import_numpy_core_submodule("_internal") + .attr("_dtype_from_pep3118"); + }) + .get_stored(); } dtype strip_padding(ssize_t itemsize) { @@ -788,9 +925,7 @@ class array : public buffer { } /// Byte size of a single element - ssize_t itemsize() const { - return detail::array_descriptor_proxy(detail::array_proxy(m_ptr)->descr)->elsize; - } + ssize_t itemsize() const { return dtype().itemsize(); } /// Total number of bytes ssize_t nbytes() const { return size() * itemsize(); } @@ -1008,7 +1143,7 @@ class array : public buffer { /// Create array from any object -- always returns a new reference static PyObject *raw_array(PyObject *ptr, int ExtraFlags = 0) { if (ptr == nullptr) { - PyErr_SetString(PyExc_ValueError, "cannot create a pybind11::array from a nullptr"); + set_error(PyExc_ValueError, "cannot create a pybind11::array from a nullptr"); return nullptr; } return detail::npy_api::get().PyArray_FromAny_( @@ -1155,7 +1290,7 @@ class array_t : public array { /// Create array from any object -- always returns a new reference static PyObject *raw_array_t(PyObject *ptr) { if (ptr == nullptr) { - PyErr_SetString(PyExc_ValueError, "cannot create a pybind11::array_t from a nullptr"); + set_error(PyExc_ValueError, "cannot create a pybind11::array_t from a nullptr"); return nullptr; } return detail::npy_api::get().PyArray_FromAny_(ptr, diff --git a/extern/pybind11/include/pybind11/pybind11.h b/extern/pybind11/include/pybind11/pybind11.h index 3bce1a01b..429d2138d 100644 --- a/extern/pybind11/include/pybind11/pybind11.h +++ b/extern/pybind11/include/pybind11/pybind11.h @@ -14,7 +14,9 @@ #include "detail/init.h" #include "attr.h" #include "gil.h" +#include "gil_safe_call_once.h" #include "options.h" +#include "typing.h" #include #include @@ -52,6 +54,47 @@ PYBIND11_WARNING_DISABLE_MSVC(4127) PYBIND11_NAMESPACE_BEGIN(detail) +inline std::string replace_newlines_and_squash(const char *text) { + const char *whitespaces = " \t\n\r\f\v"; + std::string result(text); + bool previous_is_whitespace = false; + + if (result.size() >= 2) { + // Do not modify string representations + char first_char = result[0]; + char last_char = result[result.size() - 1]; + if (first_char == last_char && first_char == '\'') { + return result; + } + } + result.clear(); + + // Replace characters in whitespaces array with spaces and squash consecutive spaces + while (*text != '\0') { + if (std::strchr(whitespaces, *text)) { + if (!previous_is_whitespace) { + result += ' '; + previous_is_whitespace = true; + } + } else { + result += *text; + previous_is_whitespace = false; + } + ++text; + } + + // Strip leading and trailing whitespaces + const size_t str_begin = result.find_first_not_of(whitespaces); + if (str_begin == std::string::npos) { + return ""; + } + + const size_t str_end = result.find_last_not_of(whitespaces); + const size_t str_range = str_end - str_begin + 1; + + return result.substr(str_begin, str_range); +} + // Apply all the extensions translators from a list // Return true if one of the translators completed without raising an exception // itself. Return of false indicates that if there are other translators @@ -424,7 +467,7 @@ class cpp_function : public function { // Write default value if available. if (!is_starred && arg_index < rec->args.size() && rec->args[arg_index].descr) { signature += " = "; - signature += rec->args[arg_index].descr; + signature += detail::replace_newlines_and_squash(rec->args[arg_index].descr); } // Separator for positional-only arguments (placed after the // argument, rather than before like * @@ -449,9 +492,7 @@ class cpp_function : public function { signature += rec->scope.attr("__module__").cast() + "." + rec->scope.attr("__qualname__").cast(); } else { - std::string tname(t->name()); - detail::clean_type_id(tname); - signature += tname; + signature += detail::quote_cpp_type_name(detail::clean_type_id(t->name())); } } else { signature += c; @@ -680,7 +721,7 @@ class cpp_function : public function { /* Iterator over the list of potentially admissible overloads */ const function_record *overloads = reinterpret_cast( PyCapsule_GetPointer(self, get_function_record_capsule_name())), - *it = overloads; + *current_overload = overloads; assert(overloads != nullptr); /* Need to know how many arguments + keyword arguments there are to pick the right @@ -694,9 +735,8 @@ class cpp_function : public function { if (overloads->is_constructor) { if (!parent || !PyObject_TypeCheck(parent.ptr(), (PyTypeObject *) overloads->scope.ptr())) { - PyErr_SetString( - PyExc_TypeError, - "__init__(self, ...) called with invalid or missing `self` argument"); + set_error(PyExc_TypeError, + "__init__(self, ...) called with invalid or missing `self` argument"); return nullptr; } @@ -719,9 +759,10 @@ class cpp_function : public function { std::vector second_pass; // However, if there are no overloads, we can just skip the no-convert pass entirely - const bool overloaded = it != nullptr && it->next != nullptr; + const bool overloaded + = current_overload != nullptr && current_overload->next != nullptr; - for (; it != nullptr; it = it->next) { + for (; current_overload != nullptr; current_overload = current_overload->next) { /* For each overload: 1. Copy all positional arguments we were given, also checking to make sure that @@ -742,7 +783,7 @@ class cpp_function : public function { a result other than PYBIND11_TRY_NEXT_OVERLOAD. */ - const function_record &func = *it; + const function_record &func = *current_overload; size_t num_args = func.nargs; // Number of positional arguments that we need if (func.has_args) { --num_args; // (but don't count py::args @@ -980,10 +1021,10 @@ class cpp_function : public function { } if (result.ptr() != PYBIND11_TRY_NEXT_OVERLOAD) { - // The error reporting logic below expects 'it' to be valid, as it would be - // if we'd encountered this failure in the first-pass loop. + // The error reporting logic below expects 'current_overload' to be valid, + // as it would be if we'd encountered this failure in the first-pass loop. if (!result) { - it = &call.func; + current_overload = &call.func; } break; } @@ -1007,7 +1048,7 @@ class cpp_function : public function { A translator may choose to do one of the following: - - catch the exception and call PyErr_SetString or PyErr_SetObject + - catch the exception and call py::set_error() to set a standard (or custom) Python exception, or - do nothing and let the exception fall through to the next translator, or - delegate translation to the next translator by throwing a new type of exception. @@ -1023,8 +1064,7 @@ class cpp_function : public function { return nullptr; } - PyErr_SetString(PyExc_SystemError, - "Exception escaped from default exception translator!"); + set_error(PyExc_SystemError, "Exception escaped from default exception translator!"); return nullptr; } @@ -1102,7 +1142,7 @@ class cpp_function : public function { } msg += "kwargs: "; bool first = true; - for (auto kwarg : kwargs) { + for (const auto &kwarg : kwargs) { if (first) { first = false; } else { @@ -1125,20 +1165,21 @@ class cpp_function : public function { raise_from(PyExc_TypeError, msg.c_str()); return nullptr; } - PyErr_SetString(PyExc_TypeError, msg.c_str()); + set_error(PyExc_TypeError, msg.c_str()); return nullptr; } if (!result) { std::string msg = "Unable to convert function return value to a " "Python type! The signature was\n\t"; - msg += it->signature; + assert(current_overload != nullptr); + msg += current_overload->signature; append_note_if_missing_header_is_suspected(msg); // Attach additional error info to the exception if supported if (PyErr_Occurred()) { raise_from(PyExc_TypeError, msg.c_str()); return nullptr; } - PyErr_SetString(PyExc_TypeError, msg.c_str()); + set_error(PyExc_TypeError, msg.c_str()); return nullptr; } if (overloads->is_constructor && !self_value_and_holder.holder_constructed()) { @@ -1149,6 +1190,15 @@ class cpp_function : public function { } }; +PYBIND11_NAMESPACE_BEGIN(detail) + +template <> +struct handle_type_name { + static constexpr auto name = const_name("Callable"); +}; + +PYBIND11_NAMESPACE_END(detail) + /// Wrapper for Python extension modules class module_ : public object { public: @@ -1276,6 +1326,15 @@ class module_ : public object { } }; +PYBIND11_NAMESPACE_BEGIN(detail) + +template <> +struct handle_type_name { + static constexpr auto name = const_name("module"); +}; + +PYBIND11_NAMESPACE_END(detail) + // When inside a namespace (or anywhere as long as it's not the first item on a line), // C++20 allows "module" to be used. This is provided for backward compatibility, and for // simplicity, if someone wants to use py::module for example, that is perfectly safe. @@ -1977,7 +2036,7 @@ struct enum_base { object type_name = type::handle_of(arg).attr("__name__"); return pybind11::str("{}.{}").format(std::move(type_name), enum_name(arg)); }, - name("name"), + name("__str__"), is_method(m_base)); if (options::show_enum_members_docstring()) { @@ -2395,7 +2454,7 @@ iterator make_iterator_impl(Iterator first, Sentinel last, Extra &&...extra) { Policy); } - return cast(state{first, last, true}); + return cast(state{std::forward(first), std::forward(last), true}); } PYBIND11_NAMESPACE_END(detail) @@ -2406,13 +2465,15 @@ template ::result_type, typename... Extra> -iterator make_iterator(Iterator first, Sentinel last, Extra &&...extra) { +typing::Iterator make_iterator(Iterator first, Sentinel last, Extra &&...extra) { return detail::make_iterator_impl, Policy, Iterator, Sentinel, ValueType, - Extra...>(first, last, std::forward(extra)...); + Extra...>(std::forward(first), + std::forward(last), + std::forward(extra)...); } /// Makes a python iterator over the keys (`.first`) of a iterator over pairs from a @@ -2422,13 +2483,15 @@ template ::result_type, typename... Extra> -iterator make_key_iterator(Iterator first, Sentinel last, Extra &&...extra) { +typing::Iterator make_key_iterator(Iterator first, Sentinel last, Extra &&...extra) { return detail::make_iterator_impl, Policy, Iterator, Sentinel, KeyType, - Extra...>(first, last, std::forward(extra)...); + Extra...>(std::forward(first), + std::forward(last), + std::forward(extra)...); } /// Makes a python iterator over the values (`.second`) of a iterator over pairs from a @@ -2438,21 +2501,25 @@ template ::result_type, typename... Extra> -iterator make_value_iterator(Iterator first, Sentinel last, Extra &&...extra) { +typing::Iterator make_value_iterator(Iterator first, Sentinel last, Extra &&...extra) { return detail::make_iterator_impl, Policy, Iterator, Sentinel, ValueType, - Extra...>(first, last, std::forward(extra)...); + Extra...>(std::forward(first), + std::forward(last), + std::forward(extra)...); } /// Makes an iterator over values of an stl container or other container supporting /// `std::begin()`/`std::end()` template ()))>::result_type, typename... Extra> -iterator make_iterator(Type &value, Extra &&...extra) { +typing::Iterator make_iterator(Type &value, Extra &&...extra) { return make_iterator( std::begin(value), std::end(value), std::forward(extra)...); } @@ -2461,8 +2528,10 @@ iterator make_iterator(Type &value, Extra &&...extra) { /// `std::begin()`/`std::end()` template ()))>::result_type, typename... Extra> -iterator make_key_iterator(Type &value, Extra &&...extra) { +typing::Iterator make_key_iterator(Type &value, Extra &&...extra) { return make_key_iterator( std::begin(value), std::end(value), std::forward(extra)...); } @@ -2471,8 +2540,10 @@ iterator make_key_iterator(Type &value, Extra &&...extra) { /// `std::begin()`/`std::end()` template ()))>::result_type, typename... Extra> -iterator make_value_iterator(Type &value, Extra &&...extra) { +typing::Iterator make_value_iterator(Type &value, Extra &&...extra) { return make_value_iterator( std::begin(value), std::end(value), std::forward(extra)...); } @@ -2528,7 +2599,7 @@ inline void register_local_exception_translator(ExceptionTranslator &&translator /** * Wrapper to generate a new Python exception type. * - * This should only be used with PyErr_SetString for now. + * This should only be used with py::set_error() for now. * It is not (yet) possible to use as a py::base. * Template type argument is reserved for future use. */ @@ -2549,27 +2620,25 @@ class exception : public object { } // Sets the current python exception to this exception object with the given message - void operator()(const char *message) { PyErr_SetString(m_ptr, message); } + PYBIND11_DEPRECATED("Please use py::set_error() instead " + "(https://github.com/pybind/pybind11/pull/4772)") + void operator()(const char *message) const { set_error(*this, message); } }; PYBIND11_NAMESPACE_BEGIN(detail) -// Returns a reference to a function-local static exception object used in the simple -// register_exception approach below. (It would be simpler to have the static local variable -// directly in register_exception, but that makes clang <3.5 segfault - issue #1349). -template -exception &get_exception_object() { - static exception ex; - return ex; -} + +template <> +struct handle_type_name> { + static constexpr auto name = const_name("Exception"); +}; // Helper function for register_exception and register_local_exception template exception & register_exception_impl(handle scope, const char *name, handle base, bool isLocal) { - auto &ex = detail::get_exception_object(); - if (!ex) { - ex = exception(scope, name, base); - } + PYBIND11_CONSTINIT static gil_safe_call_once_and_store> exc_storage; + exc_storage.call_once_and_store_result( + [&]() { return exception(scope, name, base); }); auto register_func = isLocal ? ®ister_local_exception_translator : ®ister_exception_translator; @@ -2581,10 +2650,10 @@ register_exception_impl(handle scope, const char *name, handle base, bool isLoca try { std::rethrow_exception(p); } catch (const CppException &e) { - detail::get_exception_object()(e.what()); + set_error(exc_storage.get_stored(), e.what()); } }); - return ex; + return exc_storage.get_stored(); } PYBIND11_NAMESPACE_END(detail) @@ -2703,7 +2772,11 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char * if ((std::string) str(f_code->co_name) == name && f_code->co_argcount > 0) { PyObject *locals = PyEval_GetLocals(); if (locals != nullptr) { +# if PY_VERSION_HEX >= 0x030b0000 + PyObject *co_varnames = PyCode_GetVarnames(f_code); +# else PyObject *co_varnames = PyObject_GetAttrString((PyObject *) f_code, "co_varnames"); +# endif PyObject *self_arg = PyTuple_GET_ITEM(co_varnames, 0); Py_DECREF(co_varnames); PyObject *self_caller = dict_getitem(locals, self_arg); diff --git a/extern/pybind11/include/pybind11/pytypes.h b/extern/pybind11/include/pybind11/pytypes.h index 64aad6347..d5f6af8e0 100644 --- a/extern/pybind11/include/pybind11/pytypes.h +++ b/extern/pybind11/include/pybind11/pytypes.h @@ -59,6 +59,7 @@ struct sequence_item; struct list_item; struct tuple_item; } // namespace accessor_policies +// PLEASE KEEP handle_type_name SPECIALIZATIONS IN SYNC. using obj_attr_accessor = accessor; using str_attr_accessor = accessor; using item_accessor = accessor; @@ -305,19 +306,19 @@ class handle : public detail::object_api { "https://pybind11.readthedocs.io/en/stable/advanced/" "misc.html#common-sources-of-global-interpreter-lock-errors for debugging advice.\n" "If you are convinced there is no bug in your code, you can #define " - "PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF" + "PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF " "to disable this check. In that case you have to ensure this #define is consistently " "used for all translation units linked into a given pybind11 extension, otherwise " "there will be ODR violations.", function_name.c_str()); - fflush(stderr); if (Py_TYPE(m_ptr)->tp_name != nullptr) { fprintf(stderr, - "The failing %s call was triggered on a %s object.\n", + " The failing %s call was triggered on a %s object.", function_name.c_str(), Py_TYPE(m_ptr)->tp_name); - fflush(stderr); } + fprintf(stderr, "\n"); + fflush(stderr); throw std::runtime_error(function_name + " PyGILState_Check() failure."); } #endif @@ -334,6 +335,14 @@ class handle : public detail::object_api { #endif }; +inline void set_error(const handle &type, const char *message) { + PyErr_SetString(type.ptr(), message); +} + +inline void set_error(const handle &type, const handle &value) { + PyErr_SetObject(type.ptr(), value.ptr()); +} + /** \rst Holds a reference to a Python object (with reference counting) @@ -1612,7 +1621,15 @@ inline namespace literals { /** \rst String literal version of `str` \endrst */ -inline str operator"" _s(const char *s, size_t size) { return {s, size}; } +inline str +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 5 +operator"" _s // gcc 4.8.5 insists on having a space (hard error). +#else +operator""_s // clang 17 generates a deprecation warning if there is a space. +#endif + (const char *s, size_t size) { + return {s, size}; +} } // namespace literals /// \addtogroup pytypes diff --git a/extern/pybind11/include/pybind11/stl.h b/extern/pybind11/include/pybind11/stl.h index f39f44f7c..71bc5902e 100644 --- a/extern/pybind11/include/pybind11/stl.h +++ b/extern/pybind11/include/pybind11/stl.h @@ -100,7 +100,7 @@ struct set_caster { return s.release(); } - PYBIND11_TYPE_CASTER(type, const_name("Set[") + key_conv::name + const_name("]")); + PYBIND11_TYPE_CASTER(type, const_name("set[") + key_conv::name + const_name("]")); }; template @@ -157,7 +157,7 @@ struct map_caster { } PYBIND11_TYPE_CASTER(Type, - const_name("Dict[") + key_conv::name + const_name(", ") + value_conv::name + const_name("dict[") + key_conv::name + const_name(", ") + value_conv::name + const_name("]")); }; @@ -172,7 +172,7 @@ struct list_caster { auto s = reinterpret_borrow(src); value.clear(); reserve_maybe(s, &value); - for (auto it : s) { + for (const auto &it : s) { value_conv conv; if (!conv.load(it, convert)) { return false; @@ -208,7 +208,7 @@ struct list_caster { return l.release(); } - PYBIND11_TYPE_CASTER(Type, const_name("List[") + value_conv::name + const_name("]")); + PYBIND11_TYPE_CASTER(Type, const_name("list[") + value_conv::name + const_name("]")); }; template @@ -247,7 +247,7 @@ struct array_caster { return false; } size_t ctr = 0; - for (auto it : l) { + for (const auto &it : l) { value_conv conv; if (!conv.load(it, convert)) { return false; @@ -274,7 +274,7 @@ struct array_caster { PYBIND11_TYPE_CASTER(ArrayType, const_name(const_name(""), const_name("Annotated[")) - + const_name("List[") + value_conv::name + const_name("]") + + const_name("list[") + value_conv::name + const_name("]") + const_name(const_name(""), const_name(", FixedSize(") + const_name() + const_name(")]"))); @@ -421,7 +421,8 @@ struct variant_caster> { using Type = V; PYBIND11_TYPE_CASTER(Type, - const_name("Union[") + detail::concat(make_caster::name...) + const_name("Union[") + + ::pybind11::detail::concat(make_caster::name...) + const_name("]")); }; diff --git a/extern/pybind11/include/pybind11/stl_bind.h b/extern/pybind11/include/pybind11/stl_bind.h index 49f1b7782..a226cbc0e 100644 --- a/extern/pybind11/include/pybind11/stl_bind.h +++ b/extern/pybind11/include/pybind11/stl_bind.h @@ -525,7 +525,7 @@ class_ bind_vector(handle scope, std::string const &name, A [](const Vector &v) -> bool { return !v.empty(); }, "Check whether the list is nonempty"); - cl.def("__len__", &Vector::size); + cl.def("__len__", [](const Vector &vec) { return vec.size(); }); #if 0 // C++ style functions deprecated, leaving it here as an example @@ -645,49 +645,50 @@ auto map_if_insertion_operator(Class_ &cl, std::string const &name) "Return the canonical string representation of this map."); } -template struct keys_view { virtual size_t len() = 0; virtual iterator iter() = 0; - virtual bool contains(const KeyType &k) = 0; - virtual bool contains(const object &k) = 0; + virtual bool contains(const handle &k) = 0; virtual ~keys_view() = default; }; -template struct values_view { virtual size_t len() = 0; virtual iterator iter() = 0; virtual ~values_view() = default; }; -template struct items_view { virtual size_t len() = 0; virtual iterator iter() = 0; virtual ~items_view() = default; }; -template -struct KeysViewImpl : public KeysView { +template +struct KeysViewImpl : public detail::keys_view { explicit KeysViewImpl(Map &map) : map(map) {} size_t len() override { return map.size(); } iterator iter() override { return make_key_iterator(map.begin(), map.end()); } - bool contains(const typename Map::key_type &k) override { return map.find(k) != map.end(); } - bool contains(const object &) override { return false; } + bool contains(const handle &k) override { + try { + return map.find(k.template cast()) != map.end(); + } catch (const cast_error &) { + return false; + } + } Map ↦ }; -template -struct ValuesViewImpl : public ValuesView { +template +struct ValuesViewImpl : public detail::values_view { explicit ValuesViewImpl(Map &map) : map(map) {} size_t len() override { return map.size(); } iterator iter() override { return make_value_iterator(map.begin(), map.end()); } Map ↦ }; -template -struct ItemsViewImpl : public ItemsView { +template +struct ItemsViewImpl : public detail::items_view { explicit ItemsViewImpl(Map &map) : map(map) {} size_t len() override { return map.size(); } iterator iter() override { return make_iterator(map.begin(), map.end()); } @@ -700,11 +701,9 @@ template , typename... class_ bind_map(handle scope, const std::string &name, Args &&...args) { using KeyType = typename Map::key_type; using MappedType = typename Map::mapped_type; - using StrippedKeyType = detail::remove_cvref_t; - using StrippedMappedType = detail::remove_cvref_t; - using KeysView = detail::keys_view; - using ValuesView = detail::values_view; - using ItemsView = detail::items_view; + using KeysView = detail::keys_view; + using ValuesView = detail::values_view; + using ItemsView = detail::items_view; using Class_ = class_; // If either type is a non-module-local bound type then make the map binding non-local as well; @@ -718,39 +717,20 @@ class_ bind_map(handle scope, const std::string &name, Args && } Class_ cl(scope, name.c_str(), pybind11::module_local(local), std::forward(args)...); - static constexpr auto key_type_descr = detail::make_caster::name; - static constexpr auto mapped_type_descr = detail::make_caster::name; - std::string key_type_name(key_type_descr.text), mapped_type_name(mapped_type_descr.text); - // If key type isn't properly wrapped, fall back to C++ names - if (key_type_name == "%") { - key_type_name = detail::type_info_description(typeid(KeyType)); - } - // Similarly for value type: - if (mapped_type_name == "%") { - mapped_type_name = detail::type_info_description(typeid(MappedType)); - } - - // Wrap KeysView[KeyType] if it wasn't already wrapped + // Wrap KeysView if it wasn't already wrapped if (!detail::get_type_info(typeid(KeysView))) { - class_ keys_view( - scope, ("KeysView[" + key_type_name + "]").c_str(), pybind11::module_local(local)); + class_ keys_view(scope, "KeysView", pybind11::module_local(local)); keys_view.def("__len__", &KeysView::len); keys_view.def("__iter__", &KeysView::iter, keep_alive<0, 1>() /* Essential: keep view alive while iterator exists */ ); - keys_view.def("__contains__", - static_cast(&KeysView::contains)); - // Fallback for when the object is not of the key type - keys_view.def("__contains__", - static_cast(&KeysView::contains)); + keys_view.def("__contains__", &KeysView::contains); } // Similarly for ValuesView: if (!detail::get_type_info(typeid(ValuesView))) { - class_ values_view(scope, - ("ValuesView[" + mapped_type_name + "]").c_str(), - pybind11::module_local(local)); + class_ values_view(scope, "ValuesView", pybind11::module_local(local)); values_view.def("__len__", &ValuesView::len); values_view.def("__iter__", &ValuesView::iter, @@ -759,10 +739,7 @@ class_ bind_map(handle scope, const std::string &name, Args && } // Similarly for ItemsView: if (!detail::get_type_info(typeid(ItemsView))) { - class_ items_view( - scope, - ("ItemsView[" + key_type_name + ", ").append(mapped_type_name + "]").c_str(), - pybind11::module_local(local)); + class_ items_view(scope, "ItemsView", pybind11::module_local(local)); items_view.def("__len__", &ItemsView::len); items_view.def("__iter__", &ItemsView::iter, @@ -788,25 +765,19 @@ class_ bind_map(handle scope, const std::string &name, Args && cl.def( "keys", - [](Map &m) { - return std::unique_ptr(new detail::KeysViewImpl(m)); - }, + [](Map &m) { return std::unique_ptr(new detail::KeysViewImpl(m)); }, keep_alive<0, 1>() /* Essential: keep map alive while view exists */ ); cl.def( "values", - [](Map &m) { - return std::unique_ptr(new detail::ValuesViewImpl(m)); - }, + [](Map &m) { return std::unique_ptr(new detail::ValuesViewImpl(m)); }, keep_alive<0, 1>() /* Essential: keep map alive while view exists */ ); cl.def( "items", - [](Map &m) { - return std::unique_ptr(new detail::ItemsViewImpl(m)); - }, + [](Map &m) { return std::unique_ptr(new detail::ItemsViewImpl(m)); }, keep_alive<0, 1>() /* Essential: keep map alive while view exists */ ); @@ -843,7 +814,8 @@ class_ bind_map(handle scope, const std::string &name, Args && m.erase(it); }); - cl.def("__len__", &Map::size); + // Always use a lambda in case of `using` declaration + cl.def("__len__", [](const Map &m) { return m.size(); }); return cl; } diff --git a/extern/pybind11/include/pybind11/typing.h b/extern/pybind11/include/pybind11/typing.h new file mode 100644 index 000000000..bc275fc50 --- /dev/null +++ b/extern/pybind11/include/pybind11/typing.h @@ -0,0 +1,125 @@ +/* + pybind11/typing.h: Convenience wrapper classes for basic Python types + with more explicit annotations. + + Copyright (c) 2023 Dustin Spicuzza + + All rights reserved. Use of this source code is governed by a + BSD-style license that can be found in the LICENSE file. +*/ + +#pragma once + +#include "detail/common.h" +#include "cast.h" +#include "pytypes.h" + +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(typing) + +/* + The following types can be used to direct pybind11-generated docstrings + to have have more explicit types (e.g., `list[str]` instead of `list`). + Just use these in place of existing types. + + There is no additional enforcement of types at runtime. +*/ + +template +class Tuple : public tuple { + using tuple::tuple; +}; + +template +class Dict : public dict { + using dict::dict; +}; + +template +class List : public list { + using list::list; +}; + +template +class Set : public set { + using set::set; +}; + +template +class Iterable : public iterable { + using iterable::iterable; +}; + +template +class Iterator : public iterator { + using iterator::iterator; +}; + +template +class Callable; + +template +class Callable : public function { + using function::function; +}; + +PYBIND11_NAMESPACE_END(typing) + +PYBIND11_NAMESPACE_BEGIN(detail) + +template +struct handle_type_name> { + static constexpr auto name = const_name("tuple[") + + ::pybind11::detail::concat(make_caster::name...) + + const_name("]"); +}; + +template <> +struct handle_type_name> { + // PEP 484 specifies this syntax for an empty tuple + static constexpr auto name = const_name("tuple[()]"); +}; + +template +struct handle_type_name> { + // PEP 484 specifies this syntax for a variable-length tuple + static constexpr auto name + = const_name("tuple[") + make_caster::name + const_name(", ...]"); +}; + +template +struct handle_type_name> { + static constexpr auto name = const_name("dict[") + make_caster::name + const_name(", ") + + make_caster::name + const_name("]"); +}; + +template +struct handle_type_name> { + static constexpr auto name = const_name("list[") + make_caster::name + const_name("]"); +}; + +template +struct handle_type_name> { + static constexpr auto name = const_name("set[") + make_caster::name + const_name("]"); +}; + +template +struct handle_type_name> { + static constexpr auto name = const_name("Iterable[") + make_caster::name + const_name("]"); +}; + +template +struct handle_type_name> { + static constexpr auto name = const_name("Iterator[") + make_caster::name + const_name("]"); +}; + +template +struct handle_type_name> { + using retval_type = conditional_t::value, void_type, Return>; + static constexpr auto name + = const_name("Callable[[") + ::pybind11::detail::concat(make_caster::name...) + + const_name("], ") + make_caster::name + const_name("]"); +}; + +PYBIND11_NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/extern/pybind11/noxfile.py b/extern/pybind11/noxfile.py index 021ced245..f95b64912 100644 --- a/extern/pybind11/noxfile.py +++ b/extern/pybind11/noxfile.py @@ -57,7 +57,7 @@ def tests_packaging(session: nox.Session) -> None: Run the packaging tests. """ - session.install("-r", "tests/requirements.txt", "--prefer-binary") + session.install("-r", "tests/requirements.txt") session.run("pytest", "tests/extra_python_package", *session.posargs) diff --git a/extern/pybind11/pybind11/_version.py b/extern/pybind11/pybind11/_version.py index 9280fa054..ab5a7bf5f 100644 --- a/extern/pybind11/pybind11/_version.py +++ b/extern/pybind11/pybind11/_version.py @@ -8,5 +8,5 @@ def _to_int(s: str) -> Union[int, str]: return s -__version__ = "2.11.1" +__version__ = "2.12.0" version_info = tuple(_to_int(s) for s in __version__.split(".")) diff --git a/extern/pybind11/pybind11/setup_helpers.py b/extern/pybind11/pybind11/setup_helpers.py index aeeee9dcf..3b16dca88 100644 --- a/extern/pybind11/pybind11/setup_helpers.py +++ b/extern/pybind11/pybind11/setup_helpers.py @@ -66,7 +66,9 @@ from setuptools import Extension as _Extension from setuptools.command.build_ext import build_ext as _build_ext except ImportError: - from distutils.command.build_ext import build_ext as _build_ext # type: ignore[assignment] + from distutils.command.build_ext import ( # type: ignore[assignment] + build_ext as _build_ext, + ) from distutils.extension import Extension as _Extension # type: ignore[assignment] import distutils.ccompiler diff --git a/extern/pybind11/pyproject.toml b/extern/pybind11/pyproject.toml index 59c15ea63..5af6015a6 100644 --- a/extern/pybind11/pyproject.toml +++ b/extern/pybind11/pyproject.toml @@ -19,7 +19,7 @@ ignore = [ [tool.mypy] files = ["pybind11"] -python_version = "3.6" +python_version = "3.7" strict = true show_error_codes = true enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] @@ -57,10 +57,12 @@ messages_control.disable = [ "unused-argument", # covered by Ruff ARG ] - [tool.ruff] -select = [ - "E", "F", "W", # flake8 +target-version = "py37" +src = ["src"] + +[tool.ruff.lint] +extend-select = [ "B", # flake8-bugbear "I", # isort "N", # pep8-naming @@ -68,7 +70,6 @@ select = [ "C4", # flake8-comprehensions "EM", # flake8-errmsg "ICN", # flake8-import-conventions - "ISC", # flake8-implicit-str-concat "PGH", # pygrep-hooks "PIE", # flake8-pie "PL", # pylint @@ -86,13 +87,9 @@ ignore = [ "PT004", # Fixture that doesn't return needs underscore (no, it is fine) "SIM118", # iter(x) is not always the same as iter(x.keys()) ] -target-version = "py37" -src = ["src"] unfixable = ["T20"] -exclude = [] -line-length = 120 isort.known-first-party = ["env", "pybind11_cross_module_tests", "pybind11_tests"] -[tool.ruff.per-file-ignores] -"tests/**" = ["EM", "N"] +[tool.ruff.lint.per-file-ignores] +"tests/**" = ["EM", "N", "E721"] "tests/test_call_policies.py" = ["PLC1901"] diff --git a/extern/pybind11/tests/CMakeLists.txt b/extern/pybind11/tests/CMakeLists.txt index 80ee9c1f1..e347a2e5c 100644 --- a/extern/pybind11/tests/CMakeLists.txt +++ b/extern/pybind11/tests/CMakeLists.txt @@ -7,13 +7,13 @@ cmake_minimum_required(VERSION 3.5) -# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with +# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with # some versions of VS that have a patched CMake 3.11. This forces us to emulate # the behavior using the following workaround: -if(${CMAKE_VERSION} VERSION_LESS 3.26) +if(${CMAKE_VERSION} VERSION_LESS 3.27) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) else() - cmake_policy(VERSION 3.26) + cmake_policy(VERSION 3.27) endif() # Filter out items; print an optional message if any items filtered. This ignores extensions. @@ -144,6 +144,7 @@ set(PYBIND11_TEST_FILES test_opaque_types test_operator_overloading test_pickling + test_python_multiple_inheritance test_pytypes test_sequences_and_iterators test_smart_ptr @@ -519,11 +520,15 @@ set(PYBIND11_TEST_PREFIX_COMMAND "" CACHE STRING "Put this before pytest, use for checkers and such") +set(PYBIND11_PYTEST_ARGS + "" + CACHE STRING "Extra arguments for pytest") + # A single command to compile and run the tests add_custom_target( pytest COMMAND ${PYBIND11_TEST_PREFIX_COMMAND} ${PYTHON_EXECUTABLE} -m pytest - ${PYBIND11_ABS_PYTEST_FILES} + ${PYBIND11_ABS_PYTEST_FILES} ${PYBIND11_PYTEST_ARGS} DEPENDS ${test_targets} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" USES_TERMINAL) diff --git a/extern/pybind11/tests/conftest.py b/extern/pybind11/tests/conftest.py index ad5b47b4b..8ebc70222 100644 --- a/extern/pybind11/tests/conftest.py +++ b/extern/pybind11/tests/conftest.py @@ -218,4 +218,5 @@ def pytest_report_header(config): f" {pybind11_tests.cpp_std}" f" {pybind11_tests.PYBIND11_INTERNALS_ID}" f" PYBIND11_SIMPLE_GIL_MANAGEMENT={pybind11_tests.PYBIND11_SIMPLE_GIL_MANAGEMENT}" + f" PYBIND11_NUMPY_1_ONLY={pybind11_tests.PYBIND11_NUMPY_1_ONLY}" ) diff --git a/extern/pybind11/tests/cross_module_interleaved_error_already_set.cpp b/extern/pybind11/tests/cross_module_interleaved_error_already_set.cpp index fdd9939e4..3493a7e61 100644 --- a/extern/pybind11/tests/cross_module_interleaved_error_already_set.cpp +++ b/extern/pybind11/tests/cross_module_interleaved_error_already_set.cpp @@ -16,12 +16,12 @@ namespace { namespace py = pybind11; void interleaved_error_already_set() { - PyErr_SetString(PyExc_RuntimeError, "1st error."); + py::set_error(PyExc_RuntimeError, "1st error."); try { throw py::error_already_set(); } catch (const py::error_already_set &) { // The 2nd error could be conditional in a real application. - PyErr_SetString(PyExc_RuntimeError, "2nd error."); + py::set_error(PyExc_RuntimeError, "2nd error."); } // Here the 1st error is destroyed before the 2nd error is fetched. // The error_already_set dtor triggers a pybind11::detail::get_internals() // call via pybind11::gil_scoped_acquire. diff --git a/extern/pybind11/tests/extra_python_package/test_files.py b/extern/pybind11/tests/extra_python_package/test_files.py index 57387dd8b..344e70d5d 100644 --- a/extern/pybind11/tests/extra_python_package/test_files.py +++ b/extern/pybind11/tests/extra_python_package/test_files.py @@ -35,6 +35,7 @@ "include/pybind11/eval.h", "include/pybind11/functional.h", "include/pybind11/gil.h", + "include/pybind11/gil_safe_call_once.h", "include/pybind11/iostream.h", "include/pybind11/numpy.h", "include/pybind11/operators.h", @@ -44,6 +45,7 @@ "include/pybind11/stl.h", "include/pybind11/stl_bind.h", "include/pybind11/type_caster_pyobject_ptr.h", + "include/pybind11/typing.h", } detail_headers = { diff --git a/extern/pybind11/tests/pybind11_cross_module_tests.cpp b/extern/pybind11/tests/pybind11_cross_module_tests.cpp index 9379f3f25..ad68e9a54 100644 --- a/extern/pybind11/tests/pybind11_cross_module_tests.cpp +++ b/extern/pybind11/tests/pybind11_cross_module_tests.cpp @@ -31,11 +31,11 @@ PYBIND11_MODULE(pybind11_cross_module_tests, m) { // test_exceptions.py py::register_local_exception(m, "LocalSimpleException"); m.def("raise_runtime_error", []() { - PyErr_SetString(PyExc_RuntimeError, "My runtime error"); + py::set_error(PyExc_RuntimeError, "My runtime error"); throw py::error_already_set(); }); m.def("raise_value_error", []() { - PyErr_SetString(PyExc_ValueError, "My value error"); + py::set_error(PyExc_ValueError, "My value error"); throw py::error_already_set(); }); m.def("throw_pybind_value_error", []() { throw py::value_error("pybind11 value error"); }); @@ -49,7 +49,7 @@ PYBIND11_MODULE(pybind11_cross_module_tests, m) { std::rethrow_exception(p); } } catch (const shared_exception &e) { - PyErr_SetString(PyExc_KeyError, e.what()); + py::set_error(PyExc_KeyError, e.what()); } }); @@ -60,7 +60,7 @@ PYBIND11_MODULE(pybind11_cross_module_tests, m) { std::rethrow_exception(p); } } catch (const LocalException &e) { - PyErr_SetString(PyExc_KeyError, e.what()); + py::set_error(PyExc_KeyError, e.what()); } }); diff --git a/extern/pybind11/tests/pybind11_tests.cpp b/extern/pybind11/tests/pybind11_tests.cpp index 624034648..81869ebe2 100644 --- a/extern/pybind11/tests/pybind11_tests.cpp +++ b/extern/pybind11/tests/pybind11_tests.cpp @@ -80,10 +80,10 @@ PYBIND11_MODULE(pybind11_tests, m) { // Intentionally kept minimal to not create a maintenance chore // ("just enough" to be conclusive). -#if defined(_MSC_FULL_VER) - m.attr("compiler_info") = "MSVC " PYBIND11_TOSTRING(_MSC_FULL_VER); -#elif defined(__VERSION__) +#if defined(__VERSION__) m.attr("compiler_info") = __VERSION__; +#elif defined(_MSC_FULL_VER) + m.attr("compiler_info") = "MSVC " PYBIND11_TOSTRING(_MSC_FULL_VER); #else m.attr("compiler_info") = py::none(); #endif @@ -95,6 +95,12 @@ PYBIND11_MODULE(pybind11_tests, m) { #else false; #endif + m.attr("PYBIND11_NUMPY_1_ONLY") = +#if defined(PYBIND11_NUMPY_1_ONLY) + true; +#else + false; +#endif bind_ConstructorStats(m); diff --git a/extern/pybind11/tests/requirements.txt b/extern/pybind11/tests/requirements.txt index 4ba101119..e056c6fa8 100644 --- a/extern/pybind11/tests/requirements.txt +++ b/extern/pybind11/tests/requirements.txt @@ -1,9 +1,15 @@ -build==0.8.0 -numpy==1.21.5; platform_python_implementation=="PyPy" and sys_platform=="linux" and python_version=="3.7" -numpy==1.19.3; platform_python_implementation!="PyPy" and python_version=="3.6" -numpy==1.21.5; platform_python_implementation!="PyPy" and python_version>="3.7" and python_version<"3.10" -numpy==1.22.2; platform_python_implementation!="PyPy" and python_version>="3.10" and python_version<"3.11" -pytest==7.0.0 +--only-binary=:all: +build~=0.9; python_version=="3.6" +build~=1.0; python_version>="3.7" +numpy~=1.20.0; python_version=="3.7" and platform_python_implementation=="PyPy" +numpy~=1.23.0; python_version=="3.8" and platform_python_implementation=="PyPy" +numpy~=1.25.0; python_version=="3.9" and platform_python_implementation=='PyPy' +numpy~=1.19.3; platform_python_implementation!="PyPy" and python_version=="3.6" +numpy~=1.21.5; platform_python_implementation!="PyPy" and python_version>="3.7" and python_version<"3.10" +numpy~=1.22.2; platform_python_implementation!="PyPy" and python_version=="3.10" +numpy~=1.26.0; platform_python_implementation!="PyPy" and python_version>="3.11" and python_version<"3.13" +pytest~=7.0 pytest-timeout -scipy==1.5.4; platform_python_implementation!="PyPy" and python_version<"3.10" -scipy==1.10.0; platform_python_implementation!="PyPy" and python_version=="3.10" +scipy~=1.5.4; platform_python_implementation!="PyPy" and python_version<"3.10" +scipy~=1.8.0; platform_python_implementation!="PyPy" and python_version=="3.10" +scipy~=1.11.1; platform_python_implementation!="PyPy" and python_version>="3.11" and python_version<"3.13" diff --git a/extern/pybind11/tests/test_buffers.py b/extern/pybind11/tests/test_buffers.py index 63d9d869f..5d33625ba 100644 --- a/extern/pybind11/tests/test_buffers.py +++ b/extern/pybind11/tests/test_buffers.py @@ -219,3 +219,10 @@ def test_ctypes_from_buffer(): assert cinfo.shape == pyinfo.shape assert cinfo.strides == pyinfo.strides assert not cinfo.readonly + + +def test_buffer_docstring(): + assert ( + m.get_buffer_info.__doc__.strip() + == "get_buffer_info(arg0: Buffer) -> pybind11_tests.buffers.buffer_info" + ) diff --git a/extern/pybind11/tests/test_builtin_casters.py b/extern/pybind11/tests/test_builtin_casters.py index b1f57bdd9..dbac1cbc2 100644 --- a/extern/pybind11/tests/test_builtin_casters.py +++ b/extern/pybind11/tests/test_builtin_casters.py @@ -352,7 +352,7 @@ def test_tuple(doc): assert ( doc(m.pair_passthrough) == """ - pair_passthrough(arg0: Tuple[bool, str]) -> Tuple[str, bool] + pair_passthrough(arg0: tuple[bool, str]) -> tuple[str, bool] Return a pair in reversed order """ @@ -360,7 +360,7 @@ def test_tuple(doc): assert ( doc(m.tuple_passthrough) == """ - tuple_passthrough(arg0: Tuple[bool, str, int]) -> Tuple[int, str, bool] + tuple_passthrough(arg0: tuple[bool, str, int]) -> tuple[int, str, bool] Return a triple in reversed order """ diff --git a/extern/pybind11/tests/test_callbacks.py b/extern/pybind11/tests/test_callbacks.py index 4a652f53e..86c767455 100644 --- a/extern/pybind11/tests/test_callbacks.py +++ b/extern/pybind11/tests/test_callbacks.py @@ -216,3 +216,10 @@ def test_custom_func(): def test_custom_func2(): assert m.custom_function2(3) == 27 assert m.roundtrip(m.custom_function2)(3) == 27 + + +def test_callback_docstring(): + assert ( + m.test_tuple_unpacking.__doc__.strip() + == "test_tuple_unpacking(arg0: Callable) -> object" + ) diff --git a/extern/pybind11/tests/test_class.py b/extern/pybind11/tests/test_class.py index ee7467cf8..73a48309e 100644 --- a/extern/pybind11/tests/test_class.py +++ b/extern/pybind11/tests/test_class.py @@ -1,3 +1,5 @@ +from unittest import mock + import pytest import env @@ -203,6 +205,18 @@ def __init__(self): assert msg(exc_info.value) == expected +@pytest.mark.parametrize( + "mock_return_value", [None, (1, 2, 3), m.Pet("Polly", "parrot"), m.Dog("Molly")] +) +def test_mock_new(mock_return_value): + with mock.patch.object( + m.Pet, "__new__", return_value=mock_return_value + ) as mock_new: + obj = m.Pet("Noname", "Nospecies") + assert obj is mock_return_value + mock_new.assert_called_once_with(m.Pet, "Noname", "Nospecies") + + def test_automatic_upcasting(): assert type(m.return_class_1()).__name__ == "DerivedClass1" assert type(m.return_class_2()).__name__ == "DerivedClass2" diff --git a/extern/pybind11/tests/test_cmake_build/CMakeLists.txt b/extern/pybind11/tests/test_cmake_build/CMakeLists.txt index e5aa975cf..f28bde08e 100644 --- a/extern/pybind11/tests/test_cmake_build/CMakeLists.txt +++ b/extern/pybind11/tests/test_cmake_build/CMakeLists.txt @@ -5,9 +5,8 @@ function(pybind11_add_build_test name) set(build_options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}") + list(APPEND build_options "-DPYBIND11_FINDPYTHON=${PYBIND11_FINDPYTHON}") if(PYBIND11_FINDPYTHON) - list(APPEND build_options "-DPYBIND11_FINDPYTHON=${PYBIND11_FINDPYTHON}") - if(DEFINED Python_ROOT_DIR) list(APPEND build_options "-DPython_ROOT_DIR=${Python_ROOT_DIR}") endif() diff --git a/extern/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt b/extern/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt index d9dcb45e4..89207a36d 100644 --- a/extern/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt +++ b/extern/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt @@ -1,12 +1,12 @@ cmake_minimum_required(VERSION 3.5) -# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with +# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with # some versions of VS that have a patched CMake 3.11. This forces us to emulate # the behavior using the following workaround: -if(${CMAKE_VERSION} VERSION_LESS 3.26) +if(${CMAKE_VERSION} VERSION_LESS 3.27) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) else() - cmake_policy(VERSION 3.26) + cmake_policy(VERSION 3.27) endif() project(test_installed_embed CXX) diff --git a/extern/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt b/extern/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt index 2f4f64275..e752494e6 100644 --- a/extern/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt +++ b/extern/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt @@ -1,13 +1,13 @@ cmake_minimum_required(VERSION 3.5) project(test_installed_module CXX) -# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with +# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with # some versions of VS that have a patched CMake 3.11. This forces us to emulate # the behavior using the following workaround: -if(${CMAKE_VERSION} VERSION_LESS 3.26) +if(${CMAKE_VERSION} VERSION_LESS 3.27) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) else() - cmake_policy(VERSION 3.26) + cmake_policy(VERSION 3.27) endif() project(test_installed_function CXX) diff --git a/extern/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt b/extern/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt index a981e236f..3f7eb514e 100644 --- a/extern/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt +++ b/extern/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt @@ -1,12 +1,12 @@ cmake_minimum_required(VERSION 3.5) -# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with +# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with # some versions of VS that have a patched CMake 3.11. This forces us to emulate # the behavior using the following workaround: -if(${CMAKE_VERSION} VERSION_LESS 3.26) +if(${CMAKE_VERSION} VERSION_LESS 3.27) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) else() - cmake_policy(VERSION 3.26) + cmake_policy(VERSION 3.27) endif() project(test_installed_target CXX) diff --git a/extern/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt b/extern/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt index f286746b9..7e7133435 100644 --- a/extern/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt +++ b/extern/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt @@ -1,12 +1,12 @@ cmake_minimum_required(VERSION 3.5) -# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with +# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with # some versions of VS that have a patched CMake 3.11. This forces us to emulate # the behavior using the following workaround: -if(${CMAKE_VERSION} VERSION_LESS 3.26) +if(${CMAKE_VERSION} VERSION_LESS 3.27) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) else() - cmake_policy(VERSION 3.26) + cmake_policy(VERSION 3.27) endif() project(test_subdirectory_embed CXX) @@ -16,6 +16,12 @@ set(PYBIND11_INSTALL CACHE BOOL "") set(PYBIND11_EXPORT_NAME test_export) +# Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests +# (makes transition easier while we support both modes). +if(DEFINED PYTHON_EXECUTABLE AND NOT DEFINED Python_EXECUTABLE) + set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}") +endif() + add_subdirectory("${pybind11_SOURCE_DIR}" pybind11) # Test basic target functionality diff --git a/extern/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt b/extern/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt index 275a75c0b..56b8b3d98 100644 --- a/extern/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt +++ b/extern/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt @@ -1,16 +1,22 @@ cmake_minimum_required(VERSION 3.5) -# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with +# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with # some versions of VS that have a patched CMake 3.11. This forces us to emulate # the behavior using the following workaround: -if(${CMAKE_VERSION} VERSION_LESS 3.26) +if(${CMAKE_VERSION} VERSION_LESS 3.27) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) else() - cmake_policy(VERSION 3.26) + cmake_policy(VERSION 3.27) endif() project(test_subdirectory_function CXX) +# Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests +# (makes transition easier while we support both modes). +if(DEFINED PYTHON_EXECUTABLE AND NOT DEFINED Python_EXECUTABLE) + set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}") +endif() + add_subdirectory("${pybind11_SOURCE_DIR}" pybind11) pybind11_add_module(test_subdirectory_function ../main.cpp) set_target_properties(test_subdirectory_function PROPERTIES OUTPUT_NAME test_cmake_build) diff --git a/extern/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt b/extern/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt index 37bb2c56e..72d880b37 100644 --- a/extern/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt +++ b/extern/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt @@ -1,16 +1,22 @@ cmake_minimum_required(VERSION 3.5) -# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with +# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with # some versions of VS that have a patched CMake 3.11. This forces us to emulate # the behavior using the following workaround: -if(${CMAKE_VERSION} VERSION_LESS 3.26) +if(${CMAKE_VERSION} VERSION_LESS 3.27) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) else() - cmake_policy(VERSION 3.26) + cmake_policy(VERSION 3.27) endif() project(test_subdirectory_target CXX) +# Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests +# (makes transition easier while we support both modes). +if(DEFINED PYTHON_EXECUTABLE AND NOT DEFINED Python_EXECUTABLE) + set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}") +endif() + add_subdirectory("${pybind11_SOURCE_DIR}" pybind11) add_library(test_subdirectory_target MODULE ../main.cpp) diff --git a/extern/pybind11/tests/test_constants_and_functions.cpp b/extern/pybind11/tests/test_constants_and_functions.cpp index 312edca9e..bf42b4155 100644 --- a/extern/pybind11/tests/test_constants_and_functions.cpp +++ b/extern/pybind11/tests/test_constants_and_functions.cpp @@ -54,7 +54,11 @@ int f2(int x) noexcept(true) { return x + 2; } int f3(int x) noexcept(false) { return x + 3; } PYBIND11_WARNING_PUSH PYBIND11_WARNING_DISABLE_GCC("-Wdeprecated") +#if defined(__clang_major__) && __clang_major__ >= 5 +PYBIND11_WARNING_DISABLE_CLANG("-Wdeprecated-dynamic-exception-spec") +#else PYBIND11_WARNING_DISABLE_CLANG("-Wdeprecated") +#endif // NOLINTNEXTLINE(modernize-use-noexcept) int f4(int x) throw() { return x + 4; } // Deprecated equivalent to noexcept(true) PYBIND11_WARNING_POP diff --git a/extern/pybind11/tests/test_custom_type_casters.cpp b/extern/pybind11/tests/test_custom_type_casters.cpp index b4af02a45..3cbb8687f 100644 --- a/extern/pybind11/tests/test_custom_type_casters.cpp +++ b/extern/pybind11/tests/test_custom_type_casters.cpp @@ -134,6 +134,16 @@ struct type_caster : public other_lib::my_caster {}; } // namespace detail } // namespace PYBIND11_NAMESPACE +// This simply is required to compile +namespace ADL_issue { +template +OutStringType concat(Args &&...) { + return OutStringType(); +} + +struct test {}; +} // namespace ADL_issue + TEST_SUBMODULE(custom_type_casters, m) { // test_custom_type_casters @@ -206,4 +216,6 @@ TEST_SUBMODULE(custom_type_casters, m) { py::return_value_policy::reference); m.def("other_lib_type", [](other_lib::MyType x) { return x; }); + + m.def("_adl_issue", [](const ADL_issue::test &) {}); } diff --git a/extern/pybind11/tests/test_eigen_matrix.cpp b/extern/pybind11/tests/test_eigen_matrix.cpp index 554cc4d7f..0c003d05e 100644 --- a/extern/pybind11/tests/test_eigen_matrix.cpp +++ b/extern/pybind11/tests/test_eigen_matrix.cpp @@ -330,6 +330,23 @@ TEST_SUBMODULE(eigen_matrix, m) { m.def("dense_c", [mat]() -> DenseMatrixC { return DenseMatrixC(mat); }); m.def("dense_copy_r", [](const DenseMatrixR &m) -> DenseMatrixR { return m; }); m.def("dense_copy_c", [](const DenseMatrixC &m) -> DenseMatrixC { return m; }); + // test_defaults + bool have_numpy = true; + try { + py::module_::import("numpy"); + } catch (const py::error_already_set &) { + have_numpy = false; + } + if (have_numpy) { + py::module_::import("numpy"); + Eigen::Matrix defaultMatrix = Eigen::Matrix3d::Identity(); + m.def( + "defaults_mat", [](const Eigen::Matrix3d &) {}, py::arg("mat") = defaultMatrix); + + Eigen::VectorXd defaultVector = Eigen::VectorXd::Ones(32); + m.def( + "defaults_vec", [](const Eigen::VectorXd &) {}, py::arg("vec") = defaultMatrix); + } // test_sparse, test_sparse_signature m.def("sparse_r", [mat]() -> SparseMatrixR { // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) diff --git a/extern/pybind11/tests/test_eigen_matrix.py b/extern/pybind11/tests/test_eigen_matrix.py index b2e76740b..9a2cafc0a 100644 --- a/extern/pybind11/tests/test_eigen_matrix.py +++ b/extern/pybind11/tests/test_eigen_matrix.py @@ -608,7 +608,9 @@ def test_both_ref_mutators(): def test_nocopy_wrapper(): # get_elem requires a column-contiguous matrix reference, but should be # callable with other types of matrix (via copying): - int_matrix_colmajor = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], order="F") + int_matrix_colmajor = np.array( + [[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype="l", order="F" + ) dbl_matrix_colmajor = np.array( int_matrix_colmajor, dtype="double", order="F", copy=True ) @@ -716,6 +718,11 @@ def test_dense_signature(doc): ) +def test_defaults(doc): + assert "\n" not in str(doc(m.defaults_mat)) + assert "\n" not in str(doc(m.defaults_vec)) + + def test_named_arguments(): a = np.array([[1.0, 2], [3, 4], [5, 6]]) b = np.ones((2, 1)) diff --git a/extern/pybind11/tests/test_enum.py b/extern/pybind11/tests/test_enum.py index 4e85d29c3..6b75b7ae5 100644 --- a/extern/pybind11/tests/test_enum.py +++ b/extern/pybind11/tests/test_enum.py @@ -60,9 +60,7 @@ def test_unscoped_enum(): ETwo : Docstring for ETwo - EThree : Docstring for EThree""".split( - "\n" - ): + EThree : Docstring for EThree""".split("\n"): assert docstring_line in m.UnscopedEnum.__doc__ # Unscoped enums will accept ==/!= int comparisons @@ -264,3 +262,8 @@ def test_docstring_signatures(): for attr in enum_type.__dict__.values(): # Issue #2623/PR #2637: Add argument names to enum_ methods assert "arg0" not in (attr.__doc__ or "") + + +def test_str_signature(): + for enum_type in [m.ScopedEnum, m.UnscopedEnum]: + assert enum_type.__str__.__doc__.startswith("__str__") diff --git a/extern/pybind11/tests/test_exceptions.cpp b/extern/pybind11/tests/test_exceptions.cpp index 854c7e6f7..c1d05bb24 100644 --- a/extern/pybind11/tests/test_exceptions.cpp +++ b/extern/pybind11/tests/test_exceptions.cpp @@ -6,6 +6,8 @@ All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. */ +#include + #include "test_exceptions.h" #include "local_bindings.h" @@ -25,6 +27,10 @@ class MyException : public std::exception { std::string message = ""; }; +class MyExceptionUseDeprecatedOperatorCall : public MyException { + using MyException::MyException; +}; + // A type that should be translated to a standard Python exception class MyException2 : public std::exception { public: @@ -109,8 +115,10 @@ TEST_SUBMODULE(exceptions, m) { m.def("throw_std_exception", []() { throw std::runtime_error("This exception was intentionally thrown."); }); - // make a new custom exception and use it as a translation target - static py::exception ex(m, "MyException"); + // PLEASE KEEP IN SYNC with docs/advanced/exceptions.rst + PYBIND11_CONSTINIT static py::gil_safe_call_once_and_store ex_storage; + ex_storage.call_once_and_store_result( + [&]() { return py::exception(m, "MyException"); }); py::register_exception_translator([](std::exception_ptr p) { try { if (p) { @@ -118,7 +126,32 @@ TEST_SUBMODULE(exceptions, m) { } } catch (const MyException &e) { // Set MyException as the active python error - ex(e.what()); + py::set_error(ex_storage.get_stored(), e.what()); + } + }); + + // Same as above, but using the deprecated `py::exception<>::operator()` + // We want to be sure it still works, until it's removed. + static const auto *const exd = new py::exception( + m, "MyExceptionUseDeprecatedOperatorCall"); + py::register_exception_translator([](std::exception_ptr p) { + try { + if (p) { + std::rethrow_exception(p); + } + } catch (const MyExceptionUseDeprecatedOperatorCall &e) { +#if defined(__INTEL_COMPILER) || defined(__NVCOMPILER) + // It is not worth the trouble dealing with warning suppressions for these compilers. + // Falling back to the recommended approach to keep the test code simple. + py::set_error(*exd, e.what()); +#else + PYBIND11_WARNING_PUSH + PYBIND11_WARNING_DISABLE_CLANG("-Wdeprecated-declarations") + PYBIND11_WARNING_DISABLE_GCC("-Wdeprecated-declarations") + PYBIND11_WARNING_DISABLE_MSVC(4996) + (*exd)(e.what()); + PYBIND11_WARNING_POP +#endif } }); @@ -132,7 +165,7 @@ TEST_SUBMODULE(exceptions, m) { } } catch (const MyException2 &e) { // Translate this exception to a standard RuntimeError - PyErr_SetString(PyExc_RuntimeError, e.what()); + py::set_error(PyExc_RuntimeError, e.what()); } }); @@ -162,11 +195,16 @@ TEST_SUBMODULE(exceptions, m) { std::rethrow_exception(p); } } catch (const MyException6 &e) { - PyErr_SetString(PyExc_RuntimeError, e.what()); + py::set_error(PyExc_RuntimeError, e.what()); } }); - m.def("throws1", []() { throw MyException("this error should go to a custom type"); }); + m.def("throws1", + []() { throw MyException("this error should go to py::exception"); }); + m.def("throws1d", []() { + throw MyExceptionUseDeprecatedOperatorCall( + "this error should go to py::exception"); + }); m.def("throws2", []() { throw MyException2("this error should go to a standard Python exception"); }); m.def("throws3", []() { throw MyException3("this error cannot be translated"); }); @@ -222,7 +260,7 @@ TEST_SUBMODULE(exceptions, m) { m.def("throw_already_set", [](bool err) { if (err) { - PyErr_SetString(PyExc_ValueError, "foo"); + py::set_error(PyExc_ValueError, "foo"); } try { throw py::error_already_set(); @@ -238,7 +276,7 @@ TEST_SUBMODULE(exceptions, m) { } PyErr_Clear(); if (err) { - PyErr_SetString(PyExc_ValueError, "foo"); + py::set_error(PyExc_ValueError, "foo"); } throw py::error_already_set(); }); @@ -247,7 +285,7 @@ TEST_SUBMODULE(exceptions, m) { bool retval = false; try { PythonCallInDestructor set_dict_in_destructor(d); - PyErr_SetString(PyExc_ValueError, "foo"); + py::set_error(PyExc_ValueError, "foo"); throw py::error_already_set(); } catch (const py::error_already_set &) { retval = true; @@ -282,14 +320,14 @@ TEST_SUBMODULE(exceptions, m) { m.def("throw_should_be_translated_to_key_error", []() { throw shared_exception(); }); m.def("raise_from", []() { - PyErr_SetString(PyExc_ValueError, "inner"); + py::set_error(PyExc_ValueError, "inner"); py::raise_from(PyExc_ValueError, "outer"); throw py::error_already_set(); }); m.def("raise_from_already_set", []() { try { - PyErr_SetString(PyExc_ValueError, "inner"); + py::set_error(PyExc_ValueError, "inner"); throw py::error_already_set(); } catch (py::error_already_set &e) { py::raise_from(e, PyExc_ValueError, "outer"); @@ -306,7 +344,7 @@ TEST_SUBMODULE(exceptions, m) { }); m.def("error_already_set_what", [](const py::object &exc_type, const py::object &exc_value) { - PyErr_SetObject(exc_type.ptr(), exc_value.ptr()); + py::set_error(exc_type, exc_value); std::string what = py::error_already_set().what(); bool py_err_set_after_what = (PyErr_Occurred() != nullptr); PyErr_Clear(); @@ -321,7 +359,7 @@ TEST_SUBMODULE(exceptions, m) { }); m.def("test_error_already_set_double_restore", [](bool dry_run) { - PyErr_SetString(PyExc_ValueError, "Random error."); + py::set_error(PyExc_ValueError, "Random error."); py::error_already_set e; e.restore(); PyErr_Clear(); @@ -344,4 +382,7 @@ TEST_SUBMODULE(exceptions, m) { // function returns None instead of int, should give a useful error message fn().cast(); }); + + // m.def("pass_exception_void", [](const py::exception&) {}); // Does not compile. + m.def("return_exception_void", []() { return py::exception(); }); } diff --git a/extern/pybind11/tests/test_exceptions.h b/extern/pybind11/tests/test_exceptions.h index 03684b89f..2eaa3d3d1 100644 --- a/extern/pybind11/tests/test_exceptions.h +++ b/extern/pybind11/tests/test_exceptions.h @@ -9,5 +9,5 @@ class PYBIND11_EXPORT_EXCEPTION shared_exception : public pybind11::builtin_exce public: using builtin_exception::builtin_exception; explicit shared_exception() : shared_exception("") {} - void set_error() const override { PyErr_SetString(PyExc_RuntimeError, what()); } + void set_error() const override { py::set_error(PyExc_RuntimeError, what()); } }; diff --git a/extern/pybind11/tests/test_exceptions.py b/extern/pybind11/tests/test_exceptions.py index ccac4536d..01fcb918e 100644 --- a/extern/pybind11/tests/test_exceptions.py +++ b/extern/pybind11/tests/test_exceptions.py @@ -4,7 +4,7 @@ import env import pybind11_cross_module_tests as cm -import pybind11_tests # noqa: F401 +import pybind11_tests from pybind11_tests import exceptions as m @@ -139,7 +139,15 @@ def test_custom(msg): # Can we catch a MyException? with pytest.raises(m.MyException) as excinfo: m.throws1() - assert msg(excinfo.value) == "this error should go to a custom type" + assert msg(excinfo.value) == "this error should go to py::exception" + + # Can we catch a MyExceptionUseDeprecatedOperatorCall? + with pytest.raises(m.MyExceptionUseDeprecatedOperatorCall) as excinfo: + m.throws1d() + assert ( + msg(excinfo.value) + == "this error should go to py::exception" + ) # Can we translate to standard Python exceptions? with pytest.raises(RuntimeError) as excinfo: @@ -240,6 +248,11 @@ def pycatch(exctype, f, *args): # noqa: ARG001 assert str(excinfo.value) == "this is a helper-defined translated exception" +# TODO: Investigate this crash, see pybind/pybind11#5062 for background +@pytest.mark.skipif( + sys.platform.startswith("win32") and "Clang" in pybind11_tests.compiler_info, + reason="Started segfaulting February 2024", +) def test_throw_nested_exception(): with pytest.raises(RuntimeError) as excinfo: m.throw_nested_exception() @@ -411,3 +424,9 @@ def test_fn_cast_int_exception(): assert str(excinfo.value).startswith( "Unable to cast Python instance of type to C++ type" ) + + +def test_return_exception_void(): + with pytest.raises(TypeError) as excinfo: + m.return_exception_void() + assert "Exception" in str(excinfo.value) diff --git a/extern/pybind11/tests/test_factory_constructors.py b/extern/pybind11/tests/test_factory_constructors.py index 04df80260..a9004cbf6 100644 --- a/extern/pybind11/tests/test_factory_constructors.py +++ b/extern/pybind11/tests/test_factory_constructors.py @@ -77,7 +77,7 @@ def test_init_factory_signature(msg): 1. m.factory_constructors.TestFactory1(arg0: m.factory_constructors.tag.unique_ptr_tag, arg1: int) 2. m.factory_constructors.TestFactory1(arg0: str) 3. m.factory_constructors.TestFactory1(arg0: m.factory_constructors.tag.pointer_tag) - 4. m.factory_constructors.TestFactory1(arg0: handle, arg1: int, arg2: handle) + 4. m.factory_constructors.TestFactory1(arg0: object, arg1: int, arg2: object) Invoked with: 'invalid', 'constructor', 'arguments' """ @@ -95,7 +95,7 @@ def test_init_factory_signature(msg): 3. __init__(self: m.factory_constructors.TestFactory1, arg0: m.factory_constructors.tag.pointer_tag) -> None - 4. __init__(self: m.factory_constructors.TestFactory1, arg0: handle, arg1: int, arg2: handle) -> None + 4. __init__(self: m.factory_constructors.TestFactory1, arg0: object, arg1: int, arg2: object) -> None """ ) diff --git a/extern/pybind11/tests/test_kwargs_and_defaults.cpp b/extern/pybind11/tests/test_kwargs_and_defaults.cpp index 77e72c0c7..9a12c42af 100644 --- a/extern/pybind11/tests/test_kwargs_and_defaults.cpp +++ b/extern/pybind11/tests/test_kwargs_and_defaults.cpp @@ -42,6 +42,52 @@ TEST_SUBMODULE(kwargs_and_defaults, m) { m.def("kw_func_udl", kw_func, "x"_a, "y"_a = 300); m.def("kw_func_udl_z", kw_func, "x"_a, "y"_a = 0); + // test line breaks in default argument representation + struct CustomRepr { + std::string repr_string; + + explicit CustomRepr(const std::string &repr) : repr_string(repr) {} + + std::string __repr__() const { return repr_string; } + }; + + py::class_(m, "CustomRepr") + .def(py::init()) + .def("__repr__", &CustomRepr::__repr__); + + m.def( + "kw_lb_func0", + [](const CustomRepr &) {}, + py::arg("custom") = CustomRepr(" array([[A, B], [C, D]]) ")); + m.def( + "kw_lb_func1", + [](const CustomRepr &) {}, + py::arg("custom") = CustomRepr(" array([[A, B],\n[C, D]]) ")); + m.def( + "kw_lb_func2", + [](const CustomRepr &) {}, + py::arg("custom") = CustomRepr("\v\n array([[A, B], [C, D]])")); + m.def( + "kw_lb_func3", + [](const CustomRepr &) {}, + py::arg("custom") = CustomRepr("array([[A, B], [C, D]]) \f\n")); + m.def( + "kw_lb_func4", + [](const CustomRepr &) {}, + py::arg("custom") = CustomRepr("array([[A, B],\n\f\n[C, D]])")); + m.def( + "kw_lb_func5", + [](const CustomRepr &) {}, + py::arg("custom") = CustomRepr("array([[A, B],\r [C, D]])")); + m.def( + "kw_lb_func6", [](const CustomRepr &) {}, py::arg("custom") = CustomRepr(" \v\t ")); + m.def( + "kw_lb_func7", + [](const std::string &) {}, + py::arg("str_arg") = "First line.\n Second line."); + m.def( + "kw_lb_func8", [](const CustomRepr &) {}, py::arg("custom") = CustomRepr("")); + // test_args_and_kwargs m.def("args_function", [](py::args args) -> py::tuple { PYBIND11_WARNING_PUSH diff --git a/extern/pybind11/tests/test_kwargs_and_defaults.py b/extern/pybind11/tests/test_kwargs_and_defaults.py index 7174726fc..0e3bbdb76 100644 --- a/extern/pybind11/tests/test_kwargs_and_defaults.py +++ b/extern/pybind11/tests/test_kwargs_and_defaults.py @@ -8,7 +8,7 @@ def test_function_signatures(doc): assert doc(m.kw_func1) == "kw_func1(x: int, y: int) -> str" assert doc(m.kw_func2) == "kw_func2(x: int = 100, y: int = 200) -> str" assert doc(m.kw_func3) == "kw_func3(data: str = 'Hello world!') -> None" - assert doc(m.kw_func4) == "kw_func4(myList: List[int] = [13, 17]) -> str" + assert doc(m.kw_func4) == "kw_func4(myList: list[int] = [13, 17]) -> str" assert doc(m.kw_func_udl) == "kw_func_udl(x: int, y: int = 300) -> str" assert doc(m.kw_func_udl_z) == "kw_func_udl_z(x: int, y: int = 0) -> str" assert doc(m.args_function) == "args_function(*args) -> tuple" @@ -23,6 +23,42 @@ def test_function_signatures(doc): doc(m.KWClass.foo1) == "foo1(self: m.kwargs_and_defaults.KWClass, x: int, y: float) -> None" ) + assert ( + doc(m.kw_lb_func0) + == "kw_lb_func0(custom: m.kwargs_and_defaults.CustomRepr = array([[A, B], [C, D]])) -> None" + ) + assert ( + doc(m.kw_lb_func1) + == "kw_lb_func1(custom: m.kwargs_and_defaults.CustomRepr = array([[A, B], [C, D]])) -> None" + ) + assert ( + doc(m.kw_lb_func2) + == "kw_lb_func2(custom: m.kwargs_and_defaults.CustomRepr = array([[A, B], [C, D]])) -> None" + ) + assert ( + doc(m.kw_lb_func3) + == "kw_lb_func3(custom: m.kwargs_and_defaults.CustomRepr = array([[A, B], [C, D]])) -> None" + ) + assert ( + doc(m.kw_lb_func4) + == "kw_lb_func4(custom: m.kwargs_and_defaults.CustomRepr = array([[A, B], [C, D]])) -> None" + ) + assert ( + doc(m.kw_lb_func5) + == "kw_lb_func5(custom: m.kwargs_and_defaults.CustomRepr = array([[A, B], [C, D]])) -> None" + ) + assert ( + doc(m.kw_lb_func6) + == "kw_lb_func6(custom: m.kwargs_and_defaults.CustomRepr = ) -> None" + ) + assert ( + doc(m.kw_lb_func7) + == "kw_lb_func7(str_arg: str = 'First line.\\n Second line.') -> None" + ) + assert ( + doc(m.kw_lb_func8) + == "kw_lb_func8(custom: m.kwargs_and_defaults.CustomRepr = ) -> None" + ) def test_named_arguments(): diff --git a/extern/pybind11/tests/test_methods_and_attributes.py b/extern/pybind11/tests/test_methods_and_attributes.py index 955a85f67..7fdf4e3af 100644 --- a/extern/pybind11/tests/test_methods_and_attributes.py +++ b/extern/pybind11/tests/test_methods_and_attributes.py @@ -232,25 +232,29 @@ def test_no_mixed_overloads(): with pytest.raises(RuntimeError) as excinfo: m.ExampleMandA.add_mixed_overloads1() - assert str( - excinfo.value - ) == "overloading a method with both static and instance methods is not supported; " + ( - "#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more details" - if not detailed_error_messages_enabled - else "error while attempting to bind static method ExampleMandA.overload_mixed1" - "(arg0: float) -> str" + assert ( + str(excinfo.value) + == "overloading a method with both static and instance methods is not supported; " + + ( + "#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more details" + if not detailed_error_messages_enabled + else "error while attempting to bind static method ExampleMandA.overload_mixed1" + "(arg0: float) -> str" + ) ) with pytest.raises(RuntimeError) as excinfo: m.ExampleMandA.add_mixed_overloads2() - assert str( - excinfo.value - ) == "overloading a method with both static and instance methods is not supported; " + ( - "#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more details" - if not detailed_error_messages_enabled - else "error while attempting to bind instance method ExampleMandA.overload_mixed2" - "(self: pybind11_tests.methods_and_attributes.ExampleMandA, arg0: int, arg1: int)" - " -> str" + assert ( + str(excinfo.value) + == "overloading a method with both static and instance methods is not supported; " + + ( + "#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more details" + if not detailed_error_messages_enabled + else "error while attempting to bind instance method ExampleMandA.overload_mixed2" + "(self: pybind11_tests.methods_and_attributes.ExampleMandA, arg0: int, arg1: int)" + " -> str" + ) ) diff --git a/extern/pybind11/tests/test_numpy_array.py b/extern/pybind11/tests/test_numpy_array.py index 12e7d17d1..25ad09ec3 100644 --- a/extern/pybind11/tests/test_numpy_array.py +++ b/extern/pybind11/tests/test_numpy_array.py @@ -298,7 +298,7 @@ def test_constructors(): results = m.converting_constructors([1, 2, 3]) for a in results.values(): np.testing.assert_array_equal(a, [1, 2, 3]) - assert results["array"].dtype == np.int_ + assert results["array"].dtype == np.dtype(int) assert results["array_t"].dtype == np.int32 assert results["array_t"].dtype == np.float64 @@ -536,7 +536,12 @@ def test_format_descriptors_for_floating_point_types(test_func): @pytest.mark.parametrize("contiguity", [None, "C", "F"]) @pytest.mark.parametrize("noconvert", [False, True]) @pytest.mark.filterwarnings( - "ignore:Casting complex values to real discards the imaginary part:numpy.ComplexWarning" + "ignore:Casting complex values to real discards the imaginary part:" + + ( + "numpy.exceptions.ComplexWarning" + if hasattr(np, "exceptions") + else "numpy.ComplexWarning" + ) ) def test_argument_conversions(forcecast, contiguity, noconvert): function_name = "accept_double" @@ -583,7 +588,8 @@ def test_argument_conversions(forcecast, contiguity, noconvert): def test_dtype_refcount_leak(): from sys import getrefcount - dtype = np.dtype(np.float_) + # Was np.float_ but that alias for float64 was removed in NumPy 2. + dtype = np.dtype(np.float64) a = np.array([1], dtype=dtype) before = getrefcount(dtype) m.ndim(a) diff --git a/extern/pybind11/tests/test_numpy_dtypes.cpp b/extern/pybind11/tests/test_numpy_dtypes.cpp index 6654f9ed8..519b69f40 100644 --- a/extern/pybind11/tests/test_numpy_dtypes.cpp +++ b/extern/pybind11/tests/test_numpy_dtypes.cpp @@ -157,7 +157,7 @@ py::array mkarray_via_buffer(size_t n) { do { \ (s).bool_ = (i) % 2 != 0; \ (s).uint_ = (uint32_t) (i); \ - (s).float_ = (float) (i) *1.5f; \ + (s).float_ = (float) (i) * 1.5f; \ (s).ldbl_ = (long double) (i) * -2.5L; \ } while (0) @@ -405,10 +405,35 @@ TEST_SUBMODULE(numpy_dtypes, m) { }); // test_dtype + // Below we use `L` for unsigned long as unfortunately the only name that + // works reliably on Both NumPy 2.x and old NumPy 1.x. std::vector dtype_names{ - "byte", "short", "intc", "int_", "longlong", "ubyte", "ushort", - "uintc", "uint", "ulonglong", "half", "single", "double", "longdouble", - "csingle", "cdouble", "clongdouble", "bool_", "datetime64", "timedelta64", "object_"}; + "byte", + "short", + "intc", + "long", + "longlong", + "ubyte", + "ushort", + "uintc", + "L", + "ulonglong", + "half", + "single", + "double", + "longdouble", + "csingle", + "cdouble", + "clongdouble", + "bool_", + "datetime64", + "timedelta64", + "object_", + // platform dependent aliases (int_ and uint are also NumPy version dependent on windows) + "int_", + "uint", + "intp", + "uintp"}; m.def("print_dtypes", []() { py::list l; diff --git a/extern/pybind11/tests/test_numpy_dtypes.py b/extern/pybind11/tests/test_numpy_dtypes.py index d10457eeb..e7854df4a 100644 --- a/extern/pybind11/tests/test_numpy_dtypes.py +++ b/extern/pybind11/tests/test_numpy_dtypes.py @@ -3,6 +3,7 @@ import pytest import env # noqa: F401 +from pybind11_tests import PYBIND11_NUMPY_1_ONLY from pybind11_tests import numpy_dtypes as m np = pytest.importorskip("numpy") @@ -172,13 +173,20 @@ def test_dtype(simple_dtype): np.zeros(1, m.trailing_padding_dtype()) ) - expected_chars = "bhilqBHILQefdgFDG?MmO" - assert m.test_dtype_kind() == list("iiiiiuuuuuffffcccbMmO") + expected_chars = list("bhilqBHILQefdgFDG?MmO") + # Note that int_ and uint size and mapping is NumPy version dependent: + expected_chars += [np.dtype(_).char for _ in ("int_", "uint", "intp", "uintp")] + assert m.test_dtype_kind() == list("iiiiiuuuuuffffcccbMmOiuiu") assert m.test_dtype_char_() == list(expected_chars) assert m.test_dtype_num() == [np.dtype(ch).num for ch in expected_chars] assert m.test_dtype_byteorder() == [np.dtype(ch).byteorder for ch in expected_chars] assert m.test_dtype_alignment() == [np.dtype(ch).alignment for ch in expected_chars] - assert m.test_dtype_flags() == [chr(np.dtype(ch).flags) for ch in expected_chars] + if not PYBIND11_NUMPY_1_ONLY: + assert m.test_dtype_flags() == [np.dtype(ch).flags for ch in expected_chars] + else: + assert m.test_dtype_flags() == [ + chr(np.dtype(ch).flags) for ch in expected_chars + ] def test_recarray(simple_dtype, packed_dtype): diff --git a/extern/pybind11/tests/test_python_multiple_inheritance.cpp b/extern/pybind11/tests/test_python_multiple_inheritance.cpp new file mode 100644 index 000000000..689917158 --- /dev/null +++ b/extern/pybind11/tests/test_python_multiple_inheritance.cpp @@ -0,0 +1,45 @@ +#include "pybind11_tests.h" + +namespace test_python_multiple_inheritance { + +// Copied from: +// https://github.com/google/clif/blob/5718e4d0807fd3b6a8187dde140069120b81ecef/clif/testing/python_multiple_inheritance.h + +struct CppBase { + explicit CppBase(int value) : base_value(value) {} + int get_base_value() const { return base_value; } + void reset_base_value(int new_value) { base_value = new_value; } + +private: + int base_value; +}; + +struct CppDrvd : CppBase { + explicit CppDrvd(int value) : CppBase(value), drvd_value(value * 3) {} + int get_drvd_value() const { return drvd_value; } + void reset_drvd_value(int new_value) { drvd_value = new_value; } + + int get_base_value_from_drvd() const { return get_base_value(); } + void reset_base_value_from_drvd(int new_value) { reset_base_value(new_value); } + +private: + int drvd_value; +}; + +} // namespace test_python_multiple_inheritance + +TEST_SUBMODULE(python_multiple_inheritance, m) { + using namespace test_python_multiple_inheritance; + + py::class_(m, "CppBase") + .def(py::init()) + .def("get_base_value", &CppBase::get_base_value) + .def("reset_base_value", &CppBase::reset_base_value); + + py::class_(m, "CppDrvd") + .def(py::init()) + .def("get_drvd_value", &CppDrvd::get_drvd_value) + .def("reset_drvd_value", &CppDrvd::reset_drvd_value) + .def("get_base_value_from_drvd", &CppDrvd::get_base_value_from_drvd) + .def("reset_base_value_from_drvd", &CppDrvd::reset_base_value_from_drvd); +} diff --git a/extern/pybind11/tests/test_python_multiple_inheritance.py b/extern/pybind11/tests/test_python_multiple_inheritance.py new file mode 100644 index 000000000..3bddd67df --- /dev/null +++ b/extern/pybind11/tests/test_python_multiple_inheritance.py @@ -0,0 +1,35 @@ +# Adapted from: +# https://github.com/google/clif/blob/5718e4d0807fd3b6a8187dde140069120b81ecef/clif/testing/python/python_multiple_inheritance_test.py + +from pybind11_tests import python_multiple_inheritance as m + + +class PC(m.CppBase): + pass + + +class PPCC(PC, m.CppDrvd): + pass + + +def test_PC(): + d = PC(11) + assert d.get_base_value() == 11 + d.reset_base_value(13) + assert d.get_base_value() == 13 + + +def test_PPCC(): + d = PPCC(11) + assert d.get_drvd_value() == 33 + d.reset_drvd_value(55) + assert d.get_drvd_value() == 55 + + assert d.get_base_value() == 11 + assert d.get_base_value_from_drvd() == 11 + d.reset_base_value(20) + assert d.get_base_value() == 20 + assert d.get_base_value_from_drvd() == 20 + d.reset_base_value_from_drvd(30) + assert d.get_base_value() == 30 + assert d.get_base_value_from_drvd() == 30 diff --git a/extern/pybind11/tests/test_pytypes.cpp b/extern/pybind11/tests/test_pytypes.cpp index b4ee64289..12e615181 100644 --- a/extern/pybind11/tests/test_pytypes.cpp +++ b/extern/pybind11/tests/test_pytypes.cpp @@ -7,6 +7,8 @@ BSD-style license that can be found in the LICENSE file. */ +#include + #include "pybind11_tests.h" #include @@ -23,7 +25,7 @@ PyObject *conv(PyObject *o) { ret = PyFloat_FromDouble(v); } } else { - PyErr_SetString(PyExc_TypeError, "Unexpected type"); + py::set_error(PyExc_TypeError, "Unexpected type"); } return ret; } @@ -39,6 +41,15 @@ class float_ : public py::object { }; } // namespace external +namespace pybind11 { +namespace detail { +template <> +struct handle_type_name { + static constexpr auto name = const_name("float"); +}; +} // namespace detail +} // namespace pybind11 + namespace implicit_conversion_from_0_to_handle { // Uncomment to trigger compiler error. Note: Before PR #4008 this used to compile successfully. // void expected_to_trigger_compiler_error() { py::handle(0); } @@ -660,8 +671,8 @@ TEST_SUBMODULE(pytypes, m) { // This is "most correct" and enforced on these platforms. # define PYBIND11_AUTO_IT auto it #else -// This works on many platforms and is (unfortunately) reflective of existing user code. -// NOLINTNEXTLINE(bugprone-macro-parentheses) + // This works on many platforms and is (unfortunately) reflective of existing user code. + // NOLINTNEXTLINE(bugprone-macro-parentheses) # define PYBIND11_AUTO_IT auto &it #endif @@ -820,4 +831,16 @@ TEST_SUBMODULE(pytypes, m) { a >>= b; return a; }); + + m.def("annotate_tuple_float_str", [](const py::typing::Tuple &) {}); + m.def("annotate_tuple_empty", [](const py::typing::Tuple<> &) {}); + m.def("annotate_tuple_variable_length", + [](const py::typing::Tuple &) {}); + m.def("annotate_dict_str_int", [](const py::typing::Dict &) {}); + m.def("annotate_list_int", [](const py::typing::List &) {}); + m.def("annotate_set_str", [](const py::typing::Set &) {}); + m.def("annotate_iterable_str", [](const py::typing::Iterable &) {}); + m.def("annotate_iterator_int", [](const py::typing::Iterator &) {}); + m.def("annotate_fn", + [](const py::typing::Callable, py::str)> &) {}); } diff --git a/extern/pybind11/tests/test_pytypes.py b/extern/pybind11/tests/test_pytypes.py index eda7a20a9..f6271a628 100644 --- a/extern/pybind11/tests/test_pytypes.py +++ b/extern/pybind11/tests/test_pytypes.py @@ -121,7 +121,7 @@ def test_set(capture, doc): assert m.anyset_contains({"foo"}, "foo") assert doc(m.get_set) == "get_set() -> set" - assert doc(m.print_anyset) == "print_anyset(arg0: anyset) -> None" + assert doc(m.print_anyset) == "print_anyset(arg0: Union[set, frozenset]) -> None" def test_frozenset(capture, doc): @@ -896,3 +896,59 @@ def test_inplace_lshift(a, b): def test_inplace_rshift(a, b): expected = a >> b assert m.inplace_rshift(a, b) == expected + + +def test_tuple_nonempty_annotations(doc): + assert ( + doc(m.annotate_tuple_float_str) + == "annotate_tuple_float_str(arg0: tuple[float, str]) -> None" + ) + + +def test_tuple_empty_annotations(doc): + assert ( + doc(m.annotate_tuple_empty) == "annotate_tuple_empty(arg0: tuple[()]) -> None" + ) + + +def test_tuple_variable_length_annotations(doc): + assert ( + doc(m.annotate_tuple_variable_length) + == "annotate_tuple_variable_length(arg0: tuple[float, ...]) -> None" + ) + + +def test_dict_annotations(doc): + assert ( + doc(m.annotate_dict_str_int) + == "annotate_dict_str_int(arg0: dict[str, int]) -> None" + ) + + +def test_list_annotations(doc): + assert doc(m.annotate_list_int) == "annotate_list_int(arg0: list[int]) -> None" + + +def test_set_annotations(doc): + assert doc(m.annotate_set_str) == "annotate_set_str(arg0: set[str]) -> None" + + +def test_iterable_annotations(doc): + assert ( + doc(m.annotate_iterable_str) + == "annotate_iterable_str(arg0: Iterable[str]) -> None" + ) + + +def test_iterator_annotations(doc): + assert ( + doc(m.annotate_iterator_int) + == "annotate_iterator_int(arg0: Iterator[int]) -> None" + ) + + +def test_fn_annotations(doc): + assert ( + doc(m.annotate_fn) + == "annotate_fn(arg0: Callable[[list[str], str], int]) -> None" + ) diff --git a/extern/pybind11/tests/test_sequences_and_iterators.cpp b/extern/pybind11/tests/test_sequences_and_iterators.cpp index 1de65edbf..4a1d37f4d 100644 --- a/extern/pybind11/tests/test_sequences_and_iterators.cpp +++ b/extern/pybind11/tests/test_sequences_and_iterators.cpp @@ -28,6 +28,13 @@ class NonZeroIterator { public: explicit NonZeroIterator(const T *ptr) : ptr_(ptr) {} + + // Make the iterator non-copyable and movable + NonZeroIterator(const NonZeroIterator &) = delete; + NonZeroIterator(NonZeroIterator &&) noexcept = default; + NonZeroIterator &operator=(const NonZeroIterator &) = delete; + NonZeroIterator &operator=(NonZeroIterator &&) noexcept = default; + const T &operator*() const { return *ptr_; } NonZeroIterator &operator++() { ++ptr_; @@ -78,6 +85,7 @@ class NonCopyableInt { int value_; }; using NonCopyableIntPair = std::pair; + PYBIND11_MAKE_OPAQUE(std::vector); PYBIND11_MAKE_OPAQUE(std::vector); @@ -375,6 +383,17 @@ TEST_SUBMODULE(sequences_and_iterators, m) { private: std::vector> data_; }; + + { + // #4383 : Make sure `py::make_*iterator` functions work with move-only iterators + using iterator_t = NonZeroIterator>; + + static_assert(std::is_move_assignable::value, ""); + static_assert(std::is_move_constructible::value, ""); + static_assert(!std::is_copy_assignable::value, ""); + static_assert(!std::is_copy_constructible::value, ""); + } + py::class_(m, "IntPairs") .def(py::init>>()) .def( diff --git a/extern/pybind11/tests/test_sequences_and_iterators.py b/extern/pybind11/tests/test_sequences_and_iterators.py index dc129f2bf..c13f03dd8 100644 --- a/extern/pybind11/tests/test_sequences_and_iterators.py +++ b/extern/pybind11/tests/test_sequences_and_iterators.py @@ -58,6 +58,15 @@ def test_generalized_iterators_simple(): assert list(m.IntPairs([(1, 2), (3, 4), (0, 5)]).simple_values()) == [2, 4, 5] +def test_iterator_doc_annotations(): + assert m.IntPairs.nonref.__doc__.endswith("-> Iterator[tuple[int, int]]\n") + assert m.IntPairs.nonref_keys.__doc__.endswith("-> Iterator[int]\n") + assert m.IntPairs.nonref_values.__doc__.endswith("-> Iterator[int]\n") + assert m.IntPairs.simple_iterator.__doc__.endswith("-> Iterator[tuple[int, int]]\n") + assert m.IntPairs.simple_keys.__doc__.endswith("-> Iterator[int]\n") + assert m.IntPairs.simple_values.__doc__.endswith("-> Iterator[int]\n") + + def test_iterator_referencing(): """Test that iterators reference rather than copy their referents.""" vec = m.VectorNonCopyableInt() @@ -171,6 +180,10 @@ def __len__(self): assert m.sequence_length("hello") == 5 +def test_sequence_doc(): + assert m.sequence_length.__doc__.strip() == "sequence_length(arg0: Sequence) -> int" + + def test_map_iterator(): sm = m.StringMap({"hi": "bye", "black": "white"}) assert sm["hi"] == "bye" diff --git a/extern/pybind11/tests/test_smart_ptr.cpp b/extern/pybind11/tests/test_smart_ptr.cpp index 6d9efcedc..496073b3c 100644 --- a/extern/pybind11/tests/test_smart_ptr.cpp +++ b/extern/pybind11/tests/test_smart_ptr.cpp @@ -103,21 +103,26 @@ class MyObject3 : public std::enable_shared_from_this { int value; }; +template +std::unordered_set &pointer_set() { + // https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables + static auto singleton = new std::unordered_set(); + return *singleton; +} + // test_unique_nodelete // Object with a private destructor -class MyObject4; -std::unordered_set myobject4_instances; class MyObject4 { public: explicit MyObject4(int value) : value{value} { print_created(this); - myobject4_instances.insert(this); + pointer_set().insert(this); } int value; static void cleanupAllInstances() { - auto tmp = std::move(myobject4_instances); - myobject4_instances.clear(); + auto tmp = std::move(pointer_set()); + pointer_set().clear(); for (auto *o : tmp) { delete o; } @@ -125,7 +130,7 @@ class MyObject4 { private: ~MyObject4() { - myobject4_instances.erase(this); + pointer_set().erase(this); print_destroyed(this); } }; @@ -133,19 +138,17 @@ class MyObject4 { // test_unique_deleter // Object with std::unique_ptr where D is not matching the base class // Object with a protected destructor -class MyObject4a; -std::unordered_set myobject4a_instances; class MyObject4a { public: explicit MyObject4a(int i) : value{i} { print_created(this); - myobject4a_instances.insert(this); + pointer_set().insert(this); }; int value; static void cleanupAllInstances() { - auto tmp = std::move(myobject4a_instances); - myobject4a_instances.clear(); + auto tmp = std::move(pointer_set()); + pointer_set().clear(); for (auto *o : tmp) { delete o; } @@ -153,7 +156,7 @@ class MyObject4a { protected: virtual ~MyObject4a() { - myobject4a_instances.erase(this); + pointer_set().erase(this); print_destroyed(this); } }; diff --git a/extern/pybind11/tests/test_stl.py b/extern/pybind11/tests/test_stl.py index 8a614f8b8..b08bd4680 100644 --- a/extern/pybind11/tests/test_stl.py +++ b/extern/pybind11/tests/test_stl.py @@ -16,8 +16,8 @@ def test_vector(doc): assert m.load_bool_vector([True, False]) assert m.load_bool_vector((True, False)) - assert doc(m.cast_vector) == "cast_vector() -> List[int]" - assert doc(m.load_vector) == "load_vector(arg0: List[int]) -> bool" + assert doc(m.cast_vector) == "cast_vector() -> list[int]" + assert doc(m.load_vector) == "load_vector(arg0: list[int]) -> bool" # Test regression caused by 936: pointers to stl containers weren't castable assert m.cast_ptr_vector() == ["lvalue", "lvalue"] @@ -39,10 +39,10 @@ def test_array(doc): assert m.load_array(lst) assert m.load_array(tuple(lst)) - assert doc(m.cast_array) == "cast_array() -> Annotated[List[int], FixedSize(2)]" + assert doc(m.cast_array) == "cast_array() -> Annotated[list[int], FixedSize(2)]" assert ( doc(m.load_array) - == "load_array(arg0: Annotated[List[int], FixedSize(2)]) -> bool" + == "load_array(arg0: Annotated[list[int], FixedSize(2)]) -> bool" ) @@ -53,8 +53,8 @@ def test_valarray(doc): assert m.load_valarray(lst) assert m.load_valarray(tuple(lst)) - assert doc(m.cast_valarray) == "cast_valarray() -> List[int]" - assert doc(m.load_valarray) == "load_valarray(arg0: List[int]) -> bool" + assert doc(m.cast_valarray) == "cast_valarray() -> list[int]" + assert doc(m.load_valarray) == "load_valarray(arg0: list[int]) -> bool" def test_map(doc): @@ -66,8 +66,8 @@ def test_map(doc): assert "key2" in d assert m.load_map(d) - assert doc(m.cast_map) == "cast_map() -> Dict[str, str]" - assert doc(m.load_map) == "load_map(arg0: Dict[str, str]) -> bool" + assert doc(m.cast_map) == "cast_map() -> dict[str, str]" + assert doc(m.load_map) == "load_map(arg0: dict[str, str]) -> bool" def test_set(doc): @@ -78,8 +78,8 @@ def test_set(doc): assert m.load_set(s) assert m.load_set(frozenset(s)) - assert doc(m.cast_set) == "cast_set() -> Set[str]" - assert doc(m.load_set) == "load_set(arg0: Set[str]) -> bool" + assert doc(m.cast_set) == "cast_set() -> set[str]" + assert doc(m.load_set) == "load_set(arg0: set[str]) -> bool" def test_recursive_casting(): @@ -303,7 +303,7 @@ def test_stl_pass_by_pointer(msg): msg(excinfo.value) == """ stl_pass_by_pointer(): incompatible function arguments. The following argument types are supported: - 1. (v: List[int] = None) -> List[int] + 1. (v: list[int] = None) -> list[int] Invoked with: """ @@ -315,7 +315,7 @@ def test_stl_pass_by_pointer(msg): msg(excinfo.value) == """ stl_pass_by_pointer(): incompatible function arguments. The following argument types are supported: - 1. (v: List[int] = None) -> List[int] + 1. (v: list[int] = None) -> list[int] Invoked with: None """ diff --git a/extern/pybind11/tests/test_stl_binders.cpp b/extern/pybind11/tests/test_stl_binders.cpp index 1681760aa..96af9a4c4 100644 --- a/extern/pybind11/tests/test_stl_binders.cpp +++ b/extern/pybind11/tests/test_stl_binders.cpp @@ -15,6 +15,7 @@ #include #include #include +#include class El { public: @@ -83,6 +84,71 @@ struct RecursiveMap : std::map { using Parent::Parent; }; +class UserVectorLike : private std::vector { +public: + // This is only a subset of the member functions, as needed at the time. + using Base = std::vector; + using typename Base::const_iterator; + using typename Base::difference_type; + using typename Base::iterator; + using typename Base::size_type; + using typename Base::value_type; + + using Base::at; + using Base::back; + using Base::Base; + using Base::begin; + using Base::cbegin; + using Base::cend; + using Base::clear; + using Base::empty; + using Base::end; + using Base::erase; + using Base::front; + using Base::insert; + using Base::pop_back; + using Base::push_back; + using Base::reserve; + using Base::shrink_to_fit; + using Base::swap; + using Base::operator[]; + using Base::capacity; + using Base::size; +}; + +bool operator==(UserVectorLike const &, UserVectorLike const &) { return true; } +bool operator!=(UserVectorLike const &, UserVectorLike const &) { return false; } + +class UserMapLike : private std::map { +public: + // This is only a subset of the member functions, as needed at the time. + using Base = std::map; + using typename Base::const_iterator; + using typename Base::iterator; + using typename Base::key_type; + using typename Base::mapped_type; + using typename Base::size_type; + using typename Base::value_type; + + using Base::at; + using Base::Base; + using Base::begin; + using Base::cbegin; + using Base::cend; + using Base::clear; + using Base::emplace; + using Base::emplace_hint; + using Base::empty; + using Base::end; + using Base::erase; + using Base::find; + using Base::insert; + using Base::max_size; + using Base::swap; + using Base::operator[]; + using Base::size; +}; + /* * Pybind11 does not catch more complicated recursion schemes, such as mutual * recursion. @@ -126,6 +192,16 @@ TEST_SUBMODULE(stl_binders, m) { py::bind_map>(m, "UnorderedMapStringDoubleConst"); + // test_map_view_types + py::bind_map>(m, "MapStringFloat"); + py::bind_map>(m, "UnorderedMapStringFloat"); + + py::bind_map, int32_t>>(m, "MapPairDoubleIntInt32"); + py::bind_map, int64_t>>(m, "MapPairDoubleIntInt64"); + + py::bind_map>(m, "MapIntObject"); + py::bind_map>(m, "MapStringObject"); + py::class_(m, "ENC").def(py::init()).def_readwrite("value", &E_nc::value); // test_noncopyable_containers @@ -173,6 +249,10 @@ TEST_SUBMODULE(stl_binders, m) { py::bind_map(m, "MutuallyRecursiveContainerPairMV"); py::bind_vector(m, "MutuallyRecursiveContainerPairVM"); + // Bind with private inheritance + `using` directives. + py::bind_vector(m, "UserVectorLike"); + py::bind_map(m, "UserMapLike"); + // The rest depends on numpy: try { py::module_::import("numpy"); diff --git a/extern/pybind11/tests/test_stl_binders.py b/extern/pybind11/tests/test_stl_binders.py index e002f5b67..d1bf64aa0 100644 --- a/extern/pybind11/tests/test_stl_binders.py +++ b/extern/pybind11/tests/test_stl_binders.py @@ -209,7 +209,7 @@ def test_map_string_double_const(): def test_noncopyable_containers(): # std::vector vnc = m.get_vnc(5) - for i in range(0, 5): + for i in range(5): assert vnc[i].value == i + 1 for i, j in enumerate(vnc, start=1): @@ -217,7 +217,7 @@ def test_noncopyable_containers(): # std::deque dnc = m.get_dnc(5) - for i in range(0, 5): + for i in range(5): assert dnc[i].value == i + 1 i = 1 @@ -252,7 +252,7 @@ def test_noncopyable_containers(): # nested std::map nvnc = m.get_nvnc(5) for i in range(1, 6): - for j in range(0, 5): + for j in range(5): assert nvnc[i][j].value == j + 1 # Note: maps do not have .values() @@ -317,9 +317,9 @@ def test_map_view_types(): map_string_double_const = m.MapStringDoubleConst() unordered_map_string_double_const = m.UnorderedMapStringDoubleConst() - assert map_string_double.keys().__class__.__name__ == "KeysView[str]" - assert map_string_double.values().__class__.__name__ == "ValuesView[float]" - assert map_string_double.items().__class__.__name__ == "ItemsView[str, float]" + assert map_string_double.keys().__class__.__name__ == "KeysView" + assert map_string_double.values().__class__.__name__ == "ValuesView" + assert map_string_double.items().__class__.__name__ == "ItemsView" keys_type = type(map_string_double.keys()) assert type(unordered_map_string_double.keys()) is keys_type @@ -336,6 +336,30 @@ def test_map_view_types(): assert type(map_string_double_const.items()) is items_type assert type(unordered_map_string_double_const.items()) is items_type + map_string_float = m.MapStringFloat() + unordered_map_string_float = m.UnorderedMapStringFloat() + + assert type(map_string_float.keys()) is keys_type + assert type(unordered_map_string_float.keys()) is keys_type + assert type(map_string_float.values()) is values_type + assert type(unordered_map_string_float.values()) is values_type + assert type(map_string_float.items()) is items_type + assert type(unordered_map_string_float.items()) is items_type + + map_pair_double_int_int32 = m.MapPairDoubleIntInt32() + map_pair_double_int_int64 = m.MapPairDoubleIntInt64() + + assert type(map_pair_double_int_int32.values()) is values_type + assert type(map_pair_double_int_int64.values()) is values_type + + map_int_object = m.MapIntObject() + map_string_object = m.MapStringObject() + + assert type(map_int_object.keys()) is keys_type + assert type(map_string_object.keys()) is keys_type + assert type(map_int_object.items()) is items_type + assert type(map_string_object.items()) is items_type + def test_recursive_vector(): recursive_vector = m.RecursiveVector() @@ -353,3 +377,17 @@ def test_recursive_map(): recursive_map[100][101] = m.RecursiveMap() recursive_map[100][102] = m.RecursiveMap() assert list(recursive_map[100].keys()) == [101, 102] + + +def test_user_vector_like(): + vec = m.UserVectorLike() + vec.append(2) + assert vec[0] == 2 + assert len(vec) == 1 + + +def test_user_like_map(): + map = m.UserMapLike() + map[33] = 44 + assert map[33] == 44 + assert len(map) == 1 diff --git a/extern/pybind11/tests/test_type_caster_pyobject_ptr.cpp b/extern/pybind11/tests/test_type_caster_pyobject_ptr.cpp index 1667ea126..8069f7dcd 100644 --- a/extern/pybind11/tests/test_type_caster_pyobject_ptr.cpp +++ b/extern/pybind11/tests/test_type_caster_pyobject_ptr.cpp @@ -78,14 +78,14 @@ TEST_SUBMODULE(type_caster_pyobject_ptr, m) { m.def("cast_to_pyobject_ptr_nullptr", [](bool set_error) { if (set_error) { - PyErr_SetString(PyExc_RuntimeError, "Reflective of healthy error handling."); + py::set_error(PyExc_RuntimeError, "Reflective of healthy error handling."); } PyObject *ptr = nullptr; py::cast(ptr); }); m.def("cast_to_pyobject_ptr_non_nullptr_with_error_set", []() { - PyErr_SetString(PyExc_RuntimeError, "Reflective of unhealthy error handling."); + py::set_error(PyExc_RuntimeError, "Reflective of unhealthy error handling."); py::cast(Py_None); }); diff --git a/extern/pybind11/tools/FindPythonLibsNew.cmake b/extern/pybind11/tools/FindPythonLibsNew.cmake index 76537631e..8275b9d5a 100644 --- a/extern/pybind11/tools/FindPythonLibsNew.cmake +++ b/extern/pybind11/tools/FindPythonLibsNew.cmake @@ -95,14 +95,24 @@ if(NOT PythonLibsNew_FIND_VERSION) set(PythonLibsNew_FIND_VERSION "3.6") endif() -if(POLICY CMP0148) - cmake_policy(SET CMP0148 OLD) #---LIBOPENCOR--- +if(NOT CMAKE_VERSION VERSION_LESS "3.27") + cmake_policy(GET CMP0148 _pybind11_cmp0148) + if(NOT _pybind11_cmp0148) + message( + AUTHOR_WARNING + "Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs " + "modules are removed. Run \"cmake --help-policy CMP0148\" for policy " + "details. Use the cmake_policy command to set the policy and suppress " + "this warning, or preferably upgrade to using FindPython, either by " + "calling it explicitly before pybind11, or by setting " + "PYBIND11_FINDPYTHON ON before pybind11.") + endif() + cmake_policy(SET CMP0148 OLD) + unset(_pybind11_cmp0148) endif() + find_package(PythonInterp ${PythonLibsNew_FIND_VERSION} ${_pythonlibs_required} ${_pythonlibs_quiet}) -if(POLICY CMP0148) - cmake_policy(SET CMP0148 NEW) #---LIBOPENCOR--- -endif() if(NOT PYTHONINTERP_FOUND) set(PYTHONLIBS_FOUND FALSE) @@ -178,13 +188,20 @@ _pybind11_get_if_undef(_PYTHON_VALUES 0 _PYTHON_VERSION_LIST) _pybind11_get_if_undef(_PYTHON_VALUES 1 PYTHON_PREFIX) _pybind11_get_if_undef(_PYTHON_VALUES 2 PYTHON_INCLUDE_DIR) _pybind11_get_if_undef(_PYTHON_VALUES 3 PYTHON_SITE_PACKAGES) -_pybind11_get_if_undef(_PYTHON_VALUES 4 PYTHON_MODULE_EXTENSION) _pybind11_get_if_undef(_PYTHON_VALUES 5 PYTHON_IS_DEBUG) _pybind11_get_if_undef(_PYTHON_VALUES 6 PYTHON_SIZEOF_VOID_P) _pybind11_get_if_undef(_PYTHON_VALUES 7 PYTHON_LIBRARY_SUFFIX) _pybind11_get_if_undef(_PYTHON_VALUES 8 PYTHON_LIBDIR) _pybind11_get_if_undef(_PYTHON_VALUES 9 PYTHON_MULTIARCH) +list(GET _PYTHON_VALUES 4 _PYTHON_MODULE_EXT_SUFFIX) +if(PYBIND11_PYTHONLIBS_OVERWRITE OR NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX) + get_filename_component(PYTHON_MODULE_DEBUG_POSTFIX "${_PYTHON_MODULE_EXT_SUFFIX}" NAME_WE) +endif() +if(PYBIND11_PYTHONLIBS_OVERWRITE OR NOT DEFINED PYTHON_MODULE_EXTENSION) + get_filename_component(PYTHON_MODULE_EXTENSION "${_PYTHON_MODULE_EXT_SUFFIX}" EXT) +endif() + # Make sure the Python has the same pointer-size as the chosen compiler # Skip if CMAKE_SIZEOF_VOID_P is not defined # This should be skipped for (non-Apple) cross-compiles (like EMSCRIPTEN) diff --git a/extern/pybind11/tools/make_changelog.py b/extern/pybind11/tools/make_changelog.py index b5bd83294..89cf66483 100755 --- a/extern/pybind11/tools/make_changelog.py +++ b/extern/pybind11/tools/make_changelog.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +from __future__ import annotations import re @@ -29,6 +30,18 @@ ) issues = (issue for page in issues_pages for issue in page) missing = [] +cats_descr = { + "feat": "New Features", + "fix": "Bug fixes", + "fix(types)": "", + "fix(cmake)": "", + "docs": "Documentation", + "tests": "Tests", + "ci": "CI", + "chore": "Other", + "unknown": "Uncategorised", +} +cats: dict[str, list[str]] = {c: [] for c in cats_descr} for issue in issues: changelog = ENTRY.findall(issue.body or "") @@ -36,14 +49,29 @@ missing.append(issue) else: (msg,) = changelog + if msg.startswith("- "): + msg = msg[2:] if not msg.startswith("* "): msg = "* " + msg if not msg.endswith("."): msg += "." msg += f"\n `#{issue.number} <{issue.html_url}>`_" + for cat in cats: + if issue.title.lower().startswith(f"{cat}:"): + cats[cat].append(msg) + break + else: + cats["unknown"].append(msg) - print(Syntax(msg, "rst", theme="ansi_light", word_wrap=True)) +for cat, msgs in cats.items(): + if msgs: + desc = cats_descr[cat] + print(f"[bold]{desc}:" if desc else f".. {cat}") + print() + for msg in msgs: + print(Syntax(msg, "rst", theme="ansi_light", word_wrap=True)) + print() print() if missing: diff --git a/extern/pybind11/tools/pybind11Common.cmake b/extern/pybind11/tools/pybind11Common.cmake index 308d1b70d..57721aeb1 100644 --- a/extern/pybind11/tools/pybind11Common.cmake +++ b/extern/pybind11/tools/pybind11Common.cmake @@ -173,12 +173,16 @@ endif() # Check to see which Python mode we are in, new, old, or no python if(PYBIND11_NOPYTHON) set(_pybind11_nopython ON) + # We won't use new FindPython if PYBIND11_FINDPYTHON is defined and falselike + # Otherwise, we use if FindPythonLibs is missing or if FindPython was already used elseif( - _pybind11_missing_old_python STREQUAL "NEW" - OR PYBIND11_FINDPYTHON - OR Python_FOUND - OR Python2_FOUND - OR Python3_FOUND) + (NOT DEFINED PYBIND11_FINDPYTHON OR PYBIND11_FINDPYTHON) + AND (_pybind11_missing_old_python STREQUAL "NEW" + OR PYBIND11_FINDPYTHON + OR Python_FOUND + OR Python3_FOUND + )) + # New mode include("${CMAKE_CURRENT_LIST_DIR}/pybind11NewTools.cmake") @@ -218,8 +222,15 @@ if(NOT _pybind11_nopython) execute_process( COMMAND - ${${_Python}_EXECUTABLE} -c - "from pkg_resources import get_distribution; print(get_distribution('${PYPI_NAME}').version)" + ${${_Python}_EXECUTABLE} -c " +try: + from importlib.metadata import version +except ImportError: + from pkg_resources import get_distribution + def version(s): + return get_distribution(s).version +print(version('${PYPI_NAME}')) + " RESULT_VARIABLE RESULT_PRESENT OUTPUT_VARIABLE PKG_VERSION ERROR_QUIET) @@ -300,21 +311,24 @@ function(_pybind11_generate_lto target prefer_thin_lto) set(cxx_append ";-fno-fat-lto-objects") endif() - if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le" OR CMAKE_SYSTEM_PROCESSOR MATCHES "mips64") - set(NO_FLTO_ARCH TRUE) + if(prefer_thin_lto) + set(thin "=thin") else() - set(NO_FLTO_ARCH FALSE) + set(thin "") endif() - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" - AND prefer_thin_lto - AND NOT NO_FLTO_ARCH) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le" OR CMAKE_SYSTEM_PROCESSOR MATCHES "mips64") + # Do nothing + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES emscripten) + # This compile is very costly when cross-compiling, so set this without checking + set(PYBIND11_LTO_CXX_FLAGS "-flto${thin}${cxx_append}") + set(PYBIND11_LTO_LINKER_FLAGS "-flto${thin}${linker_append}") + elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") _pybind11_return_if_cxx_and_linker_flags_work( - HAS_FLTO_THIN "-flto=thin${cxx_append}" "-flto=thin${linker_append}" + HAS_FLTO_THIN "-flto${thin}${cxx_append}" "-flto=${thin}${linker_append}" PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS) endif() - - if(NOT HAS_FLTO_THIN AND NOT NO_FLTO_ARCH) + if(NOT HAS_FLTO_THIN) _pybind11_return_if_cxx_and_linker_flags_work( HAS_FLTO "-flto${cxx_append}" "-flto${linker_append}" PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS) diff --git a/extern/pybind11/tools/pybind11Config.cmake.in b/extern/pybind11/tools/pybind11Config.cmake.in index 5734f437b..304f1d907 100644 --- a/extern/pybind11/tools/pybind11Config.cmake.in +++ b/extern/pybind11/tools/pybind11Config.cmake.in @@ -149,7 +149,7 @@ default is ``MODULE``. There are several options: ``OPT_SIZE`` Optimize for size, even if the ``CMAKE_BUILD_TYPE`` is not ``MinSizeRel``. ``THIN_LTO`` - Use thin TLO instead of regular if there's a choice (pybind11's selection + Use thin LTO instead of regular if there's a choice (pybind11's selection is disabled if ``CMAKE_INTERPROCEDURAL_OPTIMIZATIONS`` is set). ``WITHOUT_SOABI`` Disable the SOABI component (``PYBIND11_NEWPYTHON`` mode only). diff --git a/extern/pybind11/tools/pybind11NewTools.cmake b/extern/pybind11/tools/pybind11NewTools.cmake index 7d7424a79..9fe2eb08d 100644 --- a/extern/pybind11/tools/pybind11NewTools.cmake +++ b/extern/pybind11/tools/pybind11NewTools.cmake @@ -32,17 +32,54 @@ if(NOT Python_FOUND AND NOT Python3_FOUND) set(Python_ROOT_DIR "$ENV{pythonLocation}") endif() - find_package(Python 3.6 REQUIRED COMPONENTS Interpreter Development ${_pybind11_quiet}) + # Development.Module support (required for manylinux) started in 3.18 + if(CMAKE_VERSION VERSION_LESS 3.18) + set(_pybind11_dev_component Development) + else() + set(_pybind11_dev_component Development.Module OPTIONAL_COMPONENTS Development.Embed) + endif() + + # Callers need to be able to access Python_EXECUTABLE + set(_pybind11_global_keyword "") + if(NOT is_config AND NOT DEFINED Python_ARTIFACTS_INTERACTIVE) + set(Python_ARTIFACTS_INTERACTIVE TRUE) + if(NOT CMAKE_VERSION VERSION_LESS 3.24) + set(_pybind11_global_keyword "GLOBAL") + endif() + endif() + + find_package(Python 3.6 REQUIRED COMPONENTS Interpreter ${_pybind11_dev_component} + ${_pybind11_quiet} ${_pybind11_global_keyword}) # If we are in submodule mode, export the Python targets to global targets. # If this behavior is not desired, FindPython _before_ pybind11. - if(NOT is_config) - set_property(TARGET Python::Python PROPERTY IMPORTED_GLOBAL TRUE) + if(NOT is_config + AND Python_ARTIFACTS_INTERACTIVE + AND _pybind11_global_keyword STREQUAL "") + if(TARGET Python::Python) + set_property(TARGET Python::Python PROPERTY IMPORTED_GLOBAL TRUE) + endif() set_property(TARGET Python::Interpreter PROPERTY IMPORTED_GLOBAL TRUE) if(TARGET Python::Module) set_property(TARGET Python::Module PROPERTY IMPORTED_GLOBAL TRUE) endif() endif() + + # Explicitly export version for callers (including our own functions) + if(NOT is_config AND Python_ARTIFACTS_INTERACTIVE) + set(Python_VERSION + "${Python_VERSION}" + CACHE INTERNAL "") + set(Python_VERSION_MAJOR + "${Python_VERSION_MAJOR}" + CACHE INTERNAL "") + set(Python_VERSION_MINOR + "${Python_VERSION_MINOR}" + CACHE INTERNAL "") + set(Python_VERSION_PATCH + "${Python_VERSION_PATCH}" + CACHE INTERNAL "") + endif() endif() if(Python_FOUND) @@ -73,15 +110,17 @@ if(NOT DEFINED ${_Python}_EXECUTABLE) endif() -if(NOT ${_Python}_EXECUTABLE STREQUAL PYBIND11_PYTHON_EXECUTABLE_LAST) +if(DEFINED PYBIND11_PYTHON_EXECUTABLE_LAST AND NOT ${_Python}_EXECUTABLE STREQUAL + PYBIND11_PYTHON_EXECUTABLE_LAST) # Detect changes to the Python version/binary in subsequent CMake runs, and refresh config if needed unset(PYTHON_IS_DEBUG CACHE) unset(PYTHON_MODULE_EXTENSION CACHE) - set(PYBIND11_PYTHON_EXECUTABLE_LAST - "${${_Python}_EXECUTABLE}" - CACHE INTERNAL "Python executable during the last CMake run") endif() +set(PYBIND11_PYTHON_EXECUTABLE_LAST + "${${_Python}_EXECUTABLE}" + CACHE INTERNAL "Python executable during the last CMake run") + if(NOT DEFINED PYTHON_IS_DEBUG) # Debug check - see https://stackoverflow.com/questions/646518/python-how-to-detect-debug-Interpreter execute_process( @@ -95,25 +134,36 @@ endif() # Get the suffix - SO is deprecated, should use EXT_SUFFIX, but this is # required for PyPy3 (as of 7.3.1) -if(NOT DEFINED PYTHON_MODULE_EXTENSION) +if(NOT DEFINED PYTHON_MODULE_EXTENSION OR NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX) execute_process( COMMAND "${${_Python}_EXECUTABLE}" "-c" "import sys, importlib; s = importlib.import_module('distutils.sysconfig' if sys.version_info < (3, 10) else 'sysconfig'); print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'))" - OUTPUT_VARIABLE _PYTHON_MODULE_EXTENSION - ERROR_VARIABLE _PYTHON_MODULE_EXTENSION_ERR + OUTPUT_VARIABLE _PYTHON_MODULE_EXT_SUFFIX + ERROR_VARIABLE _PYTHON_MODULE_EXT_SUFFIX_ERR OUTPUT_STRIP_TRAILING_WHITESPACE) - if(_PYTHON_MODULE_EXTENSION STREQUAL "") + if(_PYTHON_MODULE_EXT_SUFFIX STREQUAL "") message( FATAL_ERROR "pybind11 could not query the module file extension, likely the 'distutils'" - "package is not installed. Full error message:\n${_PYTHON_MODULE_EXTENSION_ERR}") + "package is not installed. Full error message:\n${_PYTHON_MODULE_EXT_SUFFIX_ERR}" + ) endif() # This needs to be available for the pybind11_extension function - set(PYTHON_MODULE_EXTENSION - "${_PYTHON_MODULE_EXTENSION}" - CACHE INTERNAL "") + if(NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX) + get_filename_component(_PYTHON_MODULE_DEBUG_POSTFIX "${_PYTHON_MODULE_EXT_SUFFIX}" NAME_WE) + set(PYTHON_MODULE_DEBUG_POSTFIX + "${_PYTHON_MODULE_DEBUG_POSTFIX}" + CACHE INTERNAL "") + endif() + + if(NOT DEFINED PYTHON_MODULE_EXTENSION) + get_filename_component(_PYTHON_MODULE_EXTENSION "${_PYTHON_MODULE_EXT_SUFFIX}" EXT) + set(PYTHON_MODULE_EXTENSION + "${_PYTHON_MODULE_EXTENSION}" + CACHE INTERNAL "") + endif() endif() # Python debug libraries expose slightly different objects before 3.8 @@ -233,11 +283,13 @@ function(pybind11_add_module target_name) endif() endif() - # Use case-insensitive comparison to match the result of $ - string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) - if(NOT MSVC AND NOT "${uppercase_CMAKE_BUILD_TYPE}" MATCHES DEBUG|RELWITHDEBINFO) - # Strip unnecessary sections of the binary on Linux/macOS - pybind11_strip(${target_name}) + if(DEFINED CMAKE_BUILD_TYPE) # see https://github.com/pybind/pybind11/issues/4454 + # Use case-insensitive comparison to match the result of $ + string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) + if(NOT MSVC AND NOT "${uppercase_CMAKE_BUILD_TYPE}" MATCHES DEBUG|RELWITHDEBINFO) + # Strip unnecessary sections of the binary on Linux/macOS + pybind11_strip(${target_name}) + endif() endif() if(MSVC) @@ -251,6 +303,9 @@ endfunction() function(pybind11_extension name) # The extension is precomputed - set_target_properties(${name} PROPERTIES PREFIX "" SUFFIX "${PYTHON_MODULE_EXTENSION}") - + set_target_properties( + ${name} + PROPERTIES PREFIX "" + DEBUG_POSTFIX "${PYTHON_MODULE_DEBUG_POSTFIX}" + SUFFIX "${PYTHON_MODULE_EXTENSION}") endfunction() diff --git a/extern/pybind11/tools/pybind11Tools.cmake b/extern/pybind11/tools/pybind11Tools.cmake index 66ad00a47..045e5f1e7 100644 --- a/extern/pybind11/tools/pybind11Tools.cmake +++ b/extern/pybind11/tools/pybind11Tools.cmake @@ -43,7 +43,7 @@ endif() # A user can set versions manually too set(Python_ADDITIONAL_VERSIONS - "3.11;3.10;3.9;3.8;3.7;3.6" + "3.12;3.11;3.10;3.9;3.8;3.7;3.6" CACHE INTERNAL "") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") @@ -65,6 +65,7 @@ _pybind11_promote_to_cache(PYTHON_INCLUDE_DIRS) _pybind11_promote_to_cache(PYTHON_LIBRARIES) _pybind11_promote_to_cache(PYTHON_MODULE_PREFIX) _pybind11_promote_to_cache(PYTHON_MODULE_EXTENSION) +_pybind11_promote_to_cache(PYTHON_MODULE_DEBUG_POSTFIX) _pybind11_promote_to_cache(PYTHON_VERSION_MAJOR) _pybind11_promote_to_cache(PYTHON_VERSION_MINOR) _pybind11_promote_to_cache(PYTHON_VERSION) @@ -148,8 +149,11 @@ endif() function(pybind11_extension name) # The prefix and extension are provided by FindPythonLibsNew.cmake - set_target_properties(${name} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}" - SUFFIX "${PYTHON_MODULE_EXTENSION}") + set_target_properties( + ${name} + PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}" + DEBUG_POSTFIX "${PYTHON_MODULE_DEBUG_POSTFIX}" + SUFFIX "${PYTHON_MODULE_EXTENSION}") endfunction() # Build a Python extension module: @@ -212,10 +216,12 @@ function(pybind11_add_module target_name) endif() endif() - # Use case-insensitive comparison to match the result of $ - string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) - if(NOT MSVC AND NOT "${uppercase_CMAKE_BUILD_TYPE}" MATCHES DEBUG|RELWITHDEBINFO) - pybind11_strip(${target_name}) + if(DEFINED CMAKE_BUILD_TYPE) # see https://github.com/pybind/pybind11/issues/4454 + # Use case-insensitive comparison to match the result of $ + string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) + if(NOT MSVC AND NOT "${uppercase_CMAKE_BUILD_TYPE}" MATCHES DEBUG|RELWITHDEBINFO) + pybind11_strip(${target_name}) + endif() endif() if(MSVC) From 2b760c1111bd45c1d15dab701d01ceafc72bdd8b Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 21 May 2024 14:57:48 +1200 Subject: [PATCH 02/11] CMake: some minor cleaning up. --- cmake/common.cmake | 2 +- cmake/packages.cmake | 6 +++--- src/3rdparty/CMakeLists.txt | 6 +++--- src/bindings/javascript/CMakeLists.txt | 2 -- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/cmake/common.cmake b/cmake/common.cmake index 7e323f520..c4ccbc6af 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -347,7 +347,7 @@ endfunction() macro(add_target TARGET) add_custom_target(${TARGET} ${ARGN}) - set(TARGETS "${TARGETS};${TARGET}") + list(APPEND TARGETS ${TARGET}) list(SORT TARGETS) diff --git a/cmake/packages.cmake b/cmake/packages.cmake index 2cd67b48d..109be3e93 100644 --- a/cmake/packages.cmake +++ b/cmake/packages.cmake @@ -22,7 +22,7 @@ function(check_dependent_packages PACKAGE) if(LIBOPENCOR_PREBUILT_${DEPENDENT_PACKAGE_UC}) set(LIBOPENCOR_PREBUILT_${DEPENDENT_PACKAGE_UC} OFF CACHE BOOL "${LIBOPENCOR_PREBUILT_${PACKAGE_UC}_DOCSTRING}" FORCE) - set(DEPENDENT_PACKAGES_TO_BUILD "${DEPENDENT_PACKAGES_TO_BUILD};${DEPENDENT_PACKAGE}") + list(APPEND DEPENDENT_PACKAGES_TO_BUILD ${DEPENDENT_PACKAGE}) list(SORT DEPENDENT_PACKAGES_TO_BUILD) @@ -131,7 +131,7 @@ function(add_package PACKAGE) # Keep track of the package. - set(AVAILABLE_PACKAGES "${AVAILABLE_PACKAGES};${PACKAGE}") + list(APPEND AVAILABLE_PACKAGES ${PACKAGE}) list(SORT AVAILABLE_PACKAGES) @@ -141,7 +141,7 @@ function(add_package PACKAGE) file(GLOB PACKAGE_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${PACKAGE}/*.h") - set(THIRD_PARTY_HEADER_FILES "${THIRD_PARTY_HEADER_FILES};${PACKAGE_HEADER_FILES}") + list(APPEND THIRD_PARTY_HEADER_FILES ${PACKAGE_HEADER_FILES}) set(THIRD_PARTY_HEADER_FILES "${THIRD_PARTY_HEADER_FILES}" CACHE INTERNAL "Third-party (special) header files.") endfunction() diff --git a/src/3rdparty/CMakeLists.txt b/src/3rdparty/CMakeLists.txt index 18724855b..115c8f248 100644 --- a/src/3rdparty/CMakeLists.txt +++ b/src/3rdparty/CMakeLists.txt @@ -30,7 +30,7 @@ foreach(PACKAGE ${PACKAGES}) string(TOUPPER "${PACKAGE}" PACKAGE_UC) if(NOT LIBOPENCOR_PREBUILT_${PACKAGE_UC}) - set(PACKAGES_TO_BUILD "${PACKAGES_TO_BUILD};${PACKAGE}") + list(APPEND PACKAGES_TO_BUILD ${PACKAGE}) endif() endforeach() @@ -99,10 +99,10 @@ add_package(zipper) # Requires zlib. # Required third-party libraries. add_package(libCellML) # Requires libxml2 and zlib. -add_package(libCOMBINE) # Requires libSBML, zipper and zlib. +add_package(libCOMBINE) # Requires libSBML, zipper, and zlib. if(NOT EMSCRIPTEN) - add_package(libcurl) # Requires libssh2, OpenSSL and zlib. + add_package(libcurl) # Requires libssh2, OpenSSL, and zlib. endif() add_package(libSEDML) # Requires libNuML and libSBML. diff --git a/src/bindings/javascript/CMakeLists.txt b/src/bindings/javascript/CMakeLists.txt index dbb57d808..1e175b358 100644 --- a/src/bindings/javascript/CMakeLists.txt +++ b/src/bindings/javascript/CMakeLists.txt @@ -47,7 +47,6 @@ if(EMSCRIPTEN OR LIBOPENCOR_JAVASCRIPT_BINDINGS) ${CLCACHE_EXE} ${EMCMAKE_EXE} ${EMCONFIGURE_EXE} - ${NATIVE_PREBUILT_DIR} ) else() # Build our JavaScript bindings. @@ -73,7 +72,6 @@ if(EMSCRIPTEN OR LIBOPENCOR_JAVASCRIPT_BINDINGS) -DLIBOPENCOR_PREBUILT_SUNDIALS=${LIBOPENCOR_PREBUILT_SUNDIALS} -DLIBOPENCOR_PREBUILT_ZIPPER=${LIBOPENCOR_PREBUILT_ZIPPER} -DLIBOPENCOR_PREBUILT_ZLIB=${LIBOPENCOR_PREBUILT_ZLIB} - -DNATIVE_PREBUILT_DIR=${PREBUILT_DIR} -DREAL_CMAKE_PROJECT_NAME=${CMAKE_PROJECT_NAME} COMMAND ${CMAKE_COMMAND} --build build) From ceff64610083feb4f973f3a1ff1dc4b9d6a31b97 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Sat, 25 May 2024 20:56:20 +1200 Subject: [PATCH 03/11] CMake: optimised the building of third-party libraries. Only add the third-party libraries that are relevant. --- .github/workflows/buildThirdPartyLibrary.yml | 1 - cmake/packages.cmake | 32 ++++++++++++++++++++ src/3rdparty/CMakeLists.txt | 25 +++++++++++++++ src/CMakeLists.txt | 8 +++++ src/bindings/javascript/CMakeLists.txt | 13 +++++--- src/dummy.cpp | 20 ++++++++++++ 6 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 src/dummy.cpp diff --git a/.github/workflows/buildThirdPartyLibrary.yml b/.github/workflows/buildThirdPartyLibrary.yml index 6fef7f533..a6559d07a 100644 --- a/.github/workflows/buildThirdPartyLibrary.yml +++ b/.github/workflows/buildThirdPartyLibrary.yml @@ -92,7 +92,6 @@ jobs: with: arch: ${{ matrix.arch }} - name: Configure libOpenCOR - shell: bash run: | mkdir build cd build diff --git a/cmake/packages.cmake b/cmake/packages.cmake index 109be3e93..163a6f2fa 100644 --- a/cmake/packages.cmake +++ b/cmake/packages.cmake @@ -32,6 +32,26 @@ function(check_dependent_packages PACKAGE) endif() endfunction() +function(check_required_packages PACKAGE) + string(TOUPPER "${PACKAGE}" PACKAGE_UC) + + if(NOT LIBOPENCOR_PREBUILT_${PACKAGE_UC}) + foreach(REQUIRED_PACKAGE ${ARGN}) + string(TOUPPER "${REQUIRED_PACKAGE}" DEPENDENT_PACKAGE_UC) + + list(FIND REQUIRED_PACKAGES_TO_ADD ${REQUIRED_PACKAGE} INDEX) + + if(INDEX EQUAL -1) + list(APPEND REQUIRED_PACKAGES_TO_ADD ${REQUIRED_PACKAGE}) + + list(SORT REQUIRED_PACKAGES_TO_ADD) + + set(REQUIRED_PACKAGES_TO_ADD "${REQUIRED_PACKAGES_TO_ADD}" CACHE INTERNAL "Required packages to be added.") + endif() + endforeach() + endif() +endfunction() + function(build_package PACKAGE_NAME) # Configure and run a CMake script to build the package for us. @@ -127,6 +147,18 @@ function(create_package PACKAGE_NAME PACKAGE_VERSION PACKAGE_REPOSITORY RELEASE_ endfunction() function(add_package PACKAGE) + # Check whether the package is one that we want to add. + + if(ONLY_BUILD_THIRD_PARTY_LIBRARIES) + list(FIND PACKAGES_TO_ADD ${PACKAGE} INDEX) + + if(INDEX EQUAL -1) + return() + endif() + endif() + + # Add the package. + add_subdirectory(${PACKAGE}) # Keep track of the package. diff --git a/src/3rdparty/CMakeLists.txt b/src/3rdparty/CMakeLists.txt index 115c8f248..16ed8e626 100644 --- a/src/3rdparty/CMakeLists.txt +++ b/src/3rdparty/CMakeLists.txt @@ -72,6 +72,26 @@ if(NOT "${DEPENDENT_PACKAGES_TO_BUILD}" STREQUAL "") endforeach() endif() +# Keep track of which packages are required to build the requested packages. + +check_required_packages(libSBML libxml2) +check_required_packages(libNuML libSBML) + +if(NOT EMSCRIPTEN) + check_required_packages(libssh2 OpenSSL) +endif() + +check_required_packages(zipper zlib) + +check_required_packages(libCellML libxml2 zlib) +check_required_packages(libCOMBINE libSBML zipper zlib) + +if(NOT EMSCRIPTEN) + check_required_packages(libcurl libssh2 OpenSSL zlib) +endif() + +check_required_packages(libSEDML libNuML libSBML) + # Initialise/reset our available packages and third-party (special) header files. set(AVAILABLE_PACKAGES "" CACHE INTERNAL "Available packages.") @@ -79,6 +99,11 @@ set(THIRD_PARTY_HEADER_FILES "" CACHE INTERNAL "Third-party (special) header fil # Prerequisite third-party libraries, respecting their own prerequisites. +set(PACKAGES_TO_ADD ${REQUIRED_PACKAGES_TO_ADD} ${PACKAGES_TO_BUILD} ${DEPENDENT_PACKAGES_TO_BUILD}) + +list(REMOVE_DUPLICATES PACKAGES_TO_ADD) +list(SORT PACKAGES_TO_ADD) + add_package(libxml2) if(NOT EMSCRIPTEN) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b3513bc91..9c443b66f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,14 @@ endif() add_subdirectory(3rdparty) +if(ONLY_BUILD_THIRD_PARTY_LIBRARIES) + add_executable(${CMAKE_PROJECT_NAME} dummy.cpp) + + add_subdirectory(bindings) + + return() +endif() + # Configure the version file. foreach(VERSION_PART PROJECT_VERSION_MAJOR PROJECT_VERSION_MINOR PROJECT_VERSION_PATCH) diff --git a/src/bindings/javascript/CMakeLists.txt b/src/bindings/javascript/CMakeLists.txt index 1e175b358..07ee3b3c8 100644 --- a/src/bindings/javascript/CMakeLists.txt +++ b/src/bindings/javascript/CMakeLists.txt @@ -32,11 +32,13 @@ if(EMSCRIPTEN OR LIBOPENCOR_JAVASCRIPT_BINDINGS) if(EMSCRIPTEN) # Add some sources to our WebAssembly version of libOpenCOR so we can access its internals. - target_sources(${CMAKE_PROJECT_NAME} PRIVATE - ${JAVASCRIPT_SOURCE_FILES}) + if(NOT ONLY_BUILD_THIRD_PARTY_LIBRARIES) + target_sources(${CMAKE_PROJECT_NAME} PRIVATE + ${JAVASCRIPT_SOURCE_FILES}) - target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE - $) + target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE + $) + endif() # Use the variables that we passed to CMake but that may or may not end up being used. # Note: this prevents us from getting a warning about unused variables. @@ -47,6 +49,8 @@ if(EMSCRIPTEN OR LIBOPENCOR_JAVASCRIPT_BINDINGS) ${CLCACHE_EXE} ${EMCMAKE_EXE} ${EMCONFIGURE_EXE} + ${LIBOPENCOR_JAVASCRIPT_UNIT_TESTING} + ${REAL_CMAKE_PROJECT_NAME} ) else() # Build our JavaScript bindings. @@ -72,6 +76,7 @@ if(EMSCRIPTEN OR LIBOPENCOR_JAVASCRIPT_BINDINGS) -DLIBOPENCOR_PREBUILT_SUNDIALS=${LIBOPENCOR_PREBUILT_SUNDIALS} -DLIBOPENCOR_PREBUILT_ZIPPER=${LIBOPENCOR_PREBUILT_ZIPPER} -DLIBOPENCOR_PREBUILT_ZLIB=${LIBOPENCOR_PREBUILT_ZLIB} + -DONLY_BUILD_THIRD_PARTY_LIBRARIES=${ONLY_BUILD_THIRD_PARTY_LIBRARIES} -DREAL_CMAKE_PROJECT_NAME=${CMAKE_PROJECT_NAME} COMMAND ${CMAKE_COMMAND} --build build) diff --git a/src/dummy.cpp b/src/dummy.cpp new file mode 100644 index 000000000..2aeaa071a --- /dev/null +++ b/src/dummy.cpp @@ -0,0 +1,20 @@ +/* +Copyright libOpenCOR contributors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +int main() +{ + return 0; +} From c92e6da7a5d4fc80df7e3c21f162c05fc3753633 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Thu, 23 May 2024 19:43:44 +1200 Subject: [PATCH 04/11] Removed ARM support for Windows and Linux. Indeed, we can't build the latest version (18.1.6) of LLVM+Clang on Windows ARM unless we use Clang rather than MSVC (see https://github.com/llvm/llvm-project/issues/88368) while on Linux we can but then for some reasons we can't create an ORC-based JIT (!?). --- .github/workflows/buildThirdPartyLibrary.yml | 42 ++------------- .github/workflows/cd.yml | 37 ++----------- cmake/packages.cmake | 10 ++-- src/3rdparty/LLVMClang/CMakeLists.txt | 46 ++++------------ .../LLVMClang/scripts/buildllvmclangtblgen | 19 ------- src/3rdparty/OpenSSL/CMakeLists.txt | 54 +++++-------------- src/3rdparty/SUNDIALS/CMakeLists.txt | 36 ++++--------- src/3rdparty/libCOMBINE/CMakeLists.txt | 36 ++++--------- src/3rdparty/libCellML/CMakeLists.txt | 36 ++++--------- src/3rdparty/libNuML/CMakeLists.txt | 36 ++++--------- src/3rdparty/libSBML/CMakeLists.txt | 36 ++++--------- src/3rdparty/libSEDML/CMakeLists.txt | 36 ++++--------- src/3rdparty/libcurl/CMakeLists.txt | 36 ++++--------- src/3rdparty/libssh2/CMakeLists.txt | 36 ++++--------- src/3rdparty/libxml2/CMakeLists.txt | 36 ++++--------- src/3rdparty/zipper/CMakeLists.txt | 36 ++++--------- src/3rdparty/zlib/CMakeLists.txt | 36 ++++--------- 17 files changed, 135 insertions(+), 469 deletions(-) delete mode 100755 src/3rdparty/LLVMClang/scripts/buildllvmclangtblgen diff --git a/.github/workflows/buildThirdPartyLibrary.yml b/.github/workflows/buildThirdPartyLibrary.yml index a6559d07a..0a9b9a68e 100644 --- a/.github/workflows/buildThirdPartyLibrary.yml +++ b/.github/workflows/buildThirdPartyLibrary.yml @@ -19,23 +19,13 @@ jobs: fail-fast: false matrix: include: - - name: 'Windows release (Intel)' + - name: 'Windows release' os: windows-latest - arch: amd64 build_type: Release - - name: 'Windows debug (Intel)' + - name: 'Windows debug' os: windows-latest - arch: amd64 build_type: Debug - - name: 'Windows release (ARM)' - os: windows-latest - arch: amd64_arm64 - build_type: Release - - name: 'Windows debug (ARM)' - os: windows-latest - arch: amd64_arm64 - build_type: Debug - - name: 'Linux (Intel)' + - name: 'Linux' os: ubuntu-20.04 # Note: we must use ubuntu-20.04 rather than ubuntu-latest (i.e. ubuntu-22.04 at this stage). Indeed, # Ubuntu 22.04's copy of glibc doesn't include libpthread anymore (see @@ -44,11 +34,6 @@ jobs: # of glibc with libpthread, hence getting various messages about __libc_single_threaded being # undefined when trying to build our Python wheels using third-party libraries built on ubuntu-22.04. build_type: Release - - name: 'Linux (ARM)' - os: ubuntu-latest - arch: arm - cmake_prereqs: CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ - build_type: Release - name: 'macOS (Intel)' os: macos-13 build_type: Release @@ -63,39 +48,20 @@ jobs: steps: - name: Check out libOpenCOR uses: actions/checkout@v4 - - name: Install ARM compiler - if: ${{ matrix.arch == 'arm' }} - run: | - sudo apt update - sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - name: Install CMake and Ninja uses: lukka/get-cmake@latest - name: Install buildcache uses: mikehardy/buildcache-action@v2 with: cache_key: libraries-${{ matrix.os }}-${{ matrix.shared_libs }} - - name: Configure MSVC (to build an Intel-based version of llvm-tblgen and clang-tblgen) - if: ${{ (runner.os == 'Windows') && (matrix.arch == 'amd64_arm64') }} - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: amd64 - - name: Build llvm-tblgen and clang-tblgen - if: ${{ (((runner.os == 'Windows') && (matrix.arch == 'amd64_arm64')) || ((runner.os == 'Linux') && (matrix.arch == 'arm'))) }} - shell: bash - run: | - source src/3rdparty/LLVMClang/scripts/buildllvmclangtblgen ${{ runner.os == 'Windows' }} - echo "DLLVMCLANG_LLVM_TABLEGEN=$DLLVMCLANG_LLVM_TABLEGEN" >> $GITHUB_ENV - echo "DLLVMCLANG_CLANG_TABLEGEN=$DLLVMCLANG_CLANG_TABLEGEN" >> $GITHUB_ENV - name: Configure MSVC if: ${{ runner.os == 'Windows' }} uses: ilammy/msvc-dev-cmd@v1 - with: - arch: ${{ matrix.arch }} - name: Configure libOpenCOR run: | mkdir build cd build - ${{ matrix.cmake_prereqs }} cmake -G Ninja -DBUILD_TYPE=${{ matrix.build_type }} -DONLY_BUILD_THIRD_PARTY_LIBRARIES=ON -DPREBUILT_${{ inputs.third_party_library_name }}=OFF ${{ env.DLLVMCLANG_LLVM_TABLEGEN }} ${{ env.DLLVMCLANG_CLANG_TABLEGEN }} .. + ${{ matrix.cmake_prereqs }} cmake -G Ninja -DBUILD_TYPE=${{ matrix.build_type }} -DONLY_BUILD_THIRD_PARTY_LIBRARIES=ON -DPREBUILT_${{ inputs.third_party_library_name }}=OFF .. - name: Upload library artifact if: ${{ !startsWith(github.ref, 'refs/tags/v') }} uses: actions/upload-artifact@v4 diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 86399d2cc..6dd7729f5 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -15,38 +15,18 @@ jobs: fail-fast: false matrix: include: - - name: 'Windows static library (Intel)' + - name: 'Windows static library' os: windows-latest - msvc_arch: amd64 shared_libs: OFF - - name: 'Windows shared library (Intel)' + - name: 'Windows shared library' os: windows-latest - msvc_arch: amd64 shared_libs: ON - - name: 'Windows static library (ARM)' - os: windows-latest - msvc_arch: amd64_arm64 - shared_libs: OFF - - name: 'Windows shared library (ARM)' - os: windows-latest - msvc_arch: amd64_arm64 - shared_libs: ON - - name: 'Linux static library (Intel)' - os: ubuntu-latest - shared_libs: OFF - - name: 'Linux shared library (Intel)' - os: ubuntu-latest - shared_libs: ON - - name: 'Linux static library (ARM)' + - name: 'Linux static library' os: ubuntu-latest - arch: arm shared_libs: OFF - cmake_prereqs: CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ - - name: 'Linux shared library (ARM)' + - name: 'Linux shared library' os: ubuntu-latest - arch: arm shared_libs: ON - cmake_prereqs: CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ - name: 'macOS static library (Intel)' os: macos-13 shared_libs: OFF @@ -67,11 +47,6 @@ jobs: steps: - name: Check out libOpenCOR uses: actions/checkout@v4 - - name: Install ARM compiler - if: ${{ matrix.arch == 'arm' }} - run: | - sudo apt update - sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - name: Install CMake and Ninja uses: lukka/get-cmake@latest - name: Install buildcache @@ -81,13 +56,11 @@ jobs: - name: Configure MSVC if: ${{ runner.os == 'Windows' }} uses: ilammy/msvc-dev-cmd@v1 - with: - arch: ${{ matrix.msvc_arch }} - name: Configure libOpenCOR run: | mkdir build cd build - ${{ matrix.cmake_prereqs }} cmake -G Ninja -DBUILD_TYPE=Release -DCODE_ANALYSIS=OFF -DCODE_COVERAGE=OFF -DDOCUMENTATION=OFF -DJAVASCRIPT_BINDINGS=OFF -DMEMORY_CHECKS=OFF -DPYTHON_BINDINGS=OFF -DPYTHON_UNIT_TESTING=OFF -DSHARED_LIBS=${{ matrix.shared_libs }} -DUNIT_TESTING=OFF .. + cmake -G Ninja -DBUILD_TYPE=Release -DCODE_ANALYSIS=OFF -DCODE_COVERAGE=OFF -DDOCUMENTATION=OFF -DJAVASCRIPT_BINDINGS=OFF -DMEMORY_CHECKS=OFF -DPYTHON_BINDINGS=OFF -DPYTHON_UNIT_TESTING=OFF -DSHARED_LIBS=${{ matrix.shared_libs }} -DUNIT_TESTING=OFF .. - name: Build libOpenCOR run: | cd build diff --git a/cmake/packages.cmake b/cmake/packages.cmake index 163a6f2fa..4dac41bbd 100644 --- a/cmake/packages.cmake +++ b/cmake/packages.cmake @@ -273,10 +273,12 @@ else() set(TARGET_PLATFORM_ARCHITECTURE linux) endif() - if("${LIBOPENCOR_TARGET_ARCHITECTURE}" STREQUAL "Intel") - set(TARGET_PLATFORM_ARCHITECTURE ${TARGET_PLATFORM_ARCHITECTURE}.intel) - else() - set(TARGET_PLATFORM_ARCHITECTURE ${TARGET_PLATFORM_ARCHITECTURE}.arm) + if(APPLE) + if("${LIBOPENCOR_TARGET_ARCHITECTURE}" STREQUAL "Intel") + set(TARGET_PLATFORM_ARCHITECTURE ${TARGET_PLATFORM_ARCHITECTURE}.intel) + else() + set(TARGET_PLATFORM_ARCHITECTURE ${TARGET_PLATFORM_ARCHITECTURE}.arm) + endif() endif() endif() diff --git a/src/3rdparty/LLVMClang/CMakeLists.txt b/src/3rdparty/LLVMClang/CMakeLists.txt index 5cff0957b..9f41b7a0e 100644 --- a/src/3rdparty/LLVMClang/CMakeLists.txt +++ b/src/3rdparty/LLVMClang/CMakeLists.txt @@ -23,46 +23,28 @@ set(INSTALL_DIR ${PREBUILT_DIR}/${PACKAGE_NAME}) if(LIBOPENCOR_PREBUILT_LLVMCLANG) if(WIN32) if(RELEASE_MODE) - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 8ce4afcab9008cb845b4044b16fc0873aeba418c) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 665eeefd2e331034e5962b9ec9114f5dd6826ed1) - endif() - else() - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 7a3168fd20a0f4c034f0c1252401ca17074095b9) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 24febbe8391b8c7dea406261c8b520671b3c38a6) - endif() - endif() - elseif(APPLE) - if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 006e8969fccc75f2c5020b69cb6a196c2e3c43b8) + 8ce4afcab9008cb845b4044b16fc0873aeba418c) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - edab86a319335dec8cd38fc86b3fd11ef71fb789) + 7a3168fd20a0f4c034f0c1252401ca17074095b9) endif() - else() + elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - acc80f89781960d71046c26ffb40593c8e91f476) + 006e8969fccc75f2c5020b69cb6a196c2e3c43b8) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 25fe0235182221c14a897c0fe8e1d43041479ac8) + edab86a319335dec8cd38fc86b3fd11ef71fb789) endif() + else() + retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} + ${PACKAGE_REPOSITORY} ${RELEASE_TAG} + acc80f89781960d71046c26ffb40593c8e91f476) endif() else() # Build our package. @@ -73,14 +55,6 @@ else() set(LLVM_TARGETS_TO_BUILD AArch64) endif() - if(LLVMCLANG_LLVM_TABLEGEN) - set(LLVM_TABLEGEN -DLLVM_TABLEGEN=${LLVMCLANG_LLVM_TABLEGEN}) - endif() - - if(LLVMCLANG_CLANG_TABLEGEN) - set(CLANG_TABLEGEN -DCLANG_TABLEGEN=${LLVMCLANG_CLANG_TABLEGEN}) - endif() - build_package(${PACKAGE_NAME} URL https://github.com/opencor/${PACKAGE_REPOSITORY}/archive/refs/tags/${RELEASE_TAG}.tar.gz @@ -94,7 +68,6 @@ else() -DCLANG_INCLUDE_DOCS=OFF -DCLANG_INCLUDE_TESTS=OFF -DCLANG_PLUGIN_SUPPORT=OFF - ${CLANG_TABLEGEN} -DCLANG_TOOLING_BUILD_AST_INTROSPECTION=OFF -DCLANG_TOOL_HANDLE_CXX_BUILD=OFF -DCLANG_TOOL_HANDLE_LLVM_BUILD=OFF @@ -132,7 +105,6 @@ else() -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_TOOLS=ON -DLLVM_INCLUDE_UTILS=OFF - ${LLVM_TABLEGEN} -DLLVM_TARGETS_TO_BUILD=${LLVM_TARGETS_TO_BUILD} ) diff --git a/src/3rdparty/LLVMClang/scripts/buildllvmclangtblgen b/src/3rdparty/LLVMClang/scripts/buildllvmclangtblgen deleted file mode 100755 index b991615d1..000000000 --- a/src/3rdparty/LLVMClang/scripts/buildllvmclangtblgen +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -LLVMCLANG_VERSION=14.0.3d - -curl -Ls https://github.com/opencor/llvm-project/archive/refs/tags/llvmorg-$LLVMCLANG_VERSION.zip -o llvm-project-llvmorg-$LLVMCLANG_VERSION.zip -unzip -qq llvm-project-llvmorg-$LLVMCLANG_VERSION.zip -\rm llvm-project-llvmorg-$LLVMCLANG_VERSION.zip - -cd llvm-project-llvmorg-$LLVMCLANG_VERSION - -cmake -G Ninja -S ./llvm -B build -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=clang -cmake --build build -t llvm-tblgen clang-tblgen - -if [ "$1" = "true" ]; then - EXTENSION=.exe -fi - -export DLLVMCLANG_LLVM_TABLEGEN=-DLLVMCLANG_LLVM_TABLEGEN=$PWD/build/bin/llvm-tblgen$EXTENSION -export DLLVMCLANG_CLANG_TABLEGEN=-DLLVMCLANG_CLANG_TABLEGEN=$PWD/build/bin/clang-tblgen$EXTENSION diff --git a/src/3rdparty/OpenSSL/CMakeLists.txt b/src/3rdparty/OpenSSL/CMakeLists.txt index d70ba952d..6b74d0c91 100644 --- a/src/3rdparty/OpenSSL/CMakeLists.txt +++ b/src/3rdparty/OpenSSL/CMakeLists.txt @@ -23,46 +23,28 @@ set(INSTALL_DIR ${PREBUILT_DIR}/${PACKAGE_NAME}) if(LIBOPENCOR_PREBUILT_OPENSSL) if(WIN32) if(RELEASE_MODE) - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 558ef03a9b9cce739a7f3e2699d5b698c8b2fba3) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 63abbd1d6540351d26af557a4a0bded041ca221b) - endif() - else() - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 2bc0770b3d9abca54eaa5ddb1e434b28be7326ee) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - e801d457e4e1eba429e3f13f624a08cd03cd1f1c) - endif() - endif() - elseif(APPLE) - if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 847b9b0e0c70bf4b458796c453d8c03c4b0d4252) + 558ef03a9b9cce739a7f3e2699d5b698c8b2fba3) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - ae38760197be0715d0398cd88945ad74fe16ff45) + 2bc0770b3d9abca54eaa5ddb1e434b28be7326ee) endif() - else() + elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - f3f1619acc385df0165fbb932fdf23f5b6eb5179) + 847b9b0e0c70bf4b458796c453d8c03c4b0d4252) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 0411e8ce55a452ea6b72f031f4b07b9dba6b98df) + ae38760197be0715d0398cd88945ad74fe16ff45) endif() + else() + retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} + ${PACKAGE_REPOSITORY} ${RELEASE_TAG} + f3f1619acc385df0165fbb932fdf23f5b6eb5179) endif() else() # Build our package. @@ -75,17 +57,9 @@ else() list(APPEND CONFIG_OPTIONS no-asm) if(RELEASE_MODE) - if(INTEL_MODE) - set(PLATFORM VC-WIN64A) - else() - set(PLATFORM VC-WIN64-ARM) - endif() + set(PLATFORM VC-WIN64A) else() - if(INTEL_MODE) - set(PLATFORM debug-VC-WIN64A) - else() - set(PLATFORM debug-VC-WIN64-ARM) - endif() + set(PLATFORM debug-VC-WIN64A) endif() # Patch the generated makefile since it contains non-escaped paths that result in our build to fail. (Not sure @@ -108,11 +82,7 @@ else() list(APPEND CONFIG_OPTIONS "-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}") else() - if(INTEL_MODE) - set(PLATFORM linux-x86_64) - else() - set(PLATFORM linux-aarch64) - endif() + set(PLATFORM linux-x86_64) list(APPEND CONFIG_OPTIONS "-Wa,--noexecstack") endif() diff --git a/src/3rdparty/SUNDIALS/CMakeLists.txt b/src/3rdparty/SUNDIALS/CMakeLists.txt index 9a7198b9a..bd0bbc02a 100644 --- a/src/3rdparty/SUNDIALS/CMakeLists.txt +++ b/src/3rdparty/SUNDIALS/CMakeLists.txt @@ -28,46 +28,28 @@ if(LIBOPENCOR_PREBUILT_SUNDIALS) else() if(WIN32) if(RELEASE_MODE) - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 7bc8ba9a62a6bb8efd52bc7aea1f17aa2d8ef024) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 59647bc79af40a528802941f6dce584fd1cbe50e) - endif() - else() - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 1471019d8221d5f079a30baa0394e0dc54ba3edb) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - d9367c7fa4f33d8e2f9b1b1654a1766d26abaa60) - endif() - endif() - elseif(APPLE) - if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - ef844d27b82a63b7167f3165e45ce78d20c3a7cf) + 7bc8ba9a62a6bb8efd52bc7aea1f17aa2d8ef024) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - a2399ef9cf50d64c1dad7d6e554700a47adde9b2) + 1471019d8221d5f079a30baa0394e0dc54ba3edb) endif() - else() + elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - b0d953dffcab7be7440d148bf334cac7913914dd) + ef844d27b82a63b7167f3165e45ce78d20c3a7cf) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - bcaaad18087d6e4a002b3eda5f5c49eca7e255cc) + a2399ef9cf50d64c1dad7d6e554700a47adde9b2) endif() + else() + retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} + ${PACKAGE_REPOSITORY} ${RELEASE_TAG} + b0d953dffcab7be7440d148bf334cac7913914dd) endif() endif() else() diff --git a/src/3rdparty/libCOMBINE/CMakeLists.txt b/src/3rdparty/libCOMBINE/CMakeLists.txt index c20aa1d53..0eb5c22df 100644 --- a/src/3rdparty/libCOMBINE/CMakeLists.txt +++ b/src/3rdparty/libCOMBINE/CMakeLists.txt @@ -32,46 +32,28 @@ if(LIBOPENCOR_PREBUILT_LIBCOMBINE) else() if(WIN32) if(RELEASE_MODE) - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 3694f8043163db0f0a140f50d63aca5230f30abe) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 75f4c3c895dddce5b0523a5f8392bf2efdff7f67) - endif() - else() - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 22431c4e857d1f3a2661a880cb6142be905bfe66) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 41303bd3c6333aebfdf91571002520e6690cde77) - endif() - endif() - elseif(APPLE) - if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 1b7ec9932dd53f37e5bad7ae20f98a2c1f32f342) + 3694f8043163db0f0a140f50d63aca5230f30abe) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - a8657b4e8d3b36ece2dd1571a830184500f89ea4) + 22431c4e857d1f3a2661a880cb6142be905bfe66) endif() - else() + elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 18ebd3acc651040f127f94284ed5241e2bb38380) + 1b7ec9932dd53f37e5bad7ae20f98a2c1f32f342) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 9bce82e9a99759bbc27ebf265c54f50033d51af8) + a8657b4e8d3b36ece2dd1571a830184500f89ea4) endif() + else() + retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} + ${PACKAGE_REPOSITORY} ${RELEASE_TAG} + 18ebd3acc651040f127f94284ed5241e2bb38380) endif() endif() else() diff --git a/src/3rdparty/libCellML/CMakeLists.txt b/src/3rdparty/libCellML/CMakeLists.txt index ca2142294..1f8d24282 100644 --- a/src/3rdparty/libCellML/CMakeLists.txt +++ b/src/3rdparty/libCellML/CMakeLists.txt @@ -38,46 +38,28 @@ if(LIBOPENCOR_PREBUILT_LIBCELLML) else() if(WIN32) if(RELEASE_MODE) - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 5b0aa69fc09659705851bad924ad9bcc1e3ac2b9) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 926f60f6861a3a29fb69e91ed830e7aa79125346) - endif() - else() - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - a08555bab6dc8de348baded059bb1ad6827923af) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - cddaf4c78f18d9e8a47c794a2f0fa13cddc9f222) - endif() - endif() - elseif(APPLE) - if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 70d39e1ad85ea060693f328dfd65d295e424eb41) + 5b0aa69fc09659705851bad924ad9bcc1e3ac2b9) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - c5025de0a25e21857a688bbd51779e5bf17070d6) + a08555bab6dc8de348baded059bb1ad6827923af) endif() - else() + elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 10e5dfa5b150971c5787c86938c00dafc2082735) + 70d39e1ad85ea060693f328dfd65d295e424eb41) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - ffe67306d9096f232e5cb6c83243c57f53915b61) + c5025de0a25e21857a688bbd51779e5bf17070d6) endif() + else() + retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} + ${PACKAGE_REPOSITORY} ${RELEASE_TAG} + 10e5dfa5b150971c5787c86938c00dafc2082735) endif() endif() else() diff --git a/src/3rdparty/libNuML/CMakeLists.txt b/src/3rdparty/libNuML/CMakeLists.txt index 229c692bc..11beccfa2 100644 --- a/src/3rdparty/libNuML/CMakeLists.txt +++ b/src/3rdparty/libNuML/CMakeLists.txt @@ -32,46 +32,28 @@ if(LIBOPENCOR_PREBUILT_LIBNUML) else() if(WIN32) if(RELEASE_MODE) - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 849756984debf9a74601a31ccd72f434724f655e) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - e2c1e4b73bfb6a67c0a84a9295e7bbbe9ef05e77) - endif() - else() - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 6b4214108546a24fab6c5dc77af9655d7484c2c6) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - eee56d12b1dcd31a8ba77da05263aac7aa9bf661) - endif() - endif() - elseif(APPLE) - if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - b1aa08c1f2bb41298675165a1608bf6029743a5a) + 849756984debf9a74601a31ccd72f434724f655e) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 8424f3ee04bcaa973160f56c6807b2d9d21e1482) + 6b4214108546a24fab6c5dc77af9655d7484c2c6) endif() - else() + elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 826470e27e446414a9d1269efa89d935c8a1eb55) + b1aa08c1f2bb41298675165a1608bf6029743a5a) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 4acdd314a5c90a1208fd725901b36918dea1add9) + 8424f3ee04bcaa973160f56c6807b2d9d21e1482) endif() + else() + retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} + ${PACKAGE_REPOSITORY} ${RELEASE_TAG} + 826470e27e446414a9d1269efa89d935c8a1eb55) endif() endif() else() diff --git a/src/3rdparty/libSBML/CMakeLists.txt b/src/3rdparty/libSBML/CMakeLists.txt index ad5eb0971..36a99cfeb 100644 --- a/src/3rdparty/libSBML/CMakeLists.txt +++ b/src/3rdparty/libSBML/CMakeLists.txt @@ -32,46 +32,28 @@ if(LIBOPENCOR_PREBUILT_LIBSBML) else() if(WIN32) if(RELEASE_MODE) - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 9908f803eaa644aa262df64c17243e38d1f5f8f4) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 0851ffd1b2e78228fd8faaf997c1923398f2f19f) - endif() - else() - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - b8a48f56f18e495062ba20f087ab5097e0d4b2ce) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 7a05f3cd6684b7152f9863d9f6a13913af42793d) - endif() - endif() - elseif(APPLE) - if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - f9d89084dd9bcb724e68beddcba924c6fb21147e) + 9908f803eaa644aa262df64c17243e38d1f5f8f4) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 694ad628772f8fd5009d6f048a4062079cafa5c8) + b8a48f56f18e495062ba20f087ab5097e0d4b2ce) endif() - else() + elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - b968f19fc3f91f6b639ba7df671025d0838780c8) + f9d89084dd9bcb724e68beddcba924c6fb21147e) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - f70f0b25a9f13fc1fbe398bf89cbfd03c31633b2) + 694ad628772f8fd5009d6f048a4062079cafa5c8) endif() + else() + retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} + ${PACKAGE_REPOSITORY} ${RELEASE_TAG} + b968f19fc3f91f6b639ba7df671025d0838780c8) endif() endif() else() diff --git a/src/3rdparty/libSEDML/CMakeLists.txt b/src/3rdparty/libSEDML/CMakeLists.txt index 8e7ec7329..8344bb9c2 100644 --- a/src/3rdparty/libSEDML/CMakeLists.txt +++ b/src/3rdparty/libSEDML/CMakeLists.txt @@ -32,46 +32,28 @@ if(LIBOPENCOR_PREBUILT_LIBSEDML) else() if(WIN32) if(RELEASE_MODE) - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - c7a7fea81af5544fb8ccc2d3c078041920f8b556) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - f501a31c487f82b243149528a8128238d639cb4f) - endif() - else() - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 175f6f935dc0596d306846077b80b6d05d284b96) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 7aec25c64059f11f34f4271c9f376cfb3cb89050) - endif() - endif() - elseif(APPLE) - if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - d4a3a3bcd0be4137967517b63167cb7d169dd353) + c7a7fea81af5544fb8ccc2d3c078041920f8b556) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - c0823de700727c4872da11e6bbed0ff9e005fb73) + 175f6f935dc0596d306846077b80b6d05d284b96) endif() - else() + elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 7a50da22899f7d7a8ec01a2a3afd5de5cc64e6b2) + d4a3a3bcd0be4137967517b63167cb7d169dd353) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 14e3294cc84585c5c33f4494481d90555b23b3b7) + c0823de700727c4872da11e6bbed0ff9e005fb73) endif() + else() + retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} + ${PACKAGE_REPOSITORY} ${RELEASE_TAG} + 7a50da22899f7d7a8ec01a2a3afd5de5cc64e6b2) endif() endif() else() diff --git a/src/3rdparty/libcurl/CMakeLists.txt b/src/3rdparty/libcurl/CMakeLists.txt index 19b714562..79ecca495 100644 --- a/src/3rdparty/libcurl/CMakeLists.txt +++ b/src/3rdparty/libcurl/CMakeLists.txt @@ -27,46 +27,28 @@ endif() if(LIBOPENCOR_PREBUILT_LIBCURL) if(WIN32) if(RELEASE_MODE) - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - a0e03230c20533bea04ceba6a2587b8878eca80f) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 110614df0c1c9f8c627b22a19bcb2a9ed52e86d7) - endif() - else() - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - f4352511ab7e1e90d691265a8d7814388e43aec2) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 158887aa551e1439e224a0a9763fd72f15756361) - endif() - endif() - elseif(APPLE) - if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 8476306e95a657dc0a224b19797b9cdea5215c5f) + a0e03230c20533bea04ceba6a2587b8878eca80f) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - d7e55af2f4f71599680b5c6dd1c3953b729548d0) + f4352511ab7e1e90d691265a8d7814388e43aec2) endif() - else() + elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - a1251435ea2228af7e87a9f6ed1d7bd89a7592a1) + 8476306e95a657dc0a224b19797b9cdea5215c5f) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 1d41aebf3040f0ae86845f4cac26b8f05e35abc1) + d7e55af2f4f71599680b5c6dd1c3953b729548d0) endif() + else() + retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} + ${PACKAGE_REPOSITORY} ${RELEASE_TAG} + a1251435ea2228af7e87a9f6ed1d7bd89a7592a1) endif() else() # Build our package. diff --git a/src/3rdparty/libssh2/CMakeLists.txt b/src/3rdparty/libssh2/CMakeLists.txt index 6ac132f39..8fe89e9dd 100644 --- a/src/3rdparty/libssh2/CMakeLists.txt +++ b/src/3rdparty/libssh2/CMakeLists.txt @@ -23,46 +23,28 @@ set(INSTALL_DIR ${PREBUILT_DIR}/${PACKAGE_NAME}) if(LIBOPENCOR_PREBUILT_LIBSSH2) if(WIN32) if(RELEASE_MODE) - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - a036e09966b8fe4fb51799b6027ef751d2d853bf) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - d074e0a4ac949c7cfc4d74c56e7040fe25ee6332) - endif() - else() - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 61ad26586df1fbf494c43e12548898a285a84d4b) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 6532912f33cf074616d3d9e18888643061449fab) - endif() - endif() - elseif(APPLE) - if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 555726b2220a89d3de8c405297d2898311ff415e) + a036e09966b8fe4fb51799b6027ef751d2d853bf) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 52a3363adaeeccf94116e689af1ed541bfa14aaa) + 61ad26586df1fbf494c43e12548898a285a84d4b) endif() - else() + elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 748feccb81c12663f28023b171925ee255ed3acc) + 555726b2220a89d3de8c405297d2898311ff415e) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 19e3ffa73e95969fa13beb7f8a37fecf4d595b6b) + 52a3363adaeeccf94116e689af1ed541bfa14aaa) endif() + else() + retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} + ${PACKAGE_REPOSITORY} ${RELEASE_TAG} + 748feccb81c12663f28023b171925ee255ed3acc) endif() else() # Build our package. diff --git a/src/3rdparty/libxml2/CMakeLists.txt b/src/3rdparty/libxml2/CMakeLists.txt index ded81b490..eda16bebc 100644 --- a/src/3rdparty/libxml2/CMakeLists.txt +++ b/src/3rdparty/libxml2/CMakeLists.txt @@ -28,46 +28,28 @@ if(LIBOPENCOR_PREBUILT_LIBXML2) else() if(WIN32) if(RELEASE_MODE) - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 50c8dd2d47cdd9c1129b70698d3f2c5d20cfe1b7) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 3f25822e6063a0eed1bf1229f1bccab5e6b1bf3f) - endif() - else() - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 818561c4203fa1cf90c4b42b833a09b13d51a927) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 907f061cf35afba3133daa47336d7b65292cfcaf) - endif() - endif() - elseif(APPLE) - if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - b7ff7646e76eb5bbbcb294425c54046df6a406a5) + 50c8dd2d47cdd9c1129b70698d3f2c5d20cfe1b7) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 64cfda1c014fc4cf79b5b3d6681af0beb5bb202d) + 818561c4203fa1cf90c4b42b833a09b13d51a927) endif() - else() + elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - ac01337f47b66c3c58fa13d703cfe0f26e0ae31e) + b7ff7646e76eb5bbbcb294425c54046df6a406a5) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 45f31d7ddad7784978fec9753506cb504d81d4c5) + 64cfda1c014fc4cf79b5b3d6681af0beb5bb202d) endif() + else() + retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} + ${PACKAGE_REPOSITORY} ${RELEASE_TAG} + ac01337f47b66c3c58fa13d703cfe0f26e0ae31e) endif() endif() else() diff --git a/src/3rdparty/zipper/CMakeLists.txt b/src/3rdparty/zipper/CMakeLists.txt index e7e4289e7..03de708ca 100644 --- a/src/3rdparty/zipper/CMakeLists.txt +++ b/src/3rdparty/zipper/CMakeLists.txt @@ -28,46 +28,28 @@ if(LIBOPENCOR_PREBUILT_ZIPPER) else() if(WIN32) if(RELEASE_MODE) - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 9bf375fbce91eb4df163992a8a3d5c2b24efc204) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - a1e5c3f2955982439262ec8c65635485383f7855) - endif() - else() - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - a3fcc47aec91f46bf8b039a1c2aa6d0efb9970fe) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 813df4f923912d0245304ae56f3ffecb7167fcd3) - endif() - endif() - elseif(APPLE) - if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 934654bea9a68d2dd1ccad70d3942cec9a17e101) + 9bf375fbce91eb4df163992a8a3d5c2b24efc204) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 372736c5821254782e1794b5b902a5de120379d4) + a3fcc47aec91f46bf8b039a1c2aa6d0efb9970fe) endif() - else() + elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 7a75f83c6dae5237701775795e14b7579d8030aa) + 934654bea9a68d2dd1ccad70d3942cec9a17e101) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 9e5e0c2b547c9ecf4bce20afea9a0f45cf2e8ae6) + 372736c5821254782e1794b5b902a5de120379d4) endif() + else() + retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} + ${PACKAGE_REPOSITORY} ${RELEASE_TAG} + 7a75f83c6dae5237701775795e14b7579d8030aa) endif() endif() else() diff --git a/src/3rdparty/zlib/CMakeLists.txt b/src/3rdparty/zlib/CMakeLists.txt index 6465663f3..80a24483f 100644 --- a/src/3rdparty/zlib/CMakeLists.txt +++ b/src/3rdparty/zlib/CMakeLists.txt @@ -28,46 +28,28 @@ if(LIBOPENCOR_PREBUILT_ZLIB) else() if(WIN32) if(RELEASE_MODE) - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 7c015f7895f7fbe64ba5b16706bcc43b01bcd0d7) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 922e6e43c90d457c9d5a73ff03d4e63abe3936e3) - endif() - else() - if(INTEL_MODE) - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 02dc0bb878774be91b4a2a3130ec9a50eb177537) - else() - retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} - ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 3c6afd53f25338b4d8491cda6ef720f381950ba3) - endif() - endif() - elseif(APPLE) - if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 36c02336dba035a149b6aa45106bc48dc0a86410) + 7c015f7895f7fbe64ba5b16706bcc43b01bcd0d7) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 5d5e78176c1c30bab29f51f5688d2848add1a4e2) + 02dc0bb878774be91b4a2a3130ec9a50eb177537) endif() - else() + elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 01c902f7f7870de1ae1bc25c57e572f8969380ab) + 36c02336dba035a149b6aa45106bc48dc0a86410) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 1d1079c4494e8ca56babf376d087b70dda99e87c) + 5d5e78176c1c30bab29f51f5688d2848add1a4e2) endif() + else() + retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} + ${PACKAGE_REPOSITORY} ${RELEASE_TAG} + 01c902f7f7870de1ae1bc25c57e572f8969380ab) endif() endif() else() From 8f45fe458e478fe99d535bc20fac337d4ac4df83 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Thu, 23 May 2024 12:50:42 +1200 Subject: [PATCH 05/11] CI: some minor cleaning up. --- .github/workflows/ci.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d44f02d4..78d0e18de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -221,7 +221,7 @@ jobs: shared_libs: OFF unit_testing: ON context: PATH=$GITHUB_WORKSPACE:$PATH CC=/usr/local/bin/clang CXX=/usr/local/bin/clang++ - - name: 'Coverage' + - name: 'Code coverage' os: macos-latest build_type: Release code_analysis: OFF @@ -288,12 +288,12 @@ jobs: if: ${{ runner.os == 'Windows' }} uses: ilammy/msvc-dev-cmd@v1 - name: Install LLVM - if: ${{ matrix.target == 'code_coverage' }} + if: ${{ matrix.code_coverage == 'ON' }} run: | brew install --overwrite llvm brew info llvm - name: Install Clang - if: ${{ matrix.name == 'Code analysis' }} + if: ${{ matrix.code_analysis == 'ON' }} run: | wget https://github.com/opencor/gha/releases/download/ci/clang.$LLVMCLANG_VERSION.linux.tar.gz -O - | tar -xz sudo mv clang /usr/local/bin @@ -311,7 +311,7 @@ jobs: wget https://github.com/opencor/gha/releases/download/ci/clang-tidy.$LLVMCLANG_VERSION.linux.tar.gz -O - | tar -xz sudo mv clang-tidy /usr/local/bin - name: Install Emscripten - if: ${{ matrix.target == 'javascript_unit_testing' }} + if: ${{ matrix.javascript_unit_testing == 'ON' }} run: brew install --overwrite emscripten - name: Install Prettier if: ${{ matrix.target == 'javascript_check_code_formatting' }} @@ -325,7 +325,7 @@ jobs: sudo apt update sudo apt install valgrind - name: Install pytest and pytest-html - if: ${{ matrix.target == 'python_unit_testing' }} + if: ${{ matrix.python_unit_testing == 'ON' }} run: pip3 install pytest pytest-html - name: Install Sphinx and some Sphinx packages if: ${{ matrix.documentation == 'ON' }} @@ -341,27 +341,27 @@ jobs: cd build ${{ matrix.context }} cmake -G Ninja -DBUILD_TYPE=${{ matrix.build_type }} -DCODE_ANALYSIS=${{ matrix.code_analysis }} -DCODE_COVERAGE=${{ matrix.code_coverage }} -DDOCUMENTATION=${{ matrix.documentation }} -DINSTALL_PREFIX=${{ github.workspace }}/install -DJAVASCRIPT_BINDINGS=${{ matrix.javascript_bindings }} -DJAVASCRIPT_UNIT_TESTING=${{ matrix.javascript_unit_testing }} -DMEMORY_CHECKS=${{ matrix.memory_checks }} -DPYTHON_BINDINGS=${{ matrix.python_bindings }} -DPYTHON_UNIT_TESTING=${{ matrix.python_unit_testing }} -DSHARED_LIBS=${{ matrix.shared_libs }} -DUNIT_TESTING=${{ matrix.unit_testing }} .. - name: Build libOpenCOR - if: ${{ (matrix.target == 'unit_testing') || (matrix.target == 'javascript_unit_testing') }} + if: ${{ (matrix.unit_testing == 'ON') || (matrix.javascript_unit_testing == 'ON') }} run: | cd build ninja - name: Unit testing - if: ${{ matrix.target == 'unit_testing' }} + if: ${{ matrix.unit_testing == 'ON' }} run: | cd build ninja ${{ matrix.target }} - name: JavaScript unit testing - if: ${{ matrix.target == 'javascript_unit_testing' }} + if: ${{ matrix.javascript_unit_testing == 'ON' }} run: | cd build ninja ${{ matrix.target }} - name: Python unit testing - if: ${{ matrix.target == 'python_unit_testing' }} + if: ${{ matrix.python_unit_testing == 'ON' }} run: | cd build ninja ${{ matrix.target }} - name: Python unit testing report - if: ${{ matrix.target == 'python_unit_testing' }} + if: ${{ matrix.python_unit_testing == 'ON' }} run: | cd build ninja ${{ matrix.target }}_report @@ -386,23 +386,23 @@ jobs: cd build ninja - name: Coverage - if: ${{ matrix.target == 'code_coverage' }} + if: ${{ matrix.code_coverage == 'ON' }} run: | cd build ninja ${{ matrix.target }} if [ `ninja ${{ matrix.target }} | grep TOTAL | sed 's/ /\n/g' | grep "100.00%" | wc -l | sed 's/ //g'` -eq 4 ]; then exit 0; else exit 1; fi - name: Coverage report - if: ${{ matrix.target == 'code_coverage' }} + if: ${{ matrix.code_coverage == 'ON' }} run: | cd build ninja ${{ matrix.target }}_report - name: Memory checks - if: ${{ matrix.target == 'memory_checks' }} + if: ${{ matrix.memory_checks == 'ON' }} run: | cd build ninja ${{ matrix.target }} - name: Documentation - if: ${{ matrix.target == 'documentation' }} + if: ${{ matrix.documentation == 'ON' }} run: | cd build ninja ${{ matrix.target }} From 2fe9fc5f3544449a93dd93443877f679065e23b0 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Thu, 23 May 2024 11:07:12 +1200 Subject: [PATCH 06/11] CI: now have tests for both macOS Intel and ARM. --- .github/workflows/ci.yml | 53 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78d0e18de..10f34bcd2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,7 +73,37 @@ jobs: unit_testing: ON target: unit_testing install_uninstall_and_package: ON - - name: 'macOS static library' + - name: 'macOS static library (Intel)' + os: macos-13 + build_type: Release + code_analysis: OFF + code_coverage: OFF + documentation: OFF + javascript_bindings: OFF + javascript_unit_testing: OFF + memory_checks: OFF + python_bindings: OFF + python_unit_testing: OFF + shared_libs: OFF + unit_testing: ON + target: unit_testing + install_uninstall_and_package: ON + - name: 'macOS shared library (Intel)' + os: macos-13 + build_type: Release + code_analysis: OFF + code_coverage: OFF + documentation: OFF + javascript_bindings: OFF + javascript_unit_testing: OFF + memory_checks: OFF + python_bindings: OFF + python_unit_testing: OFF + shared_libs: ON + unit_testing: ON + target: unit_testing + install_uninstall_and_package: ON + - name: 'macOS static library (ARM)' os: macos-latest build_type: Release code_analysis: OFF @@ -88,7 +118,7 @@ jobs: unit_testing: ON target: unit_testing install_uninstall_and_package: ON - - name: 'macOS shared library' + - name: 'macOS shared library (ARM)' os: macos-latest build_type: Release code_analysis: OFF @@ -147,7 +177,24 @@ jobs: unit_testing: OFF target: python_unit_testing pip_install_test_and_uninstall: ON - - name: 'macOS Python bindings' + - name: 'macOS Python bindings (Intel)' + os: macos-13 + build_type: Release + code_analysis: OFF + code_coverage: OFF + documentation: OFF + javascript_bindings: OFF + javascript_unit_testing: OFF + memory_checks: OFF + python_bindings: ON + python_unit_testing: ON + shared_libs: OFF + unit_testing: OFF + context: PATH=/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH + target: python_unit_testing + pip_install_prerequisites: sudo pip3 install cmake scikit-build + pip_install_test_and_uninstall: ON + - name: 'macOS Python bindings (ARM)' os: macos-latest build_type: Release code_analysis: OFF From e12278adc9073af74f40813f75deb5f9ce668eab Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 28 May 2024 00:17:20 +1200 Subject: [PATCH 07/11] CI: use LLVM+Clang 18.1.6. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10f34bcd2..3fd7ba83d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -317,7 +317,7 @@ jobs: BUILDCACHE_DEBUG: -1 BUILDCACHE_LOG_FILE: "" DOXYGEN_VERSION: 1.9.3 - LLVMCLANG_VERSION: 17.0.6 + LLVMCLANG_VERSION: 18.1.6 steps: - name: Check out libOpenCOR uses: actions/checkout@v4 From 08779a6cb930ffa8544987ea06bc50ae4f5b7ed3 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 28 May 2024 00:41:00 +1200 Subject: [PATCH 08/11] Third-party libraries: new binaries for libNuML, libSEDML, and zipper. They have merely been rebuilt. --- src/3rdparty/libNuML/CMakeLists.txt | 12 ++++++------ src/3rdparty/libSEDML/CMakeLists.txt | 12 ++++++------ src/3rdparty/zipper/CMakeLists.txt | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/3rdparty/libNuML/CMakeLists.txt b/src/3rdparty/libNuML/CMakeLists.txt index 11beccfa2..1f86e3a54 100644 --- a/src/3rdparty/libNuML/CMakeLists.txt +++ b/src/3rdparty/libNuML/CMakeLists.txt @@ -28,32 +28,32 @@ if(LIBOPENCOR_PREBUILT_LIBNUML) if(EMSCRIPTEN) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - b3e53917bc59f6b15c1f1958fd251d238208de46) + 436de3e7c036555b347edaca41f737208f3f0bc3) else() if(WIN32) if(RELEASE_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 849756984debf9a74601a31ccd72f434724f655e) + b3b6570a62ea935252124cda43d014f2107b7e49) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 6b4214108546a24fab6c5dc77af9655d7484c2c6) + 6afe121663e51c8022a49c456cc9ec1e663b0d76) endif() elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - b1aa08c1f2bb41298675165a1608bf6029743a5a) + 3a1f9279d709a4dde107729967d8c7c5e660971d) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 8424f3ee04bcaa973160f56c6807b2d9d21e1482) + b951a1b35afbc6062f946dbb3df68e459d7e9a5b) endif() else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 826470e27e446414a9d1269efa89d935c8a1eb55) + adfb4864debeca88c8c79a27b7fd14c53860b912) endif() endif() else() diff --git a/src/3rdparty/libSEDML/CMakeLists.txt b/src/3rdparty/libSEDML/CMakeLists.txt index 8344bb9c2..17ded76fb 100644 --- a/src/3rdparty/libSEDML/CMakeLists.txt +++ b/src/3rdparty/libSEDML/CMakeLists.txt @@ -28,32 +28,32 @@ if(LIBOPENCOR_PREBUILT_LIBSEDML) if(EMSCRIPTEN) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - fa14fca899067a9472a2435271f103962f758025) + a790812f0d1d9c7d65232bf9201806aded82147c) else() if(WIN32) if(RELEASE_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - c7a7fea81af5544fb8ccc2d3c078041920f8b556) + 47ec99b72e8dfdafe6d84790f745c811ab063fdf) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 175f6f935dc0596d306846077b80b6d05d284b96) + e2eecd96cda3d80e9b792fd7a8fcb766edde12ec) endif() elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - d4a3a3bcd0be4137967517b63167cb7d169dd353) + 263f6acecec69eb67483ab7813c0dec2d284187c) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - c0823de700727c4872da11e6bbed0ff9e005fb73) + 55270953aa8ff92510cff41ec5bd8eee7047c516) endif() else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 7a50da22899f7d7a8ec01a2a3afd5de5cc64e6b2) + 46f605d77e87c26c28374ae306fde2223087d3f1) endif() endif() else() diff --git a/src/3rdparty/zipper/CMakeLists.txt b/src/3rdparty/zipper/CMakeLists.txt index 03de708ca..d049abf7f 100644 --- a/src/3rdparty/zipper/CMakeLists.txt +++ b/src/3rdparty/zipper/CMakeLists.txt @@ -24,32 +24,32 @@ if(LIBOPENCOR_PREBUILT_ZIPPER) if(EMSCRIPTEN) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 87d083fa72532dc97c44db032515e6fd5221de54) + 5897b58ebcaedfb98e7f2b7394f13df6c626ae06) else() if(WIN32) if(RELEASE_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 9bf375fbce91eb4df163992a8a3d5c2b24efc204) + 1b29a495deef311a3029c9a84ed70624b566c3c4) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - a3fcc47aec91f46bf8b039a1c2aa6d0efb9970fe) + 0e25d62e63310b4a94ccf70fad7d5a237fc78c72) endif() elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 934654bea9a68d2dd1ccad70d3942cec9a17e101) + 019dd20f83d6e21103c5c51b767527133893495d) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 372736c5821254782e1794b5b902a5de120379d4) + 6cdbc63773163e668d7f14b2d67a6a09819e4203) endif() else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 7a75f83c6dae5237701775795e14b7579d8030aa) + 5faa7c54d6b0b5709957e3079c6bd0beb7d86167) endif() endif() else() From bfa272de706d5610bd325e071919f3b57b84c459 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 24 May 2024 11:39:02 +1200 Subject: [PATCH 09/11] libCOMBINE: upgraded to version 0.2.20. --- src/3rdparty/CMakeLists.txt | 4 ++-- src/3rdparty/libCOMBINE/CMakeLists.txt | 18 ++++++++++-------- tests/api/version/tests.cpp | 4 ++-- tests/bindings/javascript/version.test.js | 4 ++-- tests/bindings/python/test_version.py | 4 ++-- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/3rdparty/CMakeLists.txt b/src/3rdparty/CMakeLists.txt index 16ed8e626..1d23d0607 100644 --- a/src/3rdparty/CMakeLists.txt +++ b/src/3rdparty/CMakeLists.txt @@ -84,7 +84,7 @@ endif() check_required_packages(zipper zlib) check_required_packages(libCellML libxml2 zlib) -check_required_packages(libCOMBINE libSBML zipper zlib) +check_required_packages(libCOMBINE libSBML libxml2 zipper zlib) if(NOT EMSCRIPTEN) check_required_packages(libcurl libssh2 OpenSSL zlib) @@ -124,7 +124,7 @@ add_package(zipper) # Requires zlib. # Required third-party libraries. add_package(libCellML) # Requires libxml2 and zlib. -add_package(libCOMBINE) # Requires libSBML, zipper, and zlib. +add_package(libCOMBINE) # Requires libSBML, libxml2, zipper, and zlib. if(NOT EMSCRIPTEN) add_package(libcurl) # Requires libssh2, OpenSSL, and zlib. diff --git a/src/3rdparty/libCOMBINE/CMakeLists.txt b/src/3rdparty/libCOMBINE/CMakeLists.txt index 0eb5c22df..dd85c4896 100644 --- a/src/3rdparty/libCOMBINE/CMakeLists.txt +++ b/src/3rdparty/libCOMBINE/CMakeLists.txt @@ -13,9 +13,9 @@ # limitations under the License. set(PACKAGE_NAME libCOMBINE) -set(PACKAGE_VERSION 0.2.18) +set(PACKAGE_VERSION 0.2.20) set(PACKAGE_REPOSITORY libCombine) -set(RELEASE_TAG v0.2.18) +set(RELEASE_TAG v0.2.20b) set(INSTALL_DIR ${PREBUILT_DIR}/${PACKAGE_NAME}) # Either retrieve or build our package. @@ -28,32 +28,32 @@ if(LIBOPENCOR_PREBUILT_LIBCOMBINE) if(EMSCRIPTEN) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 21f9435b7de4bee3b71a6439152d07751f7490e9) + bba8ce8929527e84d9aca91329d7959f930ae2ca) else() if(WIN32) if(RELEASE_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 3694f8043163db0f0a140f50d63aca5230f30abe) + af256ee3c239c4834e472dfe7b723bc2e974d237) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 22431c4e857d1f3a2661a880cb6142be905bfe66) + 68e967fb8673c853730b1277fb2a4ceffa948b44) endif() elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 1b7ec9932dd53f37e5bad7ae20f98a2c1f32f342) + ec3bbe156c96f3f7c3cc46e458aff7f9dc3de19c) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - a8657b4e8d3b36ece2dd1571a830184500f89ea4) + a2192cc11cc9d272029bc25774eaff986bd41656) endif() else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 18ebd3acc651040f127f94284ed5241e2bb38380) + f258c3b50f22c9cc3eb02d5c6b9377dd3d92b26e) endif() endif() else() @@ -74,6 +74,8 @@ else() -DLIBSBML_LIBRARY=${LIBSBML_LIBRARY_FILE} -DWITH_CPP_NAMESPACE=ON -DWITH_SWIG=OFF + -DXML_INCLUDE_DIR=${LIBXML2_INCLUDE_DIR} + -DXML_LIBRARY=${LIBXML2_LIBRARY_FILE} -DZIPPER_INCLUDE_DIR=${ZIPPER_INCLUDE_DIR} -DZIPPER_LIBRARY=${ZIPPER_LIBRARY_FILE} -DZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIR} diff --git a/tests/api/version/tests.cpp b/tests/api/version/tests.cpp index 3a89dbbfd..38e58c2c6 100644 --- a/tests/api/version/tests.cpp +++ b/tests/api/version/tests.cpp @@ -38,8 +38,8 @@ TEST(VersionTest, libCellML) TEST(VersionTest, libCOMBINE) { - EXPECT_EQ(218U, libOpenCOR::libcombineVersion()); - EXPECT_EQ("0.2.18", libOpenCOR::libcombineVersionString()); + EXPECT_EQ(220U, libOpenCOR::libcombineVersion()); + EXPECT_EQ("0.2.20", libOpenCOR::libcombineVersionString()); } TEST(VersionTest, libcurl) diff --git a/tests/bindings/javascript/version.test.js b/tests/bindings/javascript/version.test.js index d26c64391..13ca0115b 100644 --- a/tests/bindings/javascript/version.test.js +++ b/tests/bindings/javascript/version.test.js @@ -30,8 +30,8 @@ describe("Version tests", () => { }); test("libCOMBINE", () => { - expect(libopencor.libcombineVersion()).toBe(218); - expect(libopencor.libcombineVersionString()).toBe("0.2.18"); + expect(libopencor.libcombineVersion()).toBe(220); + expect(libopencor.libcombineVersionString()).toBe("0.2.20"); }); test("libSEDML", () => { diff --git a/tests/bindings/python/test_version.py b/tests/bindings/python/test_version.py index dcca9a2f8..17eb7fe4b 100644 --- a/tests/bindings/python/test_version.py +++ b/tests/bindings/python/test_version.py @@ -48,12 +48,12 @@ def test_libcellml_version_string(): def test_libcombine_version(): assert isinstance(oc.libcombine_version(), int) - assert oc.libcombine_version() == 218 + assert oc.libcombine_version() == 220 def test_libcombine_version_string(): assert isinstance(oc.libcombine_version_string(), str) - assert oc.libcombine_version_string() == "0.2.18" + assert oc.libcombine_version_string() == "0.2.20" def test_libcurl_version(): From 1ff49b78fae6b8419841cc7b39938429a38b4387 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Wed, 22 May 2024 12:43:34 +1200 Subject: [PATCH 10/11] LLVM+Clang: upgraded to version 18.1.6. About disabling zstd: this is a new library that LLVM+Clang uses if available and it is available on macOS, for instance, except that it has a minimum target of 13.0 on Intel and 14.0 on ARM, which causes problems when trying to repair our Python wheels (through cibuildwheel). --- cmake/common.cmake | 7 +++++ src/3rdparty/LLVMClang/CMakeLists.txt | 37 +++++++++++++++++++++------ src/3rdparty/LLVMClang/llvmbegin.h | 3 +++ src/misc/compiler.cpp | 6 ++--- tests/api/version/tests.cpp | 8 +++--- tests/bindings/python/test_version.py | 8 +++--- tests/misc/compiler/tests.cpp | 34 ++++++++++++------------ 7 files changed, 67 insertions(+), 36 deletions(-) diff --git a/cmake/common.cmake b/cmake/common.cmake index c4ccbc6af..3c3efbf77 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -63,6 +63,13 @@ function(configure_target TARGET) endif() endif() + # Make it possible to use LLVM+Clang 18+ when building using MSVC (see + # https://github.com/llvm/llvm-project/issues/86028). + + if(BUILDING_USING_MSVC) + target_compile_options(${TARGET} PRIVATE /Zc:preprocessor) + endif() + # Analyse the code. if(LIBOPENCOR_CODE_ANALYSIS) diff --git a/src/3rdparty/LLVMClang/CMakeLists.txt b/src/3rdparty/LLVMClang/CMakeLists.txt index 9f41b7a0e..198581c30 100644 --- a/src/3rdparty/LLVMClang/CMakeLists.txt +++ b/src/3rdparty/LLVMClang/CMakeLists.txt @@ -13,9 +13,9 @@ # limitations under the License. set(PACKAGE_NAME LLVMClang) -set(PACKAGE_VERSION 14.0.3) +set(PACKAGE_VERSION 18.1.6) set(PACKAGE_REPOSITORY llvm-project) -set(RELEASE_TAG llvmorg-14.0.3d) +set(RELEASE_TAG llvmorg-18.1.6) set(INSTALL_DIR ${PREBUILT_DIR}/${PACKAGE_NAME}) # Either retrieve or build our package. @@ -25,26 +25,26 @@ if(LIBOPENCOR_PREBUILT_LLVMCLANG) if(RELEASE_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 8ce4afcab9008cb845b4044b16fc0873aeba418c) + bbdbb972fd20adc8752afe47815b544c0787f520) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 7a3168fd20a0f4c034f0c1252401ca17074095b9) + 9855ca84efdc2ef54a41eee47a8db34ac953dd13) endif() elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 006e8969fccc75f2c5020b69cb6a196c2e3c43b8) + 85f407ff82526778ebfbe5a7e5311b655c4ed725) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - edab86a319335dec8cd38fc86b3fd11ef71fb789) + 4b07f621f8e8ce287922597aeb7b8255876d4b30) endif() else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - acc80f89781960d71046c26ffb40593c8e91f476) + 05c1db4ffb9a451ad7261a53de17136dce8ec734) endif() else() # Build our package. @@ -97,6 +97,7 @@ else() -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_WARNINGS=OFF -DLLVM_ENABLE_ZLIB=OFF + -DLLVM_ENABLE_ZSTD=OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_DOCS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF @@ -161,6 +162,7 @@ set(LLVMCLANG_INCLUDE_DIR ${INSTALL_DIR}/include CACHE INTERNAL "${PACKAGE_NAME} set(LLVMCLANG_LIBRARIES clangAnalysis clangAnalysisFlowSensitive + clangAnalysisFlowSensitiveModels clangAPINotes clangAST clangASTMatchers @@ -172,6 +174,7 @@ set(LLVMCLANG_LIBRARIES clangDriver clangDynamicASTMatchers clangEdit + clangExtractAPI clangFormat clangFrontend clangFrontendTool @@ -187,11 +190,12 @@ set(LLVMCLANG_LIBRARIES clangStaticAnalyzerCheckers clangStaticAnalyzerCore clangStaticAnalyzerFrontend - clangTesting + clangSupport clangTooling clangToolingASTDiff clangToolingCore clangToolingInclusions + clangToolingInclusionsStdlib clangToolingRefactoring clangToolingSyntax clangTransformer @@ -207,33 +211,44 @@ set(LLVMCLANG_LIBRARIES LLVMCFGuard LLVMCFIVerify LLVMCodeGen + LLVMCodeGenTypes LLVMCore LLVMCoroutines LLVMCoverage + LLVMDebugInfoBTF LLVMDebugInfoCodeView LLVMDebuginfod LLVMDebugInfoDWARF LLVMDebugInfoGSYM + LLVMDebugInfoLogicalView LLVMDebugInfoMSF LLVMDebugInfoPDB LLVMDemangle LLVMDiff LLVMDlltoolDriver LLVMDWARFLinker + LLVMDWARFLinkerClassic + LLVMDWARFLinkerParallel LLVMDWP LLVMExecutionEngine LLVMExegesis LLVMExtensions LLVMFileCheck + LLVMFrontendDriver + LLVMFrontendHLSL + LLVMFrontendOffloading LLVMFrontendOpenACC LLVMFrontendOpenMP + LLVMFuzzerCLI LLVMFuzzMutate LLVMGlobalISel + LLVMHipStdPar LLVMInstCombine LLVMInstrumentation LLVMInterfaceStub LLVMInterpreter LLVMipo + LLVMIRPrinter LLVMIRReader LLVMJITLink LLVMLibDriver @@ -247,9 +262,11 @@ set(LLVMCLANG_LIBRARIES LLVMMCParser LLVMMIRParser LLVMObjCARCOpts + LLVMObjCopy LLVMObject LLVMObjectYAML LLVMOption + LLVMOrcDebugging LLVMOrcJIT LLVMOrcShared LLVMOrcTargetProcess @@ -262,11 +279,15 @@ set(LLVMCLANG_LIBRARIES LLVMSupport LLVMSymbolize LLVMTableGen + LLVMTableGenCommon LLVMTableGenGlobalISel LLVMTarget + LLVMTargetParser LLVMTextAPI + LLVMTextAPIBinaryReader LLVMTransformUtils LLVMVectorize + LLVMWindowsDriver LLVMWindowsManifest LLVMXRay ${EXTRA_LLVMCLANG_LIBRARIES} diff --git a/src/3rdparty/LLVMClang/llvmbegin.h b/src/3rdparty/LLVMClang/llvmbegin.h index 27fd8fe1b..65e860414 100644 --- a/src/3rdparty/LLVMClang/llvmbegin.h +++ b/src/3rdparty/LLVMClang/llvmbegin.h @@ -16,6 +16,7 @@ limitations under the License. #if defined(BUILDING_USING_MSVC) # pragma warning(push) +# pragma warning(disable: 4003) # pragma warning(disable: 4100) # pragma warning(disable: 4127) # pragma warning(disable: 4146) @@ -25,6 +26,7 @@ limitations under the License. # pragma warning(disable: 4291) # pragma warning(disable: 4324) # pragma warning(disable: 4389) +# pragma warning(disable: 4456) # pragma warning(disable: 4458) # pragma warning(disable: 4459) # pragma warning(disable: 4624) @@ -69,6 +71,7 @@ limitations under the License. # pragma clang diagnostic ignored "-Wswitch-default" # pragma clang diagnostic ignored "-Wswitch-enum" # pragma clang diagnostic ignored "-Wtautological-type-limit-compare" +# pragma clang diagnostic ignored "-Wtautological-unsigned-zero-compare" # pragma clang diagnostic ignored "-Wundefined-func-template" # pragma clang diagnostic ignored "-Wunused-but-set-variable" # pragma clang diagnostic ignored "-Wunused-parameter" diff --git a/src/misc/compiler.cpp b/src/misc/compiler.cpp index 7acdbca2d..eecbf970c 100644 --- a/src/misc/compiler.cpp +++ b/src/misc/compiler.cpp @@ -32,8 +32,8 @@ limitations under the License. #include "clangend.h" #include "llvmbegin.h" -#include "llvm/Support/Host.h" #include "llvm/Support/TargetSelect.h" +#include "llvm/TargetParser/Host.h" #include "llvm-c/Core.h" #include "llvmend.h" @@ -323,7 +323,7 @@ bool Compiler::Impl::addFunction(const std::string &pName, void *pFunction) // name, and function. const bool res = !mLljit->getMainJITDylib().define(llvm::orc::absoluteSymbols({ - {mLljit->mangleAndIntern(pName), llvm::JITEvaluatedSymbol(llvm::pointerToJITTargetAddress(pFunction), llvm::JITSymbolFlags::Exported)}, + {mLljit->mangleAndIntern(pName), {llvm::orc::ExecutorAddr::fromPtr(pFunction), llvm::JITSymbolFlags::Exported}}, })); #ifndef CODE_COVERAGE_ENABLED @@ -343,7 +343,7 @@ void *Compiler::Impl::function(const std::string &pName) const auto symbol = mLljit->lookup(pName); if (symbol) { - return reinterpret_cast(symbol->getAddress()); // NOLINT + return reinterpret_cast(symbol->getValue()); // NOLINT } return {}; diff --git a/tests/api/version/tests.cpp b/tests/api/version/tests.cpp index 38e58c2c6..c746dcd47 100644 --- a/tests/api/version/tests.cpp +++ b/tests/api/version/tests.cpp @@ -26,8 +26,8 @@ TEST(VersionTest, libOpenCOR) TEST(VersionTest, Clang) { - EXPECT_EQ(0x140003U, libOpenCOR::clangVersion()); - EXPECT_EQ("14.0.3", libOpenCOR::clangVersionString()); + EXPECT_EQ(0x180106U, libOpenCOR::clangVersion()); + EXPECT_EQ("18.1.6", libOpenCOR::clangVersionString()); } TEST(VersionTest, libCellML) @@ -56,8 +56,8 @@ TEST(VersionTest, libSEDML) TEST(VersionTest, LLVM) { - EXPECT_EQ(0x140003U, libOpenCOR::llvmVersion()); - EXPECT_EQ("14.0.3", libOpenCOR::llvmVersionString()); + EXPECT_EQ(0x180106U, libOpenCOR::llvmVersion()); + EXPECT_EQ("18.1.6", libOpenCOR::llvmVersionString()); } TEST(VersionTest, SUNDIALS) diff --git a/tests/bindings/python/test_version.py b/tests/bindings/python/test_version.py index 17eb7fe4b..b86393a0a 100644 --- a/tests/bindings/python/test_version.py +++ b/tests/bindings/python/test_version.py @@ -28,12 +28,12 @@ def test_version_string(): def test_clang_version(): assert isinstance(oc.clang_version(), int) - assert oc.clang_version() == 0x140003 + assert oc.clang_version() == 0x180106 def test_clang_version_string(): assert isinstance(oc.clang_version_string(), str) - assert oc.clang_version_string() == "14.0.3" + assert oc.clang_version_string() == "18.1.6" def test_libcellml_version(): @@ -78,12 +78,12 @@ def test_libsedml_version_string(): def test_llvm_version(): assert isinstance(oc.llvm_version(), int) - assert oc.llvm_version() == 0x140003 + assert oc.llvm_version() == 0x180106 def test_llvm_version_string(): assert isinstance(oc.llvm_version_string(), str) - assert oc.llvm_version_string() == "14.0.3" + assert oc.llvm_version_string() == "18.1.6" def test_sundials_version(): diff --git a/tests/misc/compiler/tests.cpp b/tests/misc/compiler/tests.cpp index 81aedc091..09f9b7620 100644 --- a/tests/misc/compiler/tests.cpp +++ b/tests/misc/compiler/tests.cpp @@ -39,7 +39,7 @@ TEST_F(CompilerTest, basic) static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_01 = { {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, - {libOpenCOR::Issue::Type::ERROR, "Expected identifier or '(':\nvoid\n ^"}, + {libOpenCOR::Issue::Type::ERROR, "Expected identifier or '(':\n 38 | void\n | ^"}, }; EXPECT_FALSE(mCompiler->compile("void")); @@ -49,8 +49,8 @@ TEST_F(CompilerTest, basic) static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_02 = { {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, - {libOpenCOR::Issue::Type::ERROR, "Variable has incomplete type 'void':\nvoid function\n ^"}, - {libOpenCOR::Issue::Type::ERROR, "Expected ';' after top level declarator:\nvoid function\n ^\n ;"}, + {libOpenCOR::Issue::Type::ERROR, "Variable has incomplete type 'void':\n 38 | void function\n | ^"}, + {libOpenCOR::Issue::Type::ERROR, "Expected ';' after top level declarator:\n 38 | void function\n | ^\n | ;"}, }; EXPECT_FALSE(mCompiler->compile("void function")); @@ -60,9 +60,9 @@ TEST_F(CompilerTest, basic) static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_03 = { {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, - {libOpenCOR::Issue::Type::ERROR, "Expected parameter declarator:\nvoid function(\n ^"}, - {libOpenCOR::Issue::Type::ERROR, "Expected ')' to match this '(':\nvoid function(\n ^"}, - {libOpenCOR::Issue::Type::ERROR, "Expected function body after function declarator:\nvoid function(\n ^"}, + {libOpenCOR::Issue::Type::ERROR, "Expected parameter declarator:\n 38 | void function(\n | ^"}, + {libOpenCOR::Issue::Type::ERROR, "Expected ')' to match this '(':\n 38 | void function(\n | ^"}, + {libOpenCOR::Issue::Type::ERROR, "Expected function body after function declarator:\n 38 | void function(\n | ^"}, }; EXPECT_FALSE(mCompiler->compile("void function(")); @@ -72,7 +72,7 @@ TEST_F(CompilerTest, basic) static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_04 = { {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, - {libOpenCOR::Issue::Type::ERROR, "Expected function body after function declarator:\nvoid function()\n ^"}, + {libOpenCOR::Issue::Type::ERROR, "Expected function body after function declarator:\n 38 | void function()\n | ^"}, }; EXPECT_FALSE(mCompiler->compile("void function()")); @@ -82,7 +82,7 @@ TEST_F(CompilerTest, basic) static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_05 = { {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, - {libOpenCOR::Issue::Type::ERROR, "Expected '}':\nvoid function() {\n ^\nto match this '{':\nvoid function() {\n ^"}, + {libOpenCOR::Issue::Type::ERROR, "Expected '}':\n 38 | void function() {\n | ^\nto match this '{':\n 38 | void function() {\n | ^"}, }; EXPECT_FALSE(mCompiler->compile("void function() {")); @@ -101,7 +101,7 @@ TEST_F(CompilerTest, basic) static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_06 = { {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, - {libOpenCOR::Issue::Type::ERROR, "Non-void function does not return a value:\ndouble function() {}\n ^"}, + {libOpenCOR::Issue::Type::ERROR, "Non-void function does not return a value:\n 38 | double function() {}\n | ^"}, }; EXPECT_FALSE(mCompiler->compile("double function() {}")); @@ -111,8 +111,8 @@ TEST_F(CompilerTest, basic) static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_07 = { {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, - {libOpenCOR::Issue::Type::ERROR, "Expected expression:\ndouble function() { return\n ^"}, - {libOpenCOR::Issue::Type::ERROR, "Expected '}' to match this '{':\ndouble function() { return\n ^"}, + {libOpenCOR::Issue::Type::ERROR, "Expected expression:\n 38 | double function() { return\n | ^"}, + {libOpenCOR::Issue::Type::ERROR, "Expected '}' to match this '{':\n 38 | double function() { return\n | ^"}, }; EXPECT_FALSE(mCompiler->compile("double function() { return")); @@ -122,8 +122,8 @@ TEST_F(CompilerTest, basic) static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_08 = { {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, - {libOpenCOR::Issue::Type::ERROR, "Expected ';' after return statement:\ndouble function() { return 3.0\n ^\n ;"}, - {libOpenCOR::Issue::Type::ERROR, "Expected '}' to match this '{':\ndouble function() { return 3.0\n ^"}, + {libOpenCOR::Issue::Type::ERROR, "Expected ';' after return statement:\n 38 | double function() { return 3.0\n | ^\n | ;"}, + {libOpenCOR::Issue::Type::ERROR, "Expected '}' to match this '{':\n 38 | double function() { return 3.0\n | ^"}, }; EXPECT_FALSE(mCompiler->compile("double function() { return 3.0")); @@ -133,7 +133,7 @@ TEST_F(CompilerTest, basic) static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_09 = { {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, - {libOpenCOR::Issue::Type::ERROR, "Expected '}':\ndouble function() { return 3.0;\n ^\nto match this '{':\ndouble function() { return 3.0;\n ^"}, + {libOpenCOR::Issue::Type::ERROR, "Expected '}':\n 38 | double function() { return 3.0;\n | ^\nto match this '{':\n 38 | double function() { return 3.0;\n | ^"}, }; EXPECT_FALSE(mCompiler->compile("double function() { return 3.0;")); @@ -149,7 +149,7 @@ TEST_F(CompilerTest, basic) static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_10 = { {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, - {libOpenCOR::Issue::Type::ERROR, "Expected identifier or '(':\ndouble .function() { return 3.0; }\n ^"}, + {libOpenCOR::Issue::Type::ERROR, "Expected identifier or '(':\n 38 | double .function() { return 3.0; }\n | ^"}, }; EXPECT_FALSE(mCompiler->compile("double .function() { return 3.0; }")); @@ -159,8 +159,8 @@ TEST_F(CompilerTest, basic) static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES_11 = { {libOpenCOR::Issue::Type::ERROR, "The given code could not be compiled."}, - {libOpenCOR::Issue::Type::ERROR, "Expected expression:\ndouble function() { return 3.0+*-/a; }\n ^"}, - {libOpenCOR::Issue::Type::ERROR, "Use of undeclared identifier 'a':\ndouble function() { return 3.0+*-/a; }\n ^"}, + {libOpenCOR::Issue::Type::ERROR, "Expected expression:\n 38 | double function() { return 3.0+*-/a; }\n | ^"}, + {libOpenCOR::Issue::Type::ERROR, "Use of undeclared identifier 'a':\n 38 | double function() { return 3.0+*-/a; }\n | ^"}, }; EXPECT_FALSE(mCompiler->compile("double function() { return 3.0+*-/a; }")); From 40bb2ddc71092e53f019939d9cbe6215632d9fd1 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 21 May 2024 14:57:40 +1200 Subject: [PATCH 11/11] SUNDIALS: upgraded to version 7.0.0. --- cmake/common.cmake | 10 ++++++ src/3rdparty/SUNDIALS/CMakeLists.txt | 18 +++++----- src/solver/solvercvode.cpp | 31 ++++++++++++------ src/solver/solverkinsol.cpp | 19 +++++++---- tests/api/sed/runtests.cpp | 10 ++++++ tests/api/solver/cvodetests.cpp | 36 ++++++++++---------- tests/api/version/tests.cpp | 4 +-- tests/bindings/javascript/version.test.js | 4 +-- tests/bindings/python/test_sed_run.py | 15 ++++++++- tests/bindings/python/test_solver_cvode.py | 38 +++++++++++----------- tests/bindings/python/test_version.py | 4 +-- 11 files changed, 119 insertions(+), 70 deletions(-) diff --git a/cmake/common.cmake b/cmake/common.cmake index 3c3efbf77..111a8b636 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -209,6 +209,16 @@ function(configure_target TARGET) BUILDING_ON_LINUX) endif() + # Let the target know which architecture we are using. + + if(INTEL_MODE) + target_compile_definitions(${TARGET} PRIVATE + BUILDING_ON_INTEL) + else() + target_compile_definitions(${TARGET} PRIVATE + BUILDING_ON_ARM) + endif() + # Let the target know which compiler we are using. if(BUILDING_USING_MSVC) diff --git a/src/3rdparty/SUNDIALS/CMakeLists.txt b/src/3rdparty/SUNDIALS/CMakeLists.txt index bd0bbc02a..46d245508 100644 --- a/src/3rdparty/SUNDIALS/CMakeLists.txt +++ b/src/3rdparty/SUNDIALS/CMakeLists.txt @@ -13,9 +13,9 @@ # limitations under the License. set(PACKAGE_NAME SUNDIALS) -set(PACKAGE_VERSION v6.2.0) +set(PACKAGE_VERSION v7.0.0) set(PACKAGE_REPOSITORY sundials) -set(RELEASE_TAG v6.2.0-libopencor) +set(RELEASE_TAG v7.0.0) set(INSTALL_DIR ${PREBUILT_DIR}/${PACKAGE_NAME}) # Either retrieve or build our package. @@ -24,32 +24,32 @@ if(LIBOPENCOR_PREBUILT_SUNDIALS) if(EMSCRIPTEN) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 42770edddf6ed996a55a50078e54e387ceb8da0a) + 78bce667f10758e3e5f2fcdc56a401514e323c0d) else() if(WIN32) if(RELEASE_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 7bc8ba9a62a6bb8efd52bc7aea1f17aa2d8ef024) + 4ae38fb1382236a092282c9cb5cd456db6ab746c) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 1471019d8221d5f079a30baa0394e0dc54ba3edb) + b2725d3140839774a5f253d59f39fda2cd33cfe0) endif() elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - ef844d27b82a63b7167f3165e45ce78d20c3a7cf) + c55dc7e76e72eb2389b7902b67ccbe3e3a344ef0) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - a2399ef9cf50d64c1dad7d6e554700a47adde9b2) + 35e6771a04f8943353b3ebef009d04fd3ed02bdf) endif() else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - b0d953dffcab7be7440d148bf334cac7913914dd) + 737f908f53c3a70224cea78ed5a5bf290207261c) endif() endif() else() @@ -86,9 +86,9 @@ set(SUNDIALS_CMAKE_PACKAGE_NAME ${PACKAGE_NAME} CACHE INTERNAL "${PACKAGE_NAME}' set(SUNDIALS_INCLUDE_DIR ${INSTALL_DIR}/include CACHE INTERNAL "${PACKAGE_NAME}'s include directory.") set(SUNDIALS_LIBRARIES SUNDIALS::arkode_static + SUNDIALS::core_static SUNDIALS::cvode_static SUNDIALS::cvodes_static - SUNDIALS::generic_static SUNDIALS::ida_static SUNDIALS::idas_static SUNDIALS::kinsol_static diff --git a/src/solver/solvercvode.cpp b/src/solver/solvercvode.cpp index 0152af8eb..4622f9dba 100644 --- a/src/solver/solvercvode.cpp +++ b/src/solver/solvercvode.cpp @@ -37,10 +37,13 @@ namespace libOpenCOR { namespace { -void errorHandler(int pErrorCode, const char *pModule, const char *pFunction, char *pErrorMessage, void *pUserData) +void errorHandler(int pLine, const char *pFunction, const char *pFile, const char *pErrorMessage, SUNErrCode pErrorCode, + void *pUserData, SUNContext pSunContext) { - (void)pModule; + (void)pLine; (void)pFunction; + (void)pFile; + (void)pSunContext; #ifdef CODE_COVERAGE_ENABLED (void)pErrorCode; @@ -110,6 +113,8 @@ void SolverCvode::Impl::resetInternals() CVodeFree(&mSolver); + SUNContext_PopErrHandler(mSunContext); + SUNContext_Free(&mSunContext); } } @@ -207,7 +212,7 @@ bool SolverCvode::Impl::initialise(double pVoi, size_t pSize, double *pStates, d // Create our SUNDIALS context. - ASSERT_EQ(SUNContext_Create(nullptr, &mSunContext), 0); + ASSERT_EQ(SUNContext_Create(SUN_COMM_NULL, &mSunContext), 0); // Create our CVODE solver. @@ -217,7 +222,7 @@ bool SolverCvode::Impl::initialise(double pVoi, size_t pSize, double *pStates, d // Use our own error handler. - ASSERT_EQ(CVodeSetErrHandlerFn(mSolver, errorHandler, &mErrorMessage), CV_SUCCESS); + ASSERT_EQ(SUNContext_PushErrHandler(mSunContext, errorHandler, &mErrorMessage), CV_SUCCESS); // Initialise our CVODE solver. @@ -274,11 +279,11 @@ bool SolverCvode::Impl::initialise(double pVoi, size_t pSize, double *pStates, d if (mPreconditioner == Preconditioner::BANDED) { if (mLinearSolver == LinearSolver::GMRES) { - mSunLinearSolver = SUNLinSol_SPGMR(mStatesVector, PREC_LEFT, 0, mSunContext); + mSunLinearSolver = SUNLinSol_SPGMR(mStatesVector, SUN_PREC_LEFT, 0, mSunContext); } else if (mLinearSolver == LinearSolver::BICGSTAB) { - mSunLinearSolver = SUNLinSol_SPBCGS(mStatesVector, PREC_LEFT, 0, mSunContext); + mSunLinearSolver = SUNLinSol_SPBCGS(mStatesVector, SUN_PREC_LEFT, 0, mSunContext); } else { - mSunLinearSolver = SUNLinSol_SPTFQMR(mStatesVector, PREC_LEFT, 0, mSunContext); + mSunLinearSolver = SUNLinSol_SPTFQMR(mStatesVector, SUN_PREC_LEFT, 0, mSunContext); } ASSERT_NE(mSunLinearSolver, nullptr); @@ -290,11 +295,11 @@ bool SolverCvode::Impl::initialise(double pVoi, size_t pSize, double *pStates, d CVLS_SUCCESS); } else { if (mLinearSolver == LinearSolver::GMRES) { - mSunLinearSolver = SUNLinSol_SPGMR(mStatesVector, PREC_NONE, 0, mSunContext); + mSunLinearSolver = SUNLinSol_SPGMR(mStatesVector, SUN_PREC_NONE, 0, mSunContext); } else if (mLinearSolver == LinearSolver::BICGSTAB) { - mSunLinearSolver = SUNLinSol_SPBCGS(mStatesVector, PREC_NONE, 0, mSunContext); + mSunLinearSolver = SUNLinSol_SPBCGS(mStatesVector, SUN_PREC_NONE, 0, mSunContext); } else { - mSunLinearSolver = SUNLinSol_SPTFQMR(mStatesVector, PREC_NONE, 0, mSunContext); + mSunLinearSolver = SUNLinSol_SPTFQMR(mStatesVector, SUN_PREC_NONE, 0, mSunContext); } ASSERT_NE(mSunLinearSolver, nullptr); @@ -360,6 +365,12 @@ bool SolverCvode::Impl::solve(double &pVoi, double pVoiEnd) // Make sure that everything went fine. if (res < CV_SUCCESS) { +#ifndef CODE_COVERAGE_ENABLED + if (mErrorMessage.back() != '.') { + mErrorMessage += '.'; + } +#endif + addError(mErrorMessage); return false; diff --git a/src/solver/solverkinsol.cpp b/src/solver/solverkinsol.cpp index 1086d962f..4ad0d4c82 100644 --- a/src/solver/solverkinsol.cpp +++ b/src/solver/solverkinsol.cpp @@ -35,10 +35,13 @@ namespace libOpenCOR { namespace { #ifndef CODE_COVERAGE_ENABLED -void errorHandler(int pErrorCode, const char *pModule, const char *pFunction, char *pErrorMessage, void *pUserData) +void errorHandler(int pLine, const char *pFunction, const char *pFile, const char *pErrorMessage, SUNErrCode pErrorCode, + void *pUserData, SUNContext pSunContext) { - (void)pModule; + (void)pLine; (void)pFunction; + (void)pFile; + (void)pSunContext; if (pErrorCode != KIN_WARNING) { *static_cast(pUserData) = pErrorMessage; @@ -139,7 +142,7 @@ bool SolverKinsol::Impl::solve(ComputeSystem pComputeSystem, double *pU, size_t SUNContext context = nullptr; - ASSERT_EQ(SUNContext_Create(nullptr, &context), 0); + ASSERT_EQ(SUNContext_Create(SUN_COMM_NULL, &context), 0); // Create our KINSOL solver. @@ -150,7 +153,7 @@ bool SolverKinsol::Impl::solve(ComputeSystem pComputeSystem, double *pU, size_t // Use our own error handler. #ifndef CODE_COVERAGE_ENABLED - ASSERT_EQ(KINSetErrHandlerFn(solver, errorHandler, &mErrorMessage), KIN_SUCCESS); + ASSERT_EQ(SUNContext_PushErrHandler(context, errorHandler, &mErrorMessage), KIN_SUCCESS); #endif // Initialise our KINSOL solver. @@ -188,11 +191,11 @@ bool SolverKinsol::Impl::solve(ComputeSystem pComputeSystem, double *pU, size_t sunMatrix = nullptr; if (mLinearSolver == LinearSolver::GMRES) { - sunLinearSolver = SUNLinSol_SPGMR(u, PREC_NONE, 0, context); + sunLinearSolver = SUNLinSol_SPGMR(u, SUN_PREC_NONE, 0, context); } else if (mLinearSolver == LinearSolver::BICGSTAB) { - sunLinearSolver = SUNLinSol_SPBCGS(u, PREC_NONE, 0, context); + sunLinearSolver = SUNLinSol_SPBCGS(u, SUN_PREC_NONE, 0, context); } else { - sunLinearSolver = SUNLinSol_SPTFQMR(u, PREC_NONE, 0, context); + sunLinearSolver = SUNLinSol_SPTFQMR(u, SUN_PREC_NONE, 0, context); } } @@ -229,6 +232,8 @@ bool SolverKinsol::Impl::solve(ComputeSystem pComputeSystem, double *pU, size_t KINFree(&solver); + SUNContext_PopErrHandler(context); + SUNContext_Free(&context); // Check whether everything went fine. diff --git a/tests/api/sed/runtests.cpp b/tests/api/sed/runtests.cpp index aa4cc7ae5..d2af9017c 100644 --- a/tests/api/sed/runtests.cpp +++ b/tests/api/sed/runtests.cpp @@ -119,7 +119,17 @@ namespace { void runOdeModel(bool pCompiled) { static const libOpenCOR::ExpectedIssues expectedIssues = { +#if defined(BUILDING_ON_WINDOWS) {libOpenCOR::Issue::Type::ERROR, "At t = 0.00140014, mxstep steps taken before reaching tout."}, +#elif defined(BUILDING_ON_LINUX) + {libOpenCOR::Issue::Type::ERROR, "At t = 1, mxstep steps taken before reaching tout."}, +#else +# ifdef BUILDING_ON_INTEL + {libOpenCOR::Issue::Type::ERROR, "At t = 5.00577e+06, mxstep steps taken before reaching tout."}, +# else + {libOpenCOR::Issue::Type::ERROR, "At t = 0.00140014, mxstep steps taken before reaching tout."}, +# endif +#endif }; auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); diff --git a/tests/api/solver/cvodetests.cpp b/tests/api/solver/cvodetests.cpp index 4f369cadd..b1154f06d 100644 --- a/tests/api/solver/cvodetests.cpp +++ b/tests/api/solver/cvodetests.cpp @@ -233,10 +233,10 @@ TEST(CvodeSolverTest, solveWithAdamsMoultonIntegrationMethod) { static const auto STATE_VALUES = std::vector({-63.89, 0.13501, 0.98434, 0.74097}); static const auto STATE_ABS_TOLS = std::vector({0.01, 0.00001, 0.00001, 0.00001}); - static const auto RATE_VALUES = std::vector({49.726, -0.12820, -0.0509, 0.09866}); - static const auto RATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.0001, 0.00001}); - static const auto VARIABLE_VALUES = std::vector({0.0, -15.982, -823.52, 789.78, 1.0, 0.0, -10.613, 0.3, -115.0, 120.0, 3.97, 0.11498, 0.002869, 0.96735, 12.0, 36.0, 0.5413, 0.056245}); - static const auto VARIABLE_ABS_TOLS = std::vector({0.0, 0.001, 0.01, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.00001, 0.000001, 0.00001, 0.0, 0.0, 0.0001, 0.000001}); + static const auto RATE_VALUES = std::vector({49.726, -0.12820, -0.0509, 0.0987}); + static const auto RATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.0001, 0.0001}); + static const auto VARIABLE_VALUES = std::vector({0.0, -15.982, -823.52, 789.78, 1.0, 0.0, -10.613, 0.3, -115.0, 120.0, 3.97, 0.11498, 0.002869, 0.96735, 12.0, 36.0, 0.5413, 0.05625}); + static const auto VARIABLE_ABS_TOLS = std::vector({0.0, 0.001, 0.01, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.00001, 0.000001, 0.00001, 0.0, 0.0, 0.0001, 0.00001}); auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode/model.cellml")); auto document = libOpenCOR::SedDocument::create(file); @@ -290,8 +290,8 @@ TEST(CvodeSolverTest, solveWithDiagonalLinearSolver) { static const auto STATE_VALUES = std::vector({-63.887, 0.13501, 0.984334, 0.74097}); static const auto STATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.000001, 0.00001}); - static const auto RATE_VALUES = std::vector({49.725, -0.128193, -0.05090, 0.09865}); - static const auto RATE_ABS_TOLS = std::vector({0.001, 0.000001, 0.00001, 0.00001}); + static const auto RATE_VALUES = std::vector({49.725, -0.12819, -0.05090, 0.09865}); + static const auto RATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.00001, 0.00001}); static const auto VARIABLE_VALUES = std::vector({0.0, -15.98, -823.52, 789.78, 1.0, 0.0, -10.613, 0.3, -115.0, 120.0, 3.9699, 0.11498, 0.00287, 0.96735, 12.0, 36.0, 0.54134, 0.056246}); static const auto VARIABLE_ABS_TOLS = std::vector({0.0, 0.01, 0.01, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0001, 0.00001, 0.00001, 0.00001, 0.0, 0.0, 0.00001, 0.000001}); @@ -366,8 +366,8 @@ TEST(CvodeSolverTest, solveWithGmresLinearSolverAndNoPreconditioner) { static const auto STATE_VALUES = std::vector({-63.887, 0.135009, 0.984334, 0.740971}); static const auto STATE_ABS_TOLS = std::vector({0.001, 0.000001, 0.000001, 0.000001}); - static const auto RATE_VALUES = std::vector({49.7259, -0.128194, -0.05090, 0.098651}); - static const auto RATE_ABS_TOLS = std::vector({0.0001, 0.000001, 0.00001, 0.000001}); + static const auto RATE_VALUES = std::vector({49.726, -0.128194, -0.05090, 0.098651}); + static const auto RATE_ABS_TOLS = std::vector({0.001, 0.000001, 0.00001, 0.000001}); static const auto VARIABLE_VALUES = std::vector({0.0, -15.9821, -823.517, 789.779, 1.0, 0.0, -10.613, 0.3, -115.0, 120.0, 3.9699, 0.11498, 0.00287, 0.967348, 12.0, 36.0, 0.54134, 0.056246}); static const auto VARIABLE_ABS_TOLS = std::vector({0.0, 0.0001, 0.001, 0.001, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0001, 0.00001, 0.00001, 0.000001, 0.0, 0.0, 0.00001, 0.000001}); @@ -384,12 +384,12 @@ TEST(CvodeSolverTest, solveWithGmresLinearSolverAndNoPreconditioner) TEST(CvodeSolverTest, solveWithBicgstabLinearSolverAndNoPreconditioner) { - static const auto STATE_VALUES = std::vector({-63.8859, 0.135007, 0.984333, 0.740972}); - static const auto STATE_ABS_TOLS = std::vector({0.0001, 0.000001, 0.000001, 0.000001}); - static const auto RATE_VALUES = std::vector({49.725, -0.128192, -0.050904, 0.098649}); - static const auto RATE_ABS_TOLS = std::vector({0.001, 0.000001, 0.000001, 0.000001}); - static const auto VARIABLE_VALUES = std::vector({0.0, -15.9819, -823.52, 789.779, 1.0, 0.0, -10.613, 0.3, -115.0, 120.0, 3.96987, 0.114988, 0.00287, 0.967346, 12.0, 36.0, 0.541332, 0.056246}); - static const auto VARIABLE_ABS_TOLS = std::vector({0.0, 0.0001, 0.01, 0.001, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.00001, 0.000001, 0.00001, 0.000001, 0.0, 0.0, 0.000001, 0.000001}); + static const auto STATE_VALUES = std::vector({-63.886, 0.13501, 0.984333, 0.740972}); + static const auto STATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.000001, 0.000001}); + static const auto RATE_VALUES = std::vector({49.725, -0.12819, -0.050904, 0.098649}); + static const auto RATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.000001, 0.000001}); + static const auto VARIABLE_VALUES = std::vector({0.0, -15.9819, -823.52, 789.779, 1.0, 0.0, -10.613, 0.3, -115.0, 120.0, 3.9699, 0.11499, 0.00287, 0.96735, 12.0, 36.0, 0.54133, 0.056246}); + static const auto VARIABLE_ABS_TOLS = std::vector({0.0, 0.0001, 0.01, 0.001, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0001, 0.00001, 0.00001, 0.00001, 0.0, 0.0, 0.00001, 0.000001}); auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode/model.cellml")); auto document = libOpenCOR::SedDocument::create(file); @@ -404,12 +404,12 @@ TEST(CvodeSolverTest, solveWithBicgstabLinearSolverAndNoPreconditioner) TEST(CvodeSolverTest, solveWithTfqmrLinearSolverAndNoPreconditioner) { - static const auto STATE_VALUES = std::vector({-63.886, 0.13501, 0.984333, 0.74097}); - static const auto STATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.000001, 0.00001}); + static const auto STATE_VALUES = std::vector({-63.886, 0.13501, 0.98433, 0.74097}); + static const auto STATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.00001, 0.00001}); static const auto RATE_VALUES = std::vector({49.726, -0.12819, -0.05090, 0.09865}); static const auto RATE_ABS_TOLS = std::vector({0.001, 0.00001, 0.00001, 0.00001}); - static const auto VARIABLE_VALUES = std::vector({0.0, -15.982, -823.52, 789.779, 1.0, 0.0, -10.613, 0.3, -115.0, 120.0, 3.9699, 0.11499, 0.00287, 0.96735, 12.0, 36.0, 0.54133, 0.056246}); - static const auto VARIABLE_ABS_TOLS = std::vector({0.0, 0.001, 0.01, 0.001, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0001, 0.00001, 0.00001, 0.00001, 0.0, 0.0, 0.00001, 0.000001}); + static const auto VARIABLE_VALUES = std::vector({0.0, -15.982, -823.52, 789.78, 1.0, 0.0, -10.613, 0.3, -115.0, 120.0, 3.9699, 0.11499, 0.00287, 0.96735, 12.0, 36.0, 0.54133, 0.056246}); + static const auto VARIABLE_ABS_TOLS = std::vector({0.0, 0.001, 0.01, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0001, 0.00001, 0.00001, 0.00001, 0.0, 0.0, 0.00001, 0.000001}); auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("api/solver/ode/model.cellml")); auto document = libOpenCOR::SedDocument::create(file); diff --git a/tests/api/version/tests.cpp b/tests/api/version/tests.cpp index c746dcd47..3d20551bc 100644 --- a/tests/api/version/tests.cpp +++ b/tests/api/version/tests.cpp @@ -62,6 +62,6 @@ TEST(VersionTest, LLVM) TEST(VersionTest, SUNDIALS) { - EXPECT_EQ(0x060200U, libOpenCOR::sundialsVersion()); - EXPECT_EQ("6.2.0", libOpenCOR::sundialsVersionString()); + EXPECT_EQ(0x070000U, libOpenCOR::sundialsVersion()); + EXPECT_EQ("7.0.0", libOpenCOR::sundialsVersionString()); } diff --git a/tests/bindings/javascript/version.test.js b/tests/bindings/javascript/version.test.js index 13ca0115b..a5c31c278 100644 --- a/tests/bindings/javascript/version.test.js +++ b/tests/bindings/javascript/version.test.js @@ -40,7 +40,7 @@ describe("Version tests", () => { }); test("SUNDIALS", () => { - expect(libopencor.sundialsVersion()).toBe(0x060200); - expect(libopencor.sundialsVersionString()).toBe("6.2.0"); + expect(libopencor.sundialsVersion()).toBe(0x070000); + expect(libopencor.sundialsVersionString()).toBe("7.0.0"); }); }); diff --git a/tests/bindings/python/test_sed_run.py b/tests/bindings/python/test_sed_run.py index f7dddaaab..d61d77860 100644 --- a/tests/bindings/python/test_sed_run.py +++ b/tests/bindings/python/test_sed_run.py @@ -14,6 +14,7 @@ from libopencor import File, Issue, SedDocument, SolverKinsol +import platform import utils from utils import assert_issues @@ -134,7 +135,19 @@ def run_ode_model(compiled): expected_issues = [ [ Issue.Type.Error, - "At t = 0.00140014, mxstep steps taken before reaching tout.", + ( + "At t = 0.00140014, mxstep steps taken before reaching tout." + if platform.system() == "Windows" + else ( + "At t = 1, mxstep steps taken before reaching tout." + if platform.system() == "Linux" + else ( + "At t = 5.00577e+06, mxstep steps taken before reaching tout." + if platform.machine() == "x86_64" + else "At t = 0.00140014, mxstep steps taken before reaching tout." + ) + ) + ), ], ] diff --git a/tests/bindings/python/test_solver_cvode.py b/tests/bindings/python/test_solver_cvode.py index e469d7bf5..8620c6630 100644 --- a/tests/bindings/python/test_solver_cvode.py +++ b/tests/bindings/python/test_solver_cvode.py @@ -453,8 +453,8 @@ def test_solve_with_adams_moulton_integration_method(): def test_solve_with_functional_iteration_type(): state_values = [-63.886, 0.13501, 0.984334, 0.740972] state_abs_tols = [0.001, 0.00001, 0.000001, 0.000001] - rate_values = [49.7258, -0.12820, -0.05090, 0.09865] - rate_abs_tols = [0.0001, 0.00001, 0.00001, 0.00001] + rate_values = [49.726, -0.12820, -0.05090, 0.09865] + rate_abs_tols = [0.001, 0.00001, 0.00001, 0.00001] variable_values = [ 0.0, -15.982, @@ -517,8 +517,8 @@ def test_solve_with_functional_iteration_type(): def test_solve_with_banded_linear_solver(): state_values = [-54.958, 0.114716, 0.971365, 0.756967] state_abs_tols = [0.001, 0.000001, 0.000001, 0.000001] - rate_values = [47.196, -0.102081, -0.09298, 0.062977] - rate_abs_tols = [0.001, 0.000001, 0.00001, 0.000001] + rate_values = [47.196, -0.10208, -0.09298, 0.06298] + rate_abs_tols = [0.001, 0.00001, 0.00001, 0.00001] variable_values = [ 0.0, -13.3035, @@ -581,8 +581,8 @@ def test_solve_with_banded_linear_solver(): def test_solve_with_diagonal_linear_solver(): state_values = [-63.886, 0.13501, 0.984334, 0.740971] state_abs_tols = [0.001, 0.00001, 0.000001, 0.000001] - rate_values = [49.725, -0.128193, -0.050902, 0.09865] - rate_abs_tols = [0.001, 0.000001, 0.000001, 0.00001] + rate_values = [49.725, -0.128193, -0.05090, 0.09865] + rate_abs_tols = [0.001, 0.000001, 0.00001, 0.00001] variable_values = [ 0.0, -15.982, @@ -900,13 +900,13 @@ def test_solve_with_gmres_linear_solver_and_no_preconditioner(): def test_solve_with_bicgstab_linear_solver_and_no_preconditioner(): - state_values = [-63.8859, 0.135007, 0.984333, 0.740972] - state_abs_tols = [0.0001, 0.000001, 0.000001, 0.000001] - rate_values = [49.7254, -0.128192, -0.050904, 0.098649] - rate_abs_tols = [0.0001, 0.000001, 0.000001, 0.000001] + state_values = [-63.886, 0.13501, 0.984333, 0.740972] + state_abs_tols = [0.001, 0.00001, 0.000001, 0.000001] + rate_values = [49.725, -0.12819, -0.050904, 0.098649] + rate_abs_tols = [0.001, 0.00001, 0.000001, 0.000001] variable_values = [ 0.0, - -15.98187, + -15.9819, -823.516, 789.779, 1.0, @@ -915,18 +915,18 @@ def test_solve_with_bicgstab_linear_solver_and_no_preconditioner(): 0.3, -115.0, 120.0, - 3.96987, - 0.114988, + 3.9699, + 0.11499, 0.002869, - 0.967346, + 0.96735, 12.0, 36.0, - 0.541332, + 0.54133, 0.056246, ] variable_abs_tols = [ 0.0, - 0.00001, + 0.0001, 0.001, 0.001, 0.0, @@ -935,13 +935,13 @@ def test_solve_with_bicgstab_linear_solver_and_no_preconditioner(): 0.0, 0.0, 0.0, + 0.0001, 0.00001, 0.000001, - 0.000001, - 0.000001, + 0.00001, 0.0, 0.0, - 0.000001, + 0.00001, 0.000001, ] diff --git a/tests/bindings/python/test_version.py b/tests/bindings/python/test_version.py index b86393a0a..c21186d41 100644 --- a/tests/bindings/python/test_version.py +++ b/tests/bindings/python/test_version.py @@ -88,9 +88,9 @@ def test_llvm_version_string(): def test_sundials_version(): assert isinstance(oc.sundials_version(), int) - assert oc.sundials_version() == 0x060200 + assert oc.sundials_version() == 0x070000 def test_sundials_version_string(): assert isinstance(oc.sundials_version_string(), str) - assert oc.sundials_version_string() == "6.2.0" + assert oc.sundials_version_string() == "7.0.0"