Commit 08ce3cc3 authored by Florian Klink's avatar Florian Klink
Browse files

or-tools: 9.12 -> 9.14

Some of the patches we ship(ed) had to be regenerated.

or-tools now uses abseil-cpp_202505, and we need to ensure everything
uses that, to avoid another version of abseil leaking into the build.

pybind11 needs to be downgraded to 2.13.6 (I vendored the old nixpkgs
expression for that).
pybind11 also needs to be patched to fix math_opt's elemental python
binding.
or-tools ships this in their repo as a patch to their pybind11_bazel
dep, including a patch file there. I decided to pop one layer of
patching, and vendor the patch in here.

Upstream also patches their scipopts-scip dependency, renaming some
CMake targets, so we need to patch our dependency as well (and restore
find_package() discovery that broke).
parent 003d9f75
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
From 077295f6ede59d9e2413b2d19f38cf63b64f4fec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Br=C3=BCns?= <stefan.bruens@rwth-aachen.de>
Date: Tue, 21 Oct 2025 17:05:59 +0300
Subject: [PATCH] Do not try to copy pybind11_abseil status extension module

The module is already installed in the correct location. And even if not,
it should be done as part of the pybind11_abseil build ...
---
 cmake/python.cmake         | 5 -----
 ortools/python/setup.py.in | 4 ----
 2 files changed, 9 deletions(-)

diff --git a/cmake/python.cmake b/cmake/python.cmake
index 2112ceeb66..db15434303 100644
--- a/cmake/python.cmake
+++ b/cmake/python.cmake
@@ -322,7 +322,6 @@
@@ -326,7 +326,6 @@ file(GENERATE OUTPUT ${PYTHON_PROJECT_DIR}/init/python/__init__.py CONTENT "")
 file(GENERATE OUTPUT ${PYTHON_PROJECT_DIR}/linear_solver/__init__.py CONTENT "")
 file(GENERATE OUTPUT ${PYTHON_PROJECT_DIR}/linear_solver/python/__init__.py CONTENT "")
 if(BUILD_MATH_OPT)
@@ -8,17 +22,17 @@
   file(GENERATE OUTPUT ${PYTHON_PROJECT_DIR}/math_opt/__init__.py CONTENT "")
   file(GENERATE OUTPUT ${PYTHON_PROJECT_DIR}/math_opt/core/__init__.py CONTENT "")
   file(GENERATE OUTPUT ${PYTHON_PROJECT_DIR}/math_opt/core/python/__init__.py CONTENT "")
@@ -635,9 +634,6 @@
@@ -680,9 +679,6 @@ add_custom_command(
   COMMAND ${CMAKE_COMMAND} -E
    $<IF:$<BOOL:${BUILD_MATH_OPT}>,copy,true>
    $<TARGET_FILE:math_opt_pybind11> ${PYTHON_PROJECT}/math_opt/core/python
    $<TARGET_FILE:math_opt_io_pybind11> ${PYTHON_PROJECT}/math_opt/io/python
-  COMMAND ${CMAKE_COMMAND} -E
-   $<IF:$<BOOL:${BUILD_MATH_OPT}>,copy,true>
-   $<TARGET_FILE:status_py_extension_stub> ${PYTHON_PROJECT}/../pybind11_abseil
   COMMAND ${CMAKE_COMMAND} -E
    $<IF:$<TARGET_EXISTS:pdlp_pybind11>,copy,true>
    $<$<TARGET_EXISTS:pdlp_pybind11>:$<TARGET_FILE:pdlp_pybind11>> ${PYTHON_PROJECT}/pdlp/python
@@ -696,7 +692,6 @@
@@ -744,7 +740,6 @@ add_custom_command(
   COMMAND ${stubgen_EXECUTABLE} -p ortools.constraint_solver.pywrapcp --output .
   COMMAND ${stubgen_EXECUTABLE} -p ortools.linear_solver.pywraplp --output .
   COMMAND ${stubgen_EXECUTABLE} -p ortools.linear_solver.python.model_builder_helper --output .
@@ -26,9 +40,11 @@
   COMMAND ${stubgen_EXECUTABLE} -p ortools.math_opt.core.python.solver --output .
   COMMAND ${stubgen_EXECUTABLE} -p ortools.pdlp.python.pdlp --output .
   COMMAND ${stubgen_EXECUTABLE} -p ortools.sat.python.cp_model_helper --output .
diff --git a/ortools/python/setup.py.in b/ortools/python/setup.py.in
index 0aeaa900ef..ae4fa07815 100644
--- a/ortools/python/setup.py.in
+++ b/ortools/python/setup.py.in
@@ -83,10 +83,6 @@
@@ -83,10 +83,6 @@ setup(
             '*.pyi',
             'py.typed'
         ],
@@ -37,5 +53,8 @@
-            '*.pyi'
-        ],
         '@PYTHON_PROJECT@.math_opt':['*.pyi'],
         '@PYTHON_PROJECT@.math_opt.python':['*.pyi'],
         '@PYTHON_PROJECT@.math_opt.core.python':[
             '$<TARGET_FILE_NAME:math_opt_pybind11>',
-- 
2.51.0
+26 −0
Original line number Diff line number Diff line
From 46e7d2cccd029a2c4215ce9b0c3bf72b2f2dd398 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Br=C3=BCns?= <stefan.bruens@rwth-aachen.de>
Date: Thu, 2 Jan 2025 16:32:05 +0100
Subject: [PATCH] Fix up broken CMake rules for bundled pybind stuff

Unfortunately, upstream only uses and tests the bundled code, and the
unbundled cases are bitrotting.
---
 cmake/system_deps.cmake    | 1 +
 1 files changed, 1 insertion(+)

diff --git a/cmake/system_deps.cmake b/cmake/system_deps.cmake
index d9ae923..0c176a8 100644
--- a/cmake/system_deps.cmake
+++ b/cmake/system_deps.cmake
@@ -94,6 +94,7 @@ endif()
 
 # Check language Dependencies
 if(BUILD_PYTHON)
+  find_package(Python REQUIRED Interpreter Development.Module)
   if(NOT BUILD_pybind11 AND NOT TARGET pybind11::pybind11_headers)
     find_package(pybind11 REQUIRED)
   endif()
-- 
2.47.1
+48 −16
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
  lib,
  callPackage,

  abseil-cpp_202407,
  abseil-cpp_202505,
  bzip2,
  cbc,
  cmake,
@@ -16,7 +16,7 @@
  glpk,
  highs,
  pkg-config,
  protobuf_29,
  protobuf_31,
  python3,
  re2,
  swig,
@@ -32,12 +32,45 @@ let
  # protobuf. Do not un-pin these, even if you're upgrading them to
  # what might happen to be the latest version at the current moment;
  # future upgrades *will* break the build.
  abseil-cpp = abseil-cpp_202407;
  protobuf = protobuf_29.override { inherit abseil-cpp; };
  abseil-cpp = abseil-cpp_202505;
  protobuf = protobuf_31.override { inherit abseil-cpp; };
  python-protobuf = python3.pkgs.protobuf5.override { inherit protobuf; };

  pybind11 = callPackage ./pybind11-2.13.6.nix {
    inherit (python3.pkgs)
      buildPythonPackage
      cmake
      ninja
      numpy
      pytestCheckHook
      pythonOlder
      setuptools
      ;
    python = python3;
  };
  pybind11-abseil = python3.pkgs.pybind11-abseil.override {
    inherit abseil-cpp pybind11;
  };
  pybind11-protobuf = callPackage ./pybind11-protobuf.nix {
    inherit (python3.pkgs) buildPythonPackage pybind11;
    inherit (python3.pkgs) buildPythonPackage;
    inherit pybind11;
  };
  # re2 must also use the same abseil version, else these two versions will conflict during linking
  _re2 = re2.override { inherit abseil-cpp; };

  # 77a28070b9c4c83995ac6bbfa9544722ff3342ce renamed the scip cmake target(s) differently
  # to what upstream still calls it. Apply this patch to scipopt-scip.
  _scipopt-scip = scipopt-scip.overrideAttrs (old: {
    patches = old.patches or [ ] ++ [
      # from https://github.com/google/or-tools/commit/77a28070b9c4c83995ac6bbfa9544722ff3342ce#diff-c95174a817e73db366d414af1e329c1856f70e5158ed3994d43da88765ccc98f
      ./scip.patch
    ];
    # Their patch forgets to find_package() soplex, bring it back.
    postPatch = (old.postPatch or "") + ''
      substituteInPlace CMakeLists.txt \
        --replace-fail 'message(STATUS "Finding Soplex...")' 'find_package(SOPLEX CONFIG HINTS ''${SOPLEX_DIR})'
    '';
  });

  # local revert of 58daf511687f191829238fc7f571e08dc9dedf56,
  # working around https://github.com/google/or-tools/issues/4911
@@ -61,13 +94,13 @@ let
in
stdenv.mkDerivation (finalAttrs: {
  pname = "or-tools";
  version = "9.12";
  version = "9.14";

  src = fetchFromGitHub {
    owner = "google";
    repo = "or-tools";
    tag = "v${finalAttrs.version}";
    hash = "sha256-5rFeAK51+BfjIyu/5f5ptaKMD7Hd20yHa2Vj3O3PkLU=";
    hash = "sha256-FxKe3uY4L33mavwC2aanji3fY9dPqpkwVqi6PNjovSA=";
  };

  patches = [
@@ -78,11 +111,7 @@ stdenv.mkDerivation (finalAttrs: {
      url = "https://build.opensuse.org/public/source/science/google-or-tools/0001-Revert-python-Fix-python-install-on-windows-breaks-L.patch?rev=19";
      hash = "sha256-BNB3KlgjpWcZtb9e68Jkc/4xC4K0c+Iisw0eS6ltYXE=";
    })
    (fetchpatch {
      name = "0001-Fix-up-broken-CMake-rules-for-bundled-pybind-stuff.patch";
      url = "https://build.opensuse.org/public/source/science/google-or-tools/0001-Fix-up-broken-CMake-rules-for-bundled-pybind-stuff.patch?rev=19";
      hash = "sha256-r38ZbRkEW1ZvJb0Uf56c0+HcnfouZZJeEYlIK7quSjQ=";
    })
    ./0001-Fix-up-broken-CMake-rules-for-bundled-pybind-stuff.patch
    (fetchpatch {
      name = "math_opt-only-run-SCIP-tests-if-enabled.patch";
      url = "https://github.com/google/or-tools/commit/b5a2f8ac40dd4bfa4359c35570733171454ec72b.patch";
@@ -112,6 +141,8 @@ stdenv.mkDerivation (finalAttrs: {
    (lib.cmakeFeature "CMAKE_INSTALL_INCLUDEDIR" "include")
    (lib.cmakeFeature "CMAKE_INSTALL_LIBDIR" "lib")
    (lib.cmakeBool "FETCH_PYTHON_DEPS" false)
    # not packaged in nixpkgs
    (lib.cmakeBool "USE_fuzztest" false)
    (lib.cmakeBool "USE_GLPK" true)
    (lib.cmakeBool "USE_SCIP" withScip)
    (lib.cmakeFeature "Python3_EXECUTABLE" "${python3.pythonOnBuildForHost.interpreter}")
@@ -149,14 +180,14 @@ stdenv.mkDerivation (finalAttrs: {
    gtest
    _highs
    python3.pkgs.absl-py
    python3.pkgs.pybind11
    python3.pkgs.pybind11-abseil
    pybind11
    pybind11-abseil
    pybind11-protobuf
    python3.pkgs.pytest
    python3.pkgs.scipy
    python3.pkgs.setuptools
    python3.pkgs.wheel
    re2
    _re2
    zlib
  ];
  propagatedBuildInputs = [
@@ -170,7 +201,7 @@ stdenv.mkDerivation (finalAttrs: {
  ]
  ++ lib.optionals withScip [
    # Needed for downstream cmake consumers to not need to set SCIP_ROOT explicitly
    scipopt-scip
    _scipopt-scip
  ];

  nativeCheckInputs = [
@@ -183,6 +214,7 @@ stdenv.mkDerivation (finalAttrs: {
  ];

  # some tests fail on aarch64-linux and hang on darwin
  # https://github.com/google/or-tools/issues/4746
  doCheck = stdenv.hostPlatform.isx86_64 && stdenv.hostPlatform.isLinux;

  preCheck = ''
+131 −0
Original line number Diff line number Diff line
# This is pybind11 2.13.6 from an earlier nixpkgs version, with the
# parts from https://github.com/google/or-tools/commit/7f29b27840436e19b6530d5c7f23eeadd819bd3e
# applied.
{
  stdenv,
  lib,
  buildPythonPackage,
  pythonOlder,
  fetchFromGitHub,
  cmake,
  ninja,
  setuptools,
  boost,
  eigen,
  python,
  catch2,
  numpy,
  pytestCheckHook,
  libxcrypt,
  makeSetupHook,
}:
let
  setupHook = makeSetupHook {
    name = "pybind11-setup-hook";
    substitutions = {
      out = placeholder "out";
      pythonInterpreter = python.pythonOnBuildForHost.interpreter;
      pythonIncludeDir = "${python}/include/python${python.pythonVersion}";
      pythonSitePackages = "${python}/${python.sitePackages}";
    };
  } ./pybind11-setup-hook.sh;
in
buildPythonPackage rec {
  pname = "pybind11";
  version = "2.13.6";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "pybind";
    repo = "pybind11";
    tag = "v${version}";
    hash = "sha256-SNLdtrOjaC3lGHN9MAqTf51U9EzNKQLyTMNPe0GcdrU=";
  };

  # https://github.com/google/or-tools/commit/7f29b27840436e19b6530d5c7f23eeadd819bd3e
  patches = [ ./pybind11.patch ];

  build-system = [
    cmake
    ninja
    setuptools
  ];

  buildInputs = lib.optionals (pythonOlder "3.9") [ libxcrypt ];
  propagatedNativeBuildInputs = [ setupHook ];

  dontUseCmakeBuildDir = true;

  # Don't build tests if not needed, read the doInstallCheck value at runtime
  preConfigure = ''
    if [ -n "$doInstallCheck" ]; then
      cmakeFlagsArray+=("-DBUILD_TESTING=ON")
    fi
  '';

  cmakeFlags = [
    "-DBoost_INCLUDE_DIR=${lib.getDev boost}/include"
    "-DCATCH_INCLUDE_DIR=${lib.getDev catch2}/include/catch2"
    "-DEIGEN3_INCLUDE_DIR=${lib.getDev eigen}/include/eigen3"
  ]
  ++ lib.optionals (python.isPy3k && !stdenv.cc.isClang) [ "-DPYBIND11_CXX_STANDARD=-std=c++17" ];

  postBuild = ''
    # build tests
    make -j $NIX_BUILD_CORES
  '';

  postInstall = ''
    make install
    # Symlink the CMake-installed headers to the location expected by setuptools
    mkdir -p $out/include/${python.libPrefix}
    ln -sf $out/include/pybind11 $out/include/${python.libPrefix}/pybind11
  '';

  nativeCheckInputs = [
    catch2
    numpy
    pytestCheckHook
  ];

  disabledTestPaths = [
    # require dependencies not available in nixpkgs
    "tests/test_embed/test_trampoline.py"
    "tests/test_embed/test_interpreter.py"
    # numpy changed __repr__ output of numpy dtypes
    "tests/test_numpy_dtypes.py"
    # no need to test internal packaging
    "tests/extra_python_package/test_files.py"
    # tests that try to parse setuptools stdout
    "tests/extra_setuptools/test_setuphelper.py"
  ];

  disabledTests = lib.optionals stdenv.hostPlatform.isDarwin [
    # expects KeyError, gets RuntimeError
    # https://github.com/pybind/pybind11/issues/4243
    "test_cross_module_exception_translator"
  ];

  postCheck = ''
    make cpptest
  '';

  hardeningDisable = lib.optional stdenv.hostPlatform.isMusl "fortify";

  meta = {
    homepage = "https://github.com/pybind/pybind11";
    changelog = "https://github.com/pybind/pybind11/blob/${src.rev}/docs/changelog.rst";
    description = "Seamless operability between C++11 and Python";
    mainProgram = "pybind11-config";
    longDescription = ''
      Pybind11 is a lightweight header-only library that exposes
      C++ types in Python and vice versa, mainly to create Python
      bindings of existing C++ code.
    '';
    license = lib.licenses.bsd3;
    maintainers = with lib.maintainers; [
      yuriaisaka
      dotlambda
    ];
  };
}
+12 −7
Original line number Diff line number Diff line
@@ -4,22 +4,22 @@
  buildPythonPackage,
  fetchFromGitHub,
  cmake,
  abseil-cpp_202407,
  protobuf_29,
  abseil-cpp_202505,
  protobuf,
  pybind11,
  zlib,
}:

buildPythonPackage {
  pname = "pybind11-protobuf";
  version = "0-unstable-2025-02-10";
  version = "0-unstable-2025-10-29";
  pyproject = false;

  src = fetchFromGitHub {
    owner = "pybind";
    repo = "pybind11_protobuf";
    rev = "f02a2b7653bc50eb5119d125842a3870db95d251";
    hash = "sha256-jlZcxQKYYYvTOGhk+0Sgtek4oKy6R1wDGiBOf2t+KiU=";
    rev = "4825dca68c8de73f5655fc50ce79c49c4d814652";
    hash = "sha256-SeIUyWLeThfBX3SljLdG7CbENdbuJG+X0+h/gn/ATWE=";
  };

  patches = [
@@ -28,11 +28,16 @@ buildPythonPackage {
    ./add-install-target-for-cmake-builds.patch
  ];

  postPatch = ''
    substituteInPlace cmake/dependencies/CMakeLists.txt \
      --replace-fail 'find_package(protobuf 5.29.2 REQUIRED)' 'find_package(protobuf REQUIRED)'
  '';

  nativeBuildInputs = [ cmake ];

  buildInputs = [
    abseil-cpp_202407
    protobuf_29
    abseil-cpp_202505
    protobuf
    pybind11
    zlib
  ];
Loading