projects/guix·blob ruby-team · refs

259 lines · 11.3 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2012, 2013, 2014, 2020, 2021 Ludovic Courtès <[email protected]>
3;;; Copyright © 2014 Federico Beffa <[email protected]>
4;;; Copyright © 2015, 2019 Ricardo Wurmus <[email protected]>
5;;; Copyright © 2016, 2017, 2020, 2021 Efraim Flashner <[email protected]>
6;;; Copyright © 2016, 2017 Ben Woodcroft <[email protected]>
7;;; Copyright © 2017, 2019, 2020, 2022 Marius Bakke <[email protected]>
8;;; Copyright © 2018 Tobias Geerinckx-Rice <[email protected]>
9;;; Copyright © 2019, 2021, 2025 Maxim Cournoyer <[email protected]>
10;;; Copyright © 2020 John Doe <[email protected]>
11;;; Copyright © 2024 Janneke Nieuwenhuizen <[email protected]>
12;;; Copyright © 2024 Sharlatan Hellseher <[email protected]>
13;;;
14;;; This file is part of GNU Guix.
15;;;
16;;; GNU Guix is free software; you can redistribute it and/or modify it
17;;; under the terms of the GNU General Public License as published by
18;;; the Free Software Foundation; either version 3 of the License, or (at
19;;; your option) any later version.
20;;;
21;;; GNU Guix is distributed in the hope that it will be useful, but
22;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24;;; GNU General Public License for more details.
25;;;
26;;; You should have received a copy of the GNU General Public License
27;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
28
29(define-module (gnu packages libffi)
30 #:use-module (gnu packages)
31 #:use-module (guix licenses)
32 #:use-module (guix packages)
33 #:use-module (guix gexp)
34 #:use-module (guix download)
35 #:use-module (guix git-download)
36 #:use-module (guix utils)
37 #:use-module (gnu packages check)
38 #:use-module (gnu packages crypto)
39 #:use-module (gnu packages pkg-config)
40 #:use-module (gnu packages python)
41 #:use-module (gnu packages python-build)
42 #:use-module (gnu packages python-xyz)
43 #:use-module (gnu packages ruby-check)
44 #:use-module (gnu packages ruby-xyz)
45 #:use-module (gnu packages sphinx)
46 #:use-module (guix build-system gnu)
47 #:use-module (guix build-system pyproject)
48 #:use-module (guix build-system ruby))
49
50(define-public libffi
51 (package
52 (name "libffi")
53 (version "3.4.6")
54 (source (origin
55 (method url-fetch)
56 (uri
57 (string-append "https://github.com/libffi/libffi/releases"
58 "/download/v" version "/"
59 name "-" version ".tar.gz"))
60 (sha256
61 (base32
62 "0kjsi51phx1pskjhhwa9y5fxdazzxgrl0m421sjsfqy84ggskpmh"))))
63 (build-system gnu-build-system)
64 (arguments
65 `(;; Prevent the build system from passing -march and -mtune to the
66 ;; compiler. See "ax_cc_maxopt.m4" and "ax_gcc_archflag.m4".
67 #:configure-flags '("--enable-portable-binary"
68 "--without-gcc-arch")))
69 (outputs '("out" "debug"))
70 (synopsis "Foreign function call interface library")
71 (description
72 "The libffi library provides a portable, high level programming interface
73to various calling conventions. This allows a programmer to call any
74function specified by a call interface description at run-time.
75
76FFI stands for Foreign Function Interface. A foreign function interface is
77the popular name for the interface that allows code written in one language
78to call code written in another language. The libffi library really only
79provides the lowest, machine dependent layer of a fully featured foreign
80function interface. A layer must exist above libffi that handles type
81conversions for values passed between the two languages.")
82 (home-page "https://www.sourceware.org/libffi/")
83 (properties `((release-monitoring-url . ,home-page)))
84
85 ;; See <https://github.com/atgreen/libffi/blob/master/LICENSE>.
86 (license expat)))
87
88;; Provide a variant without static trampolines as some packages
89;; (particularly GHC < 9) cannot handle them. See
90;; <https://github.com/libffi/libffi/pull/647> for a discussion.
91(define-public libffi-sans-static-trampolines
92 (hidden-package
93 (package/inherit libffi
94 (arguments
95 (substitute-keyword-arguments arguments
96 ((#:configure-flags flags #~'())
97 #~(append #$flags '("--disable-exec-static-tramp"))))))))
98
99(define-public python-cffi
100 (package
101 (name "python-cffi")
102 (version "1.17.1")
103 (source
104 (origin
105 (method url-fetch)
106 (uri (pypi-uri "cffi" version))
107 (sha256
108 (base32 "0918qn4yfjfgcy7i4imfy9q1cvl3svmm06anakflig1jdh0wcf8w"))))
109 (build-system pyproject-build-system)
110 (arguments
111 (list
112 #:test-flags
113 #~(list "src/c/" "testing/"
114 ;; Disable tests that fail (harmlessly) with glibc 2.34 and
115 ;; later, see
116 ;; <https://foss.heptapod.net/pypy/cffi/-/issues/528>.
117 "--deselect=testing/cffi0/test_ffi_backend.py::TestFFI::test_dlopen_handle"
118 "--deselect=testing/cffi1/test_re_python.py::test_dlopen_handle"
119 "--ignore=testing/embedding/test_performance.py")
120 #:phases
121 #~(modify-phases %standard-phases
122 (add-after 'unpack 'set-gcc
123 (lambda _
124 ;; XXX The "normal" approach of setting CC and friends does
125 ;; not work here. Is this the correct way of doing things?
126 (substitute* "testing/embedding/test_basic.py"
127 (("c = distutils\\.ccompiler\\.new_compiler\\(\\)")
128 (string-append "c = distutils.ccompiler.new_compiler();"
129 "c.set_executables(compiler='gcc',"
130 "compiler_so='gcc',linker_exe='gcc',"
131 "linker_so='gcc -shared')")))
132 (substitute* "testing/cffi0/test_ownlib.py"
133 (("\"cc testownlib") "\"gcc testownlib"))))
134 (add-before 'check 'patch-paths-of-dynamically-loaded-libraries
135 (lambda* (#:key inputs #:allow-other-keys)
136 ;; Shared libraries should be referred by their absolute path as
137 ;; using find_library or the like with their name fail when the
138 ;; resolved .so object is a linker script rather than an ELF
139 ;; binary (this is a limitation of the ctype library of Python).
140 (let ((libm (search-input-file inputs "lib/libm.so.6"))
141 (libc (search-input-file inputs "lib/libc.so.6")))
142 (substitute* '("testing/cffi0/test_function.py"
143 "testing/cffi0/test_parsing.py"
144 "testing/cffi0/test_unicode_literals.py"
145 "testing/cffi0/test_zdistutils.py"
146 "testing/cffi1/test_recompiler.py")
147 (("lib_m = ['\"]{1}m['\"]{1}")
148 (format #f "lib_m = '~a'" libm)))
149 (substitute* '("testing/cffi0/test_verify.py"
150 "testing/cffi1/test_verify1.py")
151 (("lib_m = \\[['\"]{1}m['\"]{1}\\]")
152 (format #f "lib_m = ['~a']" libm)))
153 (substitute* "src/c/test_c.py"
154 (("find_and_load_library\\(['\"]{1}c['\"]{1}")
155 (format #f "find_and_load_library('~a'" libc)))))))))
156 (native-inputs
157 (list pkg-config
158 python-pytest
159 python-setuptools))
160 (inputs
161 (list libffi))
162 (propagated-inputs ; required at run-time
163 (list python-pycparser))
164 (home-page "https://cffi.readthedocs.io/")
165 (synopsis "Foreign function interface for Python")
166 (description "Foreign Function Interface for Python calling C code.")
167 (license expat)))
168
169(define-public python-cffi-documentation
170 (package
171 (name "python-cffi-documentation")
172 (version (package-version python-cffi))
173 (source (package-source python-cffi))
174 (build-system gnu-build-system)
175 (arguments
176 `(#:tests? #f
177 #:phases (modify-phases %standard-phases
178 (add-after 'unpack 'chdir
179 (lambda _ (chdir "doc") #t))
180 (delete 'configure)
181 (replace 'build
182 (lambda* (#:key (make-flags '()) #:allow-other-keys)
183 (apply invoke "make" "html" make-flags)))
184 (replace 'install
185 (lambda* (#:key outputs #:allow-other-keys)
186 (let ((out (assoc-ref outputs "out")))
187 (copy-recursively "build/html" (string-append out "/html"))
188 #t))))))
189 (native-inputs
190 `(("sphinx-build" ,python-sphinx)))
191 (home-page (package-home-page python-cffi))
192 (synopsis "Documentation for the Python CFFI interface")
193 (description
194 "This package contains HTML documentation for the @code{python-cffi}
195project.")
196 (license (package-license python-cffi))))
197
198(define-public ruby-ffi
199 (package
200 (name "ruby-ffi")
201 (version "1.15.5")
202 (source (origin
203 ;; Pull from git because the RubyGems release bundles LibFFI,
204 ;; and comes with a gemspec that makes it difficult to unbundle.
205 (method git-fetch)
206 (uri (git-reference
207 (url "https://github.com/ffi/ffi")
208 (commit (string-append "v" version))))
209 (file-name (git-file-name name version))
210 (sha256
211 (base32
212 "1qk55s1zwpdjykwkj9l37m71i5n228i7f8bg3ply3ks9py16m7s6"))))
213 (build-system ruby-build-system)
214 (arguments
215 `(#:phases
216 (modify-phases %standard-phases
217 (replace 'replace-git-ls-files
218 (lambda _
219 ;; Do not try to execute git, or include the (un)bundled LibFFI.
220 (substitute* "ffi.gemspec"
221 (("git ls-files -z")
222 "find * -type f -print0 | sort -z")
223 (("lfs \\+?= .*")
224 "lfs = []\n"))
225 (substitute* "Rakefile"
226 (("git .*ls-files -z")
227 "find * -type f -print0 | sort -z")
228 (("LIBFFI_GIT_FILES = .*")
229 "LIBFFI_GIT_FILES = []\n"))))
230 (replace 'build
231 (lambda _
232 ;; Tests depend on the native extensions, so we build it
233 ;; beforehand without going through the gem machinery.
234 (invoke "rake" "compile")
235
236 ;; XXX: Ideally we'd use "rake native gem" here to prevent the
237 ;; install phase from needlessly rebuilding everything, but that
238 ;; requires the bundled LibFFI, and the install phase can not
239 ;; deal with such gems anyway.
240 (invoke "gem" "build" "ffi.gemspec")))
241 (replace 'check
242 (lambda* (#:key tests? #:allow-other-keys)
243 (if tests?
244 (begin
245 (setenv "MAKE" "make")
246 (setenv "CC" "gcc")
247 (invoke "rspec" "spec"))
248 (format #t "test suite not run~%")))))))
249 (native-inputs
250 (list ruby-rake-compiler ruby-rspec ruby-rubygems-tasks))
251 (inputs
252 (list libffi))
253 (synopsis "Ruby foreign function interface library")
254 (description "Ruby-FFI is a Ruby extension for programmatically loading
255dynamic libraries, binding functions within them, and calling those functions
256from Ruby code. Moreover, a Ruby-FFI extension works without changes on Ruby
257and JRuby.")
258 (home-page "https://wiki.github.com/ffi/ffi")
259 (license bsd-3)))