@@ -1,40 +1,84 @@
1−{ lib, stdenv, fetchFromGitHub, cmake, abseil-cpp, gflags, which
2−, lsb-release, glog, protobuf, cbc, zlib
3−, ensureNewerSourcesForZipFilesHook, python, swig }:
1+{ lib
2+, stdenv
3+, fetchFromGitHub
4+, fetchpatch
5+, cmake
6+, abseil-cpp
7+, bzip2
8+, zlib
9+, lsb-release
10+, which
11+, protobuf
12+, cbc
13+, ensureNewerSourcesForZipFilesHook
14+, python
15+, swig4
16+}:
417
518stdenv.mkDerivation rec {
619 pname = "or-tools";
7− version = "7.7";
20+ version = "8.1";
21+ disabled = python.pythonOlder "3.6"; # not supported upstream
822
923 src = fetchFromGitHub {
1024 owner = "google";
1125 repo = "or-tools";
1226 rev = "v${version}";
13− sha256 = "06ig9a1afmzgzcg817y0rdq49ahll0q9y7bhhg9d89x6zy959ypv";
27+ sha256 = "1zqgvkaw5vf2d8pwsa34g9jysbpiwplzxc8jyy8kdbzmj8ax3gpg";
1428 };
1529
30+ patches = [
31+ # This patch (on master as of Feb 11, 2021) fixes or-tools failing to respect
32+ # USE_SCIP=OFF and then failing to find scip/scip.h
33+ (fetchpatch {
34+ url = "https://github.com/google/or-tools/commit/17321869832b5adaccd9864e7e5576122730a5d5.patch";
35+ sha256 = "0bi2z1hqlpdm1if3xa5dzc2zv0qlm5xi2x979brx10f8k779ghn0";
36+ })
37+ ];
38+
1639 # The original build system uses cmake which does things like pull
1740 # in dependencies through git and Makefile creation time. We
1841 # obviously don't want to do this so instead we provide the
1942 # dependencies straight from nixpkgs and use the make build method.
43+
44+ # Cbc is linked against bzip2 and declares this in its pkgs-config file,
45+ # but this makefile doesn't use pkgs-config, so we also have to add lbz2
2046 configurePhase = ''
47+ substituteInPlace makefiles/Makefile.third_party.unix.mk \
48+ --replace 'COINUTILS_LNK = $(STATIC_COINUTILS_LNK)' \
49+ 'COINUTILS_LNK = $(STATIC_COINUTILS_LNK) -lbz2'
50+
2151 cat <<EOF > Makefile.local
22− UNIX_ABSL_DIR=${abseil-cpp}
23− UNIX_GFLAGS_DIR=${gflags}
24− UNIX_GLOG_DIR=${glog}
25− UNIX_PROTOBUF_DIR=${protobuf}
26− UNIX_CBC_DIR=${cbc}
52+ UNIX_ABSL_DIR=${abseil-cpp}
53+ UNIX_PROTOBUF_DIR=${protobuf}
54+ UNIX_CBC_DIR=${cbc}
55+ USE_SCIP=OFF
2756 EOF
2857 '';
2958
59+ # Many of these 'samples' (which are really the tests) require using SCIP, and or-tools 8.1
60+ # will just crash if SCIP is not found because it doesn't fall back to using one of
61+ # the available solvers: https://github.com/google/or-tools/blob/b77bd3ac69b7f3bb02f55b7bab6cbb4bab3917f2/ortools/linear_solver/linear_solver.cc#L427
62+ # We don't compile with SCIP because it does not have an open source license.
63+ # See https://github.com/google/or-tools/issues/2395
64+ preBuild = ''
65+ for file in ortools/linear_solver/samples/*.cc; do
66+ if grep -q SCIP_MIXED_INTEGER_PROGRAMMING $file; then
67+ substituteInPlace $file --replace SCIP_MIXED_INTEGER_PROGRAMMING CBC_MIXED_INTEGER_PROGRAMMING
68+ fi;
69+ done
70+
71+ substituteInPlace ortools/linear_solver/samples/simple_mip_program.cc \
72+ --replace 'SCIP' 'CBC'
73+ '';
3074 makeFlags = [
3175 "prefix=${placeholder "out"}"
3276 "PROTOBUF_PYTHON_DESC=${python.pkgs.protobuf}/${python.sitePackages}/google/protobuf/descriptor_pb2.py"
3377 ];
3478 buildFlags = [ "cc" "pypi_archive" ];
3579
36− checkTarget = "test_cc";
3780 doCheck = true;
81+ checkTarget = "test_cc";
3882
3983 installTargets = [ "install_cc" ];
4084 # The upstream install_python target installs to $HOME.
@@ -43,14 +87,30 @@ stdenv.mkDerivation rec {
4387 (cd temp_python/ortools; PYTHONPATH="$python/${python.sitePackages}:$PYTHONPATH" python setup.py install '--prefix=$python')
4488 '';
4589
90+ enableParallelBuilding = true;
91+
4692 nativeBuildInputs = [
47− cmake lsb-release swig which zlib python
93+ cmake
94+ lsb-release
95+ swig4
96+ which
4897 ensureNewerSourcesForZipFilesHook
49− python.pkgs.setuptools python.pkgs.wheel
98+ python.pkgs.setuptools
99+ python.pkgs.wheel
100+ ];
101+ buildInputs = [
102+ zlib
103+ bzip2
104+ python
50105 ];
51106 propagatedBuildInputs = [
52− abseil-cpp gflags glog protobuf cbc
53− python.pkgs.protobuf python.pkgs.six
107+ abseil-cpp
108+ protobuf
109+
110+ python.pkgs.protobuf
111+ python.pkgs.six
112+ python.pkgs.absl-py
113+ python.pkgs.mypy-protobuf
54114 ];
55115
56116 outputs = [ "out" "python" ];