Subject: Re: [PATCH] patch series: Update Raku ecosystem

From: "Daniel Sockwell" <[email-masked]>
Date: Tue, 30 Aug 2022 16:59:00 +0000

The fourth (and, for now, last) patch in this series updates Rakudo,
the primary Raku compiler.

Finally, I also want to note that one of the major changes in the Raku
ecosystem in the last few years is Raku's name: Raku was previously known
as "Perl 6" and the Guix module name refers to by that old name.  I'm not
sure if there's any way to update Guix's name (or add an alias?) without
breaking things.  But I wanted to bring the issue to the attention of 
people who might know the best way to proceed.

I look forward to any feedback you might have and/or to being able to
`guix install` an up-to-date version of Raku soon!

Best,
Daniel

From fcdc70a2ec483c6f1abe0c6230ad0aa9a29a2443 Mon Sep 17 00:00:00 2001
Message-Id: <[email-masked]>
From: Daniel Sockwell <[email-masked]>
Date: Tue, 30 Aug 2022 12:58:09 -0400
Subject: [PATCH] rakudo 2019.03->2022.07

---
 .../rakudo.do-not-pull-files-via-git.patch    | 26 +++++
 gnu/packages/perl6.scm                        | 98 ++++++++++++-------
 2 files changed, 88 insertions(+), 36 deletions(-)
 create mode 100644 gnu/packages/patches/rakudo.do-not-pull-files-via-git.patch

diff --git a/gnu/packages/patches/rakudo.do-not-pull-files-via-git.patch b/gnu/packages/patches/rakudo.do-not-pull-files-via-git.patch
new file mode 100644
index 0000000000..4edf67dd0d
--- /dev/null
+++ b/gnu/packages/patches/rakudo.do-not-pull-files-via-git.patch
@@ -0,0 +1,26 @@
+# Don't fetch nqp-configure from git (Guix supplies it as an input)
+diff --git a/Configure.pl b/Configure.after.pl
+index b315704..e4e3668 100755
+--- a/Configure.pl
++++ b/Configure.after.pl
+@@ -11,20 +11,6 @@ use Cwd;
+ use FindBin;
+ 
+ 
+-BEGIN {
+-    # Download / Update submodules
+-    my $set_config = !qx{git config rakudo.initialized};
+-    if ( !-e '3rdparty/nqp-configure/LICENSE' ) {
+-        my $code = system($^X, 'tools/build/update-submodules.pl', Cwd::cwd(), @ARGV);
+-        exit 1 if $code;
+-        $set_config = 1;
+-    }
+-    if ($set_config) {
+-        system("git config submodule.recurse true");
+-        system("git config rakudo.initialized 1");
+-    }
+-}
+-
+ use lib ( "$FindBin::Bin/tools/lib",
+     "$FindBin::Bin/3rdparty/nqp-configure/lib" );
+ use NQP::Config qw<system_or_die slurp>;
diff --git a/gnu/packages/perl6.scm b/gnu/packages/perl6.scm
index 5f43cd59aa..3fedf08f6d 100644
--- a/gnu/packages/perl6.scm
+++ b/gnu/packages/perl6.scm
@@ -27,6 +27,7 @@ (define-module (gnu packages perl6)
   #:use-module (guix build-system perl)
   #:use-module (guix build-system rakudo)
   #:use-module (gnu packages)
+  #:use-module (gnu packages gcc)
   #:use-module (gnu packages bdw-gc)
   #:use-module (gnu packages libevent)
   #:use-module (gnu packages libffi)
@@ -188,64 +189,89 @@ (define-public nqp
 (define-public rakudo
   (package
     (name "rakudo")
-    (version "2019.03.1")
+    (version "2022.07")
     (source
-      (origin
-        (method url-fetch)
-        (uri (string-append "https://rakudo.perl6.org/downloads/rakudo/rakudo-"
-                            version ".tar.gz"))
-        (sha256
-         (base32
-          "1nllf69v8xr6v3kkj7pmryg11n5m3ajfkr7j72pvhrgnjy8lv3r1"))))
+     (origin
+      (method url-fetch)
+      (uri (string-append "https://rakudo.perl6.org/dl/rakudo/rakudo-"
+                          version ".tar.gz"))
+      (sha256 (base32 "1bchc3r0axrif2mfgpbadcgi8vgkdq8syksv0lm7klp1akbcjfvs"))
+      (patches (search-patches "rakudo.do-not-pull-files-via-git.patch"))))
     (build-system perl-build-system)
     (arguments
      '(#:phases
        (modify-phases %standard-phases
-         (add-after 'unpack 'patch-source-date
-           (lambda _
-             (substitute* "tools/build/gen-version.pl"
-               (("gmtime") "gmtime(0)"))
-             #t))
          (add-after 'patch-source-shebangs 'patch-more-shebangs
            (lambda _
              (substitute* '("tools/build/create-js-runner.pl"
-                            "tools/build/create-moar-runner.p6"
                             "tools/build/create-jvm-runner.pl"
-                            "src/core/Proc.pm6")
-               (("/bin/sh") (which "sh")))
-             #t))
+                            "src/core.c/Proc.pm6")
+               (("/bin/sh")
+                (which "sh")))))
          (replace 'configure
            (lambda* (#:key inputs outputs #:allow-other-keys)
-             (let ((out (assoc-ref outputs "out"))
-                   (nqp (assoc-ref inputs "nqp")))
-               (invoke "perl" "./Configure.pl"
+             (let ((out  (assoc-ref outputs "out"))
+                   (nqp  (assoc-ref inputs "nqp"))
+                   (nqp-config (assoc-ref inputs "nqp-configure")))
+               (setenv "RAKULIB" (string-append nqp-config "/lib:"
+                                                (or (getenv "RAKULIB") "")))
+               (invoke "perl"
+                       "./Configure.pl"
                        "--backend=moar"
                        "--with-nqp" (string-append nqp "/bin/nqp")
                        "--prefix" out))))
-         ;; This is the recommended tool for distro maintainers to install perl6
+         (add-before 'check 'setup-for-rakudo-tests
+           (lambda _
+             ;; fudging tests requires downloading the Roast spectests
+             (substitute* "Makefile"
+               (("M_HARNESS5_WITH_FUDGE) --verbosity=1")
+                "M_HARNESS5) --verbosity=1"))
+             (setenv "HOME" "/tmp/")
+             (mkdir-p "/tmp/.raku/short") ;needed for t/05-messages/03-errors.t
+             (substitute* "t/09-moar/01-profilers.t"
+               (("ok.*\\$htmlpath" html-test-text)
+                (string-append "todo \"harness5 fails to write html profile\";"
+                               html-test-text)))))
+         ;; This is the recommended tool for distro maintainers to install Raku
          ;; modules systemwide.  See: https://github.com/ugexe/zef/issues/117
          (add-after 'install 'install-dist-tool
            (lambda* (#:key outputs #:allow-other-keys)
-             (let* ((out  (assoc-ref outputs "out"))
+             (let* ((out (assoc-ref outputs "out"))
                     (dest (string-append out "/share/perl6/tools")))
                (install-file "tools/install-dist.p6" dest)
-               (substitute* (string-append dest "/install-dist.p6")
-                 (("/usr/bin/env perl6")
-                  (string-append out "/bin/perl6"))))
-             #t)))))
+               (install-file "tools/install-dist.raku" dest)
+               (substitute* `(,(string-append dest "/install-dist.raku")
+                              ,(string-append dest "/install-dist.p6"))
+                 (("/usr/bin/env raku")
+                  (string-append out "/bin/raku")))))))))
     (inputs
-     (list moarvm nqp openssl))
+     (list libatomic-ops ;\
+           libuv         ; for NativeCall
+           libtommath    ;/
+           gcc           ; could be a native-input, but needed for NativeCall in practice
+           nqp))
+    (native-inputs
+     (list nqp-configure))
     (home-page "https://rakudo.org/")
     (native-search-paths
-      (list (search-path-specification
-              (variable "PERL6LIB")
-              (separator ",")
-              (files '("share/perl6/lib"
-                       "share/perl6/site/lib"
-                       "share/perl6/vendor/lib")))))
-    (synopsis "Perl 6 Compiler")
-    (description "Rakudo Perl is a compiler that implements the Perl 6
-specification and runs on top of several virtual machines.")
+     (list (search-path-specification
+            (variable "RAKULIB")
+            (separator ",")
+            (files '("share/nqp/lib"
+                     "share/perl6/lib"        "share/raku/lib"
+                     "share/perl6/site/lib"   "share/raku/site/lib"
+                     "share/perl6/vendor/lib" "share/raku/vendor/lib")))))
+    (synopsis "Compiler for the Raku programming language")
+    (description "Rakudo is a compiler for Raku, a programming language
+that prioritizes expressiveness and is optimized for fun.  More specifically,
+Raku is an omni-paradigm, open source, concurrency friendly, metaprogrammable,
+JIT- and AOT-compiled, interoperable, linguistically inspired, and gradually
+typed programming language with Regex/Unicode superpowers.  Raku's initial
+design was lead by Larry Wall and Raku was formerly known as Perl 6.
+
+Rakudo is written primarily in Raku, with lower-level features in NQP;
+Rakudo implements the Roast specification suite for Raku compilers and
+targets multiple virtual machines including MoarVM.")
     (license license:artistic2.0)))
 
 (define-public perl6-grammar-debugger
-- 
2.37.2