From c7b26ea2bc3f80f59ffb98cc2e718498fd44de04 Mon Sep 17 00:00:00 2001 From: TomaSajt <62384384+TomaSajt@users.noreply.github.com> Date: Mon, 12 May 2025 00:19:00 +0200 Subject: [PATCH] zinnia: fix compilation on darwin, update sourceRoot logic --- pkgs/by-name/zi/zinnia/package.nix | 20 ++++++++------ .../zinnia/remove-random-shuffle-usage.patch | 27 +++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 pkgs/by-name/zi/zinnia/remove-random-shuffle-usage.patch diff --git a/pkgs/by-name/zi/zinnia/package.nix b/pkgs/by-name/zi/zinnia/package.nix index 517902833644..df39b6c9b495 100644 --- a/pkgs/by-name/zi/zinnia/package.nix +++ b/pkgs/by-name/zi/zinnia/package.nix @@ -4,7 +4,7 @@ fetchFromGitHub, }: -stdenv.mkDerivation { +stdenv.mkDerivation (finalAttrs: { pname = "zinnia"; version = "2016-08-28"; @@ -15,15 +15,19 @@ stdenv.mkDerivation { sha256 = "1izjy5qw6swg0rs2ym2i72zndb90mwrfbd1iv8xbpwckbm4899lg"; }; - setSourceRoot = '' - sourceRoot=$(echo */zinnia) - ''; + sourceRoot = "${finalAttrs.src.name}/zinnia"; - meta = with lib; { + patches = [ + # Fixes the following error on darwin: + # svm.cpp:50:10: error: no member named 'random_shuffle' in namespace 'std' + ./remove-random-shuffle-usage.patch + ]; + + meta = { description = "Online hand recognition system with machine learning"; homepage = "http://taku910.github.io/zinnia/"; - license = licenses.bsd2; - platforms = platforms.unix; + license = lib.licenses.bsd2; + platforms = lib.platforms.unix; maintainers = [ ]; }; -} +}) diff --git a/pkgs/by-name/zi/zinnia/remove-random-shuffle-usage.patch b/pkgs/by-name/zi/zinnia/remove-random-shuffle-usage.patch new file mode 100644 index 000000000000..0ef90c7a275b --- /dev/null +++ b/pkgs/by-name/zi/zinnia/remove-random-shuffle-usage.patch @@ -0,0 +1,27 @@ +diff --git a/svm.cpp b/svm.cpp +index 3b7643e..2a34b42 100644 +--- a/svm.cpp ++++ b/svm.cpp +@@ -10,6 +10,7 @@ + #include + #include + #include ++#include + #include "feature.h" + + namespace zinnia { +@@ -43,11 +44,13 @@ bool svm_train(size_t l, + } + } + ++ std::random_device rand_device; ++ std::default_random_engine rand_engine(rand_device()); + static const size_t kMaxIteration = 2000; + for (size_t iter = 0; iter < kMaxIteration; ++iter) { + double PGmax_new = -kINF; + double PGmin_new = kINF; +- std::random_shuffle(index.begin(), index.begin() + active_size); ++ std::shuffle(index.begin(), index.begin() + active_size, rand_engine); + + for (size_t s = 0; s < active_size; ++s) { + const size_t i = index[s];