HEIMDALL

A maintenance of all Heimdall websites and services is in progress. Therefore, most of them are not yet available. Thank you for your understanding.


How to build ChezScheme on OpenBSD

July 28, 2022 // Last edited on July 29, 2022

Hi! It's me again.
Recently, I've been messing around with Scheme a lot, and I really like it so far. It's a relatively small but elegant, functional and pure Lisp dialect (you know, Lots of Irritating Superfluous Parentheses) that aims to only provide the tools to make complex functions, but not the latter. I'll probably write some articles on Scheme, but for now, see shido.info for a quick tour or TSPL4 for a complete book.

Since Scheme is a specification, there's a lot of different implementations. Among them, I tested several, such as Chicken, Guile, or Chez Scheme. The latter, being the most powerful, stable, and complete[1], naturally became my favorite, and the one I use in most cases for my projects (on Linux).

However, there was a problem. Chez didn't « officially » support OpenBSD[2]. And since my laptop has been running it, I couldn't use my favourite Scheme when I wasn't home.
So, I looked for solutions on how to build Chez on OpenBSD[3].
Here's how I did it.

It should probably work on other BSDs as well. Adjust according to your system.

The boot files

In order to run properly, ChezScheme needs some files called boot files. They're responsible for the interpretation and compilation of your programs, and are specific to each OS. In order to build them for OpenBSD, you'll need a working Linux-based PC being on the same platform (x86, x86_64..).

If you don't have any Linux computer at hand to build the boot files, don't worry!
There's already a mirror of ChezScheme that includes OpenBSD boot files on our Git. You can already skip to The actual build.

Once you've booted your favorite Linux distro, you first need to clone the repo. Assuming you're in your home folder, do:

tux@linux ~ $ git clone https://github.com/cisco/ChezScheme --depth 1
tux@linux ~ $ cd ChezScheme
We use --depth 1 here to avoid having to download 1.5GB[4] worth of commits.

As soon as you're into the right folder, you just have to configure the Makefile and build it using make.

tux@linux ~/ChezScheme $ ./configure --threads
tux@linux ~/ChezScheme $ make -j4
Here, --threads is used to tell ChezScheme to enable (posix) thread support. You should probably keep it.
Adjust make -jN to the number of cores in your computer to speed up the build considerably!

Finally, when ChezScheme has finished building itself, you can cross-compile the boot files. To do this, simply create the right folder and build the boot files using make.

tux@linux ~/ChezScheme $ mkdir boot/ta6ob/
tux@linux ~/ChezScheme $ cd ta6le
tux@linux ~/C/ta6le $ make -f Mf-boot ta6ob.boot -j4
tux@linux ~/C/ta6le $ cd ../boot/
tux@linux ~/C/boot $ ls
... ta6le  ta6ob  ...
If you built ChezScheme without thread support, remove every t (for threads) from ta6ob and ta6le in the commands above.
Again, adjust make -f ... -jN to the number of cores in your computer.

The hard part is done. You can now put boot/ta6ob/ on a USB stick (or upload it somewhere) and go to the next part.

The actual build

Before building ChezScheme, you need to know a few things.

On OpenBSD (and on some other OSes), there's a security feature called W^X[5]. It prevents a program from writing and executing data in memory at the same time, thus stopping some buffer overflow attacks, among other things. The thing is: ChezScheme needs to do that in order to work. Fortunately, on OpenBSD, /usr/local is mounted with the option wxallowed, which allows exactly that. Therefore, we will use this folder to build Chez.

If you modified your fstab or if your OpenBSD installation differs from the « official » one, please check /etc/fstab for a mountpoint with the wxallowed flag. If there's none, manually add it on a line containing /usr/local, right after rw,.

Also, OpenBSD only ships BSDmake, but Chez needs GNUmake (since its Makefile is using gmake-specific syntax). You'll need to install it by running:

puffy@openbsd ~ $ doas pkg_add gmake

Everything's ready. We can finally start building Chez. First, we'll clone the repository in /usr/local/share as root, and we'll copy our boot files into Chez's folder (assuming you built them with the --threads flag and they're in /root/ta6ob/).

puffy@openbsd ~ $ doas -s
doas (puffy@openbsd) password:
root@openbsd /h/puffy # cd /usr/local/share/
root@openbsd /u/l/share # git clone https://github.com/cisco/ChezScheme --depth 1
root@openbsd /u/l/share # cd ChezScheme/
root@openbsd /u/l/s/ChezScheme # cp -r /root/ta6ob/ boot/

Or, if you want to use chez-openbsd, our mirror of ChezScheme that includes OpenBSD boot files, you just have to clone the repo (or download the zipfile from the releases).

root@openbsd /u/l/share # git clone https://basedwa.re/tmtt/chez-openbsd --depth 1 ChezScheme
root@openbsd /u/l/share # cd ChezScheme

Now that you downloaded the repo and that the boot files are here, we can configure the Makefile and build everything.

root@openbsd /u/l/s/ChezScheme # ./configure --threads
root@openbsd /u/l/s/ChezScheme # gmake -j4
For some reasons, gmake crashes after the first run (complaining about linking errors). If it happens, simply rerun the command and it'll work.
This time, adjust gmake -jN to the number of cores in your OpenBSD computer (not the Linux one, silly).

Once the build finished, we can, after all these adventures, install it on our system.

root@openbsd /u/l/s/ChezScheme # gmake install

CONGRATS!

You did it!
Hope it was helpful.

Go ahead, fool around with your brand new Scheme implementation on your OpenBSD machine. Have fun!

I hope one day someone will make a port out of this. Maybe I'll have to do it myself..?

I guess that's all.
See you soon, and, as always, take care of yourselves.

~ tmtt


1. That's just my opinion.
2. At least, there is no pre-built binary, no port, and very little documentation on how to do build it.
3. Hence the title.
4. I'm not kidding.
5. See here for more information.