From 73a028d4641293f4eebbab75c9d3bdea9864a262 Mon Sep 17 00:00:00 2001 From: acetone <63557806+freeacetone@users.noreply.github.com> Date: Fri, 2 Oct 2026 03:52:56 -0400 Subject: [PATCH] add static musl build --- .github/workflows/build-static.yml | 64 ++++++++++++++++++++++++++++++ contrib/static/build-musl.sh | 27 +++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 .github/workflows/build-static.yml create mode 100755 contrib/static/build-musl.sh diff --git a/.github/workflows/build-static.yml b/.github/workflows/build-static.yml new file mode 100644 index 00000000..fc5f3f61 --- /dev/null +++ b/.github/workflows/build-static.yml @@ -0,0 +1,64 @@ +name: Build static binaries + +on: + push: + branches: + - '*' + paths: + - .github/workflows/build-static.yml + - contrib/static/** + - daemon/** + - i18n/** + - libi2pd/** + - libi2pd_client/** + - Makefile + - Makefile.linux + tags: + - '*' + pull_request: + branches: + - '*' + +jobs: + build: + name: musl ${{ matrix.arch }} + runs-on: ${{ matrix.runner }} + + strategy: + fail-fast: false + matrix: + include: + - arch: x86_64 + runner: ubuntu-latest + - arch: aarch64 + runner: ubuntu-24.04-arm + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build in Alpine + run: docker run --rm -v "$PWD":/src -w /src alpine:3.22 sh contrib/static/build-musl.sh + + - name: Check binary + run: | + file i2pd | grep 'statically linked' + readelf -d i2pd | grep 'There is no dynamic section' + ./i2pd --version + ./i2pd --version | grep -E '^OpenSSL (3\.([5-9]|[1-9][0-9])|[4-9])\.' + ./i2pd --version | grep -E '^Boost version 1\.(8[1-9]|9[0-9])\.' + + - name: Run + run: | + mkdir datadir + ./i2pd --datadir=datadir --log=file --logfile=datadir/i2pd.log --loglevel=info & + sleep 15 + kill -0 $! + grep 'Daemon: Starting NetDB' datadir/i2pd.log + kill -9 $! + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: i2pd-static-${{ matrix.arch }} + path: i2pd diff --git a/contrib/static/build-musl.sh b/contrib/static/build-musl.sh new file mode 100755 index 00000000..95bfe5fd --- /dev/null +++ b/contrib/static/build-musl.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Fully static i2pd, run from the source tree inside an Alpine container +set -e + +OPENSSL_VERSION=3.5.8 +JOBS=4 + +apk add --no-cache build-base perl linux-headers boost-dev boost-static zlib-dev zlib-static miniupnpc-dev + +SRC=$(pwd) +cd /tmp +OPENSSL=openssl-$OPENSSL_VERSION +wget -q https://github.com/openssl/openssl/releases/download/$OPENSSL/$OPENSSL.tar.gz +wget -q https://github.com/openssl/openssl/releases/download/$OPENSSL/$OPENSSL.tar.gz.sha256 +echo "$(cut -d' ' -f1 $OPENSSL.tar.gz.sha256) $OPENSSL.tar.gz" | sha256sum -c - +tar xzf $OPENSSL.tar.gz +cd $OPENSSL +# no-autoload-config: a static binary must not read the host's openssl.cnf +./Configure --prefix=/usr --libdir=lib --openssldir=/nonexistent \ + no-autoload-config no-shared no-module no-dso no-engine no-tests no-docs +make -j$JOBS +make install_sw + +cd "$SRC" +# USE_STATIC looks for archives in /usr/lib/$(SYS) and does not pass -static +make -j$JOBS DEBUG=no USE_STATIC=yes USE_UPNP=yes LIBDIR=/usr/lib LDFLAGS=-static i2pd +strip i2pd