From 2611e96bf3cc798f30b86871718db5855469cda8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Tue, 7 Jul 2020 15:15:46 +0200 Subject: [PATCH] python3Packages.pytorch: create separate lib output At some point pytorch.dev was added to expose the libtorch headers and libraries to non-Python users of libtorch. However, this output currently has two disadvantages: 1. An application that compiles against the dev output will also have the libtorch header files in its closure. This is not so nice when e.g. building Docker images of applications that use libtorch. 2. The dev output has a large transitive closure with many dependencies that are not necessary when compiling against libtorch. This change adds the `lib` output so that applications that only link against libtorch libraries have a small closure. Before this change, the libtorch dependency adds 746MiB: % nix path-info -S `realpath result-dev` /nix/store/10rmy81bjk628sfpbj2szxlws6brq1xn-python3.8-pytorch-1.5.1-dev 782203848 With this change it is reduced to 196MiB: % nix path-info -S `realpath result-lib` /nix/store/bck65lf0z7gdhcf89w1zs5nz333lhgwa-python3.8-pytorch-1.5.1-lib 205865056 --- pkgs/development/python-modules/pytorch/default.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkgs/development/python-modules/pytorch/default.nix b/pkgs/development/python-modules/pytorch/default.nix index a746d4c7dfb..efe6400fcbd 100644 --- a/pkgs/development/python-modules/pytorch/default.nix +++ b/pkgs/development/python-modules/pytorch/default.nix @@ -110,7 +110,8 @@ in buildPythonPackage rec { outputs = [ "out" # output standard python package - "dev" # output libtorch only + "dev" # output libtorch headers + "lib" # output libtorch libraries ]; src = fetchFromGitHub { @@ -239,9 +240,11 @@ in buildPythonPackage rec { ]; postInstall = '' mkdir $dev - cp -r $out/${python.sitePackages}/torch/lib $dev/lib cp -r $out/${python.sitePackages}/torch/include $dev/include cp -r $out/${python.sitePackages}/torch/share $dev/share + + mkdir $lib + cp -r $out/${python.sitePackages}/torch/lib $lib/lib ''; postFixup = stdenv.lib.optionalString stdenv.isDarwin ''