build: support RISCV64 build (fixes gh #266)

This commit is contained in:
Marcus Holland-Moritz 2025-06-28 08:22:49 +02:00 committed by mhx
parent d96e2d39b4
commit c0725c40fb
7 changed files with 55 additions and 7 deletions

View File

@ -51,7 +51,13 @@ RUN apk add --no-cache \
# Install UPX
ARG ARCH
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"
# 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
@ -67,7 +73,11 @@ RUN bash /usr/local/bin/install-mold.sh
# Install bloaty
COPY install-bloaty.sh /usr/local/bin/install-bloaty.sh
RUN bash /usr/local/bin/install-bloaty.sh
RUN if [ "$ARCH" != "riscv64" ]; then \
bash /usr/local/bin/install-bloaty.sh; \
else \
echo "Skipping bloaty installation for RISC-V."; \
fi
# Install all static libraries
COPY install-static-libs.sh /usr/local/bin/install-static-libs.sh

View File

@ -1,5 +1,6 @@
IMAGE_UBUNTU="dwarfs-buildenv"
IMAGE_ALPINE="dwarfs-buildenv-alpine"
IMAGE_ALPINE_RISCV="dwarfs-buildenv-alpine-riscv64"
IMAGE_UBUNTU2204="dwarfs-buildenv-ubuntu2204"
IMAGE_FEDORA="dwarfs-buildenv-fedora"
IMAGE_ARCH="dwarfs-buildenv-arch"
@ -31,6 +32,12 @@ build_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 .
run_alpine_riscv:
@docker run $(COMMON_RUN_OPTS) $(IMAGE_ALPINE_RISCV)
build_ubuntu2204:
docker build -f Dockerfile.ubuntu-2204 -t $(IMAGE_UBUNTU2204) .

View File

@ -41,12 +41,22 @@ echo "Using $GCC and $CLANG"
if [[ "$PKGS" == ":ubuntu" ]]; then
PKGS="file,bzip2,libarchive,flac,libunwind,benchmark,openssl,cpptrace"
COMPILERS="clang gcc"
elif [[ "$PKGS" == ":alpine" ]]; then
PKGS="benchmark,boost,brotli,cpptrace,double-conversion,flac,fmt,fuse,glog,jemalloc,libarchive,libunwind,libressl,lz4,mimalloc,openssl,xxhash,xz,zstd"
elif [[ "$PKGS" == ":alpine"* ]]; then
if [[ "$PKGS" == ":alpine" ]]; then
PKGS="benchmark,boost,brotli,cpptrace,double-conversion,flac,fmt,fuse,glog,jemalloc,libarchive,libunwind,libressl,lz4,mimalloc,openssl,xxhash,xz,zstd"
else
PKGS="${PKGS#:alpine:}"
fi
export COMMON_CFLAGS="-ffunction-sections -fdata-sections -fmerge-all-constants"
export COMMON_CXXFLAGS="$COMMON_CFLAGS"
export COMMON_LDFLAGS="-fuse-ld=mold"
# COMPILERS="clang clang-lto clang-minsize-lto gcc"
COMPILERS="clang clang-minsize-lto gcc"
if [[ "$ARCH" != "x86_64" && "$ARCH" != "aarch64" ]]; then
# Let's keep it simple for more exotic architectures
COMPILERS="clang-minsize-lto"
else
COMPILERS="clang clang-minsize-lto gcc"
fi
elif [[ "$PKGS" == ":none" ]]; then
echo "No libraries to build"
exit 0
@ -451,7 +461,9 @@ for COMPILER in $COMPILERS; do
./configure --prefix="$prefix" \
--without-iconv --without-xml2 --without-expat \
--without-bz2lib --without-zlib \
--disable-shared --disable-acl --disable-xattr
--disable-shared --disable-acl --disable-xattr \
--disable-bsdtar --disable-bsdcat --disable-bsdcpio \
--disable-bsdunzip
make -j$(nproc)
make install
done
@ -472,7 +484,8 @@ for COMPILER in $COMPILERS; do
cd "$HOME/pkgs/$COMPILER"
tar xf ../${FLAC_TARBALL}
cd flac-${FLAC_VERSION}
./configure --prefix="$INSTALL_DIR" --enable-static=yes --enable-shared=no --disable-doxygen-docs --disable-ogg --disable-programs --disable-examples
./configure --prefix="$INSTALL_DIR" --enable-static=yes --enable-shared=no \
--disable-doxygen-docs --disable-ogg --disable-programs --disable-examples
make -j$(nproc)
make install
fi

View File

@ -200,6 +200,9 @@ jobs:
- 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_type: clang-relsize-minimal-lto-ninja-static

View File

@ -36,6 +36,9 @@ jobs:
- Linux
- ${{ inputs.build_arch }}
# Building a docker container on RISC-V can take an awful long time
timeout-minutes: 2880
steps:
- name: Checkout
uses: actions/checkout@v4

View File

@ -1053,6 +1053,13 @@ if(STATIC_BUILD_DO_NOT_USE OR WIN32)
COMMAND ${UPX_EXE} -9 --best -o ${UNIVERSAL_OUT} $<TARGET_FILE:${tgt}>
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
else()
add_custom_command(
OUTPUT ${UNIVERSAL_OUT}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${tgt}> ${UNIVERSAL_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "UPX not found, copying binary without compression"
)
endif()
endif()

View File

@ -150,6 +150,11 @@ target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/folly>
)
# On platforms other than x86 / arm, we need to use the fallback
if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|aarch64")
target_compile_definitions(dwarfs_folly_lite PUBLIC FOLLY_F14_FORCE_FALLBACK=1)
endif()
if(NOT PREFER_SYSTEM_FAST_FLOAT)
target_include_directories(
dwarfs_folly_lite SYSTEM PRIVATE