Nuxi

Nuxi CloudABI for NetBSD

NetBSD was the first operating system CloudABI was ported to after it had initially been developed on FreeBSD. Support for CloudABI on NetBSD is fairly complete, though it has not been integrated into upstream sources yet.

This document describes how NetBSD can be used to both develop and run CloudABI applications.

1. Installing a C and C++ compiler for CloudABI

CloudABI uses a toolchain based on LLVM, Clang and LLD for building C and C++ software. Though the version of Clang shipped with pkgsrc (3.8.0) is sufficient for compiling code for CloudABI, only the upcoming version of LLD (3.9.0) is mature enough to generate executables properly. Until this version has been released and packaged by pkgsrc, we advise that LLVM is built from trunk.

The following commands can be used to build LLVM, Clang and LLD from SVN and install them into /usr/local/llvm-trunk:

$ sudo pkg_add cmake subversion $ svn co https://llvm.org/svn/llvm-project/llvm/trunk llvm $ svn co https://llvm.org/svn/llvm-project/cfe/trunk llvm/tools/clang $ svn co https://llvm.org/svn/llvm-project/lld/trunk llvm/tools/lld $ mkdir build $ cd build $ cmake -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/llvm-trunk \ -DCMAKE_INSTALL_RPATH:PATH=/usr/local/llvm-trunk/lib ../llvm ... -- Configuring done -- Generating done -- Build files have been written to: /home/ed/llvm/build $ make -j6 $ sudo make install

After installing LLVM, we can create a number of symbolic links in /usr/local/bin that point to the utilities provided by LLVM, having the CloudABI cross compilation target prefixed to their name. LLVM automatically acts like a cross compiler for CloudABI when invoked through these symbolic links.

sudo mkdir -p /usr/local/bin for target in aarch64-unknown-cloudabi i686-unknown-cloudabi x86_64-unknown-cloudabi; do for tool in ar nm objdump ranlib size; do sudo ln -s ../llvm-trunk/bin/llvm-${tool} /usr/local/bin/${target}-${tool} done sudo ln -s ../llvm-trunk/bin/clang /usr/local/bin/${target}-cc sudo ln -s ../llvm-trunk/bin/clang /usr/local/bin/${target}-c++ sudo ln -s ../llvm-trunk/bin/lld /usr/local/bin/${target}-ld sudo ln -s ../../pkg/${target} /usr/local/llvm-trunk/${target} done

The commands above set up the Clang C and C++ compiler for every architecture supported by CloudABI, thus making it very easy to cross compile software for other hardware:

$ ls /usr/local/bin/*-unknown-cloudabi-{cc,c++} /usr/local/bin/aarch64-unknown-cloudabi-c++ /usr/local/bin/aarch64-unknown-cloudabi-cc /usr/local/bin/i686-unknown-cloudabi-c++ /usr/local/bin/i686-unknown-cloudabi-cc /usr/local/bin/x86_64-unknown-cloudabi-c++ /usr/local/bin/x86_64-unknown-cloudabi-cc

2. Accessing the CloudABI Ports Collection

The CloudABI Ports Collection provides copies of precompiled libraries that you can use to build complex CloudABI applications. Software that is part of the CloudABI Ports Collection is automatically packaged for a variety of systems, including NetBSD's pkg_add.

As pkg_add can fetch packages by URL directly, there is no need to change any system configuration files to access the CloudABI Ports Collection. The NetBSD packages can be browsed online at https://nuxi.nl/distfiles/cloudabi-ports/netbsd/.

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:

$ sudo pkg_add https://nuxi.nl/distfiles/cloudabi-ports/netbsd/x86_64-unknown-cloudabi-cxx-runtime-\* $ pkg_info | grep ^x86_64-unknown-cloudabi- x86_64-unknown-cloudabi-cloudabi-0.6nb1 cloudabi for x86_64-unknown-cloudabi x86_64-unknown-cloudabi-compiler-rt-3.8.0nb3 compiler-rt for x86_64-unknown-cloudabi x86_64-unknown-cloudabi-cloudlibc-0.30nb1 cloudlibc for x86_64-unknown-cloudabi x86_64-unknown-cloudabi-libcxx-3.8.0nb5 libcxx for x86_64-unknown-cloudabi x86_64-unknown-cloudabi-libcxxabi-3.8.0nb5 libcxxabi for x86_64-unknown-cloudabi x86_64-unknown-cloudabi-libunwind-3.8.0nb4 libunwind for x86_64-unknown-cloudabi x86_64-unknown-cloudabi-cxx-runtime-1.0nb2 cxx-runtime for x86_64-unknown-cloudabi

3. Executing CloudABI applications

A patchset for the NetBSD kernel to add support for running CloudABI applications can be found on GitHub. It is sufficient to rebuild and install the kernel with the COMPAT_CLOUDABI64 configuration option enabled. Once booted, it should be possible to run CloudABI applications from the command line directly:

$ cat hello.c #include <stdio.h> int main(void) { dprintf(1, "Hello, world\n"); } $ x86_64-unknown-cloudabi-cc -o hello hello.c $ ./hello Hello, world

The cloudabi-run utility is not yet supported on NetBSD.