build: completely refactor static build to support cross-compilation

This commit is contained in:
Marcus Holland-Moritz 2025-07-23 07:31:53 +02:00
parent 9fc2b895b2
commit 2dec20b01f
15 changed files with 1223 additions and 644 deletions

View File

@ -1,9 +1,18 @@
# syntax=docker/dockerfile:1
ARG ARCH=amd64
FROM $ARCH/alpine:latest
ARG ARCH
ARG TARGET_ARCHS
ARG TOOLCHAIN_OPTIMIZE=2
RUN apk update
RUN apk upgrade
RUN apk add --no-cache \
RUN qemu_pkgs=""; \
for arch in $(echo $TARGET_ARCHS | tr ',' ' '); do \
qemu_pkgs="$qemu_pkgs qemu-$arch"; \
done; \
apk add --no-cache \
bash-completion \
build-base \
wget \
@ -11,81 +20,90 @@ RUN apk add --no-cache \
vim \
tar \
ripgrep \
py3-pip \
less \
gcc \
g++ \
clang18 \
clang19 \
clang20 \
lld \
git \
xz \
gzip \
bzip2 \
zstd \
ccache \
samurai \
ninja-build \
cmake \
make \
bison \
flex \
ronn \
perf \
py3-pip \
fuse \
fuse-dev \
fuse-static \
fuse3 \
fuse3-dev \
fuse3-static \
pkgconf \
binutils-dev \
libevent-dev \
libevent-static \
linux-headers \
date-dev \
range-v3-dev \
zlib-static \
libucontext-dev \
libdwarf-dev \
elfutils-dev \
utfcpp \
nlohmann-json \
meson \
autoconf \
strace \
gdb
gdb \
gmp-dev \
zlib-static \
zstd-static \
zlib-dev \
zstd-dev \
mpfr-dev \
mpc1-dev \
isl-dev \
texinfo \
linux-headers \
gdb-multiarch \
rsync \
screen \
$qemu_pkgs
# Install UPX
ARG ARCH
# UPX isn't supported on RISC-V yet, so skip this
RUN if [ "$ARCH" != "riscv64" ]; then \
wget -O - https://github.com/upx/upx/releases/download/v5.0.0/upx-5.0.0-$(bash -c "echo \${0//v8/}" $ARCH)_linux.tar.xz | tar -xJf - -C /usr/local/bin --strip-components=1 --wildcards "*/upx"; \
else \
echo "Skipping UPX installation for RISC-V architecture while it is not supported."; \
echo "See https://github.com/upx/upx/discussions/793 for details."; \
fi
# Install mistletoe
RUN pip3 install --break-system-packages --root-user-action ignore mistletoe
# Install size-optimized and static-link-optimized libstdc++
RUN apk add --no-cache gmp-dev mpfr-dev mpc1-dev isl-dev
COPY install-libstdcxx.sh /usr/local/bin/install-libstdcxx.sh
RUN bash /usr/local/bin/install-libstdcxx.sh
COPY fetch.sh /usr/local/bin/fetch.sh
# Install mold
COPY install-mold.sh /usr/local/bin/install-mold.sh
RUN bash /usr/local/bin/install-mold.sh
RUN --mount=type=cache,id=ccache,target=/root/.ccache --mount=type=cache,id=pkgcache,target=/root/.pkgcache \
bash /usr/local/bin/install-mold.sh
# Install bloaty
COPY install-bloaty.sh /usr/local/bin/install-bloaty.sh
RUN if [ "$ARCH" != "riscv64" ]; then \
RUN --mount=type=cache,id=ccache,target=/root/.ccache --mount=type=cache,id=pkgcache,target=/root/.pkgcache \
if [ "$ARCH" == "amd64" ]; then \
bash /usr/local/bin/install-bloaty.sh; \
else \
echo "Skipping bloaty installation for RISC-V."; \
echo "Skipping bloaty installation for $ARCH."; \
fi
RUN apk del linux-headers
# Install size-optimized and static-link-optimized libstdc++
COPY install-toolchain.sh /usr/local/bin/install-toolchain.sh
RUN --mount=type=cache,id=ccache,target=/root/.ccache --mount=type=cache,id=pkgcache,target=/root/.pkgcache \
bash /usr/local/bin/install-toolchain.sh $TOOLCHAIN_OPTIMIZE $TARGET_ARCHS
RUN apk del zlib-dev zstd-dev
# Install all static libraries
COPY install-static-libs.sh /usr/local/bin/install-static-libs.sh
RUN bash /usr/local/bin/install-static-libs.sh gcc clang-19 :alpine
# Install the *real* ninja...
# TODO: move this up if we change anything
RUN apk add --no-cache ninja-build
RUN --mount=type=cache,id=ccache,target=/root/.ccache --mount=type=cache,id=pkgcache,target=/root/.pkgcache \
bash /usr/local/bin/install-static-libs.sh :all $TARGET_ARCHS
# Install UPX
# UPX isn't supported on RISC-V/S390 (yet), so skip this
RUN if [ "$ARCH" == "amd64" ] || [ "$ARCH" == "arm64v8" ]; then \
wget -O - https://github.com/upx/upx/releases/download/v5.0.2/upx-5.0.2-$(bash -c "echo \${0//v8/}" $ARCH)_linux.tar.xz | tar -xJf - -C /usr/local/bin --strip-components=1 --wildcards "*/upx"; \
else \
echo "Skipping UPX installation for $ARCH architecture while it is not supported."; \
echo "See https://github.com/upx/upx/discussions/793 for details."; \
fi
RUN pip3 install --break-system-packages --root-user-action ignore mistletoe
# Set up git & user
RUN git config --global --add safe.directory /workspace

View File

@ -72,13 +72,6 @@ RUN apt install -y \
libflac++-dev \
nlohmann-json3-dev \
python3-mistletoe
### XXX: no more static libs for Ubuntu
# COPY install-static-libs.sh /usr/local/bin/install-static-libs.sh
# # TODO: gcc-14 cannot build the current version of libunwind
# RUN bash /usr/local/bin/install-static-libs.sh gcc-13 clang-18 :ubuntu
ARG ARCH
# upx-4.2.2 is broken for arm64 (https://github.com/upx/upx/issues/758)
RUN wget -O - https://github.com/upx/upx/releases/download/v5.0.0/upx-5.0.0-$(bash -c "echo \${0//v8/}" $ARCH)_linux.tar.xz | tar -xJf - -C /usr/local/bin --strip-components=1 --wildcards "*/upx"
# current ronn version is horribly broken
RUN gem install ronn-ng
# RUN useradd -g users -u 1000 -m mhx

View File

@ -1,7 +1,7 @@
IMAGE_UBUNTU="dwarfs-buildenv"
IMAGE_DEBIAN="dwarfs-buildenv-debian"
IMAGE_ALPINE="dwarfs-buildenv-alpine"
IMAGE_ALPINE_RISCV="dwarfs-buildenv-alpine-riscv64"
IMAGE_ALPINE_NEWARCH="dwarfs-buildenv-alpine-newarch"
IMAGE_UBUNTU2204="dwarfs-buildenv-ubuntu2204"
IMAGE_FEDORA="dwarfs-buildenv-fedora"
IMAGE_ARCH="dwarfs-buildenv-arch"
@ -34,16 +34,16 @@ run_debian:
@docker run $(COMMON_RUN_OPTS) $(IMAGE_DEBIAN)
build_alpine:
docker build -f Dockerfile.alpine -t $(IMAGE_ALPINE) .
docker buildx build -f Dockerfile.alpine --build-arg TARGET_ARCHS=x86_64,aarch64,riscv64,ppc64le,s390x,arm,i386 -t $(IMAGE_ALPINE) .
run_alpine:
@docker run $(COMMON_RUN_OPTS) $(IMAGE_ALPINE)
build_alpine_riscv:
docker build -f Dockerfile.alpine -t $(IMAGE_ALPINE_RISCV) --build-arg ARCH=riscv64 .
build_alpine_newarch:
docker buildx build -f Dockerfile.alpine --build-arg TARGET_ARCHS=s390x -t $(IMAGE_ALPINE_NEWARCH) .
run_alpine_riscv:
@docker run $(COMMON_RUN_OPTS) $(IMAGE_ALPINE_RISCV)
run_alpine_newarch:
@docker run $(COMMON_RUN_OPTS) $(IMAGE_ALPINE_NEWARCH)
build_ubuntu2204:
docker build -f Dockerfile.ubuntu-2204 -t $(IMAGE_UBUNTU2204) .

View File

@ -9,8 +9,8 @@ mkdir -p "$LOCAL_REPO_PATH"
LAST_UPDATE_FILE="$LOCAL_REPO_PATH/last-update"
WORKFLOW_LOG_DIR="/artifacts/workflow-logs/${GITHUB_RUN_ID}"
NINJA_LOG_FILE="${WORKFLOW_LOG_DIR}/ninja-${BUILD_ARCH},${BUILD_DIST},${BUILD_TYPE}.log"
BUILD_LOG_FILE="${WORKFLOW_LOG_DIR}/build-${BUILD_ARCH},${BUILD_DIST},${BUILD_TYPE}.log"
NINJA_LOG_FILE="${WORKFLOW_LOG_DIR}/ninja-${BUILD_ARCH},${CROSS_ARCH},${BUILD_DIST},${BUILD_TYPE}.log"
BUILD_LOG_FILE="${WORKFLOW_LOG_DIR}/build-${BUILD_ARCH},${CROSS_ARCH},${BUILD_DIST},${BUILD_TYPE}.log"
mkdir -p "$WORKFLOW_LOG_DIR"
log() {
@ -77,7 +77,7 @@ cd build
# Stick to clang-18, clang-19 has a regression for nilsimsa performance
if [[ "$BUILD_DIST" == "alpine" ]]; then
GCC_VERSION=
CLANG_VERSION=-19
CLANG_VERSION=-20
elif [[ "$BUILD_DIST" == "ubuntu-2204" ]]; then
GCC_VERSION=-12
CLANG_VERSION=-15
@ -114,6 +114,9 @@ case "-$BUILD_TYPE-" in
*-ubuntu-*|*-debian-*)
export CC=gcc$GCC_VERSION CXX=g++$GCC_VERSION
;;
*)
export CC=gcc CXX=g++
;;
esac
export COMPILER=gcc
;;
@ -182,7 +185,16 @@ esac
case "-$BUILD_TYPE-" in
*-static-*)
export LDFLAGS="${LDFLAGS} -fuse-ld=mold"
case "$CROSS_ARCH" in
ppc64le)
# https://github.com/rui314/mold/issues/1490
CMAKE_ARGS="${CMAKE_ARGS} -DDISABLE_MOLD=1"
export LDFLAGS="${LDFLAGS} -fuse-ld=lld"
;;
*)
export LDFLAGS="${LDFLAGS} -fuse-ld=mold"
;;
esac
;;
esac
@ -287,39 +299,49 @@ if [[ "-$BUILD_TYPE-" == *-shared-* ]]; then
fi
if [[ "-$BUILD_TYPE-" == *-static-* ]]; then
if [[ "-$BUILD_TYPE-" == *-relsize-* ]]; then
_LIBSTDCXXDIR="/opt/static-libs/libstdc++-Os/lib"
if [[ "$ARCH" == "aarch64" ]]; then
# Similar to the issue with *not* linking against `gcc_eh` in the CMakeLists.txt,
# if we link against the `gcc_eh` from the `-Os` build, we run into exactly the
# same issue. So we temporarily copy the size-optimized `libgcc.a` to a directory
# we then use for linking.
_GCCLIBDIR="/tmp/gcclib"
mkdir -p "$_GCCLIBDIR"
cp -a "$_LIBSTDCXXDIR"/gcc/*/*/libgcc.a "$_GCCLIBDIR"
else
_GCCLIBDIR=$(ls -d1 $_LIBSTDCXXDIR/gcc/*/*)
fi
LDFLAGS="${LDFLAGS} -L$_GCCLIBDIR -L$_LIBSTDCXXDIR"
# A size-optimized libgcc/libstdc++/musl will only save about 10k for the universal
# and fuse-extract binaries, so we'll just stick to using the -O2 toolchain.
_SYSROOT="/opt/cross/O2"
_MARCH="${CROSS_ARCH}"
if [[ -z "$CROSS_ARCH" ]]; then
_MARCH="${ARCH}"
fi
export LDFLAGS="${LDFLAGS} -L/opt/static-libs/$COMPILER/lib"
if [[ "$ARCH" == "aarch64" ]]; then
# For some reason, this dependency of libunwind is not resolved on aarch64
export LDFLAGS="${LDFLAGS} -lz"
if [[ "$_MARCH" == "arm" ]]; then
_TARGET="${_MARCH}-linux-musleabihf"
else
_TARGET="${_MARCH}-alpine-linux-musl"
fi
CMAKE_ARGS="${CMAKE_ARGS} -DSTATIC_BUILD_DO_NOT_USE=1 -DWITH_UNIVERSAL_BINARY=1 -DWITH_FUSE_EXTRACT_BINARY=1"
export CC="${_TARGET}-${CC}"
export CXX="${_TARGET}-${CXX}"
export STRIP_TOOL="${_TARGET}-strip"
export PATH="$_SYSROOT/usr/bin:$PATH"
_staticprefix="/opt/static-libs/$COMPILER/$_TARGET"
if [[ "$BUILD_TYPE" == *-minimal-* ]]; then
_jemallocprefix="/opt/static-libs/$COMPILER-jemalloc-minimal"
_jemallocprefix="/opt/static-libs/$COMPILER-jemalloc-minimal/$_TARGET"
else
CMAKE_ARGS="${CMAKE_ARGS} -DWITH_PXATTR=1"
_jemallocprefix="/opt/static-libs/$COMPILER-jemalloc-full"
_jemallocprefix="/opt/static-libs/$COMPILER-jemalloc-full/$_TARGET"
fi
if [[ "$BUILD_TYPE" == *-libressl-* ]]; then
_sslprefix="/opt/static-libs/$COMPILER-libressl"
_sslprefix="/opt/static-libs/$COMPILER-libressl/$_TARGET"
else
_sslprefix="/opt/static-libs/$COMPILER-openssl"
_sslprefix="/opt/static-libs/$COMPILER-openssl/$_TARGET"
fi
export LDFLAGS="${LDFLAGS} -static-libgcc -L$_staticprefix/lib -L$_sslprefix/lib"
export CFLAGS="${CFLAGS} -isystem $_staticprefix/include"
export CXXFLAGS="${CXXFLAGS} -isystem $_staticprefix/include"
if [[ "$_MARCH" == "i386" ]]; then
export LDFLAGS="${LDFLAGS} -lucontext"
fi
CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_SYSROOT=$_SYSROOT -DCMAKE_FIND_ROOT_PATH=$_staticprefix;$_sslprefix;$_jemallocprefix -DCMAKE_PREFIX_PATH=$_staticprefix;$_sslprefix;$_jemallocprefix -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY -DSTATIC_BUILD_DO_NOT_USE=1 -DWITH_UNIVERSAL_BINARY=1 -DWITH_FUSE_EXTRACT_BINARY=1"
if [[ -n "$CROSS_ARCH" ]]; then
CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=$_MARCH -DCMAKE_CROSSCOMPILING_EMULATOR=/usr/bin/qemu-$_MARCH -DFOLLY_HAVE_UNALIGNED_ACCESS=OFF -DFOLLY_HAVE_WEAK_SYMBOLS=ON -DFOLLY_HAVE_LINUX_VDSO=OFF -DFOLLY_HAVE_WCHAR_SUPPORT=OFF -DHAVE_VSNPRINTF_ERRORS=OFF"
fi
CMAKE_ARGS="${CMAKE_ARGS} -DSTATIC_BUILD_EXTRA_PREFIX=/opt/static-libs/$COMPILER;$_sslprefix;$_jemallocprefix"
fi
INSTALLDIR="$HOME/install"

View File

@ -23,6 +23,13 @@ repositories = [
# "microsoft/mimalloc",
"jemalloc/jemalloc",
"tukaani-project/xz",
"davea42/libdwarf-code",
"libevent/libevent",
"nlohmann/json",
"HowardHinnant/date",
"nemtrif/utfcpp",
"ericniebler/range-v3",
"greg7mdp/parallel-hashmap",
]

31
.docker/fetch.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/bash
set -ex
URL=$1
FILE=${2:-$(basename "$URL")}
SHA512SUM="${3}"
URLHASH=$(echo -n "$URL" | sha256sum | awk '{print $1}')
CACHEDIR="$HOME/.pkgcache"
CACHEFILE="$CACHEDIR/$URLHASH"
if [ ! -f "$CACHEFILE" ]; then
rm -f "$CACHEFILE.tmp"
curl --retry 5 -L "$URL" > "$CACHEFILE.tmp"
if [ -n "$SHA512SUM" ]; then
echo "$SHA512SUM $CACHEFILE.tmp" | sha512sum -c -
if [ $? -ne 0 ]; then
echo "Checksum verification failed for $URL"
rm -f "$CACHEFILE.tmp"
exit 1
fi
fi
mv -f "$CACHEFILE.tmp" "$CACHEFILE"
fi
if [ "$FILE" == "-" ]; then
cat "$CACHEFILE"
else
cp "$CACHEFILE" "$FILE"
fi

View File

@ -6,13 +6,16 @@ cd "$HOME"
mkdir pkgs
cd pkgs
git clone --recurse-submodules https://github.com/google/bloaty
git clone --depth=1 --recurse-submodules --shallow-submodules https://github.com/google/bloaty
cd bloaty
mkdir build
cd build
export PATH="/usr/lib/ccache/bin:$PATH"
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local
ninja
ccache -s
ninja install
cd "$HOME"

View File

@ -1,87 +0,0 @@
#!/bin/bash
set -ex
cd "$HOME"
mkdir pkgs
cd pkgs
GCC_VERSION=14.2.0
ARCH="$(uname -m)"
wget https://ftp.gwdg.de/pub/misc/gcc/releases/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz
tar xf gcc-${GCC_VERSION}.tar.xz
cd gcc-${GCC_VERSION}
for p in 0001-posix_memalign.patch \
0002-gcc-poison-system-directories.patch \
0003-specs-turn-on-Wl-z-now-by-default.patch \
0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch \
0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch \
0006-Enable-Wformat-and-Wformat-security-by-default.patch \
0007-Enable-Wtrampolines-by-default.patch \
0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch \
0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch \
0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch \
0011-libiberty-copy-PIC-objects-during-build-process.patch \
0012-libgcc_s.patch \
0013-nopie.patch \
0014-ada-fix-shared-linking.patch \
0015-build-fix-CXXFLAGS_FOR_BUILD-passing.patch \
0016-add-fortify-headers-paths.patch \
0017-Alpine-musl-package-provides-libssp_nonshared.a.-We-.patch \
0018-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch \
0019-aarch64-disable-multilib-support.patch \
0020-s390x-disable-multilib-support.patch \
0021-ppc64-le-disable-multilib-support.patch \
0022-x86_64-disable-multilib-support.patch \
0023-riscv-disable-multilib-support.patch \
0024-always-build-libgcc_eh.a.patch \
0025-ada-libgnarl-compatibility-for-musl.patch \
0026-ada-musl-support-fixes.patch \
0027-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch \
0028-configure-fix-detection-of-atomic-builtins-in-libato.patch \
0029-libstdc-do-not-throw-exceptions-for-non-C-locales-on.patch \
0030-gdc-unconditionally-link-libgphobos-against-libucont.patch \
0031-druntime-link-against-libucontext-on-all-platforms.patch \
0032-libgnat-time_t-is-always-64-bit-on-musl-libc.patch \
0033-libphobos-do-not-use-LFS64-symbols.patch \
0034-libgo-fix-lfs64-use.patch \
0035-loongarch-disable-multilib-support.patch \
0036-libphobos-add-riscv64-and-loongarch64-support.patch \
fix-arm64.patch \
ppc64le-quadmath.patch \
riscv64-improve-build-time.patch; do
curl https://gitlab.alpinelinux.org/alpine/aports/-/raw/3.21-stable/main/gcc/$p | patch -p1
done
curl https://gcc.gnu.org/pipermail/gcc-patches/attachments/20250220/c6211b02/attachment.bin | patch -p1
# for opt in s 2; do
for opt in s; do
cd "${HOME}"/pkgs
mkdir gcc-${GCC_VERSION}-build-O${opt}
cd gcc-${GCC_VERSION}-build-O${opt}
export CFLAGS="-O${opt} -ffunction-sections -fdata-sections -fmerge-all-constants -fPIC"
export CXXFLAGS="-O${opt} -ffunction-sections -fdata-sections -fmerge-all-constants -fPIC"
export LDFLAGS="-Wl,--gc-sections"
INSTALLDIR=/opt/static-libs/libstdc++-O${opt}
case "$ARCH" in
aarch64)
_arch_config="--with-arch=armv8-a --with-abi=lp64"
;;
esac
"$HOME"/pkgs/gcc-${GCC_VERSION}/configure --prefix=${INSTALLDIR} --libdir=${INSTALLDIR}/lib \
--disable-shared --enable-tls --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --disable-symvers \
--enable-threads --enable-__cxa_atexit --enable-languages=c,c++ --enable-link-serialization=2 --enable-linker-build-id \
--disable-libssp --disable-libsanitizer --with-system-zlib --enable-checking=release --disable-cet --disable-fixed-point \
--enable-default-pie --enable-default-ssp --with-linker-hash-style=gnu ${_arch_config}
make -j"$(nproc)"
make install
done
cd "$HOME"
rm -rf pkgs

View File

@ -6,14 +6,16 @@ cd "$HOME"
mkdir pkgs
cd pkgs
MOLD_VERSION=2.37.1
MOLD_VERSION=2.40.2
wget -O mold-${MOLD_VERSION}.tar.gz https://github.com/rui314/mold/archive/refs/tags/v${MOLD_VERSION}.tar.gz
fetch.sh https://github.com/rui314/mold/archive/refs/tags/v${MOLD_VERSION}.tar.gz mold-${MOLD_VERSION}.tar.gz
tar xf mold-${MOLD_VERSION}.tar.gz
cd mold-${MOLD_VERSION}
mkdir build
cd build
export PATH="/usr/lib/ccache/bin:$PATH"
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local
ninja
ninja install

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,219 @@
#!/bin/bash
set -ex
ARCH="$(uname -m)"
OPTIMIZE_STR="${1:-2}"
TARGET_ARCH_STR="${2:-$ARCH}"
BINUTILS_VERSION=2.44
GCC_VERSION=14.2.0
MUSL_VERSION=1.2.5
LINUX_VERSION=6.15.7
BINUTILS_TARBALL=binutils-${BINUTILS_VERSION}.tar.xz
GCC_TARBALL=gcc-${GCC_VERSION}.tar.xz
MUSL_TARBALL=musl-${MUSL_VERSION}.tar.gz
LINUX_TARBALL=linux-${LINUX_VERSION}.tar.xz
cd "$HOME"
mkdir pkgs
cd pkgs
fetch.sh https://mirror.netcologne.de/gnu/binutils/${BINUTILS_TARBALL}
fetch.sh https://ftp.gwdg.de/pub/misc/gcc/releases/gcc-${GCC_VERSION}/${GCC_TARBALL}
fetch.sh https://www.musl-libc.org/releases/${MUSL_TARBALL}
fetch.sh https://cdn.kernel.org/pub/linux/kernel/v6.x/${LINUX_TARBALL}
tar xf ${BINUTILS_TARBALL}
tar xf ${GCC_TARBALL}
tar xf ${LINUX_TARBALL}
cd gcc-${GCC_VERSION}
for p in 0001-posix_memalign.patch \
0002-gcc-poison-system-directories.patch \
0003-specs-turn-on-Wl-z-now-by-default.patch \
0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch \
0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch \
0006-Enable-Wformat-and-Wformat-security-by-default.patch \
0007-Enable-Wtrampolines-by-default.patch \
0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch \
0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch \
0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch \
0011-libiberty-copy-PIC-objects-during-build-process.patch \
0012-libgcc_s.patch \
0013-nopie.patch \
0014-ada-fix-shared-linking.patch \
0015-build-fix-CXXFLAGS_FOR_BUILD-passing.patch \
0016-add-fortify-headers-paths.patch \
0017-Alpine-musl-package-provides-libssp_nonshared.a.-We-.patch \
0018-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch \
0019-aarch64-disable-multilib-support.patch \
0020-s390x-disable-multilib-support.patch \
0021-ppc64-le-disable-multilib-support.patch \
0022-x86_64-disable-multilib-support.patch \
0023-riscv-disable-multilib-support.patch \
0024-always-build-libgcc_eh.a.patch \
0025-ada-libgnarl-compatibility-for-musl.patch \
0026-ada-musl-support-fixes.patch \
0027-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch \
0028-configure-fix-detection-of-atomic-builtins-in-libato.patch \
0029-libstdc-do-not-throw-exceptions-for-non-C-locales-on.patch \
0030-gdc-unconditionally-link-libgphobos-against-libucont.patch \
0031-druntime-link-against-libucontext-on-all-platforms.patch \
0032-libgnat-time_t-is-always-64-bit-on-musl-libc.patch \
0033-libphobos-do-not-use-LFS64-symbols.patch \
0034-libgo-fix-lfs64-use.patch \
0035-loongarch-disable-multilib-support.patch \
0036-libphobos-add-riscv64-and-loongarch64-support.patch \
fix-arm64.patch \
ppc64le-quadmath.patch \
riscv64-improve-build-time.patch; do
fetch.sh https://gitlab.alpinelinux.org/alpine/aports/-/raw/3.21-stable/main/gcc/$p - | patch -p1
done
fetch.sh https://gcc.gnu.org/pipermail/gcc-patches/attachments/20250220/c6211b02/attachment.bin - | patch -p1
ORIGPATH="$PATH"
export CC="/usr/bin/ccache /usr/bin/gcc"
export CXX="/usr/bin/ccache /usr/bin/g++"
export LD="/usr/bin/ld"
for target_arch in ${TARGET_ARCH_STR//,/ }; do
for OPT in ${OPTIMIZE_STR//,/ }; do
echo "==========================================================="
echo "Building for target architecture: $target_arch (-O${OPT})"
echo "==========================================================="
export TARGETARCH="$target_arch"
TARGET="${TARGETARCH}-alpine-linux-musl"
CARCH="$TARGETARCH"
case "$TARGETARCH" in
aarch64*) CARCH="arm64" ;;
arm*) CARCH="arm" ;;
mips*) CARCH="mips" ;;
s390*) CARCH="s390" ;;
ppc*) CARCH="powerpc" ;;
riscv*) CARCH="riscv" ;;
loongarch*) CARCH="loongarch" ;;
esac
case "$TARGETARCH" in
i386)
GCC_CONFIGURE_ARGS="--with-arch=i486 --with-tune=generic"
;;
aarch64*)
GCC_CONFIGURE_ARGS="--with-arch=armv8-a --with-abi=lp64"
;;
arm*)
GCC_CONFIGURE_ARGS="--with-arch=armv6 --with-fpu=vfp --with-float=hard"
TARGET="arm-linux-musleabihf"
;;
s390x)
GCC_CONFIGURE_ARGS="--with-arch=z10"
;;
*)
GCC_CONFIGURE_ARGS=""
;;
esac
export CFLAGS="-O${OPT} -ffunction-sections -fdata-sections -fmerge-all-constants -fPIC"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-Wl,--gc-sections"
SYSROOT="/opt/cross/O${OPT}"
PREFIX="$SYSROOT/usr"
PATH="$PREFIX/bin:$ORIGPATH"
GCC_NODOCS="MAKEINFO=/bin/true gcc_cv_prog_makeinfo_modern=no HELP2MAN=/bin/true TEXI2POD=/bin/true POD2MAN=/bin/true"
# Stage 1
cd "${HOME}"/pkgs
mkdir binutils-${BINUTILS_VERSION}-build-${TARGETARCH}-O${OPT}
cd binutils-${BINUTILS_VERSION}-build-${TARGETARCH}-O${OPT}
"$HOME"/pkgs/binutils-${BINUTILS_VERSION}/configure \
--target=$TARGET --program-prefix="$TARGET-" --prefix=$PREFIX --with-sysroot=$SYSROOT \
--disable-nls --disable-werror
make -j"$(nproc)"
make install
cd "$HOME"/pkgs/linux-${LINUX_VERSION}
make ARCH="$CARCH" INSTALL_HDR_PATH=$PREFIX/$TARGET headers_install
if [[ "$TARGETARCH" != "$ARCH" ]]; then
cd "$HOME"/pkgs
mkdir gcc-${GCC_VERSION}-build-${TARGETARCH}-O${OPT}-stage1
cd gcc-${GCC_VERSION}-build-${TARGETARCH}-O${OPT}-stage1
"$HOME"/pkgs/gcc-${GCC_VERSION}/configure \
--target=$TARGET --prefix=$PREFIX --with-sysroot=$SYSROOT --with-newlib --without-headers \
--disable-nls --disable-shared --disable-multilib --disable-decimal-float --disable-threads \
--disable-libatomic --disable-libgomp --disable-libquadmath --disable-libssp --disable-libvtv \
--disable-libstdcxx --enable-languages=c,c++ ${GCC_NODOCS}
make -j"$(nproc)" all-gcc ${GCC_NODOCS}
make -j"$(nproc)" all-target-libgcc ${GCC_NODOCS}
make install-gcc
make install-target-libgcc
MUSL_CC="${TARGET}-gcc"
else
MUSL_CC="gcc"
fi
cd "$HOME"/pkgs
rm -rf musl-${MUSL_VERSION}
tar xf ${MUSL_TARBALL}
cd musl-${MUSL_VERSION}
fetch.sh https://gitlab.alpinelinux.org/alpine/aports/-/raw/3.22-stable/main/musl/__stack_chk_fail_local.c
${MUSL_CC} $CFLAGS -c __stack_chk_fail_local.c -o __stack_chk_fail_local.o
${TARGET}-ar r libssp_nonshared.a __stack_chk_fail_local.o
./configure --prefix=$PREFIX/$TARGET --target=$TARGET CC=$MUSL_CC
make install-headers
make -j"$(nproc)"
make install
cp libssp_nonshared.a $PREFIX/$TARGET/lib/
if [[ "$TARGETARCH" == "$ARCH" ]]; then
# Fix for aarch64 build: rsync musl headers to native sysroot
rsync -av $PREFIX/$TARGET/include/ $PREFIX/include/
rsync -av $PREFIX/$TARGET/lib/ $PREFIX/lib/
fi
# Stage 2
cd "$HOME"/pkgs
mkdir gcc-${GCC_VERSION}-build-${TARGETARCH}-O${OPT}-final
cd gcc-${GCC_VERSION}-build-${TARGETARCH}-O${OPT}-final
"$HOME"/pkgs/gcc-${GCC_VERSION}/configure \
--target=$TARGET --prefix=$PREFIX --with-sysroot=$SYSROOT ${GCC_CONFIGURE_ARGS} \
--with-gmp=/usr --with-mpfr=/usr --with-mpc=/usr \
--disable-shared --enable-tls --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --disable-symvers \
--enable-threads --enable-__cxa_atexit --enable-languages=c,c++ --enable-link-serialization=2 --enable-linker-build-id \
--enable-libssp --disable-libsanitizer --enable-checking=release --disable-cet --disable-fixed-point \
--enable-libstdcxx-time=yes --enable-default-pie --enable-default-ssp --with-linker-hash-style=gnu ${GCC_NODOCS}
make -j"$(nproc)" ${GCC_NODOCS}
make install
# Directory for ccache symlinks
mkdir -p $PREFIX/lib/ccache/bin
# Symbolic links for clang
for clang_binary in /usr/bin/clang{++,}{-[1-9]*,}; do
name=$(basename $clang_binary)
ln -s $clang_binary $PREFIX/bin/$TARGET-$name
ln -s /usr/bin/ccache $PREFIX/lib/ccache/bin/$TARGET-$name
done
# Also provide ccache symlinks for gcc
for gcc_binary in $PREFIX/bin/$TARGET-{c++,g++,gcc,gcc-[1-9]*}; do
name=$(basename $gcc_binary)
ln -s /usr/bin/ccache $PREFIX/lib/ccache/bin/$name
done
done
done
cd "$HOME"
rm -rf pkgs

View File

@ -108,143 +108,222 @@ jobs:
strategy:
matrix:
arch:
- amd64
- arm64v8
dist:
- ubuntu
- fedora
- arch
build_type:
- gcc-debug-shared-ninja-full
- gcc-release-ninja-split
- gcc-release-shared-ninja-split
- clang-release-shared-ninja-full
exclude:
- arch: arm64v8
dist: arch
build_type: gcc-debug-shared-ninja-full
- arch: arm64v8
dist: arch
build_type: gcc-release-ninja-split
- arch: arm64v8
dist: arch
build_type: gcc-release-shared-ninja-split
- arch: arm64v8
dist: arch
build_type: clang-release-shared-ninja-full
- arch: arm64v8
dist: ubuntu
build_type: gcc-release-ninja-split
- arch: arm64v8
dist: ubuntu
build_type: gcc-release-shared-ninja-split
- arch: arm64v8
dist: fedora
build_type: gcc-release-ninja-split
- arch: arm64v8
dist: fedora
build_type: gcc-release-shared-ninja-split
include:
- arch: amd64
dist: debian
build_type: gcc-release-make-full
- arch: amd64
dist: debian
build_type: clang-debug-shared-ninja-split
- arch: amd64
dist: ubuntu
build_type: clang-reldbg-shared-asan-ninja
- arch: amd64
dist: ubuntu
build_type: clang-debug-shared-tsan-ninja
- arch: amd64
dist: ubuntu
build_type: clang-reldbg-shared-ubsan-ninja
- arch: amd64
dist: ubuntu
build_type: oldgcc-debug-shared-make-split
- arch: amd64
dist: ubuntu
build_type: gcc-debug-shared-noperfmon-ninja-split
- arch: amd64
dist: ubuntu
build_type: oldclang-debug-shared-make-split
- arch: amd64
dist: ubuntu-2204
- build_arch: amd64
build_dist: ubuntu
build_type: gcc-release-ninja-split
- build_arch: amd64
build_dist: ubuntu
build_type: gcc-release-shared-ninja-split
- arch: amd64
dist: ubuntu-2204
- build_arch: amd64
build_dist: ubuntu
build_type: gcc-debug-shared-ninja-full
- arch: amd64
dist: ubuntu-2204
build_type: clang-release-ninja-split
- arch: amd64
dist: ubuntu
- build_arch: amd64
build_dist: ubuntu
build_type: gcc-debug-shared-noperfmon-ninja-split
- build_arch: amd64
build_dist: ubuntu
build_type: clang-release-shared-ninja-full
- build_arch: amd64
build_dist: ubuntu
build_type: clang-reldbg-shared-asan-ninja
- build_arch: amd64
build_dist: ubuntu
build_type: clang-reldbg-shared-ubsan-ninja
- build_arch: amd64
build_dist: ubuntu
build_type: clang-debug-shared-tsan-ninja
- build_arch: amd64
build_dist: ubuntu
build_type: clang-debug-coverage-ninja
- arch: amd64
dist: alpine
- build_arch: amd64
build_dist: ubuntu
build_type: oldgcc-debug-shared-make-split
- build_arch: amd64
build_dist: ubuntu
build_type: oldclang-debug-shared-make-split
- build_arch: amd64
build_dist: ubuntu-2204
build_type: gcc-release-shared-ninja-split
- build_arch: amd64
build_dist: ubuntu-2204
build_type: gcc-debug-shared-ninja-full
- build_arch: amd64
build_dist: ubuntu-2204
build_type: clang-release-ninja-split
- build_arch: amd64
build_dist: fedora
build_type: gcc-release-ninja-split
- build_arch: amd64
build_dist: fedora
build_type: gcc-release-shared-ninja-split
- build_arch: amd64
build_dist: fedora
build_type: gcc-debug-shared-ninja-full
- build_arch: amd64
build_dist: fedora
build_type: clang-release-shared-ninja-full
- build_arch: amd64
build_dist: arch
build_type: gcc-release-ninja-split
- build_arch: amd64
build_dist: arch
build_type: gcc-release-shared-ninja-split
- build_arch: amd64
build_dist: arch
build_type: gcc-debug-shared-ninja-full
- build_arch: amd64
build_dist: arch
build_type: clang-release-shared-ninja-full
- build_arch: amd64
build_dist: debian
build_type: gcc-release-make-full
- build_arch: amd64
build_dist: debian
build_type: clang-debug-shared-ninja-split
- build_arch: amd64
build_dist: alpine
build_type: gcc-release-ninja-static
- arch: arm64v8
dist: alpine
build_type: gcc-release-ninja-static
- arch: amd64
dist: alpine
- build_arch: amd64
build_dist: alpine
build_type: clang-release-ninja-static
- arch: arm64v8
dist: alpine
build_type: clang-release-ninja-static
- arch: amd64
dist: alpine
- build_arch: amd64
build_dist: alpine
build_type: clang-relsize-lto-ninja-static
- arch: arm64v8
dist: alpine
build_type: clang-relsize-lto-ninja-static
- arch: amd64
dist: alpine
- build_arch: amd64
build_dist: alpine
build_type: clang-relsize-libressl-lto-ninja-static
- arch: arm64v8
dist: alpine
build_type: clang-relsize-libressl-lto-ninja-static
- arch: riscv64
dist: alpine
build_type: clang-relsize-libressl-lto-ninja-static
- arch: amd64
dist: alpine
- build_arch: amd64
build_dist: alpine
build_type: clang-relsize-minimal-lto-ninja-static
- arch: arm64v8
dist: alpine
build_type: clang-relsize-minimal-lto-ninja-static
- arch: amd64
dist: alpine
- build_arch: amd64
build_dist: alpine
build_type: clang-relsize-minimal-libressl-lto-ninja-static
# - arch: arm64v8
# dist: alpine
# build_type: clang-relsize-minimal-libressl-lto-ninja-static
- arch: amd64
dist: alpine
- build_arch: amd64
build_dist: alpine
build_type: clang-relsize-minimal-mimalloc-lto-ninja-static
- arch: arm64v8
dist: alpine
build_type: clang-relsize-minimal-mimalloc-lto-ninja-static
- arch: amd64
dist: alpine
- build_arch: amd64
build_dist: alpine
build_type: clang-relsize-minimal-mimalloc-libressl-lto-ninja-static
# - arch: arm64v8
# dist: alpine
# build_type: clang-relsize-minimal-mimalloc-libressl-lto-ninja-static
- arch: amd64
dist: alpine
- build_arch: amd64
build_dist: alpine
build_type: clang-reldbg-stacktrace-ninja-static
- arch: arm64v8
dist: alpine
- build_arch: arm64v8
build_dist: ubuntu
build_type: gcc-debug-shared-ninja-full
- build_arch: arm64v8
build_dist: ubuntu
build_type: clang-release-shared-ninja-full
- build_arch: arm64v8
build_dist: fedora
build_type: gcc-debug-shared-ninja-full
- build_arch: arm64v8
build_dist: fedora
build_type: clang-release-shared-ninja-full
- build_arch: arm64v8
build_dist: alpine
build_type: gcc-release-ninja-static
- build_arch: arm64v8
build_dist: alpine
build_type: clang-release-ninja-static
- build_arch: arm64v8
build_dist: alpine
build_type: clang-relsize-lto-ninja-static
- build_arch: arm64v8
build_dist: alpine
build_type: clang-relsize-libressl-lto-ninja-static
- build_arch: arm64v8
build_dist: alpine
build_type: clang-relsize-minimal-lto-ninja-static
- build_arch: arm64v8
build_dist: alpine
build_type: clang-relsize-minimal-mimalloc-lto-ninja-static
- build_arch: arm64v8
build_dist: alpine
build_type: clang-reldbg-stacktrace-ninja-static
- build_arch: riscv64
build_dist: debian
build_type: gcc-release-ninja-full
- build_arch: riscv64
build_dist: ubuntu
build_type: clang-debug-shared-ninja-split
- build_arch: amd64
build_dist: alpine
build_type: clang-relsize-libressl-lto-ninja-static
cross_arch: aarch64
- build_arch: amd64
build_dist: alpine
build_type: clang-relsize-libressl-lto-ninja-static
cross_arch: riscv64
- build_arch: amd64
build_dist: alpine
build_type: clang-relsize-libressl-lto-ninja-static
cross_arch: i386
- build_arch: amd64
build_dist: alpine
build_type: clang-relsize-libressl-lto-ninja-static
cross_arch: arm
- build_arch: amd64
build_dist: alpine
build_type: gcc-release-ninja-static
cross_arch: ppc64le
uses: ./.github/workflows/docker-run-build.yml
with:
build_type: ${{ matrix.build_type }}
build_arch: ${{ matrix.arch }}
build_dist: ${{ matrix.dist }}
build_arch: ${{ matrix.build_arch }}
build_dist: ${{ matrix.build_dist }}
cross_arch: ${{ matrix.cross_arch }}
build_from_tarball: true
upload_coverage: ${{ matrix.build_type == 'clang-debug-coverage-ninja' }}
upload_artifacts: ${{ endsWith(matrix.build_type, '-static') }}

View File

@ -10,6 +10,10 @@ on:
build_arch:
required: true
type: string
cross_arch:
required: false
type: string
default: ''
build_dist:
required: true
type: string
@ -47,12 +51,15 @@ jobs:
fetch-depth: '0'
ref: ${{ github.ref }}
# Only if inputs.build_arch is `amd64`, we want to build a cross-compiling
# container by setting TARGET_ARCHS. Otherwise, don't set TARGET_ARCHS.
- name: Build Docker Image
run: |
docker build \
docker buildx build --progress=plain \
-f .docker/Dockerfile.${{ inputs.build_dist }} \
-t dwarfs-linux-build-${{ inputs.build_dist }} \
--build-arg ARCH=${{ inputs.build_arch }} \
${{ inputs.build_arch == 'amd64' && '--build-arg TARGET_ARCHS=x86_64,aarch64,riscv64,ppc64le,s390x,arm,i386' || '' }} \
.docker
- name: Run Build
@ -67,6 +74,7 @@ jobs:
${{ inputs.build_from_tarball && '--env BUILD_FROM_TARBALL=1' || '' }} \
--env BUILD_TYPE=${{ inputs.build_type }} \
--env BUILD_ARCH=${{ inputs.build_arch }} \
--env CROSS_ARCH=${{ inputs.cross_arch }} \
--env BUILD_DIST=${{ inputs.build_dist }} \
--env GITHUB_REF_NAME \
--env GITHUB_REF_TYPE \

View File

@ -136,10 +136,11 @@ def main():
if args.ninja and step.get("name") == "Run Build":
run_id = job.get("run_id", 0)
# get arch, dist, config from "linux (arm64v8, alpine, clang-release-ninja-static) / docker-build"
m = re.match(r"linux \(([^,]+), ([^,]+), ([^,]+)\)", name)
m = re.match(r"linux \(([^,]+), ([^,]+), ([^,]+)(, ([^,]+))?\)", name)
if m:
build_log_path = f"{args.log_base}/{run_id}/build-{m.group(1)},{m.group(2)},{m.group(3)}.log"
ninja_log_path = f"{args.log_base}/{run_id}/ninja-{m.group(1)},{m.group(2)},{m.group(3)}.log"
cross = m.group(5) if m.group(5) else ""
build_log_path = f"{args.log_base}/{run_id}/build-{m.group(1)},{cross},{m.group(2)},{m.group(3)}.log"
ninja_log_path = f"{args.log_base}/{run_id}/ninja-{m.group(1)},{cross},{m.group(2)},{m.group(3)}.log"
build_events = {}
if os.path.exists(build_log_path):
with open(build_log_path, "r") as f:

View File

@ -140,17 +140,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules")
find_package(PkgConfig)
if(STATIC_BUILD_DO_NOT_USE)
# Strangely this is needed when linking statically against FLAC++
#add_compile_options(-fno-omit-frame-pointer)
if(STATIC_BUILD_EXTRA_PREFIX)
foreach (prefix ${STATIC_BUILD_EXTRA_PREFIX})
include_directories(BEFORE ${prefix}/include)
endforeach()
list(PREPEND CMAKE_PREFIX_PATH ${STATIC_BUILD_EXTRA_PREFIX})
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON)
endif()
set(CMAKE_FIND_LIBRARY_SUFFIXES
".a"
CACHE STRING "please look for static libs")
@ -991,7 +980,11 @@ if(STATIC_BUILD_DO_NOT_USE OR APPLE)
if(APPLE)
add_custom_target(strip COMMAND strip ${FILES_TO_STRIP})
else()
add_custom_target(strip COMMAND strip $<IF:$<BOOL:${ENABLE_STACKTRACE}>,--strip-debug,--strip-all> ${FILES_TO_STRIP})
set(STRIP_TOOL strip)
if(DEFINED ENV{STRIP_TOOL})
set(STRIP_TOOL $ENV{STRIP_TOOL})
endif()
add_custom_target(strip COMMAND ${STRIP_TOOL} $<IF:$<BOOL:${ENABLE_STACKTRACE}>,--strip-debug,--strip-all> ${FILES_TO_STRIP})
endif()
endif()
endif()
@ -1018,6 +1011,9 @@ endif()
if(DWARFS_ARTIFACT_SUFFIX)
set(DWARFS_ARTIFACT_ID "${DWARFS_ARTIFACT_ID}${DWARFS_ARTIFACT_SUFFIX}")
endif()
if(CMAKE_CROSSCOMPILING)
set(DWARFS_ARTIFACT_ID "${DWARFS_ARTIFACT_ID}-cross-${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
if(STATIC_BUILD_DO_NOT_USE OR WIN32)
if(TARGET dwarfsuniversal)
@ -1043,7 +1039,7 @@ if(STATIC_BUILD_DO_NOT_USE OR WIN32)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
else()
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(i386|x86_64|AMD64|aarch64)$")
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(i386|x86_64|AMD64|aarch64|ppc64le|arm)$")
find_program(UPX_EXE upx upx.exe PATHS "c:/bin" DOC "ultimate packer for executables")
endif()