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 });
60
61 # https://www.python.org/dev/peps/pep-0571/
62 manylinux2010Libs = manylinux2014Libs;
63
64 # https://www.python.org/dev/peps/pep-0513/
65 manylinux1Libs = getLibOutputs(manylinux2010Libs // (with pkgs; {
66 "libpanelw.so.5" = ncurses5;
67 "libncursesw.so.5" = ncurses5;
68 "libcrypt.so.1" = glibc;
69 }));
70
71in {
72 # List of libraries that are needed for manylinux compatibility.
73 # When using a wheel that is manylinux1 compatible, just extend
74 # the `buildInputs` with one of these `manylinux` lists.
75 # Additionally, add `autoPatchelfHook` to `nativeBuildInputs`.
76 manylinux1 = lib.unique (lib.attrValues manylinux1Libs);
77 manylinux2010 = lib.unique (lib.attrValues manylinux2010Libs);
78 manylinux2014 = lib.unique (lib.attrValues manylinux2014Libs);
79
80 # These are symlink trees to the relevant libs and are typically not needed
81 # These exist so as to quickly test whether all required libraries are provided
82 # by the mapped packages.
83 manylinux1Package = createManyLinuxPackage "manylinux1" manylinux1Libs;
84 manylinux2010Package = createManyLinuxPackage "manylinux2010" manylinux2010Libs;
85 manylinux2014Package = createManyLinuxPackage "manylinux2014" manylinux2014Libs;
86}