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 Efraim Flashner <efraim@flashner.co.il>
6 ;;; Copyright © 2016, 2017 Ben Woodcroft <donttrustben@gmail.com>
7 ;;; Copyright © 2017, 2019 Marius Bakke <mbakke@fastmail.com>
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 (gnu packages check)
32 #:use-module (gnu packages pkg-config)
33 #:use-module (gnu packages python)
34 #:use-module (gnu packages python-xyz)
35 #:use-module (gnu packages ruby)
36 #:use-module (gnu packages sphinx)
37 #:use-module (guix build-system gnu)
38 #:use-module (guix build-system python)
39 #:use-module (guix build-system ruby))
40
41 (define-public libffi
42 (package
43 (name "libffi")
44 (version "3.3")
45 (source (origin
46 (method url-fetch)
47 (uri
48 (string-append "ftp://sourceware.org/pub/libffi/"
49 name "-" version ".tar.gz"))
50 (sha256
51 (base32
52 "0mi0cpf8aa40ljjmzxb7im6dbj45bb0kllcd09xgmp834y9agyvj"))))
53 (build-system gnu-build-system)
54 (arguments
55 `(;; Prevent the build system from passing -march and -mtune to the
56 ;; compiler. See "ax_cc_maxopt.m4" and "ax_gcc_archflag.m4".
57 #:configure-flags '("--enable-portable-binary" "--without-gcc-arch")))
58 (outputs '("out" "debug"))
59 (synopsis "Foreign function call interface library")
60 (description
61 "The libffi library provides a portable, high level programming interface
62 to various calling conventions. This allows a programmer to call any
63 function specified by a call interface description at run-time.
64
65 FFI stands for Foreign Function Interface. A foreign function interface is
66 the popular name for the interface that allows code written in one language
67 to call code written in another language. The libffi library really only
68 provides the lowest, machine dependent layer of a fully featured foreign
69 function interface. A layer must exist above libffi that handles type
70 conversions for values passed between the two languages.")
71 (home-page "http://sources.redhat.com/libffi/")
72
73 ;; See <https://github.com/atgreen/libffi/blob/master/LICENSE>.
74 (license expat)))
75
76 (define-public python-cffi
77 (package
78 (name "python-cffi")
79 (version "1.13.2")
80 (source
81 (origin
82 (method url-fetch)
83 (uri (pypi-uri "cffi" version))
84 (sha256
85 (base32 "0iikq5rn9a405n94c7s2j6kq3jv5qs9q4xyik8657b2py27ix6jr"))))
86 (build-system python-build-system)
87 (inputs
88 `(("libffi" ,libffi)))
89 (propagated-inputs ; required at run-time
90 `(("python-pycparser" ,python-pycparser)))
91 (native-inputs
92 `(("pkg-config" ,pkg-config)
93 ("python-pytest" ,python-pytest)))
94 (arguments
95 `(#:modules ((ice-9 ftw)
96 (srfi srfi-26)
97 (guix build utils)
98 (guix build python-build-system))
99 #:phases
100 (modify-phases %standard-phases
101 (replace 'check
102 (lambda _
103 (setenv "PYTHONPATH"
104 (string-append
105 (getenv "PYTHONPATH")
106 ":" (getcwd) "/build/"
107 (car (scandir "build" (cut string-prefix? "lib." <>)))))
108
109 ;; XXX The "normal" approach of setting CC and friends does
110 ;; not work here. Is this the correct way of doing things?
111 (substitute* "testing/embedding/test_basic.py"
112 (("c = distutils\\.ccompiler\\.new_compiler\\(\\)")
113 (string-append "c = distutils.ccompiler.new_compiler();"
114 "c.set_executables(compiler='gcc',"
115 "compiler_so='gcc',linker_exe='gcc',"
116 "linker_so='gcc -shared')")))
117 (substitute* "testing/cffi0/test_ownlib.py"
118 (("\"cc testownlib") "\"gcc testownlib"))
119 (invoke "py.test" "-v" "c/" "testing/")
120 #t))
121 (add-before 'check 'patch-paths-of-dynamically-loaded-libraries
122 (lambda* (#:key inputs #:allow-other-keys)
123 ;; Shared libraries should be referred by their absolute path as
124 ;; using find_library or the like with their name fail when the
125 ;; resolved .so object is a linker script rather than an ELF
126 ;; binary (this is a limitation of the ctype library of Python).
127 (let* ((glibc (assoc-ref inputs "libc"))
128 (libm (string-append glibc "/lib/libm.so.6"))
129 (libc (string-append glibc "/lib/libc.so.6")))
130 (substitute* '("testing/cffi0/test_function.py"
131 "testing/cffi0/test_parsing.py"
132 "testing/cffi0/test_unicode_literals.py"
133 "testing/cffi0/test_zdistutils.py"
134 "testing/cffi1/test_recompiler.py")
135 (("lib_m = ['\"]{1}m['\"]{1}")
136 (format #f "lib_m = '~a'" libm)))
137 (substitute* '("testing/cffi0/test_verify.py"
138 "testing/cffi1/test_verify1.py")
139 (("lib_m = \\[['\"]{1}m['\"]{1}\\]")
140 (format #f "lib_m = ['~a']" libm)))
141 (substitute* "c/test_c.py"
142 (("find_and_load_library\\(['\"]{1}c['\"]{1}")
143 (format #f "find_and_load_library('~a'" libc)))
144 #t))))))
145 (home-page "https://cffi.readthedocs.io/")
146 (synopsis "Foreign function interface for Python")
147 (description "Foreign Function Interface for Python calling C code.")
148 (license expat)))
149
150 (define-public python2-cffi
151 (package-with-python2 python-cffi))
152
153 (define-public python-cffi-documentation
154 (package
155 (name "python-cffi-documentation")
156 (version (package-version python-cffi))
157 (source (package-source python-cffi))
158 (build-system gnu-build-system)
159 (arguments
160 `(#:tests? #f
161 #:phases (modify-phases %standard-phases
162 (add-after 'unpack 'chdir
163 (lambda _ (chdir "doc") #t))
164 (delete 'configure)
165 (replace 'build
166 (lambda* (#:key (make-flags '()) #:allow-other-keys)
167 (apply invoke "make" "html" make-flags)))
168 (replace 'install
169 (lambda* (#:key outputs #:allow-other-keys)
170 (let ((out (assoc-ref outputs "out")))
171 (copy-recursively "build/html" (string-append out "/html"))
172 #t))))))
173 (native-inputs
174 `(("sphinx-build" ,python-sphinx)))
175 (home-page (package-home-page python-cffi))
176 (synopsis "Documentation for the Python CFFI interface")
177 (description
178 "This package contains HTML documentation for the @code{python-cffi}
179 project.")
180 (license (package-license python-cffi))))
181
182 (define-public ruby-ffi
183 (package
184 (name "ruby-ffi")
185 (version "1.10.0")
186 (source (origin
187 (method url-fetch)
188 (uri (rubygems-uri "ffi" version))
189 (sha256
190 (base32
191 "0j8pzj8raxbir5w5k6s7a042sb5k02pg0f8s4na1r5lan901j00p"))))
192 (build-system ruby-build-system)
193 ;; FIXME: Before running tests the build system attempts to build libffi
194 ;; from sources.
195 (arguments `(#:tests? #f))
196 (native-inputs
197 `(("ruby-rake-compiler" ,ruby-rake-compiler)
198 ("ruby-rspec" ,ruby-rspec)
199 ("ruby-rubygems-tasks" ,ruby-rubygems-tasks)))
200 (inputs
201 `(("libffi" ,libffi)))
202 (synopsis "Ruby foreign function interface library")
203 (description "Ruby-FFI is a Ruby extension for programmatically loading
204 dynamic libraries, binding functions within them, and calling those functions
205 from Ruby code. Moreover, a Ruby-FFI extension works without changes on Ruby
206 and JRuby.")
207 (home-page "http://wiki.github.com/ffi/ffi")
208 (license bsd-3)))