As CloudABI has been inspired by FreeBSD's Capsicum sandboxing framework, it goes without saying that support for CloudABI on FreeBSD has been rock solid from day one. FreeBSD's implementation of CloudABI is treated as a reference platform.
This document explains how to develop software for CloudABI on FreeBSD and how FreeBSD can be used to run this software. These instructions also apply to TrueOS and partially to DragonFly BSD. DragonFly BSD cannot run CloudABI software yet, but can still be used for software development purposes.
A complete toolchain for CloudABI based on LLVM, Clang and LLD is already provided by both the FreeBSD and DragonFly BSD Ports Collections. This toolchain can be installed by running the following command:
This package installs a copy of the Clang C and C++ compiler for every architecture supported by CloudABI, thus making it very easy to cross compile software for other hardware:
The toolchain provided by the operating system does not ship with any code that has been cross compiled for CloudABI, meaning it cannot be used to build CloudABI applications on its own. Cross compiled libraries and tools are instead provided by the CloudABI Ports Collection. Software that is part of the CloudABI Ports Collection is automatically packaged for a variety of systems, including FreeBSD's pkg.
The CloudABI Ports Collection can be accessed by adding both a repository snippet and a public signing key to pkg's configuration directory. This can be accomplished by running the following commands:
It typically makes sense to at least install the standard C++ runtime environment package, so that it is possible to compile C and C++ applications that depend on just core C, C++ and POSIX interfaces:
A full list of packages provided by the CloudABI Ports Collection can be obtained by running the following command:
Support for running CloudABI executables is provided by the cloudabi, cloudabi32 and cloudabi64 kernel modules. The first kernel module implements all of the CPU architecture independent functionality, whereas the two latter implement system calls for 32-bits and 64-bits CPUs specifically.
These kernel modules have been integrated into the FreeBSD source tree, meaning that FreeBSD 11.0 and TrueOS ship with CloudABI support out of the box. The kernel modules can be loaded at runtime using kldload:
These modules can also be loaded automatically at system boot time by adding cloudabi32_load="YES" or cloudabi64_load="YES" to /boot/loader.conf.
The FreeBSD Ports Collection also provides the cloudabi-utils package that contains the cloudabi-run utility. This tool can be used to spawn CloudABI applications safely, ensuring that no resources are accidentally leaked into the process. The shell commands below show how cloudabi-run can be used to execute the CloudABI test suite. Please refer to cloudabi-run's manual page for more examples.
Note: As cloudabi-utils depends on FreeBSD 11.1 or newer and FreeBSD binary package builds are still performed against FreeBSD 11.0, it may be necessary to install cloudabi-utils through the FreeBSD Ports Tree. Binary packages for FreeBSD 11.1 are expected to appear in December 2017.