This commit is contained in:
Your Name
2025-05-03 13:19:41 +12:00
parent a1ea611e32
commit 11dccca171
9 changed files with 373 additions and 41 deletions

View File

@@ -1,19 +1,95 @@
#!/bin/bash
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
CACHE_DIR="${SCRIPT_DIR}/cache"
EXE_DIR="${SCRIPT_DIR}/exe"
BUILD_DIR="${SCRIPT_DIR}/build"
function title() {
echo "----------------------------------------"
# Center the text
local text="$1"
local line_length=40
local text_length=${#text}
local padding=$(( (line_length - text_length) / 2 ))
printf "%*s%s%*s\n" $padding "" "$text" $padding ""
echo "----------------------------------------"
}
function die() {
echo " "
title "$1"
echo " "
exit 1
}
function clean() {
echo "Cleaning build directories"
rm -rf build
rm -f cmake_install.cmake
rm -f CMakeCache.txt
rm -rf CMakeFiles
}
function clean_cache() {
echo "Cleaning cache directories"
rm -rf ${CACHE_DIR}
}
function build() {
ARCH=$1
clean
mkdir -p ${BUILD_DIR}
DOCKCROSS_SCRIPT="${CACHE_DIR}/dockcross-${ARCH}"
if [ ! -f "${DOCKCROSS_SCRIPT}" ]; then
echo "Downloading dockcross-${ARCH}"
docker run --rm "dockcross/${ARCH}-full" > "${DOCKCROSS_SCRIPT}"
chmod +x "${DOCKCROSS_SCRIPT}"
fi
echo "Building $ARCH executable"
cd "${SCRIPT_DIR}"
"${DOCKCROSS_SCRIPT}" bash -c "cd build && cmake .. && make -j$(nproc)"
if [ ! -f build/simple_object_storage ]; then
die "Failed to build $ARCH executable"
fi
echo "Copying $ARCH executable to $EXE_DIR/simple_object_storage-$ARCH"
cp build/simple_object_storage $EXE_DIR/simple_object_storage-$ARCH
}
# Exit on error
set -e
# Create build directory if it doesn't exist
mkdir -p build
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
cd $SCRIPT_DIR
# Enter build directory
cd build
clean_cache
# Run CMake
cmake ..
mkdir -p ${CACHE_DIR}
mkdir -p ${EXE_DIR}
# Build the project
make -j$(nproc)
title "Building linux-arm64 executable"
build linux-arm64 || die "Failed to build linux-arm64 executable"
echo "Build completed successfully!"
echo "The executable is located at: $(pwd)/simple_object_storage_template_registry"
title "Building linux-x86_64 executable"
build linux-x86_64 || die "Failed to build linux-x86_64 executable"
# use Docker architecture style
cp ${EXE_DIR}/simple_object_storage-linux-x86_64 ${EXE_DIR}/simple_object_storage-linux-amd64
echo "Compile completed successfully!"
echo "amd64 executable: ./simple_object_storage-linux-amd64"
echo "arm64 executable: ./simple_object_storage-linux-arm64"
echo "Setting up Docker BuildX"
docker buildx create --name mybuilder --use || true
echo "Building multi-platform Docker image"
docker buildx build --load -t simple-object-storage:latest --platform linux/amd64,linux/arm64 .
clean
clean_cache