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 BUILDPLATFORM
|
||||
|
||||
# 安装构建依赖(depends 系统所需工具)
|
||||
# 安装构建依赖(静态库版本)
|
||||
RUN apk add --no-cache \
|
||||
git \
|
||||
wget \
|
||||
curl \
|
||||
build-base \
|
||||
cmake \
|
||||
pkgconfig \
|
||||
autoconf \
|
||||
automake \
|
||||
libtool \
|
||||
bzip2 \
|
||||
xz \
|
||||
python3 \
|
||||
gperf \
|
||||
linux-headers
|
||||
boost-static \
|
||||
openssl-libs-static \
|
||||
zeromq-static \
|
||||
libsodium-static \
|
||||
libunwind-static \
|
||||
xz-dev \
|
||||
readline-static \
|
||||
expat-static \
|
||||
hidapi-static \
|
||||
libusb-static \
|
||||
protobuf-dev \
|
||||
eudev-dev \
|
||||
linux-headers \
|
||||
pkgconfig
|
||||
|
||||
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
|
||||
|
||||
# 使用官方 depends 系统构建静态依赖(参考 .source/Dockerfile)
|
||||
# 构建 Monero (mond) - 使用静态链接
|
||||
RUN if [ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]; then \
|
||||
MAKE_JOBS=2; \
|
||||
MAKE_JOBS="-j2"; \
|
||||
else \
|
||||
MAKE_JOBS=$(nproc); \
|
||||
MAKE_JOBS="-j$(nproc)"; \
|
||||
fi && \
|
||||
if [ "$TARGETARCH" = "arm64" ]; then \
|
||||
DEPENDS_TARGET="aarch64-linux-gnu"; \
|
||||
else \
|
||||
DEPENDS_TARGET="x86_64-linux-gnu"; \
|
||||
fi && \
|
||||
echo "Building dependencies for $DEPENDS_TARGET with $MAKE_JOBS parallel jobs" && \
|
||||
make -j$MAKE_JOBS depends target=$DEPENDS_TARGET && \
|
||||
echo "Building mond with parallel jobs: $MAKE_JOBS" && \
|
||||
mkdir -p build/release && cd build/release && \
|
||||
cmake ../.. \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBUILD_GUI_DEPS=OFF \
|
||||
-DARCH=default \
|
||||
-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 && \
|
||||
cp build/$DEPENDS_TARGET/release/bin/mond /output/mond
|
||||
cp bin/mond /output/mond
|
||||
|
||||
# 最终阶段 - 只复制静态链接的二进制文件
|
||||
FROM scratch
|
||||
|
||||
Reference in New Issue
Block a user