gnu: icecat: Update to 78.10.0-guix0-preview1 [security fixes].
[jackhill/guix/guix.git] / gnu / packages / libffi.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
b6e5eb4d 2;;; Copyright © 2012, 2013, 2014, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
0751fddd 3;;; Copyright © 2014 Federico Beffa <beffa@fbengineering.ch>
d47e99e0 4;;; Copyright © 2015, 2019 Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de>
02f5ee01 5;;; Copyright © 2016, 2017, 2020 Efraim Flashner <efraim@flashner.co.il>
838b232e 6;;; Copyright © 2016, 2017 Ben Woodcroft <donttrustben@gmail.com>
075afce2 7;;; Copyright © 2017, 2019, 2020 Marius Bakke <marius@gnu.org>
667e6f1e 8;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
4e933afd 9;;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
7eaa2f24 10;;; Copyright © 2020 John Doe <dftxbs3e@free.fr>
c44899a2 11;;;
233e7676 12;;; This file is part of GNU Guix.
c44899a2 13;;;
233e7676 14;;; GNU Guix is free software; you can redistribute it and/or modify it
c44899a2
LC
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;;;
233e7676 19;;; GNU Guix is distributed in the hope that it will be useful, but
c44899a2
LC
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
233e7676 25;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
c44899a2 26
1ffa7090 27(define-module (gnu packages libffi)
1602fcea 28 #:use-module (gnu packages)
4a44e743 29 #:use-module (guix licenses)
c44899a2 30 #:use-module (guix packages)
87f5d366 31 #:use-module (guix download)
075afce2 32 #:use-module (guix git-download)
ac257f12 33 #:use-module (gnu packages check)
0751fddd
EF
34 #:use-module (gnu packages pkg-config)
35 #:use-module (gnu packages python)
44d10b1f 36 #:use-module (gnu packages python-xyz)
838b232e 37 #:use-module (gnu packages ruby)
9d0c291e 38 #:use-module (gnu packages sphinx)
0751fddd 39 #:use-module (guix build-system gnu)
838b232e
EF
40 #:use-module (guix build-system python)
41 #:use-module (guix build-system ruby))
c44899a2
LC
42
43(define-public libffi
667e6f1e 44 (package
c44899a2 45 (name "libffi")
5f1000d5 46 (version "3.3")
c44899a2 47 (source (origin
667e6f1e
TGR
48 (method url-fetch)
49 (uri
50 (string-append "ftp://sourceware.org/pub/libffi/"
51 name "-" version ".tar.gz"))
52 (sha256
53 (base32
5f1000d5 54 "0mi0cpf8aa40ljjmzxb7im6dbj45bb0kllcd09xgmp834y9agyvj"))))
c44899a2 55 (build-system gnu-build-system)
667e6f1e 56 (arguments
1935b8d5
MB
57 `(;; Prevent the build system from passing -march and -mtune to the
58 ;; compiler. See "ax_cc_maxopt.m4" and "ax_gcc_archflag.m4".
02f5ee01
EF
59 #:configure-flags '("--enable-portable-binary" "--without-gcc-arch")
60
7eaa2f24 61 ;; TODO: Inline patches on next rebuild cycle.
02f5ee01
EF
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")))
662e7e28 69 (invoke "patch" "--force" "-p1"
02f5ee01 70 "-i" patch))))))
7eaa2f24
JD
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")))
fdb90e9e 79 (invoke "patch" "--force" "-p1"
7eaa2f24 80 "-i" patch))))))
02f5ee01
EF
81 '())))
82 (inputs
7eaa2f24
JD
83 (cond
84 ((string-prefix? "powerpc-" (or (%current-target-system)
02f5ee01 85 (%current-system)))
7eaa2f24
JD
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 '())))
9bf62d9b 93 (outputs '("out" "debug"))
089b0634 94 (synopsis "Foreign function call interface library")
c44899a2
LC
95 (description
96 "The libffi library provides a portable, high level programming interface
97to various calling conventions. This allows a programmer to call any
98function specified by a call interface description at run-time.
99
100FFI stands for Foreign Function Interface. A foreign function interface is
101the popular name for the interface that allows code written in one language
102to call code written in another language. The libffi library really only
103provides the lowest, machine dependent layer of a fully featured foreign
104function interface. A layer must exist above libffi that handles type
105conversions for values passed between the two languages.")
b6e5eb4d
LC
106 (home-page "http://www.sourceware.org/libffi/")
107 (properties `((release-monitoring-url . ,home-page)))
c44899a2 108
7bf837fd 109 ;; See <https://github.com/atgreen/libffi/blob/master/LICENSE>.
667e6f1e 110 (license expat)))
c44899a2 111
0751fddd
EF
112(define-public python-cffi
113 (package
114 (name "python-cffi")
d50a2d91 115 (version "1.14.4")
0751fddd
EF
116 (source
117 (origin
118 (method url-fetch)
119 (uri (pypi-uri "cffi" version))
120 (sha256
d50a2d91 121 (base32 "0v080s7vlrjz9z823x2yh36yc8drwpvvir6w8wfkkzd7k2z5qihs"))))
0751fddd 122 (build-system python-build-system)
0751fddd
EF
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)
0751fddd
EF
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"
41fdad9f 154 (("\"cc testownlib") "\"gcc testownlib"))
fc38e317
TGR
155 (invoke "py.test" "-v" "c/" "testing/")
156 #t))
4e933afd
MC
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)))
41fdad9f 180 #t))))))
4e933afd 181 (home-page "https://cffi.readthedocs.io/")
0751fddd 182 (synopsis "Foreign function interface for Python")
4e933afd 183 (description "Foreign Function Interface for Python calling C code.")
0751fddd
EF
184 (license expat)))
185
186(define-public python2-cffi
187 (package-with-python2 python-cffi))
838b232e 188
95dc93da
MB
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}
215project.")
216 (license (package-license python-cffi))))
217
838b232e
EF
218(define-public ruby-ffi
219 (package
220 (name "ruby-ffi")
77209ddd 221 (version "1.12.2")
838b232e 222 (source (origin
075afce2
MB
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))
838b232e
EF
230 (sha256
231 (base32
075afce2 232 "1cvqsbjr2gfjgqggq9kdx90qhhzr7qkyr9wmxdsfsik6cnxnnpmd"))))
838b232e 233 (build-system ruby-build-system)
075afce2
MB
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)))))
838b232e
EF
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
283dynamic libraries, binding functions within them, and calling those functions
284from Ruby code. Moreover, a Ruby-FFI extension works without changes on Ruby
285and JRuby.")
702a1012 286 (home-page "https://wiki.github.com/ffi/ffi")
838b232e 287 (license bsd-3)))