Files
futriix/build.sh

179 lines
5.0 KiB
Bash
Raw Normal View History

2026-05-17 20:12:47 +00:00
#!/usr/bin/env bash
# Copyright 2026 Safronov Grigorii
#
# Licensed under the CDDL, Version 1.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
# https://opensource.org/licenses/CDDL-1.0
#
2026-05-20 18:58:48 +00:00
# Универсальный скрипт сборки futriix для Linux и Illumos
2026-05-17 20:12:47 +00:00
# НЕ ТРЕБУЕТ GCC - использует CGO_ENABLED=0 для всех платформ
set -e
echo ""
2026-05-20 18:58:48 +00:00
echo "🔨 Building futriix database..."
2026-05-17 20:12:47 +00:00
# Определение ОС
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
# Цвета для вывода
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
2026-05-20 18:58:48 +00:00
LIGHT_CYAN='\033[1;36m'
2026-05-17 20:12:47 +00:00
NC='\033[0m'
else
2026-05-20 18:58:48 +00:00
RED=''; GREEN=''; YELLOW=''; LIGHT_CYAN=''; NC=''
2026-05-17 20:12:47 +00:00
fi
# Функции
error_msg() { echo -e "${RED}$1${NC}"; }
success_msg() { echo -e "${GREEN}$1${NC}"; }
2026-05-20 18:58:48 +00:00
info_msg() { echo -e "${LIGHT_CYAN}📋 $1${NC}"; }
2026-05-17 20:12:47 +00:00
warning_msg() { echo -e "${YELLOW}⚠️ $1${NC}"; }
print_separator() { echo "================================================"; }
# Проверка Go
check_go() {
info_msg "Checking Go installation..."
if ! command -v go >/dev/null 2>&1; then
error_msg "Go is not installed or not in PATH"
exit 1
fi
GO_VERSION=$(go version | awk '{print $3}')
success_msg "Go found: $GO_VERSION"
go env -w GOPROXY=https://proxy.golang.org,direct 2>/dev/null || true
info_msg "Go proxy: $(go env GOPROXY)"
}
# Подготовка vendor с видимым прогрессом
setup_vendor() {
info_msg "Checking vendor directory..."
NEED_VENDOR=false
if [ ! -d "vendor" ] || [ ! -f "vendor/modules.txt" ]; then
warning_msg "Vendor directory not found or incomplete"
NEED_VENDOR=true
elif [ "go.mod" -nt "vendor/modules.txt" ]; then
warning_msg "go.mod is newer than vendor directory"
NEED_VENDOR=true
fi
if [ "$NEED_VENDOR" = true ]; then
info_msg "Creating/updating vendor directory..."
echo ""
info_msg "Step 1/2: Downloading modules..."
go mod download -x 2>&1 | grep -E "^(GET|Downloading)" | head -20 || true
echo ""
info_msg "Step 2/2: Creating vendor directory..."
go mod vendor
success_msg "Vendor dependencies ready"
echo ""
else
info_msg "Vendor directory is up to date"
fi
}
# Сборка статического бинарника
build_static() {
local target_os=$1
local target_arch="amd64"
2026-05-20 18:58:48 +00:00
local output_name="futriix-${target_os}"
2026-05-17 20:12:47 +00:00
local output_path="bin/${output_name}"
info_msg "Building for ${target_os} (static, no CGO)..."
export GOOS="${target_os}"
export GOARCH="${target_arch}"
export CGO_ENABLED=0
local build_tags=""
if [ "${target_os}" = "illumos" ] || [ "${target_os}" = "solaris" ]; then
build_tags="-tags=illumos"
2026-05-20 18:58:48 +00:00
output_name="futriix-illumos"
output_path="bin/futriix-illumos"
2026-05-17 20:12:47 +00:00
elif [ "${target_os}" = "linux" ]; then
2026-05-20 18:58:48 +00:00
output_name="futriix-linux"
output_path="bin/futriix-linux"
2026-05-17 20:12:47 +00:00
fi
mkdir -p bin
if go build -mod=vendor ${build_tags} -ldflags="-s -w" -o "${output_path}" ./cmd/futriis; then
success_msg "Build successful for ${target_os}: ${output_path}"
cp "${output_path}" "./${output_name}" 2>/dev/null || true
info_msg "Binary copied to: ./${output_name}"
SIZE=$(ls -lh "${output_path}" | awk '{print $5}')
info_msg "Binary size: ${SIZE}"
return 0
else
error_msg "Build failed for ${target_os}"
return 1
fi
}
# Основная функция
main() {
print_separator
2026-05-20 18:58:48 +00:00
echo -e "${GREEN}🔨 Building futriix database (static, no GCC required)${NC}"
2026-05-17 20:12:47 +00:00
print_separator
info_msg "Detected OS: ${OS}"
check_go
setup_vendor
print_separator
BUILD_SUCCESS=true
case "${OS}" in
linux)
if ! build_static "linux"; then
BUILD_SUCCESS=false
fi
;;
sunos|illumos)
if ! build_static "illumos"; then
BUILD_SUCCESS=false
fi
;;
darwin)
info_msg "Detected macOS, cross-compiling for Linux..."
if ! build_static "linux"; then
BUILD_SUCCESS=false
fi
;;
*)
warning_msg "Unknown OS: ${OS}, building for Linux..."
if ! build_static "linux"; then
BUILD_SUCCESS=false
fi
;;
esac
print_separator
if [ "$BUILD_SUCCESS" = true ]; then
success_msg "Build complete!"
echo ""
info_msg "To run the database:"
2026-05-20 18:58:48 +00:00
echo " ./futriix-linux # On Linux"
echo " ./futriix-illumos # On Illumos/OpenIndiana"
2026-05-17 20:12:47 +00:00
echo ""
info_msg "Binary location: bin/"
ls -lh bin/ 2>/dev/null || true
else
error_msg "Build failed"
exit 1
fi
}
2026-05-20 18:58:48 +00:00
main "$@"