- 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.
170 lines
5.5 KiB
Bash
Executable File
170 lines
5.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Multi-platform build script for ORLY relay
|
|
# Builds binaries for Linux, macOS, Windows, and Android
|
|
# NOTE: All builds use CGO_ENABLED=0 since p8k library uses purego (not CGO)
|
|
# The library dynamically loads libsecp256k1 at runtime via purego
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
cd "$REPO_ROOT"
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Configuration
|
|
VERSION=$(cat pkg/version/version)
|
|
OUTPUT_DIR="$REPO_ROOT/build"
|
|
LIB_SOURCE="$REPO_ROOT/pkg/crypto/p8k"
|
|
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo -e "${BLUE}ORLY Multi-Platform Build Script${NC}"
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo -e "Version: ${GREEN}${VERSION}${NC}"
|
|
echo -e "Output directory: ${OUTPUT_DIR}"
|
|
echo -e "${BLUE}Build mode: Pure Go with purego${NC}"
|
|
echo ""
|
|
|
|
# Create output directory
|
|
mkdir -p "$OUTPUT_DIR"
|
|
|
|
# Function to build for a specific platform
|
|
build_platform() {
|
|
local goos=$1
|
|
local goarch=$2
|
|
local platform_name=$3
|
|
local binary_ext=$4
|
|
|
|
echo -e "${YELLOW}Building for ${platform_name} (pure Go + purego)...${NC}"
|
|
|
|
local output_name="orly-${VERSION}-${platform_name}${binary_ext}"
|
|
local output_path="${OUTPUT_DIR}/${output_name}"
|
|
|
|
# Build with CGO_ENABLED=0 (pure Go with purego)
|
|
if CGO_ENABLED=0 GOOS=$goos GOARCH=$goarch \
|
|
go build -ldflags "-s -w -X main.version=${VERSION}" \
|
|
-o "${output_path}" . 2>&1; then
|
|
|
|
echo -e "${GREEN}✓ Built: ${output_name}${NC}"
|
|
|
|
# Copy appropriate runtime library
|
|
case "$goos" in
|
|
linux)
|
|
if [ -f "${LIB_SOURCE}/libsecp256k1.so" ]; then
|
|
cp "${LIB_SOURCE}/libsecp256k1.so" "${OUTPUT_DIR}/libsecp256k1-${platform_name}.so"
|
|
echo -e "${GREEN} ✓ Copied libsecp256k1.so (runtime optional)${NC}"
|
|
fi
|
|
;;
|
|
darwin)
|
|
if [ -f "${LIB_SOURCE}/libsecp256k1.dylib" ]; then
|
|
cp "${LIB_SOURCE}/libsecp256k1.dylib" "${OUTPUT_DIR}/libsecp256k1-${platform_name}.dylib"
|
|
echo -e "${GREEN} ✓ Copied libsecp256k1.dylib (runtime optional)${NC}"
|
|
fi
|
|
;;
|
|
windows)
|
|
if [ -f "${LIB_SOURCE}/libsecp256k1.dll" ]; then
|
|
cp "${LIB_SOURCE}/libsecp256k1.dll" "${OUTPUT_DIR}/libsecp256k1-${platform_name}.dll"
|
|
echo -e "${GREEN} ✓ Copied libsecp256k1.dll (runtime optional)${NC}"
|
|
fi
|
|
;;
|
|
android)
|
|
if [ -f "${LIB_SOURCE}/libsecp256k1.so" ]; then
|
|
cp "${LIB_SOURCE}/libsecp256k1.so" "${OUTPUT_DIR}/libsecp256k1-${platform_name}.so"
|
|
echo -e "${GREEN} ✓ Copied libsecp256k1.so (runtime optional)${NC}"
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
# Create SHA256 checksum
|
|
(cd "$OUTPUT_DIR" && sha256sum "$output_name" >> "SHA256SUMS-${VERSION}.txt")
|
|
|
|
return 0
|
|
else
|
|
echo -e "${RED}✗ Failed to build for ${platform_name}${NC}"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Clean old builds
|
|
echo -e "${BLUE}Cleaning old builds...${NC}"
|
|
rm -f "${OUTPUT_DIR}/orly-"* "${OUTPUT_DIR}/libsecp256k1-"* "${OUTPUT_DIR}/SHA256SUMS-"*
|
|
echo ""
|
|
|
|
echo -e "${BLUE}Note: Pure Go builds work on all platforms${NC}"
|
|
echo -e "${BLUE} libsecp256k1 is loaded at runtime if available (faster)${NC}"
|
|
echo -e "${BLUE} Falls back to pure Go p256k1 if library not found${NC}"
|
|
echo ""
|
|
|
|
# Build for each platform
|
|
echo -e "${BLUE}Starting builds...${NC}"
|
|
echo ""
|
|
|
|
# Linux AMD64
|
|
build_platform "linux" "amd64" "linux-amd64" "" || true
|
|
|
|
# Linux ARM64
|
|
build_platform "linux" "arm64" "linux-arm64" "" || true
|
|
|
|
# macOS AMD64 (Intel)
|
|
build_platform "darwin" "amd64" "darwin-amd64" "" || true
|
|
|
|
# macOS ARM64 (Apple Silicon)
|
|
build_platform "darwin" "arm64" "darwin-arm64" "" || true
|
|
|
|
# Windows AMD64
|
|
build_platform "windows" "amd64" "windows-amd64" ".exe" || true
|
|
|
|
# Android builds
|
|
echo -e "${BLUE}Building for Android...${NC}"
|
|
|
|
# Android ARM64
|
|
build_platform "android" "arm64" "android-arm64" "" || true
|
|
|
|
# Android AMD64
|
|
build_platform "android" "amd64" "android-amd64" "" || true
|
|
|
|
echo ""
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo -e "${GREEN}Build Summary${NC}"
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo ""
|
|
|
|
# List all built binaries
|
|
if ls "${OUTPUT_DIR}"/orly-* 1> /dev/null 2>&1; then
|
|
echo -e "${GREEN}Built binaries:${NC}"
|
|
ls -lh "${OUTPUT_DIR}"/orly-* | awk '{print " " $9 " (" $5 ")"}'
|
|
echo ""
|
|
|
|
if [ -f "${OUTPUT_DIR}/SHA256SUMS-${VERSION}.txt" ]; then
|
|
echo -e "${GREEN}Checksums:${NC}"
|
|
cat "${OUTPUT_DIR}/SHA256SUMS-${VERSION}.txt" | sed 's/^/ /'
|
|
echo ""
|
|
fi
|
|
|
|
echo -e "${GREEN}Libraries:${NC}"
|
|
ls -lh "${OUTPUT_DIR}"/libsecp256k1-* 2>/dev/null | awk '{print " " $9 " (" $5 ")"}' || echo " No libraries copied"
|
|
echo ""
|
|
else
|
|
echo -e "${RED}No binaries were built successfully${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo -e "${GREEN}Build completed!${NC}"
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo ""
|
|
echo "Output directory: ${OUTPUT_DIR}"
|
|
echo ""
|
|
echo "To test a binary:"
|
|
echo " Linux: ./${OUTPUT_DIR}/orly-${VERSION}-linux-amd64"
|
|
echo " macOS: ./${OUTPUT_DIR}/orly-${VERSION}-darwin-arm64"
|
|
echo " Windows: ./${OUTPUT_DIR}/orly-${VERSION}-windows-amd64.exe"
|
|
echo ""
|
|
|