Files
SubConverter-Extended/Dockerfile.armv7-cross
2026-05-21 00:16:31 +08:00

232 lines
9.4 KiB
Docker

# ========== GO BUILD STAGE ==========
FROM --platform=$BUILDPLATFORM mirror.gcr.io/library/golang:latest AS go-builder
ARG TARGETARCH
ARG TARGETVARIANT
ARG MIHOMO_REF="Meta"
ARG MIHOMO_CACHE_BUST=1
ARG REFRESH_GO_DEPS=false
WORKDIR /build/bridge
RUN apt-get update && \
apt-get install -y --no-install-recommends \
git build-essential crossbuild-essential-armhf ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY bridge/go.mod bridge/go.sum ./
COPY bridge/converter.go ./
RUN set -xe && \
if [ "${REFRESH_GO_DEPS}" = "true" ]; then \
echo "MIHOMO_CACHE_BUST=$MIHOMO_CACHE_BUST" && \
go get github.com/metacubex/mihomo@${MIHOMO_REF} && \
go get -u all && \
go mod tidy; \
else \
go mod download; \
fi
COPY scripts/ ../scripts/
RUN go run ../scripts/generate_schemes.go mihomo_schemes.h
RUN go run ../scripts/generate_param_compat.go -o param_compat.h
RUN echo "==> Cross-compiling Go bridge for linux/arm/v7" && \
CGO_ENABLED=1 \
GOOS=linux \
GOARCH=arm \
GOARM=7 \
CC=arm-linux-gnueabihf-gcc \
go build \
-trimpath \
-buildmode=c-archive \
-o libmihomo.a \
.
RUN ls -lh libmihomo.a libmihomo.h
# ========== C++ CROSS BUILD STAGE ==========
FROM --platform=$BUILDPLATFORM mirror.gcr.io/library/debian:trixie AS builder
ARG THREADS="4"
ARG SHA=""
ARG VERSION="dev"
ARG BUILD_DATE=""
ARG REFRESH_HEADERS=false
ARG SOURCE_DEPS_CACHE_BUST=stable
ENV DEBIAN_FRONTEND=noninteractive
ENV PKG_CONFIG_ALLOW_CROSS=1
ENV PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/share/pkgconfig:/opt/armv7/lib/pkgconfig
ENV PKG_CONFIG_PATH=/opt/armv7/lib/pkgconfig
WORKDIR /
RUN dpkg --add-architecture armhf && \
apt-get update && \
apt-get install -y --no-install-recommends \
git build-essential crossbuild-essential-armhf \
cmake ninja-build ccache pkg-config curl ca-certificates file \
libcurl4-openssl-dev:armhf \
libpcre2-dev:armhf \
libyaml-cpp-dev:armhf \
libatomic1:armhf \
rapidjson-dev && \
rm -rf /var/lib/apt/lists/*
COPY cmake/linux-armv7hf.cmake /opt/armv7-toolchain.cmake
RUN set -xe && \
echo "SOURCE_DEPS_CACHE_BUST=${SOURCE_DEPS_CACHE_BUST}" && \
git clone --depth=1 --recurse-submodules --shallow-submodules https://github.com/ftk/quickjspp.git quickjspp && \
cd quickjspp && \
cmake -DCMAKE_TOOLCHAIN_FILE=/opt/armv7-toolchain.cmake -DCMAKE_BUILD_TYPE=Release . && \
make quickjs -j ${THREADS} && \
install -d /opt/armv7/lib/quickjs/ && \
install -m644 quickjs/libquickjs.a /opt/armv7/lib/quickjs/ && \
install -d /opt/armv7/include/quickjs/ && \
install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h /opt/armv7/include/quickjs/ && \
install -m644 quickjspp.hpp /opt/armv7/include/
RUN set -xe && \
echo "SOURCE_DEPS_CACHE_BUST=${SOURCE_DEPS_CACHE_BUST}" && \
git clone --depth=1 --recurse-submodules --shallow-submodules https://github.com/PerMalmberg/libcron.git libcron && \
cd libcron && \
cmake -DCMAKE_TOOLCHAIN_FILE=/opt/armv7-toolchain.cmake -DCMAKE_BUILD_TYPE=Release . && \
make libcron -j ${THREADS} && \
install -d /opt/armv7/lib/ && \
install -m644 libcron/out/Release/liblibcron.a /opt/armv7/lib/ && \
install -d /opt/armv7/include/libcron/ && \
install -m644 libcron/include/libcron/* /opt/armv7/include/libcron/ && \
install -d /opt/armv7/include/date/ && \
install -m644 libcron/externals/date/include/date/* /opt/armv7/include/date/
RUN set -xe && \
echo "SOURCE_DEPS_CACHE_BUST=${SOURCE_DEPS_CACHE_BUST}" && \
git clone --depth=1 https://github.com/ToruNiina/toml11.git toml11 && \
cd toml11 && \
install -d /opt/armv7/include && \
cp -a include/. /opt/armv7/include/
COPY --from=go-builder /build/bridge/libmihomo.a /usr/lib/
COPY --from=go-builder /build/bridge/libmihomo.h /usr/include/
COPY --from=go-builder /build/bridge/go.mod /src/bridge/go.mod
COPY --from=go-builder /build/bridge/go.sum /src/bridge/go.sum
WORKDIR /src
COPY . /src
COPY --from=go-builder /build/bridge/mihomo_schemes.h /src/src/parser/mihomo_schemes.h
COPY --from=go-builder /build/bridge/param_compat.h /src/src/parser/param_compat.h
RUN set -xe && \
if [ "${REFRESH_HEADERS}" = "true" ]; then \
echo "Downloading latest cpp-httplib..." && \
curl -fsSL https://raw.githubusercontent.com/yhirose/cpp-httplib/master/httplib.h -o include/httplib.h && \
echo "Downloading latest nlohmann/json..." && \
curl -fsSL https://github.com/nlohmann/json/releases/latest/download/json.hpp -o include/nlohmann/json.hpp && \
echo "Downloading latest inja..." && \
curl -fsSL https://raw.githubusercontent.com/pantor/inja/master/single_include/inja/inja.hpp -o include/inja.hpp && \
echo "Downloading latest jpcre2..." && \
curl -fsSL https://raw.githubusercontent.com/jpcre2/jpcre2/master/src/jpcre2.hpp -o include/jpcre2.hpp && \
echo "Copying latest quickjspp from compiled source..." && \
cp /opt/armv7/include/quickjspp.hpp include/quickjspp.hpp && \
echo "Copying latest libcron headers from compiled source..." && \
rm -rf include/libcron include/date && \
cp -a /libcron/libcron/include/libcron include/libcron && \
cp -a /libcron/libcron/externals/date/include/date include/date && \
echo "Copying latest toml11 headers from compiled source..." && \
rm -rf include/toml11 && \
cp /toml11/include/toml.hpp include/toml.hpp && \
cp -a /toml11/include/toml11 include/toml11; \
else \
echo "Using committed header libraries"; \
fi
RUN set -xe && \
[ -n "${SHA}" ] && sed -i "s/#define BUILD_ID \"\"/#define BUILD_ID \"${SHA}\"/ " src/version.h || true && \
[ -n "${VERSION}" ] && sed -i "s/#define VERSION \"dev\"/#define VERSION \"${VERSION}\"/" src/version.h || true && \
[ -n "${BUILD_DATE}" ] && sed -i "s/#define BUILD_DATE \"\"/#define BUILD_DATE \"${BUILD_DATE}\"/" src/version.h || true && \
mkdir -p bridge && \
cp /usr/lib/libmihomo.a bridge/ && \
cp /usr/include/libmihomo.h bridge/ && \
export PATH="/usr/lib/ccache:$PATH" && \
export CCACHE_DIR=/tmp/ccache && \
export CCACHE_COMPILERCHECK=content && \
cmake -GNinja \
-DCMAKE_TOOLCHAIN_FILE=/opt/armv7-toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_PREFIX_PATH=/opt/armv7 \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=OFF \
-DCURL_INCLUDE_DIR=/usr/include \
-DCURL_LIBRARY=/usr/lib/arm-linux-gnueabihf/libcurl.so \
-DPCRE2_INCLUDE_DIR=/usr/include \
-DPCRE2_LIBRARY=/usr/lib/arm-linux-gnueabihf/libpcre2-8.so \
-DQUICKJS_INCLUDE_DIRS=/opt/armv7/include \
-DQUICKJS_LIBRARY=/opt/armv7/lib/quickjs/libquickjs.a \
-DLIBCRON_INCLUDE_DIR=/opt/armv7/include \
-DDATE_INCLUDE_DIR=/opt/armv7/include \
-DLIBCRON_LIBRARY=/opt/armv7/lib/liblibcron.a \
-DRAPIDJSON_INCLUDEDIR=/usr/include \
. && \
ninja -j ${THREADS} && \
file /src/subconverter && \
arm-linux-gnueabihf-readelf -h /src/subconverter && \
arm-linux-gnueabihf-readelf -d /src/subconverter
RUN set -xe && \
mkdir -p /runtime-root/etc/ssl/certs /runtime-root/etc /runtime-root/tmp /runtime-root/usr/lib/arm-linux-gnueabihf && \
cp -aL /etc/ssl/certs/ca-certificates.crt /runtime-root/etc/ssl/certs/ && \
if [ -f /etc/nsswitch.conf ]; then cp -aL /etc/nsswitch.conf /runtime-root/etc/nsswitch.conf; fi && \
for dir in /lib/arm-linux-gnueabihf /usr/lib/arm-linux-gnueabihf /usr/arm-linux-gnueabihf/lib; do \
if [ -d "$dir" ]; then \
find "$dir" -maxdepth 1 \( -name '*.so' -o -name '*.so.*' \) -print | \
while read -r lib; do \
dest="/runtime-root/usr/lib/arm-linux-gnueabihf/$(basename "$lib")"; \
cp -aL "$lib" "$dest"; \
done; \
fi; \
done
# ========== FINAL STAGE ==========
FROM --platform=$TARGETPLATFORM mirror.gcr.io/library/debian:trixie-slim
ARG VERSION="dev"
ARG SHA=""
ARG BUILD_DATE=""
LABEL \
org.opencontainers.image.title="SubConverter-Extended" \
org.opencontainers.image.description="A Modern Evolution of subconverter; an enhanced implementation aligned with Mihomo configuration" \
org.opencontainers.image.url="https://github.com/Aethersailor/SubConverter-Extended" \
org.opencontainers.image.source="https://github.com/Aethersailor/SubConverter-Extended" \
org.opencontainers.image.licenses="GPL-3.0" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.revision="${SHA}" \
org.opencontainers.image.created="${BUILD_DATE}" \
maintainer="Aethersailor"
COPY --from=builder /runtime-root/ /
COPY --from=builder --chmod=0755 /src/subconverter /usr/bin/subconverter
COPY --from=builder /src/base /base/
ENV TZ=Asia/Shanghai
ENV LD_LIBRARY_PATH="/usr/lib/arm-linux-gnueabihf:/usr/lib"
WORKDIR /base
RUN set -e && \
printf '%s\n' \
'#!/bin/sh' \
'set -e' \
'export LD_LIBRARY_PATH="/usr/lib/arm-linux-gnueabihf:/usr/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"' \
'CONF="${PREF_PATH:-/base/pref.toml}"' \
'CONF_DIR="$(dirname "$CONF")"' \
'mkdir -p "$CONF_DIR"' \
'if [ ! -f "$CONF" ] && [ -f /base/pref.example.toml ]; then' \
' cp /base/pref.example.toml "$CONF"' \
'fi' \
'exec /usr/bin/subconverter -f "$CONF"' \
> /usr/local/bin/start-subconverter && \
chmod +x /usr/local/bin/start-subconverter
CMD ["/usr/local/bin/start-subconverter"]
EXPOSE 25500/tcp