projects/guix·blob ruby-team · refs

251 lines · 11.7 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 licenses) #:prefix license:)
32 #:use-module (guix packages)
33 #:use-module (gnu packages bdw-gc)
34 #:use-module (gnu packages nss)
35 #:use-module (gnu packages parallel)
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 #:phases
82 ,#~(modify-phases %standard-phases
83 (delete 'configure) ; no configure script
84 (add-after 'unpack 'copy-deps:www
85 (lambda _
86 (copy-recursively #$(this-package-input "atlas-checkout") "dist/atlas"
87 #:keep-permissions? #f)
88 (copy-recursively #$(this-package-input "sat-checkout") "dist/atlas/dist/sat"
89 #:keep-permissions? #f)))
90 (add-after 'unpack 'patch-installer
91 (lambda* (#:key outputs #:allow-other-keys)
92 (let ((out (assoc-ref outputs "out")))
93 (substitute* "install.sh"
94 (("/usr/local") out)
95 (("/lib/nim") "/")
96 (("/opt/nimble") (string-append out "/share/nimble"))
97 (("configdir=\"/etc/nim\"")
98 (string-append "configdir=\"" out "/etc/nim\""))))))
99 (add-after 'unpack 'patch-dynamic-libraries
100 (lambda* (#:key inputs native-inputs #:allow-other-keys)
101 (substitute* "lib/system.nim"
102 (("libgc\\.so")
103 (search-input-file (or native-inputs inputs)
104 "/lib/libgc.so")))
105 (substitute* "lib/wrappers/openssl.nim"
106 (("libssl\\.so")
107 (search-input-file (or native-inputs inputs)
108 "/lib/libssl.so"))
109 (("libcrypto\\.so")
110 (search-input-file (or native-inputs inputs)
111 "/lib/libcrypto.so")))
112 (substitute* "lib/wrappers/pcre.nim"
113 (("libpcre\\.so")
114 (search-input-file (or native-inputs inputs)
115 "/lib/libpcre.so")))))
116 (add-after 'patch-source-shebangs 'patch-more-shebangs
117 (lambda _
118
119 (define sh (which "sh"))
120 (define sh-len (string-length sh))
121
122 (define rx1 (make-regexp "^(.*NIM_CHAR data\\[)7(\\+1\\];.*)$" regexp/extended))
123 ;; } TM__HZdw8BhppcTQo8DIK46LSg_5 = { 7 | NIM_STRLIT_FLAG, "/bin/sh" };
124 (define rx2 (make-regexp
125 (string-append "^(\\} )"
126 "([^[:space:]]+)"
127 "( = \\{ )"
128 "7"
129 "( [|] NIM_STRLIT_FLAG, )"
130 "\"/bin/sh\""
131 "(.*)$")
132 regexp/extended))
133
134 (define (fixup-1 matches out)
135 (format out "~a~a~a\n"
136 ;; NI cap; NIM_CHAR data[(string-length (which "sh"))+1];
137 (match:substring matches 1) ;; NI cap; NIM_CHAR data[
138 sh-len ;; (string-length (which "sh")
139 (match:substring matches 2)) ;; +1];
140 #f)
141
142 (define (fixup-2 matches out)
143 (format out "~a~a~a~a~a~s~a\n"
144 ;; } TM__HZdw8BhppcTQo8DIK46LSg_5 = { (string-length (which "sh")) | NIM_STRLIT_FLAG, (which "sh") };
145 (match:substring matches 1) ;; }
146 (match:substring matches 2) ;; TM__HZdw8BhppcTQo8DIK46LSg_5
147 (match:substring matches 3) ;; = {
148 sh-len ;; (string-length (which "sh"))
149 (match:substring matches 4) ;; | NIM_STRLIT_FLAG,
150 sh ;; (which "sh")
151 (match:substring matches 5)) ;; };
152 ;; return a reference to patch
153 (match:substring matches 2)) ;; TM__HZdw8BhppcTQo8DIK46LSg_5
154
155 (define fixups
156 (list (list rx1 fixup-1)
157 (list rx2 fixup-2)))
158
159 (define (rx-match rx-list line in out)
160 (if (null? rx-list)
161 (begin
162 (format out "~a\n" line)
163 #f)
164
165 (match rx-list
166 (((rx fixup) . rest)
167 (let ((matches (regexp-exec rx line)))
168 (if (regexp-match? matches)
169 (fixup matches out)
170 (rx-match rest line in out)))))))
171
172 (define (fixup-bin-sh-references in out)
173 (let loop ((line (read-line in))
174 (flagged #f))
175 (let* ((pat (and (string? flagged)
176 (format #f "{7, (NimStrPayload*)&~a};" flagged)))
177 (pat-len (if (string? pat) (string-length pat) 0)))
178 (unless (eof-object? line)
179 (if (and (string? pat) (string-suffix? pat line))
180 (begin
181 (format out
182 "~a{~a, (NimStrPayload*)&~a};\n"
183 (substring line 0
184 (- (string-length line) pat-len))
185 sh-len
186 flagged)
187 (loop (read-line in) flagged))
188
189 (loop (read-line in)
190 (rx-match fixups line in out)))))))
191
192 (substitute* '("tests/stdlib/tosprocterminate.nim"
193 "tests/stdlib/tstrscans.nim"
194 "lib/pure/osproc.nim"
195 "lib/pure/strscans.nim")
196 (("/bin/sh") sh))
197
198 (for-each (lambda (f)
199 (with-atomic-file-replacement f fixup-bin-sh-references))
200 (find-files "c_code" "@posproc\\.nim\\.c"))))
201 (replace 'build
202 (lambda* (#:key (parallel-build? #t) #:allow-other-keys)
203 (setenv "XDG_CACHE_HOME" "./cache-home")
204 (setenv "HOME" "./cache-home")
205 (setenv "SHELL" (which "sh"))
206 (mkdir-p "./cache-home")
207 (invoke "sh" "build.sh"
208 "--parallel"
209 (if parallel-build?
210 (number->string (parallel-job-count))
211 "1"))
212 (sleep 5) ; Wait for the parallel builds to finish.
213 (invoke "./bin/nim" "c" "-d:release" "koch")
214 (invoke "./koch" "boot" "-d:release")
215 (invoke "./koch" "tools")))
216 (replace 'check
217 (lambda* (#:key tests? #:allow-other-keys)
218 (when tests?
219 (invoke "./koch" "tests"))))
220 (replace 'install
221 (lambda* (#:key outputs #:allow-other-keys)
222 (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
223 (mkdir-p bin)
224 (invoke "./install.sh" bin)
225 (for-each (lambda (file)
226 (install-file file bin))
227 (delete "testament" (find-files "bin"))))))
228 (add-after 'install 'install-completions
229 (lambda* (#:key outputs #:allow-other-keys)
230 (let* ((share (string-append (assoc-ref outputs "out") "/share"))
231 (bash (string-append share "/bash-completion/completions"))
232 (zsh (string-append share "/zsh/vendor_completions")))
233 (mkdir-p bash)
234 (mkdir-p zsh)
235 (copy-file "tools/nim.bash-completion"
236 (string-append bash "/nim"))
237 (copy-file "dist/nimble/nimble.bash-completion"
238 (string-append bash "/nimble"))
239 (copy-file "tools/nim.zsh-completion"
240 (string-append zsh "/_nim"))
241 (copy-file "dist/nimble/nimble.bash-completion"
242 (string-append zsh "/_nimble"))))))))
243 (inputs (list atlas libgc openssl pcre sat sqlite))
244 (native-inputs (list nss-certs parallel))
245 (home-page "https://nim-lang.org")
246 (synopsis "Statically-typed, imperative programming language")
247 (description "Nim (formerly known as Nimrod) is a statically-typed,
248imperative programming language that tries to give the programmer ultimate power
249without compromises on runtime efficiency. This means it focuses on compile-time
250mechanisms in all their various forms.")
251 (license license:expat)))