Building Real Applications in Scala Native
Session Abstract
Scala Native is great! It creates small and fast binaries, and can access all operating systems features. This workshop will introduce working with Scala Native by building a terminal based application. We’ll learn how to setup and build Native code, call into with system libraries, and use the archaic but powerful features of the terminal.
Session Description
Overview
Scala Native is a powerful tool, but underappreciated. The goal of this workshop is to show you how to work with Scala Native, and some of the unique features it unlocks. In particular the workshop will cover:
1. Building tools with Scala Native, including project setup, building executables, and using the FFI.
2. Knowledge of working with the terminal, at both a low-level (ANSI escape codes and C APIs), and a high-level (creating terminal user interfaces using a framework)
3. An appreciation of the ecosystem that is available in Scala Native.
The core of this workshop will be building an application with a terminal user interface. The exact kind of application is to be determined; current ideas are:
- an HTTP client like Slumber;
- a Bluesky client; or
- a todo list.
You must have Scala Native installed before the workshop. Scala Native requires some additional installation steps beyond installing just Scala. Furthermore, the operating system specific features we will use are only available in Unix-like systems (Linux or MacOS). If you are using Windows then you must be able to use WSL.
Details
1. Creating a sbt project that uses Scala Native. The Scala Native plugin, cross-project setup and its advantages. Building and linking. Finding the executable.
2. Interacting with the terminal. Basic ANSI escape codes. Features only available via operating system calls (tcgetattr, tcsetattr, ioctl). Using Scala Native’s existing OS bindings.
3. Using the FFI. Binding a C function in Scala Native. C types, memory allocation. Writing C stub code to produce the value of constants.
4. Building the application. We’ll switch to using Terminus so we don’t have to build everything from scratch. This will allow us to explore the Scala Native ecosystem (e.g. Cats Effect.)