summary refs log tree commit diff
path: root/pkgs/development/libraries/science/math/or-tools/default.nix
blob: 15aea5803bf187d95642636bd522854a0cffb26d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{ stdenv, fetchFromGitHub, cmake, abseil-cpp, gflags, which
, lsb-release, glog, protobuf, cbc, zlib
, ensureNewerSourcesForZipFilesHook, python, swig
, pythonProtobuf }:

stdenv.mkDerivation rec {
  pname = "or-tools";
  version = "7.3";

  src = fetchFromGitHub {
    owner = "google";
    repo = "or-tools";
    rev = "v${version}";
    sha256 = "0q06vxmds6nm3dpjw4y5jzr8j98qgfb9i8pbm9pfhmqigv791hwc";
  };

  patches = [
    ./build.patch # https://github.com/google/or-tools/pull/1619
    ./protobuf.patch # Otherwise it tries to install protobuf from pypi.
  ];

  # The original build system uses cmake which does things like pull
  # in dependencies through git and Makefile creation time. We
  # obviously don't want to do this so instead we provide the
  # dependencies straight from nixpkgs and use the make build method.
  configurePhase = ''
    cat <<EOF > Makefile.local
    UNIX_ABSL_DIR=${abseil-cpp}
    UNIX_GFLAGS_DIR=${gflags}
    UNIX_GLOG_DIR=${glog}
    UNIX_PROTOBUF_DIR=${protobuf}
    UNIX_CBC_DIR=${cbc}
    EOF
  '';

  makeFlags = [
    "prefix=${placeholder "out"}"
    "PROTOBUF_PYTHON_DESC=${pythonProtobuf}/${python.sitePackages}/google/protobuf/descriptor_pb2.py"
  ];
  buildFlags = [ "cc" "pypi_archive" ];

  checkTarget = "test_cc";
  doCheck = true;

  installTargets = [ "install_cc" ];
  # The upstream install_python target installs to $HOME.
  postInstall = ''
    mkdir -p "$python/${python.sitePackages}"
    (cd temp_python/ortools; PYTHONPATH="$python/${python.sitePackages}:$PYTHONPATH" python setup.py install '--prefix=$python')
  '';

  nativeBuildInputs = [
    cmake lsb-release swig which zlib python
    ensureNewerSourcesForZipFilesHook
    python.pkgs.setuptools python.pkgs.wheel
  ];
  propagatedBuildInputs = [
    abseil-cpp gflags glog protobuf cbc
    pythonProtobuf python.pkgs.six
  ];

  enableParallelBuilding = true;

  outputs = [ "out" "python" ];

  meta = with stdenv.lib; {
    homepage = https://github.com/google/or-tools;
    license = licenses.asl20;
    description = ''
      Google's software suite for combinatorial optimization.
    '';
    maintainers = with maintainers; [ ];
    platforms = with platforms; linux;
  };
}