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 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 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 ruby)
34 #:use-module (guix build-system gnu)
35 #:use-module (guix build-system python)
36 #:use-module (guix build-system ruby))
37
38 (define-public libffi
39 (package
40 (name "libffi")
41 (version "3.2.1")
42 (source (origin
43 (method url-fetch)
44 (uri
45 (string-append "ftp://sourceware.org/pub/libffi/"
46 name "-" version ".tar.gz"))
47 (sha256
48 (base32
49 "0dya49bnhianl0r65m65xndz6ls2jn1xngyn72gd28ls3n7bnvnh"))
50 (patches (search-patches "libffi-3.2.1-complex-alpha.patch"))))
51 (build-system gnu-build-system)
52 (arguments
53 `(#:phases
54 (modify-phases %standard-phases
55 (add-after 'install 'post-install
56 (lambda* (#:key outputs #:allow-other-keys)
57 (define out (assoc-ref outputs "out"))
58 (symlink (string-append out "/lib/libffi-3.2.1/include")
59 (string-append out "/include"))
60 #t)))))
61 (outputs '("out" "debug"))
62 (synopsis "Foreign function call interface library")
63 (description
64 "The libffi library provides a portable, high level programming interface
65 to various calling conventions. This allows a programmer to call any
66 function specified by a call interface description at run-time.
67
68 FFI stands for Foreign Function Interface. A foreign function interface is
69 the popular name for the interface that allows code written in one language
70 to call code written in another language. The libffi library really only
71 provides the lowest, machine dependent layer of a fully featured foreign
72 function interface. A layer must exist above libffi that handles type
73 conversions for values passed between the two languages.")
74 (home-page "http://sources.redhat.com/libffi/")
75
76 ;; See <https://github.com/atgreen/libffi/blob/master/LICENSE>.
77 (license expat)))
78
79 (define-public python-cffi
80 (package
81 (name "python-cffi")
82 (version "1.11.4")
83 (source
84 (origin
85 (method url-fetch)
86 (uri (pypi-uri "cffi" version))
87 (sha256
88 (base32 "07fiy4wqg8g08x38r04ydjr8n6g0g74gb8si8b6jhymijalq746z"))))
89 (build-system python-build-system)
90 (outputs '("out" "doc"))
91 (inputs
92 `(("libffi" ,libffi)))
93 (propagated-inputs ; required at run-time
94 `(("python-pycparser" ,python-pycparser)))
95 (native-inputs
96 `(("pkg-config" ,pkg-config)
97 ("python-sphinx" ,python-sphinx)
98 ("python-pytest" ,python-pytest)))
99 (arguments
100 `(#:modules ((ice-9 ftw)
101 (srfi srfi-26)
102 (guix build utils)
103 (guix build python-build-system))
104 #:phases
105 (modify-phases %standard-phases
106 (replace 'check
107 (lambda _
108 (setenv "PYTHONPATH"
109 (string-append
110 (getenv "PYTHONPATH")
111 ":" (getcwd) "/build/"
112 (car (scandir "build" (cut string-prefix? "lib." <>)))))
113
114 ;; XXX The "normal" approach of setting CC and friends does
115 ;; not work here. Is this the correct way of doing things?
116 (substitute* "testing/embedding/test_basic.py"
117 (("c = distutils\\.ccompiler\\.new_compiler\\(\\)")
118 (string-append "c = distutils.ccompiler.new_compiler();"
119 "c.set_executables(compiler='gcc',"
120 "compiler_so='gcc',linker_exe='gcc',"
121 "linker_so='gcc -shared')")))
122 (substitute* "testing/cffi0/test_ownlib.py"
123 (("'cc testownlib") "'gcc testownlib"))
124 (invoke "py.test" "-v" "c/" "testing/")
125 #t))
126 (add-before 'check 'disable-failing-test
127 ;; This is assumed to be a libffi issue:
128 ;; https://bitbucket.org/cffi/cffi/issues/312/tests-failed-with-armv8
129 (lambda _
130 (substitute* "testing/cffi0/test_ownlib.py"
131 (("ret.left") "ownlib.left"))
132 #t))
133 (add-after 'install 'install-doc
134 (lambda* (#:key outputs (make-flags '()) #:allow-other-keys)
135 (let* ((doc (string-append (assoc-ref outputs "doc")
136 "/share/doc/" ,name "-" ,version))
137 (html (string-append doc "/html")))
138 (with-directory-excursion "doc"
139 (apply invoke "make" "html" make-flags)
140 (mkdir-p html)
141 (copy-recursively "build/html" html))
142 #t))))))
143 (home-page "https://cffi.readthedocs.org")
144 (synopsis "Foreign function interface for Python")
145 (description
146 "Foreign Function Interface for Python calling C code.")
147 (license expat)))
148
149 (define-public python2-cffi
150 (package-with-python2 python-cffi))
151
152 (define-public ruby-ffi
153 (package
154 (name "ruby-ffi")
155 (version "1.9.22")
156 (source (origin
157 (method url-fetch)
158 (uri (rubygems-uri "ffi" version))
159 (sha256
160 (base32
161 "17lvnpmllg4mlzf25lxbmfzk4l6rsddlxwwdkbs4d9v5gv154529"))))
162 (build-system ruby-build-system)
163 ;; FIXME: Before running tests the build system attempts to build libffi
164 ;; from sources.
165 (arguments `(#:tests? #f))
166 (native-inputs
167 `(("ruby-rake-compiler" ,ruby-rake-compiler)
168 ("ruby-rspec" ,ruby-rspec)
169 ("ruby-rubygems-tasks" ,ruby-rubygems-tasks)))
170 (inputs
171 `(("libffi" ,libffi)))
172 (synopsis "Ruby foreign function interface library")
173 (description "Ruby-FFI is a Ruby extension for programmatically loading
174 dynamic libraries, binding functions within them, and calling those functions
175 from Ruby code. Moreover, a Ruby-FFI extension works without changes on Ruby
176 and JRuby.")
177 (home-page "http://wiki.github.com/ffi/ffi")
178 (license bsd-3)))