gnu: Remove singeli-sources.
[jackhill/guix/guix.git] / gnu / packages / bqn.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2022 Christopher Rodriguez <yewscion@gmail.com>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 (define-module (gnu packages bqn)
20 #:use-module ((guix licenses) #:prefix license:)
21 #:use-module (guix gexp)
22 #:use-module (guix packages)
23 #:use-module (guix download)
24 #:use-module (guix git-download)
25 #:use-module (guix build-system copy)
26 #:use-module (guix build-system gnu)
27 #:use-module (guix utils)
28 #:use-module (gnu packages)
29 #:use-module (gnu packages bash)
30 #:use-module (gnu packages libffi)
31 #:use-module (gnu packages base)
32 #:use-module (gnu packages pkg-config)
33 #:use-module (gnu packages llvm)
34 #:use-module (gnu packages java)
35 #:use-module (gnu packages linux)
36 #:use-module (gnu packages compression))
37
38 (define-public dbqn
39 (let ((commit "88f2b43966a75cc2c382421218eb30003bb16f4a")
40 (revision "1"))
41 (package
42 (name "dbqn")
43 (version (git-version "0.2.1" revision commit))
44 (source (origin
45 (method git-fetch)
46 (uri (git-reference
47 (url "https://github.com/dzaima/BQN")
48 (commit commit)))
49 (file-name (git-file-name name version))
50 (sha256
51 (base32
52 "06mzvv7kmandhgwb6jwz3rivsj4ic549sy8afnb5zr6mfn5isyg5"))))
53 (build-system gnu-build-system)
54 (arguments
55 (list
56 #:imported-modules `(,@%gnu-build-system-modules
57 (guix build syscalls)
58 (guix build ant-build-system))
59 #:modules `((guix build gnu-build-system)
60 ((guix build ant-build-system)
61 #:prefix ant:)
62 (guix build utils))
63 #:phases #~(modify-phases %standard-phases
64 (delete 'configure)
65 (replace 'build
66 (lambda* _
67 (invoke "./build")
68 (chmod "./BQN" #o755)))
69 (replace 'check
70 (lambda* (#:key tests? #:allow-other-keys)
71 (when tests?
72 (system "./BQN ./test/test"))))
73 (add-after 'install 'reorder-jar-content
74 (lambda* (#:key outputs #:allow-other-keys)
75 (apply (assoc-ref ant:%standard-phases
76 'reorder-jar-content)
77 #:outputs (list outputs))))
78 (add-after 'reorder-jar-content 'jar-indices
79 (lambda* (#:key outputs #:allow-other-keys)
80 (apply (assoc-ref ant:%standard-phases
81 'generate-jar-indices)
82 #:outputs (list outputs))))
83 (add-after 'jar-indices 'fix-jar-timestamps
84 (lambda* (#:key outputs #:allow-other-keys)
85 (apply (assoc-ref ant:%standard-phases
86 'reorder-jar-content)
87 #:outputs (list outputs))))
88 (replace 'install
89 (lambda* (#:key outputs #:allow-other-keys)
90 (let* ((out (assoc-ref outputs "out"))
91 (dest-bin (string-append out "/bin"))
92 (dest-jar (string-append out "/share/java")))
93 (mkdir-p dest-bin)
94 (mkdir-p dest-jar)
95 (copy-recursively "BQN"
96 (string-append dest-bin
97 "/dbqn"))
98 (install-file "BQN.jar" dest-jar)
99 (substitute* (string-append dest-bin "/dbqn")
100 (("BQN.jar")
101 (string-append dest-jar "/BQN.jar")))))))))
102 (native-inputs (list `(,icedtea-8 "jdk") zip))
103 (inputs (list icedtea-8 bash-minimal))
104 (synopsis "BQN implementation based on dzaima/APL")
105 (description
106 "dbqn is a Java implementation of the
107 @uref{https://mlochbaum.github.io/BQN/, BQN programming language} that does
108 not need to be bootstrapped, based on an earlier Java implementation of APL by
109 the same author.")
110 (home-page "https://github.com/dzaima/BQN")
111 (license license:expat))))
112
113 (define bqn-sources
114 ;; Aside from dbqn above, the main bqn repository is used by other
115 ;; implementations as a "known good" set of sources. CBQN uses dbqn to
116 ;; generate an intermediate bytecode for its own compilation.
117 (let ((commit "e219af48401473a7bac49bdd8b89d69082cf5dd8"))
118 (origin
119 (method git-fetch)
120 (uri (git-reference
121 (url "https://github.com/mlochbaum/BQN")
122 (commit commit)))
123 (file-name (git-file-name "bqn-sources" commit))
124 (sha256
125 (base32 "0r6pa9lscl2395g4xlvmg90vpdsjzhin4f1r0s7brymmpvmns2yc")))))
126
127 (define cbqn-bootstrap
128 (let* ((revision "1")
129 (commit "9c1cbdc99863b1da0116df61cd832137b196dc5c"))
130 (package
131 (name "cbqn-bootstrap")
132 (version (git-version "0" "1" commit))
133 (source (origin
134 (method git-fetch)
135 (uri (git-reference
136 (url "https://github.com/dzaima/CBQN")
137 (commit commit)))
138 (file-name (git-file-name name version))
139 (sha256
140 (base32
141 "0w38fhwf20drkyijy6nfnhmc5g5gw0zmzgmy1q605x57znlj85a2"))))
142 (build-system gnu-build-system)
143 (arguments
144 (list #:tests? #f ;skipping tests for bootstrap
145 #:phases #~(modify-phases %standard-phases
146 (delete 'configure)
147 (add-before 'build 'generate-bytecode
148 (lambda* (#:key inputs #:allow-other-keys)
149 (system (string-append #+dbqn
150 "/bin/dbqn ./genRuntime "
151 #+bqn-sources))))
152 (replace 'install
153 (lambda* (#:key outputs #:allow-other-keys)
154 (mkdir-p (string-append #$output "/bin"))
155 (chmod "BQN" #o755)
156 (copy-recursively "BQN"
157 (string-append #$output
158 "/bin/bqn")))))))
159 (native-inputs (list dbqn clang-toolchain bqn-sources))
160 (inputs (list icedtea-8 libffi))
161 (synopsis "BQN implementation in C")
162 (description "This package provides the reference implementation of
163 @uref{https://mlochbaum.github.io/BQN/, BQN}, a programming language inspired
164 by APL.")
165 (home-page "https://mlochbaum.github.io/BQN/")
166 (license license:gpl3))))
167
168 (define-public cbqn
169 (package
170 (inherit cbqn-bootstrap)
171 (name "cbqn")
172 (outputs '("out" "lib"))
173 (arguments
174 (list #:make-flags '(list "shared-o3" "o3")
175 #:phases #~(modify-phases %standard-phases
176 (delete 'configure)
177 (add-before 'build 'generate-bytecode
178 (lambda* (#:key inputs #:allow-other-keys)
179 (system (string-append #+dbqn
180 "/bin/dbqn ./genRuntime "
181 #+bqn-sources))))
182 (replace 'check
183 (lambda* (#:key inputs tests? #:allow-other-keys)
184 (when tests?
185 (system (string-append "./BQN -M 1000 \""
186 #+bqn-sources
187 "/test/this.bqn\""))
188 (map (lambda (x)
189 (system (string-append "./BQN ./test/" x
190 ".bqn")))
191 '("cmp" "equal" "copy" "random"))
192 (system "make -C test/ffi"))))
193 (replace 'install
194 (lambda* (#:key outputs #:allow-other-keys)
195 (let* ((bin (string-append (assoc-ref outputs
196 "out")
197 "/bin"))
198 (lib (string-append (assoc-ref outputs
199 "lib")
200 "/lib")))
201 (mkdir-p bin)
202 (copy-recursively "BQN"
203 (string-append bin "/bqn"))
204 (install-file "libcbqn.so" lib)))))))
205 (native-inputs (list dbqn
206 bqn-sources
207 libffi
208 clang-toolchain
209 linux-libre-headers))))