fix: Alpine 回退到静态库包方式实现纯静态链接
Some checks failed
Build and Release Mond / build-and-test (arm64, alpine) (push) Failing after 23s
Build and Release Mond / build-and-test (amd64, alpine) (push) Failing after 30s
Build and Release Mond / build-and-test (arm64, ubuntu) (push) Successful in 41s
Build and Release Mond / build-and-test (amd64, ubuntu) (push) Successful in 54s
Build and Release Mond / release (push) Has been skipped
Some checks failed
Build and Release Mond / build-and-test (arm64, alpine) (push) Failing after 23s
Build and Release Mond / build-and-test (amd64, alpine) (push) Failing after 30s
Build and Release Mond / build-and-test (arm64, ubuntu) (push) Successful in 41s
Build and Release Mond / build-and-test (amd64, ubuntu) (push) Successful in 54s
Build and Release Mond / release (push) Has been skipped
问题分析: - Alpine (musl libc) 不适合使用 depends 系统(为 glibc 设计) - ARM64 交叉编译缺少工具链 - AMD64 依然遇到 execinfo.h 错误 解决方案: 1. 回退到简单 cmake 构建,但使用所有静态库包 2. 安装 -static 后缀的包(boost-static, zeromq-static 等) 3. 强制静态链接标志: - DBUILLD_SHARED_LIBS=OFF - CMAKE_FIND_LIBRARY_SUFFIXES=".a" - CMAKE_EXE_LINKER_FLAGS="-static -static-libgcc -static-libstdc++" 4. 保留 STACK_TRACE=OFF(musl libc 必需)
This commit is contained in:
@@ -3,22 +3,26 @@ FROM alpine:3.18 AS base
|
|||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
ARG BUILDPLATFORM
|
ARG BUILDPLATFORM
|
||||||
|
|
||||||
# 安装构建依赖(depends 系统所需工具)
|
# 安装构建依赖(静态库版本)
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
git \
|
git \
|
||||||
wget \
|
wget \
|
||||||
curl \
|
|
||||||
build-base \
|
build-base \
|
||||||
cmake \
|
cmake \
|
||||||
pkgconfig \
|
boost-static \
|
||||||
autoconf \
|
openssl-libs-static \
|
||||||
automake \
|
zeromq-static \
|
||||||
libtool \
|
libsodium-static \
|
||||||
bzip2 \
|
libunwind-static \
|
||||||
xz \
|
xz-dev \
|
||||||
python3 \
|
readline-static \
|
||||||
gperf \
|
expat-static \
|
||||||
linux-headers
|
hidapi-static \
|
||||||
|
libusb-static \
|
||||||
|
protobuf-dev \
|
||||||
|
eudev-dev \
|
||||||
|
linux-headers \
|
||||||
|
pkgconfig
|
||||||
|
|
||||||
FROM base AS build
|
FROM base AS build
|
||||||
|
|
||||||
@@ -40,21 +44,26 @@ COPY ./init.sh ./init.sh
|
|||||||
|
|
||||||
RUN chmod +x ./init.sh && sed -i 's|/bin/sh|/bin/ash|' ./init.sh && ./init.sh
|
RUN chmod +x ./init.sh && sed -i 's|/bin/sh|/bin/ash|' ./init.sh && ./init.sh
|
||||||
|
|
||||||
# 使用官方 depends 系统构建静态依赖(参考 .source/Dockerfile)
|
# 构建 Monero (mond) - 使用静态链接
|
||||||
RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \
|
RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \
|
||||||
MAKE_JOBS=2; \
|
MAKE_JOBS="-j2"; \
|
||||||
else \
|
else \
|
||||||
MAKE_JOBS=$(nproc); \
|
MAKE_JOBS="-j$(nproc)"; \
|
||||||
fi && \
|
fi && \
|
||||||
if [ "$TARGETARCH" = "arm64" ]; then \
|
echo "Building mond with parallel jobs: $MAKE_JOBS" && \
|
||||||
DEPENDS_TARGET="aarch64-linux-gnu"; \
|
mkdir -p build/release && cd build/release && \
|
||||||
else \
|
cmake ../.. \
|
||||||
DEPENDS_TARGET="x86_64-linux-gnu"; \
|
-DCMAKE_BUILD_TYPE=Release \
|
||||||
fi && \
|
-DBUILD_GUI_DEPS=OFF \
|
||||||
echo "Building dependencies for $DEPENDS_TARGET with $MAKE_JOBS parallel jobs" && \
|
-DARCH=default \
|
||||||
make -j$MAKE_JOBS depends target=$DEPENDS_TARGET && \
|
-DSTATIC=ON \
|
||||||
|
-DSTACK_TRACE=OFF \
|
||||||
|
-DBUILD_SHARED_LIBS=OFF \
|
||||||
|
-DCMAKE_FIND_LIBRARY_SUFFIXES=".a" \
|
||||||
|
-DCMAKE_EXE_LINKER_FLAGS="-static -static-libgcc -static-libstdc++" && \
|
||||||
|
make $MAKE_JOBS daemon && \
|
||||||
mkdir -p /output && \
|
mkdir -p /output && \
|
||||||
cp build/$DEPENDS_TARGET/release/bin/mond /output/mond
|
cp bin/mond /output/mond
|
||||||
|
|
||||||
# 最终阶段 - 只复制静态链接的二进制文件
|
# 最终阶段 - 只复制静态链接的二进制文件
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
|||||||
Reference in New Issue
Block a user