Merge pull request #119126 from fabaff/pycomfoconnect
[NixPkgs.git] / pkgs / development / interpreters / perl / default.nix
blob01b3e995f5e4b4b5bd495bf1d9b194cde1fa430b
1 { config, lib, stdenv, fetchurl, pkgs, buildPackages, callPackage
2 , enableThreading ? true, coreutils, makeWrapper
3 }:
5 # Note: this package is used for bootstrapping fetchurl, and thus
6 # cannot use fetchpatch! All mutable patches (generated by GitHub or
7 # cgit) that are needed here should be included directly in Nixpkgs as
8 # files.
10 with lib;
12 let
14   libc = if stdenv.cc.libc or null != null then stdenv.cc.libc else "/usr";
15   libcInc = lib.getDev libc;
16   libcLib = lib.getLib libc;
17   crossCompiling = stdenv.buildPlatform != stdenv.hostPlatform;
19   common = { perl, buildPerl, version, sha256 }: stdenv.mkDerivation (rec {
20     inherit version;
22     name = "perl-${version}";
24     src = fetchurl {
25       url = "mirror://cpan/src/5.0/${name}.tar.gz";
26       inherit sha256;
27     };
29     # TODO: Add a "dev" output containing the header files.
30     outputs = [ "out" "man" "devdoc" ] ++
31       optional crossCompiling "mini";
32     setOutputFlags = false;
34     disallowedReferences = [ stdenv.cc ];
36     patches =
37       [
38         # Do not look in /usr etc. for dependencies.
39         (if (versionOlder version "5.31.1") then ./no-sys-dirs-5.29.patch
40          else ./no-sys-dirs-5.31.patch)
41       ]
42       ++ optional stdenv.isSunOS ./ld-shared.patch
43       ++ optionals stdenv.isDarwin [ ./cpp-precomp.patch ./sw_vers.patch ]
44       ++ optional crossCompiling ./MakeMaker-cross.patch
45       # Backporting https://github.com/Perl/perl5/pull/17946, can be
46       # removed if there's ever a 5.30.x release with it included.
47       ++ optional (versionOlder version "5.32.1") ./aarch64-darwin.patch;
49     # This is not done for native builds because pwd may need to come from
50     # bootstrap tools when building bootstrap perl.
51     postPatch = (if crossCompiling then ''
52       substituteInPlace dist/PathTools/Cwd.pm \
53         --replace "/bin/pwd" '${coreutils}/bin/pwd'
54       substituteInPlace cnf/configure_tool.sh --replace "cc -E -P" "cc -E"
55     '' else ''
56       substituteInPlace dist/PathTools/Cwd.pm \
57         --replace "/bin/pwd" "$(type -P pwd)"
58     '') +
59     # Perl's build system uses the src variable, and its value may end up in
60     # the output in some cases (when cross-compiling)
61     ''
62       unset src
63     '';
65     # Build a thread-safe Perl with a dynamic libperls.o.  We need the
66     # "installstyle" option to ensure that modules are put under
67     # $out/lib/perl5 - this is the general default, but because $out
68     # contains the string "perl", Configure would select $out/lib.
69     # Miniperl needs -lm. perl needs -lrt.
70     configureFlags =
71       (if crossCompiling
72        then [ "-Dlibpth=\"\"" "-Dglibpth=\"\"" "-Ddefault_inc_excludes_dot" ]
73        else [ "-de" "-Dcc=cc" ])
74       ++ [
75         "-Uinstallusrbinperl"
76         "-Dinstallstyle=lib/perl5"
77         "-Duseshrplib"
78         "-Dlocincpth=${libcInc}/include"
79         "-Dloclibpth=${libcLib}/lib"
80       ]
81       ++ optionals ((builtins.match ''5\.[0-9]*[13579]\..+'' version) != null) [ "-Dusedevel" "-Uversiononly" ]
82       ++ optional stdenv.isSunOS "-Dcc=gcc"
83       ++ optional enableThreading "-Dusethreads"
84       ++ optionals (!crossCompiling) [
85         "-Dprefix=${placeholder "out"}"
86         "-Dman1dir=${placeholder "out"}/share/man/man1"
87         "-Dman3dir=${placeholder "out"}/share/man/man3"
88       ];
90     configureScript = optionalString (!crossCompiling) "${stdenv.shell} ./Configure";
92     dontAddPrefix = !crossCompiling;
94     enableParallelBuilding = !crossCompiling;
96     preConfigure = ''
97         substituteInPlace ./Configure --replace '`LC_ALL=C; LANGUAGE=C; export LC_ALL; export LANGUAGE; $date 2>&1`' 'Thu Jan  1 00:00:01 UTC 1970'
98         substituteInPlace ./Configure --replace '$uname -a' '$uname --kernel-name --machine --operating-system'
99       '' + optionalString stdenv.isDarwin ''
100         substituteInPlace hints/darwin.sh --replace "env MACOSX_DEPLOYMENT_TARGET=10.3" ""
101       '' + optionalString (!enableThreading) ''
102         # We need to do this because the bootstrap doesn't have a static libpthread
103         sed -i 's,\(libswanted.*\)pthread,\1,g' Configure
104       '';
106     setupHook = ./setup-hook.sh;
108     passthru = rec {
109       interpreter = "${perl}/bin/perl";
110       libPrefix = "lib/perl5/site_perl";
111       pkgs = callPackage ../../../top-level/perl-packages.nix {
112         inherit perl buildPerl;
113         overrides = config.perlPackageOverrides or (p: {}); # TODO: (self: super: {}) like in python
114       };
115       buildEnv = callPackage ./wrapper.nix {
116         inherit perl;
117         inherit (pkgs) requiredPerlModules;
118       };
119       withPackages = f: buildEnv.override { extraLibs = f pkgs; };
120     };
122     doCheck = false; # some tests fail, expensive
124     # TODO: it seems like absolute paths to some coreutils is required.
125     postInstall =
126       ''
127         # Remove dependency between "out" and "man" outputs.
128         rm "$out"/lib/perl5/*/*/.packlist
130         # Remove dependencies on glibc and gcc
131         sed "/ *libpth =>/c    libpth => ' '," \
132           -i "$out"/lib/perl5/*/*/Config.pm
133         # TODO: removing those paths would be cleaner than overwriting with nonsense.
134         substituteInPlace "$out"/lib/perl5/*/*/Config_heavy.pl \
135           --replace "${libcInc}" /no-such-path \
136           --replace "${
137               if stdenv.hasCC then stdenv.cc.cc else "/no-such-path"
138             }" /no-such-path \
139           --replace "${stdenv.cc}" /no-such-path \
140           --replace "$man" /no-such-path
141       '' + optionalString crossCompiling
142       ''
143         mkdir -p $mini/lib/perl5/cross_perl/${version}
144         for dir in cnf/{stub,cpan}; do
145           cp -r $dir/* $mini/lib/perl5/cross_perl/${version}
146         done
148         mkdir -p $mini/bin
149         install -m755 miniperl $mini/bin/perl
151         export runtimeArch="$(ls $out/lib/perl5/site_perl/${version})"
152         # wrapProgram should use a runtime-native SHELL by default, but
153         # it actually uses a buildtime-native one. If we ever fix that,
154         # we'll need to fix this to use a buildtime-native one.
155         #
156         # Adding the arch-specific directory is morally incorrect, as
157         # miniperl can't load the native modules there. However, it can
158         # (and sometimes needs to) load and run some of the pure perl
159         # code there, so we add it anyway. When needed, stubs can be put
160         # into $mini/lib/perl5/cross_perl/${version}.
161         wrapProgram $mini/bin/perl --prefix PERL5LIB : \
162           "$mini/lib/perl5/cross_perl/${version}:$out/lib/perl5/${version}:$out/lib/perl5/${version}/$runtimeArch"
163       ''; # */
165     meta = {
166       homepage = "https://www.perl.org/";
167       description = "The standard implementation of the Perl 5 programmming language";
168       license = licenses.artistic1;
169       maintainers = [ maintainers.eelco ];
170       platforms = platforms.all;
171       priority = 6; # in `buildEnv' (including the one inside `perl.withPackages') the library files will have priority over files in `perl`
172     };
173   } // optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) rec {
174     crossVersion = "e53999d0c340769792ba18d749751b0df3d1d177"; # Mar 21, 2021
176     perl-cross-src = fetchurl {
177       url = "https://github.com/arsv/perl-cross/archive/${crossVersion}.tar.gz";
178       sha256 = "14vcpwjhq667yh0cs7ism70df8l7068vn4a0ww59hdjyj7yc84i6";
179     };
181     depsBuildBuild = [ buildPackages.stdenv.cc makeWrapper ];
183     postUnpack = ''
184       unpackFile ${perl-cross-src}
185       cp -R perl-cross-${crossVersion}/* perl-${version}/
186     '';
188     configurePlatforms = [ "build" "host" "target" ];
190     # TODO merge setup hooks
191     setupHook = ./setup-hook-cross.sh;
192   });
193 in {
194   # Maint version
195   perl530 = common {
196     perl = pkgs.perl530;
197     buildPerl = buildPackages.perl530;
198     version = "5.30.3";
199     sha256 = "0vs0wwwlw47sswxaflkk4hw0y45cmc7arxx788kwpbminy5lrq1j";
200   };
202   # Maint version
203   perl532 = common {
204     perl = pkgs.perl532;
205     buildPerl = buildPackages.perl532;
206     version = "5.32.1";
207     sha256 = "0b7brakq9xs4vavhg391as50nbhzryc7fy5i65r81bnq3j897dh3";
208   };
210   # the latest Devel version
211   perldevel = common {
212     perl = pkgs.perldevel;
213     buildPerl = buildPackages.perldevel;
214     version = "5.33.8";
215     sha256 = "1zr6sdsfcmk86n3f8j65x07xkv29v0pi8bwc986ahmjx7x92xzgl";
216   };