Babashka 1.13.220 gets FFI
Babashka 1.13.220, the latest release, introduces a new feature called babashka.ffi, enabling direct calls to C libraries from Babashka scripts. This functionality is also available as a standalone library for JVM Clojure projects. The API is currently experimental, but feedback is encouraged. The release includes a demo showcasing how to load libraries like libz from the system and perform mathematical operations.
The API decisions in babashka.ffi are inspired by coffi, but it differs in several ways. Users can supply an explicit library to defcfn, and it features a place concept that allows efficient reading and writing to structs and unions. Babashka.ffi builds on java.lang.foreign and requires explicit memory management via arenas. This release changes the default binary type for Babashka on Linux to mostly-static, with the exception of the glibc shared library.
The aarch64 binary remains dynamically linked. A statically linked binary can be obtained using the installer script with the --static flag. The release also brings improvements to task handling, including :exec-fn tasks composing through :depends and the ability to provide :exec-args directly on a task. Additionally, a :cmd tree can now be provided through a var, with the namespace loaded on demand.
The development of FFI and validation through examples and libraries involved the assistance of Large Language Models.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.