gnu: emacs-consult: Fix grammar.
[jackhill/guix/guix.git] / gnu / packages / libffi.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014 Federico Beffa <beffa@fbengineering.ch>
4 ;;; Copyright © 2015, 2019 Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de>
5 ;;; Copyright © 2016, 2017, 2020 Efraim Flashner <efraim@flashner.co.il>
6 ;;; Copyright © 2016, 2017 Ben Woodcroft <donttrustben@gmail.com>
7 ;;; Copyright © 2017, 2019, 2020 Marius Bakke <marius@gnu.org>
8 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
9 ;;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
10 ;;; Copyright © 2020 John Doe <dftxbs3e@free.fr>
11 ;;;
12 ;;; This file is part of GNU Guix.
13 ;;;
14 ;;; GNU Guix is free software; you can redistribute it and/or modify it
15 ;;; under the terms of the GNU General Public License as published by
16 ;;; the Free Software Foundation; either version 3 of the License, or (at
17 ;;; your option) any later version.
18 ;;;
19 ;;; GNU Guix is distributed in the hope that it will be useful, but
20 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;;; GNU General Public License for more details.
23 ;;;
24 ;;; You should have received a copy of the GNU General Public License
25 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
26
27 (define-module (gnu packages libffi)
28 #:use-module (gnu packages)
29 #:use-module (guix licenses)
30 #:use-module (guix packages)
31 #:use-module (guix download)
32 #:use-module (guix git-download)
33 #:use-module (gnu packages check)
34 #:use-module (gnu packages pkg-config)
35 #:use-module (gnu packages python)
36 #:use-module (gnu packages python-xyz)
37 #:use-module (gnu packages ruby)
38 #:use-module (gnu packages sphinx)
39 #:use-module (guix build-system gnu)
40 #:use-module (guix build-system python)
41 #:use-module (guix build-system ruby))
42
43 (define-public libffi
44 (package
45 (name "libffi")
46 (version "3.3")
47 (source (origin
48 (method url-fetch)
49 (uri
50 (string-append "ftp://sourceware.org/pub/libffi/"
51 name "-" version ".tar.gz"))
52 (sha256
53 (base32
54 "0mi0cpf8aa40ljjmzxb7im6dbj45bb0kllcd09xgmp834y9agyvj"))))
55 (build-system gnu-build-system)
56 (arguments
57 `(;; Prevent the build system from passing -march and -mtune to the
58 ;; compiler. See "ax_cc_maxopt.m4" and "ax_gcc_archflag.m4".
59 #:configure-flags '("--enable-portable-binary" "--without-gcc-arch")
60
61 ;; TODO: Inline patches on next rebuild cycle.
62 ,@(if (string-prefix? "powerpc-" (or (%current-target-system)
63 (%current-system)))
64 '(#:phases (modify-phases %standard-phases
65 (add-after 'unpack 'apply-patch
66 (lambda* (#:key inputs #:allow-other-keys)
67 (let ((patch (assoc-ref inputs
68 "powerpc-patch")))
69 (invoke "patch" "--force" "-p1"
70 "-i" patch))))))
71 '())
72 ,@(if (string-prefix? "powerpc64le-" (or (%current-target-system)
73 (%current-system)))
74 '(#:phases (modify-phases %standard-phases
75 (add-after 'unpack 'apply-patch2
76 (lambda* (#:key inputs #:allow-other-keys)
77 (let ((patch (assoc-ref inputs
78 "powerpc64le-patch")))
79 (invoke "patch" "--force" "-p1"
80 "-i" patch))))))
81 '())))
82 (inputs
83 (cond
84 ((string-prefix? "powerpc-" (or (%current-target-system)
85 (%current-system)))
86 `(("powerpc-patch" ,@(search-patches
87 "libffi-3.3-powerpc-fixes.patch"))))
88 ((string-prefix? "powerpc64le-" (or (%current-target-system)
89 (%current-system)))
90 `(("powerpc64le-patch" ,@(search-patches
91 "libffi-float128-powerpc64le.patch"))))
92 (else '())))
93 (outputs '("out" "debug"))
94 (synopsis "Foreign function call interface library")
95 (description
96 "The libffi library provides a portable, high level programming interface
97 to various calling conventions. This allows a programmer to call any
98 function specified by a call interface description at run-time.
99
100 FFI stands for Foreign Function Interface. A foreign function interface is
101 the popular name for the interface that allows code written in one language
102 to call code written in another language. The libffi library really only
103 provides the lowest, machine dependent layer of a fully featured foreign
104 function interface. A layer must exist above libffi that handles type
105 conversions for values passed between the two languages.")
106 (home-page "http://www.sourceware.org/libffi/")
107 (properties `((release-monitoring-url . ,home-page)))
108
109 ;; See <https://github.com/atgreen/libffi/blob/master/LICENSE>.
110 (license expat)))
111
112 (define-public python-cffi
113 (package
114 (name "python-cffi")
115 (version "1.14.4")
116 (source
117 (origin
118 (method url-fetch)
119 (uri (pypi-uri "cffi" version))
120 (sha256
121 (base32 "0v080s7vlrjz9z823x2yh36yc8drwpvvir6w8wfkkzd7k2z5qihs"))))
122 (build-system python-build-system)
123 (inputs
124 `(("libffi" ,libffi)))
125 (propagated-inputs ; required at run-time
126 `(("python-pycparser" ,python-pycparser)))
127 (native-inputs
128 `(("pkg-config" ,pkg-config)
129 ("python-pytest" ,python-pytest)))
130 (arguments
131 `(#:modules ((ice-9 ftw)
132 (srfi srfi-26)
133 (guix build utils)
134 (guix build python-build-system))
135 #:phases
136 (modify-phases %standard-phases
137 (replace 'check
138 (lambda _
139 (setenv "PYTHONPATH"
140 (string-append
141 (getenv "PYTHONPATH")
142 ":" (getcwd) "/build/"
143 (car (scandir "build" (cut string-prefix? "lib." <>)))))
144
145 ;; XXX The "normal" approach of setting CC and friends does
146 ;; not work here. Is this the correct way of doing things?
147 (substitute* "testing/embedding/test_basic.py"
148 (("c = distutils\\.ccompiler\\.new_compiler\\(\\)")
149 (string-append "c = distutils.ccompiler.new_compiler();"
150 "c.set_executables(compiler='gcc',"
151 "compiler_so='gcc',linker_exe='gcc',"
152 "linker_so='gcc -shared')")))
153 (substitute* "testing/cffi0/test_ownlib.py"
154 (("\"cc testownlib") "\"gcc testownlib"))
155 (invoke "py.test" "-v" "c/" "testing/")
156 #t))
157 (add-before 'check 'patch-paths-of-dynamically-loaded-libraries
158 (lambda* (#:key inputs #:allow-other-keys)
159 ;; Shared libraries should be referred by their absolute path as
160 ;; using find_library or the like with their name fail when the
161 ;; resolved .so object is a linker script rather than an ELF
162 ;; binary (this is a limitation of the ctype library of Python).
163 (let* ((glibc (assoc-ref inputs "libc"))
164 (libm (string-append glibc "/lib/libm.so.6"))
165 (libc (string-append glibc "/lib/libc.so.6")))
166 (substitute* '("testing/cffi0/test_function.py"
167 "testing/cffi0/test_parsing.py"
168 "testing/cffi0/test_unicode_literals.py"
169 "testing/cffi0/test_zdistutils.py"
170 "testing/cffi1/test_recompiler.py")
171 (("lib_m = ['\"]{1}m['\"]{1}")
172 (format #f "lib_m = '~a'" libm)))
173 (substitute* '("testing/cffi0/test_verify.py"
174 "testing/cffi1/test_verify1.py")
175 (("lib_m = \\[['\"]{1}m['\"]{1}\\]")
176 (format #f "lib_m = ['~a']" libm)))
177 (substitute* "c/test_c.py"
178 (("find_and_load_library\\(['\"]{1}c['\"]{1}")
179 (format #f "find_and_load_library('~a'" libc)))
180 #t))))))
181 (home-page "https://cffi.readthedocs.io/")
182 (synopsis "Foreign function interface for Python")
183 (description "Foreign Function Interface for Python calling C code.")
184 (license expat)))
185
186 (define-public python2-cffi
187 (package-with-python2 python-cffi))
188
189 (define-public python-cffi-documentation
190 (package
191 (name "python-cffi-documentation")
192 (version (package-version python-cffi))
193 (source (package-source python-cffi))
194 (build-system gnu-build-system)
195 (arguments
196 `(#:tests? #f
197 #:phases (modify-phases %standard-phases
198 (add-after 'unpack 'chdir
199 (lambda _ (chdir "doc") #t))
200 (delete 'configure)
201 (replace 'build
202 (lambda* (#:key (make-flags '()) #:allow-other-keys)
203 (apply invoke "make" "html" make-flags)))
204 (replace 'install
205 (lambda* (#:key outputs #:allow-other-keys)
206 (let ((out (assoc-ref outputs "out")))
207 (copy-recursively "build/html" (string-append out "/html"))
208 #t))))))
209 (native-inputs
210 `(("sphinx-build" ,python-sphinx)))
211 (home-page (package-home-page python-cffi))
212 (synopsis "Documentation for the Python CFFI interface")
213 (description
214 "This package contains HTML documentation for the @code{python-cffi}
215 project.")
216 (license (package-license python-cffi))))
217
218 (define-public ruby-ffi
219 (package
220 (name "ruby-ffi")
221 (version "1.12.2")
222 (source (origin
223 ;; Pull from git because the RubyGems release bundles LibFFI,
224 ;; and comes with a gemspec that makes it difficult to unbundle.
225 (method git-fetch)
226 (uri (git-reference
227 (url "https://github.com/ffi/ffi")
228 (commit version)))
229 (file-name (git-file-name name version))
230 (sha256
231 (base32
232 "1cvqsbjr2gfjgqggq9kdx90qhhzr7qkyr9wmxdsfsik6cnxnnpmd"))))
233 (build-system ruby-build-system)
234 (arguments
235 `(#:phases
236 (modify-phases %standard-phases
237 (add-after 'unpack 'do-not-depend-on-ccache
238 (lambda _
239 (substitute* "spec/ffi/fixtures/GNUmakefile"
240 (("^CCACHE := .*")
241 ""))
242 #t))
243 (replace 'replace-git-ls-files
244 (lambda _
245 ;; Do not try to execute git, or include the (un)bundled LibFFI.
246 (substitute* "ffi.gemspec"
247 (("git ls-files -z")
248 "find * -type f -print0 | sort -z")
249 (("lfs \\+?= .*")
250 "lfs = []\n"))
251 (substitute* "Rakefile"
252 (("LIBFFI_GIT_FILES = .*")
253 "LIBFFI_GIT_FILES = []\n"))
254 #t))
255 (replace 'build
256 (lambda _
257 ;; Tests depend on the native extensions, so we build it
258 ;; beforehand without going through the gem machinery.
259 (invoke "rake" "compile")
260
261 ;; XXX: Ideally we'd use "rake native gem" here to prevent the
262 ;; install phase from needlessly rebuilding everything, but that
263 ;; requires the bundled LibFFI, and the install phase can not
264 ;; deal with such gems anyway.
265 (invoke "gem" "build" "ffi.gemspec")))
266 (replace 'check
267 (lambda* (#:key tests? #:allow-other-keys)
268 (if tests?
269 (begin
270 (setenv "MAKE" "make")
271 (setenv "CC" "gcc")
272 (invoke "rspec" "spec"))
273 (format #t "test suite not run~%"))
274 #t)))))
275 (native-inputs
276 `(("ruby-rake-compiler" ,ruby-rake-compiler)
277 ("ruby-rspec" ,ruby-rspec)
278 ("ruby-rubygems-tasks" ,ruby-rubygems-tasks)))
279 (inputs
280 `(("libffi" ,libffi)))
281 (synopsis "Ruby foreign function interface library")
282 (description "Ruby-FFI is a Ruby extension for programmatically loading
283 dynamic libraries, binding functions within them, and calling those functions
284 from Ruby code. Moreover, a Ruby-FFI extension works without changes on Ruby
285 and JRuby.")
286 (home-page "https://wiki.github.com/ffi/ffi")
287 (license bsd-3)))