Implement multi-platform build system with pure Go support
- Introduced a comprehensive build system that supports multiple platforms (Linux, macOS, Windows, Android) using pure Go builds (`CGO_ENABLED=0`). - Updated all build and test scripts to ensure compatibility with the new purego approach, allowing for dynamic loading of `libsecp256k1` at runtime. - Added detailed documentation on the build process, platform detection, and deployment options. - Enhanced CI/CD workflows to automate builds for all supported platforms and include necessary libraries in releases. - Updated `.gitignore` to exclude build output files. - Created new documentation files for deployment and multi-platform build summaries.
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
# Dockerfile for benchmark runner
|
||||
FROM golang:1.25-alpine AS builder
|
||||
|
||||
# Install build dependencies
|
||||
RUN apk add --no-cache git ca-certificates
|
||||
# Install build dependencies including libsecp256k1 build requirements
|
||||
RUN apk add --no-cache git ca-certificates gcc musl-dev autoconf automake libtool make
|
||||
|
||||
# Build libsecp256k1
|
||||
RUN cd /tmp && \
|
||||
git clone https://github.com/bitcoin-core/secp256k1.git && \
|
||||
cd secp256k1 && \
|
||||
./autogen.sh && \
|
||||
./configure --enable-module-recovery --enable-module-ecdh --enable-module-schnorrsig --enable-module-extrakeys && \
|
||||
make && \
|
||||
make install
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /build
|
||||
@@ -14,20 +23,28 @@ RUN go mod download
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build the benchmark tool
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o benchmark cmd/benchmark/main.go
|
||||
# Build the benchmark tool with CGO enabled
|
||||
RUN CGO_ENABLED=1 GOOS=linux go build -a -o benchmark cmd/benchmark/main.go
|
||||
|
||||
# Copy libsecp256k1.so if available
|
||||
RUN if [ -f pkg/crypto/p8k/libsecp256k1.so ]; then \
|
||||
cp pkg/crypto/p8k/libsecp256k1.so /build/; \
|
||||
fi
|
||||
|
||||
# Final stage
|
||||
FROM alpine:latest
|
||||
|
||||
# Install runtime dependencies
|
||||
RUN apk --no-cache add ca-certificates curl wget
|
||||
# Install runtime dependencies including libsecp256k1
|
||||
RUN apk --no-cache add ca-certificates curl wget libsecp256k1
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy benchmark binary
|
||||
COPY --from=builder /build/benchmark /app/benchmark
|
||||
|
||||
# Copy libsecp256k1.so if available
|
||||
COPY --from=builder /build/libsecp256k1.so /app/libsecp256k1.so 2>/dev/null || true
|
||||
|
||||
# Copy benchmark runner script
|
||||
COPY cmd/benchmark/benchmark-runner.sh /app/benchmark-runner
|
||||
|
||||
@@ -39,6 +56,9 @@ RUN adduser -u 1000 -D appuser && \
|
||||
mkdir -p /reports && \
|
||||
chown -R 1000:1000 /app /reports
|
||||
|
||||
# Set library path
|
||||
ENV LD_LIBRARY_PATH=/app:/usr/local/lib:/usr/lib
|
||||
|
||||
# Environment variables
|
||||
ENV BENCHMARK_EVENTS=10000
|
||||
ENV BENCHMARK_WORKERS=8
|
||||
|
||||
@@ -48,6 +48,11 @@ COPY . .
|
||||
# Build the relay
|
||||
RUN CGO_ENABLED=1 GOOS=linux go build -gcflags "all=-N -l" -o relay .
|
||||
|
||||
# Copy libsecp256k1.so if it exists in the repo
|
||||
RUN if [ -f pkg/crypto/p8k/libsecp256k1.so ]; then \
|
||||
cp pkg/crypto/p8k/libsecp256k1.so /build/; \
|
||||
fi
|
||||
|
||||
# Create non-root user (uid 1000) for runtime in builder stage (used by analyzer)
|
||||
RUN useradd -u 1000 -m -s /bin/bash appuser && \
|
||||
chown -R 1000:1000 /build
|
||||
@@ -66,6 +71,9 @@ WORKDIR /app
|
||||
# Copy binary from builder
|
||||
COPY --from=builder /build/relay /app/relay
|
||||
|
||||
# Copy libsecp256k1.so if it was built with the binary
|
||||
COPY --from=builder /build/libsecp256k1.so /app/libsecp256k1.so 2>/dev/null || true
|
||||
|
||||
# Create runtime user and writable directories
|
||||
RUN useradd -u 1000 -m -s /bin/bash appuser && \
|
||||
mkdir -p /data /profiles /app && \
|
||||
|
||||
@@ -45,8 +45,13 @@ mkdir -p "$RUN_DIR"
|
||||
LOG_FILE="$RUN_DIR/relay.log"
|
||||
LOAD_LOG_FILE="$RUN_DIR/load.log"
|
||||
|
||||
echo "[profile.sh] Building relay binary ..."
|
||||
go build -o "$BIN" .
|
||||
echo "[profile.sh] Building relay binary (pure Go + purego)..."
|
||||
CGO_ENABLED=0 go build -o "$BIN" .
|
||||
|
||||
# Copy libsecp256k1.so next to binary if available (runtime optional)
|
||||
if [[ -f "pkg/crypto/p8k/libsecp256k1.so" ]]; then
|
||||
cp pkg/crypto/p8k/libsecp256k1.so "$(dirname "$BIN")/"
|
||||
fi
|
||||
|
||||
# Ensure we clean up the child process on exit
|
||||
RELAY_PID=""
|
||||
@@ -108,8 +113,14 @@ if [[ "$LOAD_ENABLED" == "1" ]]; then
|
||||
# Build benchmark binary if not provided
|
||||
if [[ -z "$BENCHMARK_BIN" ]]; then
|
||||
BENCHMARK_BIN="$RUN_DIR/benchmark"
|
||||
echo "[profile.sh] Building benchmark load generator ($BENCHMARK_PKG_DIR) ..."
|
||||
go build -o "$BENCHMARK_BIN" "$BENCHMARK_PKG_DIR"
|
||||
echo "[profile.sh] Building benchmark load generator (pure Go + purego) ($BENCHMARK_PKG_DIR) ..."
|
||||
cd "$BENCHMARK_PKG_DIR"
|
||||
CGO_ENABLED=0 go build -o "$BENCHMARK_BIN" .
|
||||
# Copy libsecp256k1.so if available (runtime optional)
|
||||
if [[ -f "$REPO_ROOT/pkg/crypto/p8k/libsecp256k1.so" ]]; then
|
||||
cp "$REPO_ROOT/pkg/crypto/p8k/libsecp256k1.so" "$RUN_DIR/"
|
||||
fi
|
||||
cd "$REPO_ROOT"
|
||||
fi
|
||||
BENCH_DB_DIR="$RUN_DIR/benchdb"
|
||||
mkdir -p "$BENCH_DB_DIR"
|
||||
|
||||
Reference in New Issue
Block a user