summaryrefslogtreecommitdiffstats
path: root/content/posts/openbsd-compiling-rakudo-star/index.org
blob: aaab55dd1d57aab5260da616cc44d3655b85aaf7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#+TITLE: Compiling Rakudo Star on OpenBSD
#+DATE: 2020-07-25T02:54:34-04:00
#+DRAFT: true
#+DESCRIPTION:
#+TAGS[]: openbsd raku
#+KEYWORDS[]: openbsd raku
#+SLUG:
#+SUMMARY:

I really enjoy using [[https://raku.org/][raku]] to write small scripts for system
maintenance and text parsing. Its regex and grammar engine are next
level. The problem with using it on OpenBSD is that the packaged
version is a couple years out of date. The version in ports is from
2018, which contains various bugs surrounding nativecall on OpenBSD,
not to mention a lot of performance gains and bug fixes.

Instead of just compiling everything from source and installing them
as I did on my last system, I installed it using the [[https://github.com/rakudo/star][rakudo star]]
distribution and its =rstar= command. Rakudo Star is raku plus some
community modules and the =zef= package manager. It also comes with
the =rstar= command, which helps you in the build process.

I ran into a couple issues compiling it on OpenBSD while using the
=rstar= command, so I figured I'd turn it into a post.

First, it requires =bash= to be present on the host system as a build
dependency for the =rstar= install script, which isn't on OpenBSD by
default. Not to mention that many OpenBSD users do not use bash by
choice. Not that this is an issue with =rstar=, but more of a personal
grievance.

After installing =bash=, I came across another problem. Upon running
=rstar fetch=, which fetches all of the materials required to compile
and assemble the star distribution, it failed to pull in all 3 major
components. All of the modules are pulled in via =git=, which worked
well. The main rakudo components, =MoarVM=, =nqp=, and =rakudo=, are
pulled in as gzipped tarballs. Each of them failed to download
correctly, which I suspect is down to an issue with the bash
scripts. Tar also throws a warning about one of its arguments,
although it never gets used as the files it's supposed to be operating
on never appear.

#+BEGIN_SRC
[2020-07-25T05:25:33] [NOTIC] Downloading https://www.moarvm.org/releases/MoarVM-2020.02.1.tar.gz to /home/dante/star/tmp/tmp.IMPt8mIFoC
tar: WARNING! These patterns were not matched:
--strip-components=1
[2020-07-25T05:25:34] [CRIT]  Failed to download /home/dante/star/src/moarvm-2020.02.1
[2020-07-25T05:25:34] [NOTIC] Downloading https://github.com/perl6/nqp/releases/download/2020.02.1/nqp-2020.02.1.tar.gz to /home/dante/star/tmp/tmp.zDxiGW2Sxq
tar: WARNING! These patterns were not matched:
--strip-components=1
[2020-07-25T05:25:40] [CRIT]  Failed to download /home/dante/star/src/nqp-2020.02.1
[2020-07-25T05:25:40] [NOTIC] Downloading https://github.com/rakudo/rakudo/releases/download/2020.02.1/rakudo-2020.02.1.tar.gz to /home/dante/star/tmp/tmp.W1mRYHVj1C
tar: WARNING! These patterns were not matched:
--strip-components=1
[2020-07-25T05:25:46] [CRIT]  Failed to download /home/dante/star/src/rakudo-2020.02.1
#+END_SRC

To work around this I downloaded the required files manually using
OpenBSD's =ftp= command and extracted them into the =src= directory
that had been created by the script. Another small caveat is that
MoarVM automatically extracts into a directory called
=MoarVM-2020.02.1=, which needs to be completely lower-cased for the
=rstar= to work.

#+BEGIN_SRC shell
cd src
ftp https://www.moarvm.org/releases/MoarVM-2020.02.1.tar.gz
ftp https://github.com/perl6/nqp/releases/download/2020.02.1/nqp-2020.02.1.tar.gz
ftp https://github.com/rakudo/rakudo/releases/download/2020.02.1/rakudo-2020.02.1.tar.gz
tar -xzf MoarVM-2020.02.1.tar.gz
tar -xzf nqp-2020.02.1.tar.gz
tar -xzf rakudo-2020.02.1.tar.gz
mv MoarVM-2020.02.1 moarvm-2020.02.1
rm *.tar.gz
cd ..
#+END_SRC

Running =rstar install= then began compiling things. =rstar install=
will install rakudo star into the build directory by default, but you
can change that with =-p= to specify a prefix location. MoarVM and nqp
both compiled and installed fine, but when it came to compiling
Rakudo, with a memory allocation error message.

#+BEGIN_SRC
+++ Generating	gen/moar/Compiler.nqp
+++ Generating	gen/moar/Optimizer.nqp
+++ Compiling	blib/Perl6/Optimizer.moarvm
+++ Compiling	blib/Perl6/Compiler.moarvm
+++ Compiling	rakudo.moarvm
+++ Generating	gen/moar/BOOTSTRAP/v6c.nqp
+++ Generating	gen/moar/Metamodel.nqp
+++ Compiling	blib/Perl6/Metamodel.moarvm
+++ Compiling	blib/Perl6/BOOTSTRAP/v6c.moarvm
+++ Compiling	blib/CORE.c.setting.moarvm
The following step can take a long time, please be patient.
Stage start      :   0.000
MoarVM panic: Memory allocation failed; could not allocate 84800 bytes
*** Error 1 in /home/dante/star/tmp/tmp.gqTyPvsgV1 (Makefile:800 'blib/CORE.c.setting.moarvm': @'/home/dante/star/bin/moar' --libpath='/home...)
[2020-07-25T05:38:43] [ALERT] Build failed!
#+END_SRC

I tried then manually building rakudo to see if I could figure out
what the problem was.

#+BEGIN_SRC shell
cd src/rakudo-2020.02.1
./Configure.pl --prefix /home/dante/star/
make install
#+END_SRC

While rakudo was compiling, I monitored memory usage in a separate
=tmux= pane, and noticed that the =moarvm= process was using around
760 MB of RAM before it crashed. 768 MB is the maximum amount of ram a
process can use in OpenBSD under a user with the default login class,
as specified in =/etc/login.conf=.

To remedy the problem, I changed my user's class to =staff=, which
grants it a much higher =datasize= limit, among a couple other
things. If you're interested about how this works, you can check out
[[https://man.openbsd.org/login.conf.5][=login.conf(5)=]] and the =/etc/login.conf= file on your system.

#+BEGIN_SRC shell
doas usermod -L staff dante
#+END_SRC

After that, I restarted the build and install using the =rstar=
command as before, just to make sure it sets everything up how it
wants.

After a around half an hour of text scrolling, I was finally presented
the following message.

#+BEGIN_SRC
[2020-07-25T06:34:06] [INFO]  Rakudo Star has been installed into /home/dante/star!
[2020-07-25T06:34:06] [INFO]  The installation took 0h 25m 02s.
[2020-07-25T06:34:06] [INFO]
[2020-07-25T06:34:06] [INFO]  You may need to add the following paths to your $PATH:
[2020-07-25T06:34:06] [INFO]    /home/dante/star/bin
[2020-07-25T06:34:06] [INFO]    /home/dante/star/share/perl6/site/bin
[2020-07-25T06:34:06] [INFO]    /home/dante/star/share/perl6/vendor/bin
[2020-07-25T06:34:06] [INFO]    /home/dante/star/share/perl6/core/bin
#+END_SRC

Alright!

I added to my path by editing my =~/.profile= and added the following
line.

#+BEGIN_SRC diff
  --- .profile.old Sat Jul 25 06:42:48 2020 +++ .profile Sat Jul 25
  06:42:31 2020 @@ -3,4 +3,5 @@ # sh/ksh initialization

   PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games
  +PATH=$PATH:/home/dante/star/bin:/home/dante/star/share/perl6/site/bin:/home/dante/star/share/perl6/vendor/bin:/home/dante/star/share/perl6/core/bin
  export PATH HOME TERM
#+END_SRC

I chose to keep it in the =star= directory instead of installing it to
=/usr/local= in case the version of rakudo in ports gets updated some
time.

I now have a proper up to date version of raku running on my OpenBSD
machine! Happy hacking!