Split out script for musl builds (#39758)

This commit is contained in:
Yu Watanabe
2025-11-18 02:17:05 +09:00
committed by GitHub
3 changed files with 88 additions and 73 deletions

View File

@@ -20,75 +20,5 @@ cleanup() (
trap cleanup EXIT ERR INT TERM
mkdir -p "${TMPDIR}/build"
mkdir -p "${TMPDIR}/usr/include"
mkdir -p "${TMPDIR}/usr/lib64/pkgconfig"
CFLAGS="-idirafter ${TMPDIR}/usr/include"
export PKG_CONFIG_PATH="${TMPDIR}"/usr/lib64/pkgconfig
LINKS=(
acl
archive.h
archive_entry.h
asm
asm-generic
audit-records.h
audit_logging.h
bpf
bzlib.h
curl
dwarf.h
elfutils
fido.h
gcrypt.h
gelf.h
gnutls
gpg-error.h
idn2.h
libaudit.h
libcryptsetup.h
libelf.h
libkmod.h
linux
lz4.h
lz4frame.h
lz4hc.h
lzma
lzma.h
microhttpd.h
mtd
openssl
pcre2.h
pwquality.h
qrencode.h
seccomp-syscalls.h
seccomp.h
security
selinux
sys/acl.h
sys/capability.h
tss2
xen
xkbcommon
zconf.h
zlib.h
zstd.h
zstd_errors.h
)
for t in "${LINKS[@]}"; do
[[ -e /usr/include/"$t" ]]
link="${TMPDIR}"/usr/include/"${t}"
mkdir -p "${link%/*}"
ln -s /usr/include/"$t" "$link"
done
env \
CC=musl-gcc \
CXX=musl-gcc \
CFLAGS="$CFLAGS" \
CXXFLAGS="$CFLAGS" \
meson setup --werror -Ddbus-interfaces-dir=no -Dlibc=musl "${TMPDIR}"/build
ninja -v -C "${TMPDIR}"/build
tools/setup-musl-build.sh "${TMPDIR}/build"
ninja -v -C "${TMPDIR}/build"

View File

@@ -37,7 +37,7 @@ for phase in "${PHASES[@]}"; do
info "Run phase"
# Create dummy machine ID.
echo '052e58f661f94bd080e258b96aea3f7b' > /etc/machine-id
echo '052e58f661f94bd080e258b96aea3f7b' >/etc/machine-id
# Start dbus for several unit tests.
mkdir -p /var/run/dbus

85
tools/setup-musl-build.sh Executable file
View File

@@ -0,0 +1,85 @@
#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later
# Usage:
# tools/setup-musl-build.sh <build-directory> <options…>
# E.g.
# tools/setup-musl-build.sh build-musl -Dbuildtype=debugoptimized && ninja -C build-musl
set -eu
BUILD_DIR="${1:?}"
shift
SETUP_DIR="${BUILD_DIR}/extra"
LINKS=(
acl
archive.h
archive_entry.h
asm
asm-generic
audit-records.h
audit_logging.h
bpf
bzlib.h
curl
dwarf.h
elfutils
fido.h
gcrypt.h
gelf.h
gnutls
gpg-error.h
idn2.h
libaudit.h
libcryptsetup.h
libelf.h
libkmod.h
linux
lz4.h
lz4frame.h
lz4hc.h
lzma
lzma.h
microhttpd.h
mtd
openssl
pcre2.h
pwquality.h
qrencode.h
seccomp-syscalls.h
seccomp.h
security
selinux
sys/acl.h
sys/capability.h
tss2
xen
xkbcommon
zconf.h
zlib.h
zstd.h
zstd_errors.h
)
for t in "${LINKS[@]}"; do
[[ -e /usr/include/"$t" ]]
link="${SETUP_DIR}/usr/include/${t}"
mkdir -p "${link%/*}"
ln -s /usr/include/"$t" "$link"
done
# Use an absolute path so that when we chdir into the build directory,
# the path still works. This is easier than figuring out the relative path.
[[ "${SETUP_DIR}" =~ ^/ ]] || SETUP_DIR="${PWD}/${SETUP_DIR}"
CFLAGS="-idirafter ${SETUP_DIR}/usr/include"
set -x
env \
CC=musl-gcc \
CXX=musl-gcc \
CFLAGS="$CFLAGS" \
CXXFLAGS="$CFLAGS" \
meson setup -Ddbus-interfaces-dir=no -Dlibc=musl "${BUILD_DIR}" "${@}"