gnu: gf2x: Update to 1.3.0.
[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, 2022 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 (list libffi))
95 (propagated-inputs ; required at run-time
96 (list python-pycparser))
97 (native-inputs
98 (list pkg-config python-pytest))
99 (arguments
100 `(#:phases
101 (modify-phases %standard-phases
102 (replace 'check
103 (lambda _
104 ;; XXX The "normal" approach of setting CC and friends does
105 ;; not work here. Is this the correct way of doing things?
106 (substitute* "testing/embedding/test_basic.py"
107 (("c = distutils\\.ccompiler\\.new_compiler\\(\\)")
108 (string-append "c = distutils.ccompiler.new_compiler();"
109 "c.set_executables(compiler='gcc',"
110 "compiler_so='gcc',linker_exe='gcc',"
111 "linker_so='gcc -shared')")))
112 (substitute* "testing/cffi0/test_ownlib.py"
113 (("\"cc testownlib") "\"gcc testownlib"))
114 (invoke "py.test" "-v" "c/" "testing/")))
115 (add-before 'check 'patch-paths-of-dynamically-loaded-libraries
116 (lambda* (#:key inputs #:allow-other-keys)
117 ;; Shared libraries should be referred by their absolute path as
118 ;; using find_library or the like with their name fail when the
119 ;; resolved .so object is a linker script rather than an ELF
120 ;; binary (this is a limitation of the ctype library of Python).
121 (let* ((glibc (assoc-ref inputs "libc"))
122 (libm (string-append glibc "/lib/libm.so.6"))
123 (libc (string-append glibc "/lib/libc.so.6")))
124 (substitute* '("testing/cffi0/test_function.py"
125 "testing/cffi0/test_parsing.py"
126 "testing/cffi0/test_unicode_literals.py"
127 "testing/cffi0/test_zdistutils.py"
128 "testing/cffi1/test_recompiler.py")
129 (("lib_m = ['\"]{1}m['\"]{1}")
130 (format #f "lib_m = '~a'" libm)))
131 (substitute* '("testing/cffi0/test_verify.py"
132 "testing/cffi1/test_verify1.py")
133 (("lib_m = \\[['\"]{1}m['\"]{1}\\]")
134 (format #f "lib_m = ['~a']" libm)))
135 (substitute* "c/test_c.py"
136 (("find_and_load_library\\(['\"]{1}c['\"]{1}")
137 (format #f "find_and_load_library('~a'" libc)))))))))
138 (home-page "https://cffi.readthedocs.io/")
139 (synopsis "Foreign function interface for Python")
140 (description "Foreign Function Interface for Python calling C code.")
141 (license expat)))
142
143 ;; TODO(staging): Merge with the above.
144 (define-public python-cffi-1.15
145 (package
146 (inherit python-cffi)
147 (version "1.15.0")
148 (source
149 (origin
150 (method url-fetch)
151 (uri (pypi-uri "cffi" version))
152 (sha256
153 (base32 "0m3rz2pqfmyfagx0bhj2jlbr2h58j3wr3cyv1agxkhlnm1k0s3wj"))))))
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.15.5")
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 (string-append "v" version))))
195 (file-name (git-file-name name version))
196 (sha256
197 (base32
198 "1qk55s1zwpdjykwkj9l37m71i5n228i7f8bg3ply3ks9py16m7s6"))))
199 (build-system ruby-build-system)
200 (arguments
201 `(#:phases
202 (modify-phases %standard-phases
203 (replace 'replace-git-ls-files
204 (lambda _
205 ;; Do not try to execute git, or include the (un)bundled LibFFI.
206 (substitute* "ffi.gemspec"
207 (("git ls-files -z")
208 "find * -type f -print0 | sort -z")
209 (("lfs \\+?= .*")
210 "lfs = []\n"))
211 (substitute* "Rakefile"
212 (("git .*ls-files -z")
213 "find * -type f -print0 | sort -z")
214 (("LIBFFI_GIT_FILES = .*")
215 "LIBFFI_GIT_FILES = []\n"))))
216 (replace 'build
217 (lambda _
218 ;; Tests depend on the native extensions, so we build it
219 ;; beforehand without going through the gem machinery.
220 (invoke "rake" "compile")
221
222 ;; XXX: Ideally we'd use "rake native gem" here to prevent the
223 ;; install phase from needlessly rebuilding everything, but that
224 ;; requires the bundled LibFFI, and the install phase can not
225 ;; deal with such gems anyway.
226 (invoke "gem" "build" "ffi.gemspec")))
227 (replace 'check
228 (lambda* (#:key tests? #:allow-other-keys)
229 (if tests?
230 (begin
231 (setenv "MAKE" "make")
232 (setenv "CC" "gcc")
233 (invoke "rspec" "spec"))
234 (format #t "test suite not run~%")))))))
235 (native-inputs
236 (list ruby-rake-compiler ruby-rspec ruby-rubygems-tasks))
237 (inputs
238 (list 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)))