Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 abseil-cpp_202407,
3 bzip2,
4 cbc,
5 cmake,
6 eigen,
7 ensureNewerSourcesForZipFilesHook,
8 fetchFromGitHub,
9 fetchpatch,
10 glpk,
11 highs,
12 lib,
13 pkg-config,
14 protobuf_29,
15 python3,
16 re2,
17 stdenv,
18 swig,
19 unzip,
20 zlib,
21}:
22
23let
24 # OR-Tools strictly requires specific versions of abseil-cpp and
25 # protobuf. Do not un-pin these, even if you're upgrading them to
26 # what might happen to be the latest version at the current moment;
27 # future upgrades *will* break the build.
28 abseil-cpp = abseil-cpp_202407;
29 protobuf = protobuf_29.override { inherit abseil-cpp; };
30 python-protobuf = python3.pkgs.protobuf5.override { inherit protobuf; };
31 pybind11-protobuf = python3.pkgs.pybind11-protobuf.override { protobuf_29 = protobuf; };
32
33in
34stdenv.mkDerivation (finalAttrs: {
35 pname = "or-tools";
36 version = "9.12";
37
38 src = fetchFromGitHub {
39 owner = "google";
40 repo = "or-tools";
41 tag = "v${finalAttrs.version}";
42 hash = "sha256-5rFeAK51+BfjIyu/5f5ptaKMD7Hd20yHa2Vj3O3PkLU=";
43 };
44
45 patches = [
46 # Rebased from https://build.opensuse.org/public/source/science/google-or-tools/0001-Do-not-try-to-copy-pybind11_abseil-status-extension-.patch?rev=19
47 ./0001-Do-not-try-to-copy-pybind11_abseil-status-extension-.patch
48 (fetchpatch {
49 name = "0001-Revert-python-Fix-python-install-on-windows-breaks-L.patch";
50 url = "https://build.opensuse.org/public/source/science/google-or-tools/0001-Revert-python-Fix-python-install-on-windows-breaks-L.patch?rev=19";
51 hash = "sha256-BNB3KlgjpWcZtb9e68Jkc/4xC4K0c+Iisw0eS6ltYXE=";
52 })
53 (fetchpatch {
54 name = "0001-Fix-up-broken-CMake-rules-for-bundled-pybind-stuff.patch";
55 url = "https://build.opensuse.org/public/source/science/google-or-tools/0001-Fix-up-broken-CMake-rules-for-bundled-pybind-stuff.patch?rev=19";
56 hash = "sha256-r38ZbRkEW1ZvJb0Uf56c0+HcnfouZZJeEYlIK7quSjQ=";
57 })
58 ];
59
60 # or-tools normally attempts to build Protobuf for the build platform when
61 # cross-compiling. Instead, just tell it where to find protoc.
62 postPatch = ''
63 echo "set(PROTOC_PRG $(type -p protoc))" > cmake/host.cmake
64 ''
65 # Patches from OpenSUSE:
66 # https://build.opensuse.org/projects/science/packages/google-or-tools/files/google-or-tools.spec?expand=1
67 + ''
68 sed -i -e '/CMAKE_DEPENDENT_OPTION(INSTALL_DOC/ s/BUILD_CXX AND BUILD_DOC/BUILD_CXX/' CMakeLists.txt
69 find . -iname \*CMakeLists.txt -exec sed -i -e 's/pybind11_native_proto_caster/pybind11_protobuf::pybind11_native_proto_caster/' '{}' \;
70 sed -i -e 's/TARGET pybind11_native_proto_caster/TARGET pybind11_protobuf::pybind11_native_proto_caster/' cmake/check_deps.cmake
71 sed -i -e "/protobuf/ { s/.*,/'protobuf >= 5.26',/ }" ortools/python/setup.py.in
72 '';
73
74 cmakeFlags = [
75 (lib.cmakeBool "BUILD_DEPS" false)
76 (lib.cmakeBool "BUILD_PYTHON" true)
77 (lib.cmakeBool "BUILD_pybind11" false)
78 (lib.cmakeFeature "CMAKE_INSTALL_BINDIR" "bin")
79 (lib.cmakeFeature "CMAKE_INSTALL_INCLUDEDIR" "include")
80 (lib.cmakeFeature "CMAKE_INSTALL_LIBDIR" "lib")
81 (lib.cmakeBool "FETCH_PYTHON_DEPS" false)
82 (lib.cmakeBool "USE_GLPK" true)
83 (lib.cmakeBool "USE_SCIP" false)
84 (lib.cmakeFeature "Python3_EXECUTABLE" "${python3.pythonOnBuildForHost.interpreter}")
85 ]
86 ++ lib.optionals stdenv.hostPlatform.isDarwin [
87 (lib.cmakeBool "CMAKE_MACOSX_RPATH" false)
88 ];
89
90 strictDeps = true;
91
92 nativeBuildInputs = [
93 cmake
94 ensureNewerSourcesForZipFilesHook
95 pkg-config
96 python3.pythonOnBuildForHost
97 swig
98 unzip
99 ]
100 ++ (with python3.pythonOnBuildForHost.pkgs; [
101 pip
102 mypy-protobuf
103 mypy
104 ]);
105 buildInputs = [
106 abseil-cpp
107 bzip2
108 cbc
109 eigen
110 glpk
111 highs
112 python3.pkgs.absl-py
113 python3.pkgs.pybind11
114 python3.pkgs.pybind11-abseil
115 pybind11-protobuf
116 python3.pkgs.pytest
117 python3.pkgs.scipy
118 python3.pkgs.setuptools
119 python3.pkgs.wheel
120 re2
121 zlib
122 ];
123 propagatedBuildInputs = [
124 abseil-cpp
125 highs
126 protobuf
127 python-protobuf
128 python3.pkgs.immutabledict
129 python3.pkgs.numpy
130 python3.pkgs.pandas
131 ];
132 nativeCheckInputs = [
133 python3.pkgs.matplotlib
134 python3.pkgs.virtualenv
135 ];
136
137 # some tests fail on linux and hang on darwin
138 doCheck = false;
139
140 preCheck = ''
141 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib
142 '';
143
144 # This extra configure step prevents the installer from littering
145 # $out/bin with sample programs that only really function as tests,
146 # and disables the upstream installation of a zipped Python egg that
147 # can’t be imported with our Python setup.
148 installPhase = ''
149 cmake . -DBUILD_EXAMPLES=OFF -DBUILD_PYTHON=OFF -DBUILD_SAMPLES=OFF
150 cmake --install .
151 pip install --prefix="$python" python/
152 '';
153
154 outputs = [
155 "out"
156 "python"
157 ];
158
159 meta = {
160 homepage = "https://github.com/google/or-tools";
161 license = lib.licenses.asl20;
162 description = ''
163 Google's software suite for combinatorial optimization.
164 '';
165 mainProgram = "fzn-cp-sat";
166 maintainers = with lib.maintainers; [ andersk ];
167 platforms = with lib.platforms; linux ++ darwin;
168 };
169})