gnu: dbqn: Install regular files rather than copying them recursively.
[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 ;;; Copyright © 2022 Liliana Marie Prikler <liliana.prikler@gmail.com>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
11 ;;;
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
16 ;;;
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20 (define-module (gnu packages bqn)
21 #:use-module ((guix licenses) #:prefix license:)
22 #:use-module (guix gexp)
23 #:use-module (guix packages)
24 #:use-module (guix download)
25 #:use-module (guix git-download)
26 #:use-module (guix build-system copy)
27 #:use-module (guix build-system gnu)
28 #:use-module (guix utils)
29 #:use-module (gnu packages)
30 #:use-module (gnu packages bash)
31 #:use-module (gnu packages libffi)
32 #:use-module (gnu packages base)
33 #:use-module (gnu packages pkg-config)
34 #:use-module (gnu packages llvm)
35 #:use-module (gnu packages java)
36 #:use-module (gnu packages linux)
37 #:use-module (gnu packages compression))
38
39 (define-public dbqn
40 (let ((commit "88f2b43966a75cc2c382421218eb30003bb16f4a")
41 (revision "1"))
42 (package
43 (name "dbqn")
44 (version (git-version "0.2.1" revision commit))
45 (source (origin
46 (method git-fetch)
47 (uri (git-reference
48 (url "https://github.com/dzaima/BQN")
49 (commit commit)))
50 (file-name (git-file-name name version))
51 (sha256
52 (base32
53 "06mzvv7kmandhgwb6jwz3rivsj4ic549sy8afnb5zr6mfn5isyg5"))))
54 (build-system gnu-build-system)
55 (arguments
56 (list
57 #:imported-modules `(,@%gnu-build-system-modules
58 (guix build syscalls)
59 (guix build ant-build-system))
60 #:modules `((guix build gnu-build-system)
61 ((guix build ant-build-system)
62 #:prefix ant:)
63 (guix build utils))
64 #:phases #~(modify-phases %standard-phases
65 (delete 'configure)
66 (replace 'build
67 (lambda* _
68 (invoke "./build")
69 (chmod "./BQN" #o755)))
70 (replace 'check
71 (lambda* (#:key tests? #:allow-other-keys)
72 (when tests?
73 (system "./BQN ./test/test"))))
74 (add-after 'install 'reorder-jar-content
75 (lambda* (#:key outputs #:allow-other-keys)
76 (apply (assoc-ref ant:%standard-phases
77 'reorder-jar-content)
78 #:outputs (list outputs))))
79 (add-after 'reorder-jar-content 'jar-indices
80 (lambda* (#:key outputs #:allow-other-keys)
81 (apply (assoc-ref ant:%standard-phases
82 'generate-jar-indices)
83 #:outputs (list outputs))))
84 (add-after 'jar-indices 'fix-jar-timestamps
85 (lambda* (#:key outputs #:allow-other-keys)
86 (apply (assoc-ref ant:%standard-phases
87 'reorder-jar-content)
88 #:outputs (list outputs))))
89 (replace 'install
90 (lambda* (#:key outputs #:allow-other-keys)
91 (let* ((out (assoc-ref outputs "out"))
92 (dest-bin (string-append out "/bin"))
93 (dest-jar (string-append out "/share/java")))
94 (mkdir-p dest-bin)
95 (mkdir-p dest-jar)
96 (rename-file "BQN" "dbqn")
97 (install-file "dbqn" dest-bin)
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" revision 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 #:make-flags #~(list (string-append "CC=" #$(cc-for-target)))
146 #:phases #~(modify-phases %standard-phases
147 (delete 'configure)
148 (add-before 'build 'generate-bytecode
149 (lambda* (#:key inputs #:allow-other-keys)
150 (system (string-append #+dbqn
151 "/bin/dbqn ./genRuntime "
152 #+bqn-sources))))
153 (replace 'install
154 (lambda* (#:key outputs #:allow-other-keys)
155 (mkdir-p (string-append #$output "/bin"))
156 (chmod "BQN" #o755)
157 (copy-recursively "BQN"
158 (string-append #$output
159 "/bin/bqn")))))))
160 (native-inputs (list dbqn bqn-sources))
161 (inputs (list icedtea-8 libffi))
162 (synopsis "BQN implementation in C")
163 (description "This package provides the reference implementation of
164 @uref{https://mlochbaum.github.io/BQN/, BQN}, a programming language inspired
165 by APL.")
166 (home-page "https://mlochbaum.github.io/BQN/")
167 (license license:gpl3))))
168
169 (define-public cbqn
170 (package
171 (inherit cbqn-bootstrap)
172 (name "cbqn")
173 (outputs '("out" "lib"))
174 (arguments
175 (substitute-keyword-arguments (strip-keyword-arguments
176 (list #:tests?)
177 (package-arguments cbqn-bootstrap))
178 ((#:make-flags flags #~(list))
179 #~(cons* "shared-o3" "o3" #$flags))
180 ((#:phases phases #~%standard-phases)
181 #~(modify-phases #$phases
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 "out")
196 "/bin"))
197 (lib (string-append (assoc-ref outputs "lib")
198 "/lib")))
199 (mkdir-p bin)
200 (copy-recursively "BQN"
201 (string-append bin "/bqn"))
202 (install-file "libcbqn.so" lib))))))))
203 (native-inputs (list dbqn
204 bqn-sources
205 libffi
206 linux-libre-headers))))