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 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>
12 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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))
50 (string-append "ftp://sourceware.org/pub/libffi/"
51 name "-" version ".tar.gz"))
54 "0mi0cpf8aa40ljjmzxb7im6dbj45bb0kllcd09xgmp834y9agyvj"))
55 (patches (search-patches "libffi-3.3-powerpc-fixes.patch"
56 "libffi-float128-powerpc64le.patch"))))
57 (build-system gnu-build-system)
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")
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.
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)))
79 ;; See <https://github.com/atgreen/libffi/blob/master/LICENSE>.
82 (define-public python-cffi
89 (uri (pypi-uri "cffi" version))
91 (base32 "0v080s7vlrjz9z823x2yh36yc8drwpvvir6w8wfkkzd7k2z5qihs"))))
92 (build-system python-build-system)
94 `(("libffi" ,libffi)))
95 (propagated-inputs ; required at run-time
96 `(("python-pycparser" ,python-pycparser)))
98 `(("pkg-config" ,pkg-config)
99 ("python-pytest" ,python-pytest)))
102 (modify-phases %standard-phases
105 ;; XXX The "normal" approach of setting CC and friends does
106 ;; not work here. Is this the correct way of doing things?
107 (substitute* "testing/embedding/test_basic.py"
108 (("c = distutils\\.ccompiler\\.new_compiler\\(\\)")
109 (string-append "c = distutils.ccompiler.new_compiler();"
110 "c.set_executables(compiler='gcc',"
111 "compiler_so='gcc',linker_exe='gcc',"
112 "linker_so='gcc -shared')")))
113 (substitute* "testing/cffi0/test_ownlib.py"
114 (("\"cc testownlib") "\"gcc testownlib"))
115 (invoke "py.test" "-v" "c/" "testing/")))
116 (add-before 'check 'patch-paths-of-dynamically-loaded-libraries
117 (lambda* (#:key inputs #:allow-other-keys)
118 ;; Shared libraries should be referred by their absolute path as
119 ;; using find_library or the like with their name fail when the
120 ;; resolved .so object is a linker script rather than an ELF
121 ;; binary (this is a limitation of the ctype library of Python).
122 (let* ((glibc (assoc-ref inputs "libc"))
123 (libm (string-append glibc "/lib/libm.so.6"))
124 (libc (string-append glibc "/lib/libc.so.6")))
125 (substitute* '("testing/cffi0/test_function.py"
126 "testing/cffi0/test_parsing.py"
127 "testing/cffi0/test_unicode_literals.py"
128 "testing/cffi0/test_zdistutils.py"
129 "testing/cffi1/test_recompiler.py")
130 (("lib_m = ['\"]{1}m['\"]{1}")
131 (format #f "lib_m = '~a'" libm)))
132 (substitute* '("testing/cffi0/test_verify.py"
133 "testing/cffi1/test_verify1.py")
134 (("lib_m = \\[['\"]{1}m['\"]{1}\\]")
135 (format #f "lib_m = ['~a']" libm)))
136 (substitute* "c/test_c.py"
137 (("find_and_load_library\\(['\"]{1}c['\"]{1}")
138 (format #f "find_and_load_library('~a'" libc)))))))))
139 (home-page "https://cffi.readthedocs.io/")
140 (synopsis "Foreign function interface for Python")
141 (description "Foreign Function Interface for Python calling C code.")
144 (define-public python2-cffi
145 (package-with-python2 python-cffi))
147 (define-public python-cffi-documentation
149 (name "python-cffi-documentation")
150 (version (package-version python-cffi))
151 (source (package-source python-cffi))
152 (build-system gnu-build-system)
155 #:phases (modify-phases %standard-phases
156 (add-after 'unpack 'chdir
157 (lambda _ (chdir "doc") #t))
160 (lambda* (#:key (make-flags '()) #:allow-other-keys)
161 (apply invoke "make" "html" make-flags)))
163 (lambda* (#:key outputs #:allow-other-keys)
164 (let ((out (assoc-ref outputs "out")))
165 (copy-recursively "build/html" (string-append out "/html"))
168 `(("sphinx-build" ,python-sphinx)))
169 (home-page (package-home-page python-cffi))
170 (synopsis "Documentation for the Python CFFI interface")
172 "This package contains HTML documentation for the @code{python-cffi}
174 (license (package-license python-cffi))))
176 (define-public ruby-ffi
181 ;; Pull from git because the RubyGems release bundles LibFFI,
182 ;; and comes with a gemspec that makes it difficult to unbundle.
185 (url "https://github.com/ffi/ffi")
187 (file-name (git-file-name name version))
190 "1cvqsbjr2gfjgqggq9kdx90qhhzr7qkyr9wmxdsfsik6cnxnnpmd"))))
191 (build-system ruby-build-system)
194 (modify-phases %standard-phases
195 (add-after 'unpack 'do-not-depend-on-ccache
197 (substitute* "spec/ffi/fixtures/GNUmakefile"
201 (replace 'replace-git-ls-files
203 ;; Do not try to execute git, or include the (un)bundled LibFFI.
204 (substitute* "ffi.gemspec"
206 "find * -type f -print0 | sort -z")
209 (substitute* "Rakefile"
210 (("LIBFFI_GIT_FILES = .*")
211 "LIBFFI_GIT_FILES = []\n"))
215 ;; Tests depend on the native extensions, so we build it
216 ;; beforehand without going through the gem machinery.
217 (invoke "rake" "compile")
219 ;; XXX: Ideally we'd use "rake native gem" here to prevent the
220 ;; install phase from needlessly rebuilding everything, but that
221 ;; requires the bundled LibFFI, and the install phase can not
222 ;; deal with such gems anyway.
223 (invoke "gem" "build" "ffi.gemspec")))
225 (lambda* (#:key tests? #:allow-other-keys)
228 (setenv "MAKE" "make")
230 (invoke "rspec" "spec"))
231 (format #t "test suite not run~%"))
234 `(("ruby-rake-compiler" ,ruby-rake-compiler)
235 ("ruby-rspec" ,ruby-rspec)
236 ("ruby-rubygems-tasks" ,ruby-rubygems-tasks)))
238 `(("libffi" ,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
244 (home-page "https://wiki.github.com/ffi/ffi")