projects/guix·blob python-team · refs

245 lines · 11.4 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 José Miguel Sánchez García <[email protected]>
3;;; Copyright © 2017, 2022 Efraim Flashner <[email protected]>
4;;; Copyright © 2018, 2021 Tobias Geerinckx-Rice <[email protected]>
5;;; Copyright © 2020 Tanguy Le Carrour <[email protected]>
6;;; Copyright © 2022 (unmatched parenthesis <[email protected]>
7;;; Copyright © 2022 Trevor Richards <[email protected]>
8;;; Copyright © 2023 Gruruya <[email protected]>
9;;; Copyright © 2025 Ashish SHUKLA <[email protected]>
10;;;
11;;; This file is part of GNU Guix.
12;;;
13;;; GNU Guix is free software; you can redistribute it and/or modify it
14;;; under the terms of the GNU General Public License as published by
15;;; the Free Software Foundation; either version 3 of the License, or (at
16;;; your option) any later version.
17;;;
18;;; GNU Guix is distributed in the hope that it will be useful, but
19;;; WITHOUT ANY WARRANTY; without even the implied warranty of
20;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;;; GNU General Public License for more details.
22;;;
23;;; You should have received a copy of the GNU General Public License
24;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
25
26(define-module (gnu packages nim)
27 #:use-module (guix build-system gnu)
28 #:use-module (guix download)
29 #:use-module (guix git-download)
30 #:use-module (guix gexp)
31 #:use-module (guix utils)
32 #:use-module ((guix licenses) #:prefix license:)
33 #:use-module (guix packages)
34 #:use-module (gnu packages bdw-gc)
35 #:use-module (gnu packages nss)
36 #:use-module (gnu packages pcre)
37 #:use-module (gnu packages sqlite)
38 #:use-module (gnu packages tls))
39
40(define atlas
41 (origin
42 (method git-fetch)
43 (file-name "atlas-checkout")
44 (uri
45 (git-reference
46 (url "https://github.com/nim-lang/atlas.git")
47 ;; referenced in koch.nim
48 (commit "ff1f4289482dce94ba9f95b3b0ae16d16e21eb3d")))
49 (sha256 (base32 "09bmm8as7y0r5ds4c5nlp3ix6v3zah03k8bmaf1qil0r1fzwyjar"))))
50
51(define sat
52 (origin
53 (method git-fetch)
54 (file-name "sat-checkout")
55 (uri
56 (git-reference
57 (url "https://github.com/nim-lang/sat.git")
58 ;; referenced in koch.nim
59 (commit "e63eaea8baf00bed8bcd5a29ffd8823abb265b39")))
60 (sha256 (base32 "0wrd8lgn7ym6fl9jvgmyyyfn997lgn1hvx6vxmpijm070pmksr1m"))))
61
62(define-public nim
63 (package
64 (name "nim")
65 (version "2.2.10")
66 (source
67 (origin
68 (method url-fetch)
69 (uri (string-append "https://nim-lang.org/download/"
70 name "-" version ".tar.xz"))
71 (sha256
72 (base32 "1mfmx103z7cfk8m5ac945zk7hf0m8i3knkyc1gqvq1j203nvfmvr"))))
73 (build-system gnu-build-system)
74 (arguments
75 `(#:tests? #f ; TODO: Investigate tests failures.
76 #:modules
77 ((ice-9 rdelim)
78 (ice-9 regex)
79 (ice-9 match)
80 ,@%default-gnu-modules)
81 #:make-flags (list (string-append "CC=" ,(cc-for-target)))
82 #:phases
83 ,#~(modify-phases %standard-phases
84 (delete 'configure) ; no configure script
85 (add-after 'unpack 'copy-deps:www
86 (lambda _
87 (copy-recursively #$(this-package-input "atlas-checkout") "dist/atlas"
88 #:keep-permissions? #f)
89 (copy-recursively #$(this-package-input "sat-checkout") "dist/atlas/dist/sat"
90 #:keep-permissions? #f)))
91 (add-after 'unpack 'patch-installer
92 (lambda* (#:key outputs #:allow-other-keys)
93 (let ((out (assoc-ref outputs "out")))
94 (substitute* "install.sh"
95 (("/usr/local") out)
96 (("/lib/nim") "/")
97 (("/opt/nimble") (string-append out "/share/nimble"))
98 (("configdir=\"/etc/nim\"")
99 (string-append "configdir=\"" out "/etc/nim\""))))))
100 (add-after 'unpack 'patch-dynamic-libraries
101 (lambda* (#:key inputs native-inputs #:allow-other-keys)
102 (substitute* "lib/system.nim"
103 (("libgc\\.so")
104 (search-input-file (or native-inputs inputs)
105 "/lib/libgc.so")))
106 (substitute* "lib/wrappers/openssl.nim"
107 (("libssl\\.so")
108 (search-input-file (or native-inputs inputs)
109 "/lib/libssl.so"))
110 (("libcrypto\\.so")
111 (search-input-file (or native-inputs inputs)
112 "/lib/libcrypto.so")))
113 (substitute* "lib/wrappers/pcre.nim"
114 (("libpcre\\.so")
115 (search-input-file (or native-inputs inputs)
116 "/lib/libpcre.so")))))
117 (add-after 'patch-source-shebangs 'patch-more-shebangs
118 (lambda _
119
120 (define sh (which "sh"))
121 (define sh-len (string-length sh))
122
123 (define rx1 (make-regexp "^(.*NIM_CHAR data\\[)7(\\+1\\];.*)$" regexp/extended))
124 ;; } TM__HZdw8BhppcTQo8DIK46LSg_5 = { 7 | NIM_STRLIT_FLAG, "/bin/sh" };
125 (define rx2 (make-regexp
126 (string-append "^(\\} )"
127 "([^[:space:]]+)"
128 "( = \\{ )"
129 "7"
130 "( [|] NIM_STRLIT_FLAG, )"
131 "\"/bin/sh\""
132 "(.*)$")
133 regexp/extended))
134
135 (define (fixup-1 matches out)
136 (format out "~a~a~a\n"
137 ;; NI cap; NIM_CHAR data[(string-length (which "sh"))+1];
138 (match:substring matches 1) ;; NI cap; NIM_CHAR data[
139 sh-len ;; (string-length (which "sh")
140 (match:substring matches 2)) ;; +1];
141 #f)
142
143 (define (fixup-2 matches out)
144 (format out "~a~a~a~a~a~s~a\n"
145 ;; } TM__HZdw8BhppcTQo8DIK46LSg_5 = { (string-length (which "sh")) | NIM_STRLIT_FLAG, (which "sh") };
146 (match:substring matches 1) ;; }
147 (match:substring matches 2) ;; TM__HZdw8BhppcTQo8DIK46LSg_5
148 (match:substring matches 3) ;; = {
149 sh-len ;; (string-length (which "sh"))
150 (match:substring matches 4) ;; | NIM_STRLIT_FLAG,
151 sh ;; (which "sh")
152 (match:substring matches 5)) ;; };
153 ;; return a reference to patch
154 (match:substring matches 2)) ;; TM__HZdw8BhppcTQo8DIK46LSg_5
155
156 (define fixups
157 (list (list rx1 fixup-1)
158 (list rx2 fixup-2)))
159
160 (define (rx-match rx-list line in out)
161 (if (null? rx-list)
162 (begin
163 (format out "~a\n" line)
164 #f)
165
166 (match rx-list
167 (((rx fixup) . rest)
168 (let ((matches (regexp-exec rx line)))
169 (if (regexp-match? matches)
170 (fixup matches out)
171 (rx-match rest line in out)))))))
172
173 (define (fixup-bin-sh-references in out)
174 (let loop ((line (read-line in))
175 (flagged #f))
176 (let* ((pat (and (string? flagged)
177 (format #f "{7, (NimStrPayload*)&~a};" flagged)))
178 (pat-len (if (string? pat) (string-length pat) 0)))
179 (unless (eof-object? line)
180 (if (and (string? pat) (string-suffix? pat line))
181 (begin
182 (format out
183 "~a{~a, (NimStrPayload*)&~a};\n"
184 (substring line 0
185 (- (string-length line) pat-len))
186 sh-len
187 flagged)
188 (loop (read-line in) flagged))
189
190 (loop (read-line in)
191 (rx-match fixups line in out)))))))
192
193 (substitute* '("tests/stdlib/tosprocterminate.nim"
194 "tests/stdlib/tstrscans.nim"
195 "lib/pure/osproc.nim"
196 "lib/pure/strscans.nim")
197 (("/bin/sh") sh))
198
199 (for-each (lambda (f)
200 (with-atomic-file-replacement f fixup-bin-sh-references))
201 (find-files "c_code" "@posproc\\.nim\\.c"))))
202 (replace 'build
203 (lambda args
204 (apply (assoc-ref %standard-phases 'build) args)
205 (setenv "XDG_CACHE_HOME" "./cache-home")
206 (mkdir-p "./cache-home")
207 (invoke "./bin/nim" "c" "-d:release" "koch")
208 (invoke "./koch" "boot" "-d:release")
209 (invoke "./koch" "tools")))
210 (replace 'check
211 (lambda* (#:key tests? #:allow-other-keys)
212 (when tests?
213 (invoke "./koch" "tests"))))
214 (replace 'install
215 (lambda* (#:key outputs #:allow-other-keys)
216 (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
217 (mkdir-p bin)
218 (invoke "./install.sh" bin)
219 (for-each (lambda (file)
220 (install-file file bin))
221 (delete "testament" (find-files "bin"))))))
222 (add-after 'install 'install-completions
223 (lambda* (#:key outputs #:allow-other-keys)
224 (let* ((share (string-append (assoc-ref outputs "out") "/share"))
225 (bash (string-append share "/bash-completion/completions"))
226 (zsh (string-append share "/zsh/vendor_completions")))
227 (mkdir-p bash)
228 (mkdir-p zsh)
229 (copy-file "tools/nim.bash-completion"
230 (string-append bash "/nim"))
231 (copy-file "dist/nimble/nimble.bash-completion"
232 (string-append bash "/nimble"))
233 (copy-file "tools/nim.zsh-completion"
234 (string-append zsh "/_nim"))
235 (copy-file "dist/nimble/nimble.bash-completion"
236 (string-append zsh "/_nimble"))))))))
237 (inputs (list atlas libgc openssl pcre sat sqlite))
238 (native-inputs (list nss-certs))
239 (home-page "https://nim-lang.org")
240 (synopsis "Statically-typed, imperative programming language")
241 (description "Nim (formerly known as Nimrod) is a statically-typed,
242imperative programming language that tries to give the programmer ultimate power
243without compromises on runtime efficiency. This means it focuses on compile-time
244mechanisms in all their various forms.")
245 (license license:expat)))