(λ (x) (create x) '(knowledge))

toAPK chez-scheme

Porting Cisco Chez Scheme with toAPK · April 16, 2020

SBCL 2.0.3 was just accepted into Alpine Linux, I'm finally looking at a high possibility that it will be compilable on musl libc for aarch64, and all of that means I might finally be able to move SBCL out of Alpine's testing repo and into Community. Once I've gotten it into Community it's a six month period of support and then it can be mainlined. This would be huge for me, as it would allow me to use alpine stable releases on Alpine servers and docker containers. Using stable builds would be much safer on my sanity overall. The other neat little benefit is that this means SBCL will be available for PostmarketOS phones. It's already there for armv7 systems such as the Nokia N900, but aarch64 support opens up SBCL on the Pine Phone!

As you can tell I spend a lot of time building packages for Alpine. The work is enjoyable, the maintainers are absolutely delightful people, and in the end I get to contribute to a large open source project that I personally use in my personal and professional life. But sometimes it would be nice if I could just run a script, create a MR in Gitlab and move on with my day.That wasn't a possibility when I first started. I had to learn the APKBUILD format, pick up the nuances of working with the Alpine team, and really struggle to learn about the manual compilation tools used in various packages. When I picked up SBCL I had never contemplated compiling software for redistribution, the most I had done was a simple (save-lisp-and-die) for some personal tools I made.

I'm happy to say that struggling through all of that is what gave me an understanding and appreciation for Makefiles, and the amount of work that goes into a Linux distribution, but I still have that nagging need to have a more streamlined approach. CI solved some of my problems, I have a personal APK repo on git where I can test my packages. The rest of that streamlining comes from a tool I wrote in fennel; a little lisp-1 built on top of Lua.

toAPK is my attempt to lower the barrier of entry for those that want to contribute to Alpine's package repos. The tool itself is extremely simple, and currently only targets Arch Linux style PKGBUILDs, but this provides an ample supply of constantly updated packages from which to source. For the most part the results are usable, there are minor formatting errors throughout toAPK's results, but the build/package context's and extrapolated data are more or less usable as is. Anyone using the tool for a new package is likely to hear a few complaints on minor formatting issues which are trivially solved.

The easiest way to showcase all of that is to just use it in action, so lets get an APKBUILD going for Cisco's Chez Scheme!

toAPK Showcase

Building toAPK can be done simply by cloning the repo with git, and then running make all in the root of the repo. toAPK compiles to Lua script, but is completely usable as a Fennel program as well.For our example we'll be using this PKGBUILD.

Before we run the tool for the first time we need to configure the clientconf.lua file, this will denote our contributor and maintainer information, as well as the email we want to associate with our exported packages. If you ran make all, that should be in /usr/share/lua/5.3/clientconf.lua by default.


local clientconf = {}

clientconf.Info = {
   flastname = "Will Sinatra",
   Email = ""
}

return clientconf
 

Super simply configuration, eventually I'll add some additional logic to the makefile to help generate that so that it doesn't just default to my dev information. Once we're configured though using the tool is as simple as denoting the package type, and the package itself.


devius:~$ toAPK PKGBUILD chez-scheme
 

and our results are:


# Contributor: Will Sinatra 
# Maintainer: Will Sinatra 
pkgname=chez-scheme
pkgver=9.5.2
pkgrel=0
pkgdesc="Chez Scheme is a compiler and run-time system for the language of the Revised^6 Report on Scheme (R6RS), with numerous extensions."
url="https://github.com/cisco/ChezScheme"
arch=i686 x86_64
license='APL'
depends='ncurses' 'libx11' 'libutil-linux'
source="https://github.com/cisco/ChezScheme/releases/download/v$pkgver/csv$pkgver.tar.gz"

build() {
  cd "$srcdir/${_archivename}"
  ./configure --installprefix=/usr --temproot=$pkgdir --threads
}

package() {
  cd "${srcdir}/${_archivename}"
  make install DESTDIR="$pkgdir"
}
 

Pretty slick if I say so myself. Right now the obvious compliance issues are:

  • arch=i686 x86_64
  • depends='ncurses' 'libx11' 'libutil-linux'
  • cd "$srcdir/${_archivename}"
These issues are all pretty trivial:
  • arch= should be enclosed in quotes, arch="x86 x86_64"
  • similarly depends= should be enclosed in quotes to form depends="ncurses libx11 libutil-linux"
  • and cd $srcdir/${_archivename} is just an invalid format in Alpine.

Logic can, and in due time will, be added to parse these issues automatically such that the resulting APKBUILD output is 100% compliant. The only other error that I can think of currently is that custom variables aren't retained. If you look at the PKGBUILD for chez-scheme you'll notice a _archivename=csv$pkgver, which isn't picked up at all by toAPK. In Alpine this call would be a builddir="$srcdir/csv$pkgver" variable, while not hard to implement, it simply isn't as of version 0.2.

I hope someone finds this tool helpful, if I can refine it to the point that it produces compliant APKBUILDS most of the time, I'll try and get it into the Alpine package tooling repo. If you do use it and run into issues/have a feature request feel free to submit an issue on the gitlab repo!

Bio

(defparameter *Will_Sinatra* '((Age . 31) (Occupation . DevOps Engineer) (FOSS-Dev . true) (Locale . Maine) (Languages . ("Lisp" "Fennel" "Lua" "Go" "Nim")) (Certs . ("LFCS"))))

"Very little indeed is needed to live a happy life." - Aurelius