1{
2 lib,
3 stdenv,
4 fetchurl,
5 fetchpatch,
6 boehmgc,
7 buildPackages,
8 coverageAnalysis ? null,
9 gawk,
10 gmp,
11 libffi,
12 libtool,
13 libunistring,
14 libxcrypt,
15 makeWrapper,
16 pkg-config,
17 autoreconfHook,
18 pkgsBuildBuild,
19 readline,
20 writeScript,
21}:
22
23let
24 # Do either a coverage analysis build or a standard build.
25 builder = if coverageAnalysis != null then coverageAnalysis else stdenv.mkDerivation;
26in
27builder rec {
28 pname = "guile";
29 version = "3.0.10";
30
31 src = fetchurl {
32 url = "mirror://gnu/${pname}/${pname}-${version}.tar.xz";
33 sha256 = "sha256-vXFoUX/VJjM0RtT3q4FlJ5JWNAlPvTcyLhfiuNjnY4g=";
34 };
35
36 outputs = [
37 "out"
38 "dev"
39 "info"
40 ];
41 setOutputFlags = false; # $dev gets into the library otherwise
42
43 depsBuildBuild = [
44 buildPackages.stdenv.cc
45 ]
46 ++ lib.optional (
47 !lib.systems.equals stdenv.hostPlatform stdenv.buildPlatform
48 ) pkgsBuildBuild.guile_3_0;
49
50 nativeBuildInputs = [
51 makeWrapper
52 pkg-config
53 ]
54 ++ lib.optional (!lib.systems.equals stdenv.hostPlatform stdenv.buildPlatform) autoreconfHook;
55
56 buildInputs = [
57 libffi
58 libtool
59 libunistring
60 readline
61 ]
62 ++ lib.optionals stdenv.hostPlatform.isLinux [
63 libxcrypt
64 ];
65 propagatedBuildInputs = [
66 boehmgc
67 gmp
68
69 # These ones aren't normally needed here, but `libguile*.la' has '-l'
70 # flags for them without corresponding '-L' flags. Adding them here will
71 # add the needed `-L' flags. As for why the `.la' file lacks the `-L'
72 # flags, see below.
73 libtool
74 libunistring
75 ]
76 ++ lib.optionals stdenv.hostPlatform.isLinux [
77 libxcrypt
78 ];
79
80 strictDeps = true;
81
82 # According to
83 # https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/packages/guile.scm?h=a39207f7afd977e4e4299c6f0bb34bcb6d153818#n405
84 # starting with Guile 3.0.8, parallel builds can be done
85 # bit-reproducibly as long as we're not cross-compiling
86 enableParallelBuilding = lib.systems.equals stdenv.buildPlatform stdenv.hostPlatform;
87
88 patches = [
89 ./eai_system.patch
90 ]
91 # Fix cross-compilation, can be removed at next release (as well as the autoreconfHook)
92 # Include this only conditionally so we don't have to run the autoreconfHook for the native build.
93 ++ lib.optional (!lib.systems.equals stdenv.hostPlatform stdenv.buildPlatform) (fetchpatch {
94 url = "https://cgit.git.savannah.gnu.org/cgit/guile.git/patch/?id=c117f8edc471d3362043d88959d73c6a37e7e1e9";
95 hash = "sha256-GFwJiwuU8lT1fNueMOcvHh8yvA4HYHcmPml2fY/HSjw=";
96 })
97 ++ lib.optional (coverageAnalysis != null) ./gcov-file-name.patch
98 ++ lib.optional stdenv.hostPlatform.isDarwin (fetchpatch {
99 url = "https://gitlab.gnome.org/GNOME/gtk-osx/raw/52898977f165777ad9ef169f7d4818f2d4c9b731/patches/guile-clocktime.patch";
100 sha256 = "12wvwdna9j8795x59ldryv9d84c1j3qdk2iskw09306idfsis207";
101 });
102
103 # Explicitly link against libgcc_s, to work around the infamous
104 # "libgcc_s.so.1 must be installed for pthread_cancel to work".
105
106 # don't have "libgcc_s.so.1" on clang
107 LDFLAGS = lib.optionalString (stdenv.cc.isGNU && !stdenv.hostPlatform.isStatic) "-lgcc_s";
108
109 configureFlags = [
110 "--with-libreadline-prefix=${lib.getDev readline}"
111 ]
112 ++ lib.optionals stdenv.hostPlatform.isSunOS [
113 # Make sure the right <gmp.h> is found, and not the incompatible
114 # /usr/include/mp.h from OpenSolaris. See
115 # <https://lists.gnu.org/archive/html/hydra-users/2012-08/msg00000.html>
116 # for details.
117 "--with-libgmp-prefix=${lib.getDev gmp}"
118
119 # Same for these (?).
120 "--with-libunistring-prefix=${libunistring}"
121
122 # See below.
123 "--without-threads"
124 ]
125 # At least on x86_64-darwin '-flto' autodetection is not correct:
126 # https://github.com/NixOS/nixpkgs/pull/160051#issuecomment-1046193028
127 ++ lib.optional (stdenv.hostPlatform.isDarwin) "--disable-lto";
128
129 postInstall = ''
130 wrapProgram $out/bin/guile-snarf --prefix PATH : "${gawk}/bin"
131 ''
132 # XXX: See http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/18903 for
133 # why `--with-libunistring-prefix' and similar options coming from
134 # `AC_LIB_LINKFLAGS_BODY' don't work on NixOS/x86_64.
135 + ''
136 sed -i "$out/lib/pkgconfig/guile"-*.pc \
137 -e "s|-lunistring|-L${libunistring}/lib -lunistring|g ;
138 s|-lltdl|-L${libtool.lib}/lib -lltdl|g ;
139 s|-lcrypt|-L${libxcrypt}/lib -lcrypt|g ;
140 s|^Cflags:\(.*\)$|Cflags: -I${libunistring.dev}/include \1|g ;
141 s|includedir=$out|includedir=$dev|g
142 "
143 '';
144
145 # make check doesn't work on darwin
146 # On Linuxes+Hydra the tests are flaky; feel free to investigate deeper.
147 doCheck = false;
148 doInstallCheck = doCheck;
149
150 # In procedure bytevector-u8-ref: Argument 2 out of range
151 dontStrip = stdenv.hostPlatform.isDarwin;
152
153 setupHook = ./setup-hook-3.0.sh;
154
155 passthru = rec {
156 effectiveVersion = lib.versions.majorMinor version;
157 siteCcacheDir = "lib/guile/${effectiveVersion}/site-ccache";
158 siteDir = "share/guile/site/${effectiveVersion}";
159
160 updateScript = writeScript "update-guile-3" ''
161 #!/usr/bin/env nix-shell
162 #!nix-shell -i bash -p curl pcre common-updater-scripts
163
164 set -eu -o pipefail
165
166 # Expect the text in format of '"https://ftp.gnu.org/gnu/guile/guile-3.0.8.tar.gz"'
167 new_version="$(curl -s https://www.gnu.org/software/guile/download/ |
168 pcregrep -o1 '"https://ftp.gnu.org/gnu/guile/guile-(3[.0-9]+).tar.gz"')"
169 update-source-version guile_3_0 "$new_version"
170 '';
171 };
172
173 meta = with lib; {
174 homepage = "https://www.gnu.org/software/guile/";
175 description = "Embeddable Scheme implementation";
176 longDescription = ''
177 GNU Guile is an implementation of the Scheme programming language, with
178 support for many SRFIs, packaged for use in a wide variety of
179 environments. In addition to implementing the R5RS Scheme standard and a
180 large subset of R6RS, Guile includes a module system, full access to POSIX
181 system calls, networking support, multiple threads, dynamic linking, a
182 foreign function call interface, and powerful string processing.
183 '';
184 license = licenses.lgpl3Plus;
185 maintainers = [ ];
186 platforms = platforms.all;
187 };
188}