first commit
Some checks failed
Backend Tests / Static Checks (push) Has been cancelled
Backend Tests / Tests (other) (push) Has been cancelled
Backend Tests / Tests (plugin) (push) Has been cancelled
Backend Tests / Tests (server) (push) Has been cancelled
Backend Tests / Tests (store) (push) Has been cancelled
Build Canary Image / build-frontend (push) Has been cancelled
Build Canary Image / build-push (linux/amd64) (push) Has been cancelled
Build Canary Image / build-push (linux/arm64) (push) Has been cancelled
Build Canary Image / merge (push) Has been cancelled
Frontend Tests / Lint (push) Has been cancelled
Frontend Tests / Build (push) Has been cancelled
Proto Linter / Lint Protos (push) Has been cancelled
Some checks failed
Backend Tests / Static Checks (push) Has been cancelled
Backend Tests / Tests (other) (push) Has been cancelled
Backend Tests / Tests (plugin) (push) Has been cancelled
Backend Tests / Tests (server) (push) Has been cancelled
Backend Tests / Tests (store) (push) Has been cancelled
Build Canary Image / build-frontend (push) Has been cancelled
Build Canary Image / build-push (linux/amd64) (push) Has been cancelled
Build Canary Image / build-push (linux/arm64) (push) Has been cancelled
Build Canary Image / merge (push) Has been cancelled
Frontend Tests / Lint (push) Has been cancelled
Frontend Tests / Build (push) Has been cancelled
Proto Linter / Lint Protos (push) Has been cancelled
This commit is contained in:
134
scripts/build-arm.sh
Executable file
134
scripts/build-arm.sh
Executable file
@@ -0,0 +1,134 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Change to repo root
|
||||
cd "$(dirname "$0")/../"
|
||||
|
||||
# Default values
|
||||
TARGET_OS="linux"
|
||||
TARGET_ARCH=""
|
||||
OUTPUT_DIR="./build"
|
||||
BUILD_TAGS=""
|
||||
|
||||
# Parse command line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--arch)
|
||||
TARGET_ARCH="$2"
|
||||
shift 2
|
||||
;;
|
||||
--os)
|
||||
TARGET_OS="$2"
|
||||
shift 2
|
||||
;;
|
||||
--output)
|
||||
OUTPUT_DIR="$2"
|
||||
shift 2
|
||||
;;
|
||||
--tags)
|
||||
BUILD_TAGS="$2"
|
||||
shift 2
|
||||
;;
|
||||
--help|-h)
|
||||
echo "Usage: $0 [OPTIONS]"
|
||||
echo "Build Memos for ARM architecture"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --arch ARCH Target architecture (arm, arm64, etc.)"
|
||||
echo " --os OS Target OS (linux, darwin, windows, etc.)"
|
||||
echo " --output DIR Output directory (default: ./build)"
|
||||
echo " --tags TAGS Build tags to use"
|
||||
echo " --help Show this help message"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 --arch arm64 --os linux"
|
||||
echo " $0 --arch arm --os linux"
|
||||
echo " $0 --arch arm64 --os darwin"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Validate required parameters
|
||||
if [ -z "$TARGET_ARCH" ]; then
|
||||
echo "Error: --arch is required"
|
||||
echo "Supported architectures: arm, arm64"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set output filename based on target
|
||||
case "$TARGET_OS-$TARGET_ARCH" in
|
||||
linux-arm)
|
||||
OUTPUT_NAME="memos-linux-arm"
|
||||
;;
|
||||
linux-arm64)
|
||||
OUTPUT_NAME="memos-linux-arm64"
|
||||
;;
|
||||
darwin-arm64)
|
||||
OUTPUT_NAME="memos-darwin-arm64"
|
||||
;;
|
||||
windows-arm64)
|
||||
OUTPUT_NAME="memos-windows-arm64.exe"
|
||||
;;
|
||||
*)
|
||||
OUTPUT_NAME="memos-$TARGET_OS-$TARGET_ARCH"
|
||||
;;
|
||||
esac
|
||||
|
||||
OUTPUT_PATH="$OUTPUT_DIR/$OUTPUT_NAME"
|
||||
|
||||
echo "Building Memos for $TARGET_OS/$TARGET_ARCH..."
|
||||
echo "Output: $OUTPUT_PATH"
|
||||
|
||||
# Ensure build directories exist
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
mkdir -p "$OUTPUT_DIR/.gocache"
|
||||
mkdir -p "$OUTPUT_DIR/.gomodcache"
|
||||
|
||||
# Set Go environment variables for cross-compilation
|
||||
export GOOS="$TARGET_OS"
|
||||
export GOARCH="$TARGET_ARCH"
|
||||
export GOCACHE="$(pwd)/$OUTPUT_DIR/.gocache"
|
||||
export GOMODCACHE="$(pwd)/$OUTPUT_DIR/.gomodcache"
|
||||
export CGO_ENABLED=0 # Disable CGO for pure Go build
|
||||
|
||||
# Build flags
|
||||
BUILD_FLAGS="-o $OUTPUT_PATH"
|
||||
if [ -n "$BUILD_TAGS" ]; then
|
||||
BUILD_FLAGS="$BUILD_FLAGS -tags $BUILD_TAGS"
|
||||
fi
|
||||
|
||||
# Add ldflags for smaller binary (disabled due to quoting issues)
|
||||
# BUILD_FLAGS="$BUILD_FLAGS -ldflags \"-s -w\""
|
||||
|
||||
echo "GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=$CGO_ENABLED"
|
||||
echo "Build flags: $BUILD_FLAGS"
|
||||
|
||||
# Build the executable
|
||||
go build $BUILD_FLAGS ./cmd/memos
|
||||
|
||||
# Verify the build
|
||||
if [ -f "$OUTPUT_PATH" ]; then
|
||||
echo "Build successful!"
|
||||
echo "Binary size: $(du -h "$OUTPUT_PATH" | cut -f1)"
|
||||
echo "File type: $(file "$OUTPUT_PATH")"
|
||||
|
||||
# Show checksum
|
||||
if command -v sha256sum >/dev/null 2>&1; then
|
||||
echo "SHA256: $(sha256sum "$OUTPUT_PATH" | cut -d' ' -f1)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "To run on target system:"
|
||||
echo " scp $OUTPUT_PATH user@target:/path/to/memos"
|
||||
echo " chmod +x /path/to/memos/$OUTPUT_NAME"
|
||||
echo " /path/to/memos/$OUTPUT_NAME --port 8081"
|
||||
else
|
||||
echo "Build failed: Output file not found"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user