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