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, 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, 2021 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, 2021 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 (patches (search-patches "libffi-3.3-powerpc-fixes.patch"
56 "libffi-float128-powerpc64le.patch"))))
57 (build-system gnu-build-system)
58 (arguments
59 `(;; Prevent the build system from passing -march and -mtune to the
60 ;; compiler. See "ax_cc_maxopt.m4" and "ax_gcc_archflag.m4".
61 #:configure-flags '("--enable-portable-binary"
62 "--without-gcc-arch")))
63 (outputs '("out" "debug"))
64 (synopsis "Foreign function call interface library")
65 (description
66 "The libffi library provides a portable, high level programming interface
67 to various calling conventions. This allows a programmer to call any
68 function specified by a call interface description at run-time.
69
70 FFI stands for Foreign Function Interface. A foreign function interface is
71 the popular name for the interface that allows code written in one language
72 to call code written in another language. The libffi library really only
73 provides the lowest, machine dependent layer of a fully featured foreign
74 function interface. A layer must exist above libffi that handles type
75 conversions for values passed between the two languages.")
76 (home-page "http://www.sourceware.org/libffi/")
77 (properties `((release-monitoring-url . ,home-page)))
78
79 ;; See <https://github.com/atgreen/libffi/blob/master/LICENSE>.
80 (license expat)))
81
82 (define-public python-cffi
83 (package
84 (name "python-cffi")
85 (version "1.14.4")
86 (source
87 (origin
88 (method url-fetch)
89 (uri (pypi-uri "cffi" version))
90 (sha256
91 (base32 "0v080s7vlrjz9z823x2yh36yc8drwpvvir6w8wfkkzd7k2z5qihs"))))
92 (build-system python-build-system)
93 (inputs
94 `(("libffi" ,libffi)))
95 (propagated-inputs ; required at run-time
96 `(("python-pycparser" ,python-pycparser)))
97 (native-inputs
98 `(("pkg-config" ,pkg-config)
99 ("python-pytest" ,python-pytest)))
100 (arguments
101 `(#:phases
102 (modify-phases %standard-phases
103 (replace 'check
104 (lambda _
105 ;; XXX The "normal" approach of setting CC and friends does
106 ;; not work here. Is this the correct way of doing things?
107 (substitute* "testing/embedding/test_basic.py"
108 (("c = distutils\\.ccompiler\\.new_compiler\\(\\)")
109 (string-append "c = distutils.ccompiler.new_compiler();"
110 "c.set_executables(compiler='gcc',"
111 "compiler_so='gcc',linker_exe='gcc',"
112 "linker_so='gcc -shared')")))
113 (substitute* "testing/cffi0/test_ownlib.py"
114 (("\"cc testownlib") "\"gcc testownlib"))
115 (invoke "py.test" "-v" "c/" "testing/")))
116 (add-before 'check 'patch-paths-of-dynamically-loaded-libraries
117 (lambda* (#:key inputs #:allow-other-keys)
118 ;; Shared libraries should be referred by their absolute path as
119 ;; using find_library or the like with their name fail when the
120 ;; resolved .so object is a linker script rather than an ELF
121 ;; binary (this is a limitation of the ctype library of Python).
122 (let* ((glibc (assoc-ref inputs "libc"))
123 (libm (string-append glibc "/lib/libm.so.6"))
124 (libc (string-append glibc "/lib/libc.so.6")))
125 (substitute* '("testing/cffi0/test_function.py"
126 "testing/cffi0/test_parsing.py"
127 "testing/cffi0/test_unicode_literals.py"
128 "testing/cffi0/test_zdistutils.py"
129 "testing/cffi1/test_recompiler.py")
130 (("lib_m = ['\"]{1}m['\"]{1}")
131 (format #f "lib_m = '~a'" libm)))
132 (substitute* '("testing/cffi0/test_verify.py"
133 "testing/cffi1/test_verify1.py")
134 (("lib_m = \\[['\"]{1}m['\"]{1}\\]")
135 (format #f "lib_m = ['~a']" libm)))
136 (substitute* "c/test_c.py"
137 (("find_and_load_library\\(['\"]{1}c['\"]{1}")
138 (format #f "find_and_load_library('~a'" libc)))))))))
139 (home-page "https://cffi.readthedocs.io/")
140 (synopsis "Foreign function interface for Python")
141 (description "Foreign Function Interface for Python calling C code.")
142 (license expat)))
143
144 (define-public python2-cffi
145 (package-with-python2 python-cffi))
146
147 (define-public python-cffi-documentation
148 (package
149 (name "python-cffi-documentation")
150 (version (package-version python-cffi))
151 (source (package-source python-cffi))
152 (build-system gnu-build-system)
153 (arguments
154 `(#:tests? #f
155 #:phases (modify-phases %standard-phases
156 (add-after 'unpack 'chdir
157 (lambda _ (chdir "doc") #t))
158 (delete 'configure)
159 (replace 'build
160 (lambda* (#:key (make-flags '()) #:allow-other-keys)
161 (apply invoke "make" "html" make-flags)))
162 (replace 'install
163 (lambda* (#:key outputs #:allow-other-keys)
164 (let ((out (assoc-ref outputs "out")))
165 (copy-recursively "build/html" (string-append out "/html"))
166 #t))))))
167 (native-inputs
168 `(("sphinx-build" ,python-sphinx)))
169 (home-page (package-home-page python-cffi))
170 (synopsis "Documentation for the Python CFFI interface")
171 (description
172 "This package contains HTML documentation for the @code{python-cffi}
173 project.")
174 (license (package-license python-cffi))))
175
176 (define-public ruby-ffi
177 (package
178 (name "ruby-ffi")
179 (version "1.12.2")
180 (source (origin
181 ;; Pull from git because the RubyGems release bundles LibFFI,
182 ;; and comes with a gemspec that makes it difficult to unbundle.
183 (method git-fetch)
184 (uri (git-reference
185 (url "https://github.com/ffi/ffi")
186 (commit version)))
187 (file-name (git-file-name name version))
188 (sha256
189 (base32
190 "1cvqsbjr2gfjgqggq9kdx90qhhzr7qkyr9wmxdsfsik6cnxnnpmd"))))
191 (build-system ruby-build-system)
192 (arguments
193 `(#:phases
194 (modify-phases %standard-phases
195 (add-after 'unpack 'do-not-depend-on-ccache
196 (lambda _
197 (substitute* "spec/ffi/fixtures/GNUmakefile"
198 (("^CCACHE := .*")
199 ""))
200 #t))
201 (replace 'replace-git-ls-files
202 (lambda _
203 ;; Do not try to execute git, or include the (un)bundled LibFFI.
204 (substitute* "ffi.gemspec"
205 (("git ls-files -z")
206 "find * -type f -print0 | sort -z")
207 (("lfs \\+?= .*")
208 "lfs = []\n"))
209 (substitute* "Rakefile"
210 (("LIBFFI_GIT_FILES = .*")
211 "LIBFFI_GIT_FILES = []\n"))
212 #t))
213 (replace 'build
214 (lambda _
215 ;; Tests depend on the native extensions, so we build it
216 ;; beforehand without going through the gem machinery.
217 (invoke "rake" "compile")
218
219 ;; XXX: Ideally we'd use "rake native gem" here to prevent the
220 ;; install phase from needlessly rebuilding everything, but that
221 ;; requires the bundled LibFFI, and the install phase can not
222 ;; deal with such gems anyway.
223 (invoke "gem" "build" "ffi.gemspec")))
224 (replace 'check
225 (lambda* (#:key tests? #:allow-other-keys)
226 (if tests?
227 (begin
228 (setenv "MAKE" "make")
229 (setenv "CC" "gcc")
230 (invoke "rspec" "spec"))
231 (format #t "test suite not run~%"))
232 #t)))))
233 (native-inputs
234 `(("ruby-rake-compiler" ,ruby-rake-compiler)
235 ("ruby-rspec" ,ruby-rspec)
236 ("ruby-rubygems-tasks" ,ruby-rubygems-tasks)))
237 (inputs
238 `(("libffi" ,libffi)))
239 (synopsis "Ruby foreign function interface library")
240 (description "Ruby-FFI is a Ruby extension for programmatically loading
241 dynamic libraries, binding functions within them, and calling those functions
242 from Ruby code. Moreover, a Ruby-FFI extension works without changes on Ruby
243 and JRuby.")
244 (home-page "https://wiki.github.com/ffi/ffi")
245 (license bsd-3)))