shogun: refactor build

Main changes are:

- Build with default stdenv instead of forcing GCC 8, by applying upstream
patches that fix building with newer compilers.

Together with #134390 and #134393 (and the blas library fixes on #135493
and #136535), this enables building the derivation on darwin.

- Use multiple outputs.

- Move build-only inputs to nativeBuildInputs.

- Generate the meta examples but do not compile them (they are compiled as
part of the tests), to not make the build take more time than already is.

Install the example source files into $doc (but do not install the
example binaries, only the sources).

- Enable testing by setting the CMake variable CMAKE_SKIP_BUILD_RPATH to
false (it should not be needed if #108496 is merged). This allows the
tests to locate the shogun library and run without problems.

Disable integration and meta tests to speed up the build.

With a few other minor changes:

- Use upstream URL for the json-c patch.

- Be explicit about which optional, commercial dependencies are not used,
to stop CMake searching for them.

- Do not set NIX_CFLAGS_COMPILE with '-faligned-new' because it causes a
warning when compiling C files. Set CXXFLAGS instead.

- Remove unnecessary ccache variables from the environment.

- Fix wrong Google Mock download location, which was forcing CMake to need
network access to download the tarball to the right location (which fails
within the sandbox).

+46 -27
+45 -17
pkgs/applications/science/machine-learning/shogun/default.nix
··· 6 # build 7 , cmake 8 , ctags 9 , swig 10 # math 11 , eigen ··· 30 , colpack 31 # extra support 32 , pythonSupport ? true 33 - , pythonPackages ? null 34 , opencvSupport ? false 35 , opencv ? null 36 , withSvmLight ? false ··· 56 sha256 = "05s9dclmk7x5d7wnnj4qr6r6c827m72a44gizcv09lxr28pr9inz"; 57 fetchSubmodules = true; 58 }; 59 - # we need the packed archive 60 rxcpp = fetchurl { 61 url = "https://github.com/Reactive-Extensions/RxCpp/archive/v${rxcppVersion}.tar.gz"; 62 sha256 = "0y2isr8dy2n1yjr9c5570kpc9lvdlch6jv0jvw000amwn5d3krsh"; ··· 71 stdenv.mkDerivation rec { 72 inherit pname version; 73 74 src = srcs.toolbox; 75 76 patches = [ 77 (fetchpatch { 78 - url = "https://github.com/awild82/shogun/commit/365ce4c4c700736d2eec8ba6c975327a5ac2cd9b.patch"; 79 sha256 = "158hqv4xzw648pmjbwrhxjp7qcppqa7kvriif87gn3zdn711c49s"; 80 }) 81 ] ++ lib.optional (!withSvmLight) ./svmlight-scrubber.patch; 82 83 - nativeBuildInputs = [ cmake ]; 84 85 buildInputs = [ 86 eigen ··· 100 nlopt 101 lp_solve 102 colpack 103 - ctags 104 - swig 105 - ] ++ lib.optionals pythonSupport (with pythonPackages; [ python ply numpy ]) 106 ++ lib.optional opencvSupport opencv; 107 108 cmakeFlags = let 109 enableIf = cond: if cond then "ON" else "OFF"; 110 in [ 111 - "-DBUILD_META_EXAMPLES=${enableIf doCheck}" 112 - "-DCMAKE_VERBOSE_MAKEFILE=${enableIf doCheck}" 113 "-DENABLE_TESTING=${enableIf doCheck}" 114 "-DPythonModular=${enableIf pythonSupport}" 115 "-DOpenCV=${enableIf opencvSupport}" 116 "-DUSE_SVMLIGHT=${enableIf withSvmLight}" 117 ]; 118 119 - CCACHE_DISABLE="1"; 120 - CCACHE_DIR=".ccache"; 121 122 - NIX_CFLAGS_COMPILE="-faligned-new"; 123 - 124 - # broken 125 - doCheck = false; 126 127 postUnpack = '' 128 - mkdir -p $sourceRoot/third_party/{rxcpp,gtest} 129 ln -s ${srcs.rxcpp} $sourceRoot/third_party/rxcpp/v${rxcppVersion}.tar.gz 130 - ln -s ${srcs.gtest} $sourceRoot/third_party/gtest/release-${gtestVersion}.tar.gz 131 ''; 132 133 postPatch = '' ··· 144 patchShebangs scripts/light-scrubber.sh 145 echo "removing SVMlight code" 146 ./scripts/light-scrubber.sh 147 ''; 148 149 meta = with lib; {
··· 6 # build 7 , cmake 8 , ctags 9 + , pythonPackages 10 , swig 11 # math 12 , eigen ··· 31 , colpack 32 # extra support 33 , pythonSupport ? true 34 , opencvSupport ? false 35 , opencv ? null 36 , withSvmLight ? false ··· 56 sha256 = "05s9dclmk7x5d7wnnj4qr6r6c827m72a44gizcv09lxr28pr9inz"; 57 fetchSubmodules = true; 58 }; 59 + 60 + # The CMake external projects expect the packed archives 61 rxcpp = fetchurl { 62 url = "https://github.com/Reactive-Extensions/RxCpp/archive/v${rxcppVersion}.tar.gz"; 63 sha256 = "0y2isr8dy2n1yjr9c5570kpc9lvdlch6jv0jvw000amwn5d3krsh"; ··· 72 stdenv.mkDerivation rec { 73 inherit pname version; 74 75 + outputs = [ "out" "dev" "doc" ]; 76 + 77 src = srcs.toolbox; 78 79 patches = [ 80 + # Fix compile errors with json-c 81 + # https://github.com/shogun-toolbox/shogun/pull/4104 82 (fetchpatch { 83 + url = "https://github.com/shogun-toolbox/shogun/commit/365ce4c4c700736d2eec8ba6c975327a5ac2cd9b.patch"; 84 sha256 = "158hqv4xzw648pmjbwrhxjp7qcppqa7kvriif87gn3zdn711c49s"; 85 }) 86 + 87 + # Fix compile errors with GCC 9+ 88 + # https://github.com/shogun-toolbox/shogun/pull/4811 89 + (fetchpatch { 90 + url = "https://github.com/shogun-toolbox/shogun/commit/c8b670be4790e0f06804b048a6f3d77c17c3ee95.patch"; 91 + sha256 = "sha256-MxsR3Y2noFQevfqWK3nmX5iK4OVWeKBl5tfeDNgjcXk="; 92 + }) 93 + (fetchpatch { 94 + url = "https://github.com/shogun-toolbox/shogun/commit/5aceefd9fb0e2132c354b9a0c0ceb9160cc9b2f7.patch"; 95 + sha256 = "sha256-AgJJKQA8vc5oKaTQDqMdwBR4hT4sn9+uW0jLe7GteJw="; 96 + }) 97 + 98 ] ++ lib.optional (!withSvmLight) ./svmlight-scrubber.patch; 99 100 + nativeBuildInputs = [ cmake swig ctags ] 101 + ++ (with pythonPackages; [ python jinja2 ply ]); 102 103 buildInputs = [ 104 eigen ··· 118 nlopt 119 lp_solve 120 colpack 121 + ] ++ lib.optionals pythonSupport (with pythonPackages; [ python numpy ]) 122 ++ lib.optional opencvSupport opencv; 123 124 cmakeFlags = let 125 enableIf = cond: if cond then "ON" else "OFF"; 126 in [ 127 + "-DBUILD_META_EXAMPLES=ON" 128 + "-DCMAKE_DISABLE_FIND_PACKAGE_ARPACK=ON" 129 + "-DCMAKE_DISABLE_FIND_PACKAGE_ARPREC=ON" 130 + "-DCMAKE_DISABLE_FIND_PACKAGE_CPLEX=ON" 131 + "-DCMAKE_DISABLE_FIND_PACKAGE_Mosek=ON" 132 + "-DCMAKE_DISABLE_FIND_PACKAGE_TFLogger=ON" 133 + "-DCMAKE_DISABLE_FIND_PACKAGE_ViennaCL=ON" 134 + "-DCMAKE_SKIP_BUILD_RPATH=OFF" 135 + "-DCMAKE_CTEST_ARGUMENTS='--exclude-regex;TrainedModelSerialization'" # Sporadic segfault 136 "-DENABLE_TESTING=${enableIf doCheck}" 137 + "-DDISABLE_META_INTEGRATION_TESTS=ON" 138 + "-DTRAVIS_DISABLE_META_CPP=ON" 139 "-DPythonModular=${enableIf pythonSupport}" 140 "-DOpenCV=${enableIf opencvSupport}" 141 "-DUSE_SVMLIGHT=${enableIf withSvmLight}" 142 ]; 143 144 + CXXFLAGS = "-faligned-new"; 145 146 + doCheck = true; 147 148 postUnpack = '' 149 + mkdir -p $sourceRoot/third_party/{rxcpp,GoogleMock} 150 ln -s ${srcs.rxcpp} $sourceRoot/third_party/rxcpp/v${rxcppVersion}.tar.gz 151 + ln -s ${srcs.gtest} $sourceRoot/third_party/GoogleMock/release-${gtestVersion}.tar.gz 152 ''; 153 154 postPatch = '' ··· 165 patchShebangs scripts/light-scrubber.sh 166 echo "removing SVMlight code" 167 ./scripts/light-scrubber.sh 168 + ''; 169 + 170 + postInstall = '' 171 + mkdir -p $doc/share/doc/shogun/examples 172 + mv $out/share/shogun/examples/cpp $doc/share/doc/shogun/examples 173 + cp ../examples/undocumented/libshogun/*.cpp $doc/share/doc/shogun/examples/cpp 174 + rm -r $out/share 175 ''; 176 177 meta = with lib; {
+1 -10
pkgs/top-level/all-packages.nix
··· 26918 shotcut = libsForQt5.callPackage ../applications/video/shotcut { }; 26919 26920 shogun = callPackage ../applications/science/machine-learning/shogun { 26921 - stdenv = gcc8Stdenv; 26922 - 26923 - # Workaround for the glibc abi version mismatch. 26924 - # Please note that opencv builds are by default disabled. 26925 - opencv = opencv3.override { 26926 - stdenv = gcc8Stdenv; 26927 - openexr = openexr.override { 26928 - stdenv = gcc8Stdenv; 26929 - }; 26930 - }; 26931 }; 26932 26933 smplayer = libsForQt5.callPackage ../applications/video/smplayer { };
··· 26918 shotcut = libsForQt5.callPackage ../applications/video/shotcut { }; 26919 26920 shogun = callPackage ../applications/science/machine-learning/shogun { 26921 + opencv = opencv3; 26922 }; 26923 26924 smplayer = libsForQt5.callPackage ../applications/video/smplayer { };