diff --git a/.docker/Dockerfile.alpine b/.docker/Dockerfile.alpine index 136c20e6..6062a150 100644 --- a/.docker/Dockerfile.alpine +++ b/.docker/Dockerfile.alpine @@ -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 diff --git a/.docker/Makefile b/.docker/Makefile index 7b727af6..56a1655f 100644 --- a/.docker/Makefile +++ b/.docker/Makefile @@ -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) . diff --git a/.docker/install-static-libs.sh b/.docker/install-static-libs.sh index 833824a1..b72fda34 100644 --- a/.docker/install-static-libs.sh +++ b/.docker/install-static-libs.sh @@ -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 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1f590e07..a09af273 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/.github/workflows/docker-run-build.yml b/.github/workflows/docker-run-build.yml index 8dcaf1be..79e07be0 100644 --- a/.github/workflows/docker-run-build.yml +++ b/.github/workflows/docker-run-build.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bec243e..2d10518a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1053,6 +1053,13 @@ if(STATIC_BUILD_DO_NOT_USE OR WIN32) COMMAND ${UPX_EXE} -9 --best -o ${UNIVERSAL_OUT} $ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) + else() + add_custom_command( + OUTPUT ${UNIVERSAL_OUT} + COMMAND ${CMAKE_COMMAND} -E copy $ ${UNIVERSAL_OUT} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "UPX not found, copying binary without compression" + ) endif() endif() diff --git a/cmake/folly.cmake b/cmake/folly.cmake index 5e4283fe..8d690450 100644 --- a/cmake/folly.cmake +++ b/cmake/folly.cmake @@ -150,6 +150,11 @@ target_include_directories( $ ) +# 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