Merge sublime4: 4189 -> 4192; sublime4-dev: 4188 -> 4191 (#378651)
[NixPkgs.git] / pkgs / development / libraries / science / math / or-tools / default.nix
blobc460694da0fed13b5b4ebfc35fd9a897968964d2
2   abseil-cpp,
3   bzip2,
4   cbc,
5   cmake,
6   DarwinTools, # sw_vers
7   eigen,
8   ensureNewerSourcesForZipFilesHook,
9   fetchFromGitHub,
10   substituteAll,
11   glpk,
12   lib,
13   pkg-config,
14   protobuf,
15   python,
16   re2,
17   stdenv,
18   swig,
19   unzip,
20   zlib,
23 let
24   pybind11_protobuf = fetchFromGitHub {
25     owner = "pybind";
26     repo = "pybind11_protobuf";
27     rev = "b713501f1da56d9b76c42f89efd00b97c26c9eac";
28     hash = "sha256-f6pzRWextH+7lm1xzyhx98wCIWH3lbhn59gSCcjsBVw=";
29   };
31 stdenv.mkDerivation rec {
32   pname = "or-tools";
33   version = "9.7";
35   src = fetchFromGitHub {
36     owner = "google";
37     repo = "or-tools";
38     rev = "v${version}";
39     hash = "sha256-eHukf6TbY2dx7iEf8WfwfWsjDEubPtRO02ju0kHtASo=";
40   };
42   patches = [
43     (substituteAll {
44       src = ./offline.patch;
45       pybind11_protobuf = "../../pybind11_protobuf";
46     })
47   ];
49   # or-tools normally attempts to build Protobuf for the build platform when
50   # cross-compiling. Instead, just tell it where to find protoc.
51   postPatch = ''
52     echo "set(PROTOC_PRG $(type -p protoc))" > cmake/host.cmake
54     cp -R ${pybind11_protobuf} pybind11_protobuf
55     chmod -R u+w pybind11_protobuf
56   '';
58   cmakeFlags = [
59     "-DBUILD_DEPS=OFF"
60     "-DBUILD_PYTHON=ON"
61     "-DBUILD_pybind11=OFF"
62     "-DBUILD_pybind11_protobuf=ON"
63     "-DCMAKE_INSTALL_BINDIR=bin"
64     "-DCMAKE_INSTALL_INCLUDEDIR=include"
65     "-DCMAKE_INSTALL_LIBDIR=lib"
66     "-DFETCH_PYTHON_DEPS=OFF"
67     "-DUSE_GLPK=ON"
68     "-DUSE_SCIP=OFF"
69     "-DPython3_EXECUTABLE=${python.pythonOnBuildForHost.interpreter}"
70   ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ "-DCMAKE_MACOSX_RPATH=OFF" ];
72   strictDeps = true;
74   nativeBuildInputs =
75     [
76       cmake
77       ensureNewerSourcesForZipFilesHook
78       pkg-config
79       python.pythonOnBuildForHost
80       swig
81       unzip
82     ]
83     ++ lib.optionals stdenv.hostPlatform.isDarwin [
84       DarwinTools
85     ]
86     ++ (with python.pythonOnBuildForHost.pkgs; [
87       pip
88       mypy-protobuf
89       mypy
90     ]);
91   buildInputs = [
92     abseil-cpp
93     bzip2
94     cbc
95     eigen
96     glpk
97     python.pkgs.absl-py
98     python.pkgs.pybind11
99     python.pkgs.pytest
100     python.pkgs.scipy
101     python.pkgs.setuptools
102     python.pkgs.wheel
103     re2
104     zlib
105   ];
106   propagatedBuildInputs = [
107     abseil-cpp
108     protobuf
109     (python.pkgs.protobuf4.override { protobuf = protobuf; })
110     python.pkgs.numpy
111   ];
112   nativeCheckInputs = [
113     python.pkgs.matplotlib
114     python.pkgs.pandas
115     python.pkgs.virtualenv
116   ];
118   env.NIX_CFLAGS_COMPILE = toString [
119     # fatal error: 'python/google/protobuf/proto_api.h' file not found
120     "-I${protobuf.src}"
121     # fatal error: 'pybind11_protobuf/native_proto_caster.h' file not found
122     "-I${pybind11_protobuf}"
123   ];
125   # some tests fail on linux and hang on darwin
126   doCheck = false;
128   preCheck = ''
129     export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib
130   '';
132   # This extra configure step prevents the installer from littering
133   # $out/bin with sample programs that only really function as tests,
134   # and disables the upstream installation of a zipped Python egg that
135   # can’t be imported with our Python setup.
136   installPhase = ''
137     cmake . -DBUILD_EXAMPLES=OFF -DBUILD_PYTHON=OFF -DBUILD_SAMPLES=OFF
138     cmake --install .
139     pip install --prefix="$python" python/
140   '';
142   outputs = [
143     "out"
144     "python"
145   ];
147   meta = with lib; {
148     homepage = "https://github.com/google/or-tools";
149     license = licenses.asl20;
150     description = ''
151       Google's software suite for combinatorial optimization.
152     '';
153     mainProgram = "fzn-ortools";
154     maintainers = with maintainers; [ andersk ];
155     platforms = with platforms; linux ++ darwin;
156   };