Subject: [bug#58100] [PATCH] gnu: cbqn: factor out singeli into derivative package.

From: Christopher Rodriguez <[email-masked]>
Date: Mon, 26 Sep 2022 15:12:12 -0400

Persuant to a recent conversation[1] with upstream, I've factored the
AVX2-dependent builds into their own package (defaulting to a generic build
instead).

+ gnu/packages/bqn.scm: cbqn-singeli
~ gnu/packages/bqn.scm: cbqn: changed make flags, inputs, and commit.
---
 gnu/packages/bqn.scm | 45 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 39 insertions(+), 6 deletions(-)

diff --git a/gnu/packages/bqn.scm b/gnu/packages/bqn.scm
index c4e0f39efb..56705beede 100644
--- a/gnu/packages/bqn.scm
+++ b/gnu/packages/bqn.scm
@@ -126,7 +126,7 @@ (define bqn-sources
 
 (define cbqn-bootstrap
   (let* ((revision "1")
-         (commit "9c1cbdc99863b1da0116df61cd832137b196dc5c"))
+         (commit "bd823839feaf42af4013e5a245981f58f563e659"))
     (package
       (name "cbqn-bootstrap")
       (version (git-version "0" "1" commit))
@@ -138,7 +138,7 @@ (define cbqn-bootstrap
                 (file-name (git-file-name name version))
                 (sha256
                  (base32
-                  "0w38fhwf20drkyijy6nfnhmc5g5gw0zmzgmy1q605x57znlj85a2"))))
+                  "0735mixvpgp2g1jsmbg7aaw35r4xs348y7djkwdvb0193ais6xz2"))))
       (build-system gnu-build-system)
       (arguments
        (list #:tests? #f                         ;skipping tests for bootstrap
@@ -182,12 +182,9 @@ (define-public cbqn
     (name "cbqn")
     (outputs '("out" "lib"))
     (arguments
-     (list #:make-flags '(list "shared-o3" "o3n-singeli")
+     (list #:make-flags '(list "shared-o3" "o3")
            #:phases #~(modify-phases %standard-phases
                         (delete 'configure)
-                        (add-before 'build 'link-singeli
-                          (lambda* (#:key inputs #:allow-other-keys)
-                            (symlink #+singeli-sources "Singeli")))
                         (add-before 'build 'generate-bytecode
                           (lambda* (#:key inputs #:allow-other-keys)
                             (system (string-append #+dbqn
@@ -222,3 +219,39 @@ (define-public cbqn
                          libffi
                          clang-toolchain
                          linux-libre-headers))))
+(define-public cbqn-singeli
+  (package
+    (inherit cbqn)
+    (name "cbqn-singeli")
+    (outputs '("out"))
+    (arguments
+     (list #:make-flags '(list "singeli=1 f='-mavx2 -mbmi2 -O3' c")
+           #:phases #~(modify-phases %standard-phases
+                        (delete 'configure)
+                        (add-before 'build 'link-singeli
+                          (lambda* (#:key inputs #:allow-other-keys)
+                            (symlink #+singeli-sources "Singeli")))
+                        (add-before 'build 'generate-bytecode
+                          (lambda* (#:key inputs #:allow-other-keys)
+                            (system (string-append #+dbqn
+                                                   "/bin/dbqn ./genRuntime "
+                                                   #+bqn-sources))))
+                        (replace 'check
+                          (lambda* (#:key inputs tests? #:allow-other-keys)
+                            (when tests?
+                              (system (string-append "./BQN -M 1000 \""
+                                                     #+bqn-sources
+                                                     "/test/this.bqn\""))
+                              (map (lambda (x)
+                                     (system (string-append "./BQN ./test/" x
+                                                            ".bqn")))
+                                   '("cmp" "equal" "copy" "random")))))
+                        (replace 'install
+                          (lambda* (#:key outputs #:allow-other-keys)
+                            (let* ((bin (string-append (assoc-ref outputs
+                                                                  "out")
+                                                       "/bin")))
+                              (mkdir-p bin)
+                              (copy-recursively "BQN"
+                                                (string-append bin "/bqn"))))))))))
+
-- 
2.37.3