libffi.scm 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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>
  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. (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 (guix git-download)
  32. #:use-module (gnu packages check)
  33. #:use-module (gnu packages pkg-config)
  34. #:use-module (gnu packages python)
  35. #:use-module (gnu packages python-xyz)
  36. #:use-module (gnu packages ruby)
  37. #:use-module (gnu packages sphinx)
  38. #:use-module (guix build-system gnu)
  39. #:use-module (guix build-system python)
  40. #:use-module (guix build-system ruby))
  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. (patches (search-patches "libffi-3.3-powerpc-fixes.patch"
  54. "libffi-float128-powerpc64le.patch"))))
  55. (build-system gnu-build-system)
  56. (arguments
  57. `(;; Prevent the build system from passing -march and -mtune to the
  58. ;; compiler. See "ax_cc_maxopt.m4" and "ax_gcc_archflag.m4".
  59. #:configure-flags '("--enable-portable-binary"
  60. "--without-gcc-arch")))
  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. FFI stands for Foreign Function Interface. A foreign function interface is
  68. the popular name for the interface that allows code written in one language
  69. to call code written in another language. The libffi library really only
  70. provides the lowest, machine dependent layer of a fully featured foreign
  71. function interface. A layer must exist above libffi that handles type
  72. conversions for values passed between the two languages.")
  73. (home-page "http://www.sourceware.org/libffi/")
  74. (properties `((release-monitoring-url . ,home-page)))
  75. ;; See <https://github.com/atgreen/libffi/blob/master/LICENSE>.
  76. (license expat)))
  77. (define-public python-cffi
  78. (package
  79. (name "python-cffi")
  80. (version "1.14.4")
  81. (source
  82. (origin
  83. (method url-fetch)
  84. (uri (pypi-uri "cffi" version))
  85. (sha256
  86. (base32 "0v080s7vlrjz9z823x2yh36yc8drwpvvir6w8wfkkzd7k2z5qihs"))))
  87. (build-system python-build-system)
  88. (inputs
  89. `(("libffi" ,libffi)))
  90. (propagated-inputs ; required at run-time
  91. `(("python-pycparser" ,python-pycparser)))
  92. (native-inputs
  93. `(("pkg-config" ,pkg-config)
  94. ("python-pytest" ,python-pytest)))
  95. (arguments
  96. `(#:phases
  97. (modify-phases %standard-phases
  98. (replace 'check
  99. (lambda _
  100. ;; XXX The "normal" approach of setting CC and friends does
  101. ;; not work here. Is this the correct way of doing things?
  102. (substitute* "testing/embedding/test_basic.py"
  103. (("c = distutils\\.ccompiler\\.new_compiler\\(\\)")
  104. (string-append "c = distutils.ccompiler.new_compiler();"
  105. "c.set_executables(compiler='gcc',"
  106. "compiler_so='gcc',linker_exe='gcc',"
  107. "linker_so='gcc -shared')")))
  108. (substitute* "testing/cffi0/test_ownlib.py"
  109. (("\"cc testownlib") "\"gcc testownlib"))
  110. (invoke "py.test" "-v" "c/" "testing/")))
  111. (add-before 'check 'patch-paths-of-dynamically-loaded-libraries
  112. (lambda* (#:key inputs #:allow-other-keys)
  113. ;; Shared libraries should be referred by their absolute path as
  114. ;; using find_library or the like with their name fail when the
  115. ;; resolved .so object is a linker script rather than an ELF
  116. ;; binary (this is a limitation of the ctype library of Python).
  117. (let* ((glibc (assoc-ref inputs "libc"))
  118. (libm (string-append glibc "/lib/libm.so.6"))
  119. (libc (string-append glibc "/lib/libc.so.6")))
  120. (substitute* '("testing/cffi0/test_function.py"
  121. "testing/cffi0/test_parsing.py"
  122. "testing/cffi0/test_unicode_literals.py"
  123. "testing/cffi0/test_zdistutils.py"
  124. "testing/cffi1/test_recompiler.py")
  125. (("lib_m = ['\"]{1}m['\"]{1}")
  126. (format #f "lib_m = '~a'" libm)))
  127. (substitute* '("testing/cffi0/test_verify.py"
  128. "testing/cffi1/test_verify1.py")
  129. (("lib_m = \\[['\"]{1}m['\"]{1}\\]")
  130. (format #f "lib_m = ['~a']" libm)))
  131. (substitute* "c/test_c.py"
  132. (("find_and_load_library\\(['\"]{1}c['\"]{1}")
  133. (format #f "find_and_load_library('~a'" libc)))))))))
  134. (home-page "https://cffi.readthedocs.io/")
  135. (synopsis "Foreign function interface for Python")
  136. (description "Foreign Function Interface for Python calling C code.")
  137. (license expat)))
  138. (define-public python2-cffi
  139. (package-with-python2 python-cffi))
  140. (define-public python-cffi-documentation
  141. (package
  142. (name "python-cffi-documentation")
  143. (version (package-version python-cffi))
  144. (source (package-source python-cffi))
  145. (build-system gnu-build-system)
  146. (arguments
  147. `(#:tests? #f
  148. #:phases (modify-phases %standard-phases
  149. (add-after 'unpack 'chdir
  150. (lambda _ (chdir "doc") #t))
  151. (delete 'configure)
  152. (replace 'build
  153. (lambda* (#:key (make-flags '()) #:allow-other-keys)
  154. (apply invoke "make" "html" make-flags)))
  155. (replace 'install
  156. (lambda* (#:key outputs #:allow-other-keys)
  157. (let ((out (assoc-ref outputs "out")))
  158. (copy-recursively "build/html" (string-append out "/html"))
  159. #t))))))
  160. (native-inputs
  161. `(("sphinx-build" ,python-sphinx)))
  162. (home-page (package-home-page python-cffi))
  163. (synopsis "Documentation for the Python CFFI interface")
  164. (description
  165. "This package contains HTML documentation for the @code{python-cffi}
  166. project.")
  167. (license (package-license python-cffi))))
  168. (define-public ruby-ffi
  169. (package
  170. (name "ruby-ffi")
  171. (version "1.12.2")
  172. (source (origin
  173. ;; Pull from git because the RubyGems release bundles LibFFI,
  174. ;; and comes with a gemspec that makes it difficult to unbundle.
  175. (method git-fetch)
  176. (uri (git-reference
  177. (url "https://github.com/ffi/ffi")
  178. (commit version)))
  179. (file-name (git-file-name name version))
  180. (sha256
  181. (base32
  182. "1cvqsbjr2gfjgqggq9kdx90qhhzr7qkyr9wmxdsfsik6cnxnnpmd"))))
  183. (build-system ruby-build-system)
  184. (arguments
  185. `(#:phases
  186. (modify-phases %standard-phases
  187. (add-after 'unpack 'do-not-depend-on-ccache
  188. (lambda _
  189. (substitute* "spec/ffi/fixtures/GNUmakefile"
  190. (("^CCACHE := .*")
  191. ""))
  192. #t))
  193. (replace 'replace-git-ls-files
  194. (lambda _
  195. ;; Do not try to execute git, or include the (un)bundled LibFFI.
  196. (substitute* "ffi.gemspec"
  197. (("git ls-files -z")
  198. "find * -type f -print0 | sort -z")
  199. (("lfs \\+?= .*")
  200. "lfs = []\n"))
  201. (substitute* "Rakefile"
  202. (("LIBFFI_GIT_FILES = .*")
  203. "LIBFFI_GIT_FILES = []\n"))
  204. #t))
  205. (replace 'build
  206. (lambda _
  207. ;; Tests depend on the native extensions, so we build it
  208. ;; beforehand without going through the gem machinery.
  209. (invoke "rake" "compile")
  210. ;; XXX: Ideally we'd use "rake native gem" here to prevent the
  211. ;; install phase from needlessly rebuilding everything, but that
  212. ;; requires the bundled LibFFI, and the install phase can not
  213. ;; deal with such gems anyway.
  214. (invoke "gem" "build" "ffi.gemspec")))
  215. (replace 'check
  216. (lambda* (#:key tests? #:allow-other-keys)
  217. (if tests?
  218. (begin
  219. (setenv "MAKE" "make")
  220. (setenv "CC" "gcc")
  221. (invoke "rspec" "spec"))
  222. (format #t "test suite not run~%"))
  223. #t)))))
  224. (native-inputs
  225. `(("ruby-rake-compiler" ,ruby-rake-compiler)
  226. ("ruby-rspec" ,ruby-rspec)
  227. ("ruby-rubygems-tasks" ,ruby-rubygems-tasks)))
  228. (inputs
  229. `(("libffi" ,libffi)))
  230. (synopsis "Ruby foreign function interface library")
  231. (description "Ruby-FFI is a Ruby extension for programmatically loading
  232. dynamic libraries, binding functions within them, and calling those functions
  233. from Ruby code. Moreover, a Ruby-FFI extension works without changes on Ruby
  234. and JRuby.")
  235. (home-page "https://wiki.github.com/ffi/ffi")
  236. (license bsd-3)))