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
This commit is contained in:
Daniël de Kok 2020-07-07 15:15:46 +02:00 committed by Frederik Rietdijk
parent 11cdfc0424
commit 2611e96bf3

View file

@ -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 ''