From 27d0c5a07eabd4fa6dde8844bb50e2c6dc162254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Tue, 25 Feb 2020 16:06:24 +0100 Subject: [PATCH] sentencepiece: split into multiple outputs, optional gperftools I am using sentencepiece in a downstream application where I want to minimize the resulting closures. This commit makes changes to make sentencepiece a leaner dependency: - Split the outputs, so that the binaries/headers do not end up in the transitive closure in a library dependency. - Add the `withGPerfTools` option, which is enabled by default, to make it possible to disable the gperftools dependency. According to the sentencepiece README, this dependency gives a 10-40% performance improvement. But in many cases this is overshadowed by the neural networks that use piece identifiers as input anyway. --- pkgs/development/libraries/sentencepiece/default.nix | 9 ++++++--- .../development/python-modules/sentencepiece/default.nix | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkgs/development/libraries/sentencepiece/default.nix b/pkgs/development/libraries/sentencepiece/default.nix index 05c641fab891..f825de549121 100644 --- a/pkgs/development/libraries/sentencepiece/default.nix +++ b/pkgs/development/libraries/sentencepiece/default.nix @@ -1,9 +1,10 @@ -{ config +{ lib , fetchFromGitHub , stdenv -, lib , cmake , gperftools + +, withGPerfTools ? true }: stdenv.mkDerivation rec { @@ -17,7 +18,9 @@ stdenv.mkDerivation rec { sha256 = "1ncvyw9ar0z7nd47cysxg5xrjm01y1shdlhp8l2pdpx059p3yx3w"; }; - nativeBuildInputs = [ cmake gperftools ]; + nativeBuildInputs = [ cmake ] ++ lib.optional withGPerfTools gperftools; + + outputs = [ "bin" "dev" "out" ]; meta = with stdenv.lib; { homepage = "https://github.com/google/sentencepiece"; diff --git a/pkgs/development/python-modules/sentencepiece/default.nix b/pkgs/development/python-modules/sentencepiece/default.nix index ab7a5387c024..430e61399b2f 100644 --- a/pkgs/development/python-modules/sentencepiece/default.nix +++ b/pkgs/development/python-modules/sentencepiece/default.nix @@ -6,10 +6,13 @@ buildPythonPackage rec { pname = "sentencepiece"; - inherit (sentencepiece) version src meta; + inherit (sentencepiece) version src; nativeBuildInputs = [ pkgconfig ]; - buildInputs = [ sentencepiece ]; + buildInputs = [ sentencepiece.dev ]; sourceRoot = "source/python"; + + # sentencepiece installs 'bin' output. + meta = builtins.removeAttrs sentencepiece.meta [ "outputsToInstall" ]; }