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