gnu: cbqn: Build using GCC.
[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 (copy-recursively "BQN"
97 (string-append dest-bin
98 "/dbqn"))
99 (install-file "BQN.jar" dest-jar)
100 (substitute* (string-append dest-bin "/dbqn")
101 (("BQN.jar")
102 (string-append dest-jar "/BQN.jar")))))))))
103 (native-inputs (list `(,icedtea-8 "jdk") zip))
104 (inputs (list icedtea-8 bash-minimal))
105 (synopsis "BQN implementation based on dzaima/APL")
106 (description
107 "dbqn is a Java implementation of the
108 @uref{https://mlochbaum.github.io/BQN/, BQN programming language} that does
109 not need to be bootstrapped, based on an earlier Java implementation of APL by
110 the same author.")
111 (home-page "https://github.com/dzaima/BQN")
112 (license license:expat))))
113
114 (define bqn-sources
115 ;; Aside from dbqn above, the main bqn repository is used by other
116 ;; implementations as a "known good" set of sources. CBQN uses dbqn to
117 ;; generate an intermediate bytecode for its own compilation.
118 (let ((commit "e219af48401473a7bac49bdd8b89d69082cf5dd8"))
119 (origin
120 (method git-fetch)
121 (uri (git-reference
122 (url "https://github.com/mlochbaum/BQN")
123 (commit commit)))
124 (file-name (git-file-name "bqn-sources" commit))
125 (sha256
126 (base32 "0r6pa9lscl2395g4xlvmg90vpdsjzhin4f1r0s7brymmpvmns2yc")))))
127
128 (define cbqn-bootstrap
129 (let* ((revision "1")
130 (commit "9c1cbdc99863b1da0116df61cd832137b196dc5c"))
131 (package
132 (name "cbqn-bootstrap")
133 (version (git-version "0" revision commit))
134 (source (origin
135 (method git-fetch)
136 (uri (git-reference
137 (url "https://github.com/dzaima/CBQN")
138 (commit commit)))
139 (file-name (git-file-name name version))
140 (sha256
141 (base32
142 "0w38fhwf20drkyijy6nfnhmc5g5gw0zmzgmy1q605x57znlj85a2"))))
143 (build-system gnu-build-system)
144 (arguments
145 (list #:tests? #f ;skipping tests for bootstrap
146 #:make-flags #~(list (string-append "CC=" #$(cc-for-target)))
147 #:phases #~(modify-phases %standard-phases
148 (delete 'configure)
149 (add-before 'build 'generate-bytecode
150 (lambda* (#:key inputs #:allow-other-keys)
151 (system (string-append #+dbqn
152 "/bin/dbqn ./genRuntime "
153 #+bqn-sources))))
154 (replace 'install
155 (lambda* (#:key outputs #:allow-other-keys)
156 (mkdir-p (string-append #$output "/bin"))
157 (chmod "BQN" #o755)
158 (copy-recursively "BQN"
159 (string-append #$output
160 "/bin/bqn")))))))
161 (native-inputs (list dbqn bqn-sources))
162 (inputs (list icedtea-8 libffi))
163 (synopsis "BQN implementation in C")
164 (description "This package provides the reference implementation of
165 @uref{https://mlochbaum.github.io/BQN/, BQN}, a programming language inspired
166 by APL.")
167 (home-page "https://mlochbaum.github.io/BQN/")
168 (license license:gpl3))))
169
170 (define-public cbqn
171 (package
172 (inherit cbqn-bootstrap)
173 (name "cbqn")
174 (outputs '("out" "lib"))
175 (arguments
176 (substitute-keyword-arguments (strip-keyword-arguments
177 (list #:tests?)
178 (package-arguments cbqn-bootstrap))
179 ((#:make-flags flags #~(list))
180 #~(cons* "shared-o3" "o3" #$flags))
181 ((#:phases phases #~%standard-phases)
182 #~(modify-phases #$phases
183 (replace 'check
184 (lambda* (#:key inputs tests? #:allow-other-keys)
185 (when tests?
186 (system (string-append "./BQN -M 1000 \""
187 #+bqn-sources
188 "/test/this.bqn\""))
189 (map (lambda (x)
190 (system (string-append "./BQN ./test/" x
191 ".bqn")))
192 '("cmp" "equal" "copy" "random"))
193 (system "make -C test/ffi"))))
194 (replace 'install
195 (lambda* (#:key outputs #:allow-other-keys)
196 (let* ((bin (string-append (assoc-ref outputs "out")
197 "/bin"))
198 (lib (string-append (assoc-ref outputs "lib")
199 "/lib")))
200 (mkdir-p bin)
201 (copy-recursively "BQN"
202 (string-append bin "/bqn"))
203 (install-file "libcbqn.so" lib))))))))
204 (native-inputs (list dbqn
205 bqn-sources
206 libffi
207 linux-libre-headers))))