Eric Radman : a Journal

Zig Build

In addition to being a general purpose programming language, Zig is an excelent build tool.

Use Zig as a zero-dependency, drop-in C/C++ compiler that supports cross-compilation out-of-the-box.

Configure

zig not only provides several libc variations of libc, it also allows a specific version to be specified. This is the configure step from rset(1) demonstrating that a compatibilty library has to be used for glibc prior to 3.68

$ TARGET_OS=Linux CC="zig cc -target x86_64-linux-gnu.2.38" ./configure
+ cp Makefile.linux Makefile
+ cp tests/Makefile.linux tests/Makefile
$ TARGET_OS=Linux CC="zig cc -target x86_64-linux-gnu.2.35" ./configure
+ cp Makefile.linux-compat Makefile
+ cp tests/Makefile.linux tests/Makefile

Package Naming

Development snapshots can be named by date, by number of commits, or number of commits since the last tagged release

proj=$(basename $PWD)
rel=$(awk '/^RELEASE =/ { printf $NF }' Makefile.bsd)
rev=$(git rev-list ${rel}..HEAD --count)

for target in aarch64-macos x86_64-macos x86_64-linux-musl
do
    pkg="${proj}-${rel}p${rev}-${target}"
    echo $pkg
done

A Build Script

if [ $# == 0 ]; then
    $0 Darwin aarch64-macos x86_64-macos
    $0 Linux x86_64-linux-musl aarch64-linux-gnu
    exit
fi

export TARGET_OS=$1; shift

for target in $*
do
    export CC="zig cc -target $target"
    # make, tar
done