1{ lib, pkgs }:
2
3let
4 # Create a derivation that links all desired manylinux libraries
5 createManyLinuxPackage =
6 name: libs:
7 let
8 drvs = lib.unique (lib.attrValues libs);
9 names = lib.attrNames libs;
10 in
11 pkgs.runCommand name
12 {
13 buildInputs = drvs;
14 }
15 ''
16 mkdir -p $out/lib
17 num_found=0
18
19 IFS=:
20 export DESIRED_LIBRARIES=${lib.concatStringsSep ":" names}
21 export LIBRARY_PATH=${lib.makeLibraryPath drvs}
22 for desired in $DESIRED_LIBRARIES; do
23 for path in $LIBRARY_PATH; do
24 if [ -e $path/$desired ]; then
25 echo "FOUND $path/$desired"
26 ln -s $path/$desired $out/lib/$desired
27 num_found=$((num_found+1))
28 break
29 fi
30 done
31 done
32
33 num_desired=${toString (lib.length names)}
34 echo "Found $num_found of $num_desired libraries"
35 if [ "$num_found" -ne "$num_desired" ]; then
36 echo "Error: not all desired libraries were found"
37 exit 1
38 fi
39 '';
40
41 getLibOutputs = lib.mapAttrs (k: v: lib.getLib v);
42
43 # https://www.python.org/dev/peps/pep-0599/
44 manylinux2014Libs = getLibOutputs (
45 with pkgs;
46 {
47 "libgcc_s.so.1" = glibc;
48 "libstdc++.so.6" = stdenv.cc.cc;
49 "libm.so.6" = glibc;
50 "libdl.so.2" = glibc;
51 "librt.so.1" = glibc;
52 "libc.so.6" = glibc;
53 "libnsl.so.1" = glibc;
54 "libutil.so.1" = glibc;
55 "libpthread.so.0" = glibc;
56 "libresolv.so.2" = glibc;
57 "libX11.so.6" = xorg.libX11;
58 "libXext.so.6" = xorg.libXext;
59 "libXrender.so.1" = xorg.libXrender;
60 "libICE.so.6" = xorg.libICE;
61 "libSM.so.6" = xorg.libSM;
62 "libGL.so.1" = libGL;
63 "libgobject-2.0.so.0" = glib;
64 "libgthread-2.0.so.0" = glib;
65 "libglib-2.0.so.0" = glib;
66 "libz.so.1" = zlib;
67 "libexpat.so.1" = expat;
68 }
69 );
70
71 # https://www.python.org/dev/peps/pep-0571/
72 manylinux2010Libs = manylinux2014Libs;
73
74 # https://www.python.org/dev/peps/pep-0513/
75 manylinux1Libs = getLibOutputs (
76 manylinux2010Libs
77 // (with pkgs; {
78 "libpanelw.so.5" = ncurses5;
79 "libncursesw.so.5" = ncurses5;
80 "libcrypt.so.1" = libxcrypt;
81 })
82 );
83
84in
85{
86 # List of libraries that are needed for manylinux compatibility.
87 # When using a wheel that is manylinux1 compatible, just extend
88 # the `buildInputs` with one of these `manylinux` lists.
89 # Additionally, add `autoPatchelfHook` to `nativeBuildInputs`.
90 manylinux1 = lib.unique (lib.attrValues manylinux1Libs);
91 manylinux2010 = lib.unique (lib.attrValues manylinux2010Libs);
92 manylinux2014 = lib.unique (lib.attrValues manylinux2014Libs);
93
94 # These are symlink trees to the relevant libs and are typically not needed
95 # These exist so as to quickly test whether all required libraries are provided
96 # by the mapped packages.
97 manylinux1Package = createManyLinuxPackage "manylinux1" manylinux1Libs;
98 manylinux2010Package = createManyLinuxPackage "manylinux2010" manylinux2010Libs;
99 manylinux2014Package = createManyLinuxPackage "manylinux2014" manylinux2014Libs;
100}