build-styles: add zig-build

We call this "zig-build" instead of just "zig" as this build-style
relies on usage of the zig build system. In the future, other build
systems such as meson may support zig code. Furthermore, the zig
build system may be used to build C/C++ code as well, not just zig.
This commit is contained in:
Isaac Freund 2021-11-11 11:24:26 +01:00 committed by Érico Nogueira Rolim
parent c9e79da765
commit 020e1aa54b
46 changed files with 133 additions and 0 deletions

View file

@ -0,0 +1,41 @@
do_build() {
local zig_target zig_cpu
# TODO: This duplication between build-profiles and cross-profiles
# is totally unnecessary. It would be nice if there was some way to
# avoid it.
if [ "$CROSS_BUILD" ]; then
zig_target="${XBPS_CROSS_ZIG_TARGET}"
zig_cpu="${XBPS_CROSS_ZIG_CPU}"
else
zig_target="${XBPS_ZIG_TARGET}"
zig_cpu="${XBPS_ZIG_CPU}"
fi
# Inform zig of the required libc include paths.
cat > xbps_zig_libc.txt <<-EOF
include_dir=${XBPS_CROSS_BASE}/usr/include
sys_include_dir=${XBPS_CROSS_BASE}/usr/include
crt_dir=${XBPS_CROSS_BASE}/usr/lib
msvc_lib_dir=
kernel32_lib_dir=
gcc_dir=
EOF
# The Zig build system only has a single install step, there is no
# way to build artifacts for a given prefix and then install those artifacts
# to that prefix at some later time. Therefore, we build and install to the zig-out
# directory and later copy the artifacts to the destdir in do_install().
# We use zig-out to avoid path conflicts as it is the default install
# prefix used by the zig build system.
DESTDIR="zig-out" zig build \
--sysroot "${XBPS_CROSS_BASE}" \
--libc xbps_zig_libc.txt \
-Dtarget="${zig_target}" -Dcpu="${zig_cpu}" \
-Drelease-safe --prefix /usr install \
${configure_args}
}
do_install() {
cp -r zig-out/* "${DESTDIR}"
}