Merge branch 'master' into staging
[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 ;;;
10 ;;; This file is part of GNU Guix.
11 ;;;
12 ;;; GNU Guix is free software; you can redistribute it and/or modify it
13 ;;; under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 3 of the License, or (at
15 ;;; your option) any later version.
16 ;;;
17 ;;; GNU Guix is distributed in the hope that it will be useful, but
18 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;;; GNU General Public License for more details.
21 ;;;
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24
25 (define-module (gnu packages libffi)
26 #:use-module (gnu packages)
27 #:use-module (guix licenses)
28 #:use-module (guix packages)
29 #:use-module (guix download)
30 #:use-module (gnu packages check)
31 #:use-module (gnu packages pkg-config)
32 #:use-module (gnu packages python)
33 #:use-module (gnu packages python-xyz)
34 #:use-module (gnu packages ruby)
35 #:use-module (guix build-system gnu)
36 #:use-module (guix build-system python)
37 #:use-module (guix build-system ruby))
38
39 (define-public libffi
40 (package
41 (name "libffi")
42 (version "3.2.1")
43 (source (origin
44 (method url-fetch)
45 (uri
46 (string-append "ftp://sourceware.org/pub/libffi/"
47 name "-" version ".tar.gz"))
48 (sha256
49 (base32
50 "0dya49bnhianl0r65m65xndz6ls2jn1xngyn72gd28ls3n7bnvnh"))
51 (patches (search-patches "libffi-3.2.1-complex-alpha.patch"))))
52 (build-system gnu-build-system)
53 (arguments
54 `(;; Prevent the build system from passing -march and -mtune to the
55 ;; compiler. See "ax_cc_maxopt.m4" and "ax_gcc_archflag.m4".
56 #:configure-flags '("--enable-portable-binary" "--without-gcc-arch")
57 #:phases
58 (modify-phases %standard-phases
59 (add-after 'install 'post-install
60 (lambda* (#:key outputs #:allow-other-keys)
61 (define out (assoc-ref outputs "out"))
62 (symlink (string-append out "/lib/libffi-3.2.1/include")
63 (string-append out "/include"))
64 #t)))))
65 (outputs '("out" "debug"))
66 (synopsis "Foreign function call interface library")
67 (description
68 "The libffi library provides a portable, high level programming interface
69 to various calling conventions. This allows a programmer to call any
70 function specified by a call interface description at run-time.
71
72 FFI stands for Foreign Function Interface. A foreign function interface is
73 the popular name for the interface that allows code written in one language
74 to call code written in another language. The libffi library really only
75 provides the lowest, machine dependent layer of a fully featured foreign
76 function interface. A layer must exist above libffi that handles type
77 conversions for values passed between the two languages.")
78 (home-page "http://sources.redhat.com/libffi/")
79
80 ;; See <https://github.com/atgreen/libffi/blob/master/LICENSE>.
81 (license expat)))
82
83 (define-public python-cffi
84 (package
85 (name "python-cffi")
86 (version "1.11.5")
87 (source
88 (origin
89 (method url-fetch)
90 (uri (pypi-uri "cffi" version))
91 (sha256
92 (base32 "1x3lrj928dcxx1k8k9gf3s4s3jwvzv8mc3kkyg1g7c3a1sc1f3z9"))
93 (patches (search-patches "python-cffi-x87-stack-clean.patch"))))
94 (build-system python-build-system)
95 (inputs
96 `(("libffi" ,libffi)))
97 (propagated-inputs ; required at run-time
98 `(("python-pycparser" ,python-pycparser)))
99 (native-inputs
100 `(("pkg-config" ,pkg-config)
101 ("python-pytest" ,python-pytest)))
102 (arguments
103 `(#:modules ((ice-9 ftw)
104 (srfi srfi-26)
105 (guix build utils)
106 (guix build python-build-system))
107 #:phases
108 (modify-phases %standard-phases
109 (replace 'check
110 (lambda _
111 (setenv "PYTHONPATH"
112 (string-append
113 (getenv "PYTHONPATH")
114 ":" (getcwd) "/build/"
115 (car (scandir "build" (cut string-prefix? "lib." <>)))))
116
117 ;; XXX The "normal" approach of setting CC and friends does
118 ;; not work here. Is this the correct way of doing things?
119 (substitute* "testing/embedding/test_basic.py"
120 (("c = distutils\\.ccompiler\\.new_compiler\\(\\)")
121 (string-append "c = distutils.ccompiler.new_compiler();"
122 "c.set_executables(compiler='gcc',"
123 "compiler_so='gcc',linker_exe='gcc',"
124 "linker_so='gcc -shared')")))
125 (substitute* "testing/cffi0/test_ownlib.py"
126 (("'cc testownlib") "'gcc testownlib"))
127 (invoke "py.test" "-v" "c/" "testing/")
128 #t))
129 (add-before 'check 'disable-failing-test
130 ;; This is assumed to be a libffi issue:
131 ;; https://bitbucket.org/cffi/cffi/issues/312/tests-failed-with-armv8
132 (lambda _
133 (substitute* "testing/cffi0/test_ownlib.py"
134 (("ret.left") "ownlib.left"))
135 #t)))))
136 (home-page "https://cffi.readthedocs.org")
137 (synopsis "Foreign function interface for Python")
138 (description
139 "Foreign Function Interface for Python calling C code.")
140 (license expat)))
141
142 (define-public python2-cffi
143 (package-with-python2 python-cffi))
144
145 (define-public python-cffi-documentation
146 (package
147 (name "python-cffi-documentation")
148 (version (package-version python-cffi))
149 (source (package-source python-cffi))
150 (build-system gnu-build-system)
151 (arguments
152 `(#:tests? #f
153 #:phases (modify-phases %standard-phases
154 (add-after 'unpack 'chdir
155 (lambda _ (chdir "doc") #t))
156 (delete 'configure)
157 (replace 'build
158 (lambda* (#:key (make-flags '()) #:allow-other-keys)
159 (apply invoke "make" "html" make-flags)))
160 (replace 'install
161 (lambda* (#:key outputs #:allow-other-keys)
162 (let ((out (assoc-ref outputs "out")))
163 (copy-recursively "build/html" (string-append out "/html"))
164 #t))))))
165 (native-inputs
166 `(("sphinx-build" ,python-sphinx)))
167 (home-page (package-home-page python-cffi))
168 (synopsis "Documentation for the Python CFFI interface")
169 (description
170 "This package contains HTML documentation for the @code{python-cffi}
171 project.")
172 (license (package-license python-cffi))))
173
174 (define-public ruby-ffi
175 (package
176 (name "ruby-ffi")
177 (version "1.10.0")
178 (source (origin
179 (method url-fetch)
180 (uri (rubygems-uri "ffi" version))
181 (sha256
182 (base32
183 "0j8pzj8raxbir5w5k6s7a042sb5k02pg0f8s4na1r5lan901j00p"))))
184 (build-system ruby-build-system)
185 ;; FIXME: Before running tests the build system attempts to build libffi
186 ;; from sources.
187 (arguments `(#:tests? #f))
188 (native-inputs
189 `(("ruby-rake-compiler" ,ruby-rake-compiler)
190 ("ruby-rspec" ,ruby-rspec)
191 ("ruby-rubygems-tasks" ,ruby-rubygems-tasks)))
192 (inputs
193 `(("libffi" ,libffi)))
194 (synopsis "Ruby foreign function interface library")
195 (description "Ruby-FFI is a Ruby extension for programmatically loading
196 dynamic libraries, binding functions within them, and calling those functions
197 from Ruby code. Moreover, a Ruby-FFI extension works without changes on Ruby
198 and JRuby.")
199 (home-page "http://wiki.github.com/ffi/ffi")
200 (license bsd-3)))