Merge branch 'master' into ungrafting
[jackhill/guix/guix.git] / gnu / packages / libffi.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2020 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://sources.redhat.com/libffi/")
107
108 ;; See <https://github.com/atgreen/libffi/blob/master/LICENSE>.
109 (license expat)))
110
111 (define-public python-cffi
112 (package
113 (name "python-cffi")
114 (version "1.14.0")
115 (source
116 (origin
117 (method url-fetch)
118 (uri (pypi-uri "cffi" version))
119 (sha256
120 (base32 "1dn279gw5ql8i5n3s5v4rnv96rhhjjfn7xq729qbl5bs2954yf1d"))))
121 (build-system python-build-system)
122 (inputs
123 `(("libffi" ,libffi)))
124 (propagated-inputs ; required at run-time
125 `(("python-pycparser" ,python-pycparser)))
126 (native-inputs
127 `(("pkg-config" ,pkg-config)
128 ("python-pytest" ,python-pytest)))
129 (arguments
130 `(#:modules ((ice-9 ftw)
131 (srfi srfi-26)
132 (guix build utils)
133 (guix build python-build-system))
134 #:phases
135 (modify-phases %standard-phases
136 (replace 'check
137 (lambda _
138 (setenv "PYTHONPATH"
139 (string-append
140 (getenv "PYTHONPATH")
141 ":" (getcwd) "/build/"
142 (car (scandir "build" (cut string-prefix? "lib." <>)))))
143
144 ;; XXX The "normal" approach of setting CC and friends does
145 ;; not work here. Is this the correct way of doing things?
146 (substitute* "testing/embedding/test_basic.py"
147 (("c = distutils\\.ccompiler\\.new_compiler\\(\\)")
148 (string-append "c = distutils.ccompiler.new_compiler();"
149 "c.set_executables(compiler='gcc',"
150 "compiler_so='gcc',linker_exe='gcc',"
151 "linker_so='gcc -shared')")))
152 (substitute* "testing/cffi0/test_ownlib.py"
153 (("\"cc testownlib") "\"gcc testownlib"))
154 (invoke "py.test" "-v" "c/" "testing/")
155 #t))
156 (add-before 'check 'patch-paths-of-dynamically-loaded-libraries
157 (lambda* (#:key inputs #:allow-other-keys)
158 ;; Shared libraries should be referred by their absolute path as
159 ;; using find_library or the like with their name fail when the
160 ;; resolved .so object is a linker script rather than an ELF
161 ;; binary (this is a limitation of the ctype library of Python).
162 (let* ((glibc (assoc-ref inputs "libc"))
163 (libm (string-append glibc "/lib/libm.so.6"))
164 (libc (string-append glibc "/lib/libc.so.6")))
165 (substitute* '("testing/cffi0/test_function.py"
166 "testing/cffi0/test_parsing.py"
167 "testing/cffi0/test_unicode_literals.py"
168 "testing/cffi0/test_zdistutils.py"
169 "testing/cffi1/test_recompiler.py")
170 (("lib_m = ['\"]{1}m['\"]{1}")
171 (format #f "lib_m = '~a'" libm)))
172 (substitute* '("testing/cffi0/test_verify.py"
173 "testing/cffi1/test_verify1.py")
174 (("lib_m = \\[['\"]{1}m['\"]{1}\\]")
175 (format #f "lib_m = ['~a']" libm)))
176 (substitute* "c/test_c.py"
177 (("find_and_load_library\\(['\"]{1}c['\"]{1}")
178 (format #f "find_and_load_library('~a'" libc)))
179 #t))))))
180 (home-page "https://cffi.readthedocs.io/")
181 (synopsis "Foreign function interface for Python")
182 (description "Foreign Function Interface for Python calling C code.")
183 (license expat)))
184
185 (define-public python2-cffi
186 (package-with-python2 python-cffi))
187
188 (define-public python-cffi-documentation
189 (package
190 (name "python-cffi-documentation")
191 (version (package-version python-cffi))
192 (source (package-source python-cffi))
193 (build-system gnu-build-system)
194 (arguments
195 `(#:tests? #f
196 #:phases (modify-phases %standard-phases
197 (add-after 'unpack 'chdir
198 (lambda _ (chdir "doc") #t))
199 (delete 'configure)
200 (replace 'build
201 (lambda* (#:key (make-flags '()) #:allow-other-keys)
202 (apply invoke "make" "html" make-flags)))
203 (replace 'install
204 (lambda* (#:key outputs #:allow-other-keys)
205 (let ((out (assoc-ref outputs "out")))
206 (copy-recursively "build/html" (string-append out "/html"))
207 #t))))))
208 (native-inputs
209 `(("sphinx-build" ,python-sphinx)))
210 (home-page (package-home-page python-cffi))
211 (synopsis "Documentation for the Python CFFI interface")
212 (description
213 "This package contains HTML documentation for the @code{python-cffi}
214 project.")
215 (license (package-license python-cffi))))
216
217 (define-public ruby-ffi
218 (package
219 (name "ruby-ffi")
220 (version "1.12.2")
221 (source (origin
222 ;; Pull from git because the RubyGems release bundles LibFFI,
223 ;; and comes with a gemspec that makes it difficult to unbundle.
224 (method git-fetch)
225 (uri (git-reference
226 (url "https://github.com/ffi/ffi")
227 (commit version)))
228 (file-name (git-file-name name version))
229 (sha256
230 (base32
231 "1cvqsbjr2gfjgqggq9kdx90qhhzr7qkyr9wmxdsfsik6cnxnnpmd"))))
232 (build-system ruby-build-system)
233 (arguments
234 `(#:phases
235 (modify-phases %standard-phases
236 (add-after 'unpack 'do-not-depend-on-ccache
237 (lambda _
238 (substitute* "spec/ffi/fixtures/GNUmakefile"
239 (("^CCACHE := .*")
240 ""))
241 #t))
242 (replace 'replace-git-ls-files
243 (lambda _
244 ;; Do not try to execute git, or include the (un)bundled LibFFI.
245 (substitute* "ffi.gemspec"
246 (("git ls-files -z")
247 "find * -type f -print0 | sort -z")
248 (("lfs \\+?= .*")
249 "lfs = []\n"))
250 (substitute* "Rakefile"
251 (("LIBFFI_GIT_FILES = .*")
252 "LIBFFI_GIT_FILES = []\n"))
253 #t))
254 (replace 'build
255 (lambda _
256 ;; Tests depend on the native extensions, so we build it
257 ;; beforehand without going through the gem machinery.
258 (invoke "rake" "compile")
259
260 ;; XXX: Ideally we'd use "rake native gem" here to prevent the
261 ;; install phase from needlessly rebuilding everything, but that
262 ;; requires the bundled LibFFI, and the install phase can not
263 ;; deal with such gems anyway.
264 (invoke "gem" "build" "ffi.gemspec")))
265 (replace 'check
266 (lambda* (#:key tests? #:allow-other-keys)
267 (if tests?
268 (begin
269 (setenv "MAKE" "make")
270 (setenv "CC" "gcc")
271 (invoke "rspec" "spec"))
272 (format #t "test suite not run~%"))
273 #t)))))
274 (native-inputs
275 `(("ruby-rake-compiler" ,ruby-rake-compiler)
276 ("ruby-rspec" ,ruby-rspec)
277 ("ruby-rubygems-tasks" ,ruby-rubygems-tasks)))
278 (inputs
279 `(("libffi" ,libffi)))
280 (synopsis "Ruby foreign function interface library")
281 (description "Ruby-FFI is a Ruby extension for programmatically loading
282 dynamic libraries, binding functions within them, and calling those functions
283 from Ruby code. Moreover, a Ruby-FFI extension works without changes on Ruby
284 and JRuby.")
285 (home-page "https://wiki.github.com/ffi/ffi")
286 (license bsd-3)))