-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.sh
More file actions
executable file
·149 lines (120 loc) · 4.12 KB
/
package.sh
File metadata and controls
executable file
·149 lines (120 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
# package.sh - Build and package LiNaStore for all supported platforms
# Usage: ./package.sh [version]
set -e # Exit on any error
VERSION=${1:-"unknown"}
# Define variables
PROJECT_NAME="LiNaStore"
BUILD_DIR="build"
# Function to check if Rust is installed
check_rust() {
if command -v rustc >/dev/null 2>&1; then
RUST_VERSION=$(rustc --version)
echo "Rust is already installed: $RUST_VERSION"
return 0
else
echo "Rust is not installed"
return 1
fi
}
# Function to install Rust
install_rust() {
echo "Installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
# Source cargo environment
source "$HOME/.cargo/env"
if command -v rustc >/dev/null 2>&1; then
RUST_VERSION=$(rustc --version)
echo "Rust successfully installed: $RUST_VERSION"
else
echo "Failed to install Rust"
exit 1
fi
}
# Function to check if mingw-w64 is installed (needed for Windows cross-compilation)
check_mingw_w64() {
if command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then
echo "mingw-w64 is already installed"
return 0
else
echo "mingw-w64 is not installed"
return 1
fi
}
# Function to install mingw-w64
install_mingw_w64() {
echo "Installing mingw-w64..."
# Detect OS
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Install mingw-w64 for Ubuntu/Debian
sudo apt-get update
sudo apt-get install -y mingw-w64
elif [[ "$OSTYPE" == "darwin"* ]]; then
# On macOS, use Homebrew
if ! command -v brew >/dev/null 2>&1; then
echo "Homebrew is not installed. Please install Homebrew first: https://brew.sh/"
exit 1
fi
brew install mingw-w64
else
echo "Unsupported OS. Please install mingw-w64 manually."
exit 1
fi
# Verify installation
if command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then
echo "mingw-w64 successfully installed"
else
echo "Failed to install mingw-w64"
exit 1
fi
}
# Check and install Rust if needed
echo "Checking Rust installation..."
if ! check_rust; then
install_rust
# Source cargo environment for current session
source "$HOME/.cargo/env"
fi
# Check and install mingw-w64 if needed (for Windows cross-compilation)
echo "Checking mingw-w64 installation (needed for Windows cross-compilation)..."
if ! check_mingw_w64; then
install_mingw_w64
fi
# Create build directory
echo "Creating build directory..."
mkdir -p "${BUILD_DIR}"
# Function to package for a specific platform
package_for_platform() {
local target=$1
local platform_name=$2
echo "Packaging for ${platform_name} (${target})..."
# Add target for cross-compilation
rustup target add "${target}" 2>/dev/null || true
# Build server component (main.rs)
echo "Building server component..."
cargo build --release --target "${target}"
# Build binary component (linastore.rs)
echo "Building binary component..."
cargo build --release --target "${target}" --bin linastore
# Determine file extensions
local ext=""
if [[ "${platform_name}" == *"windows"* ]]; then
ext=".exe"
fi
# Copy server binary
local server_output="${PROJECT_NAME}-server-${platform_name}${ext}"
cp "target/${target}/release/linastore-server${ext}" "${BUILD_DIR}/${server_output}" 2>/dev/null || \
cp "target/${target}/release/main${ext}" "${BUILD_DIR}/${server_output}" 2>/dev/null
# Copy binary component
local bin_output="${PROJECT_NAME}-bin-${platform_name}${ext}"
cp "target/${target}/release/linastore${ext}" "${BUILD_DIR}/${bin_output}" 2>/dev/null
echo "Created ${BUILD_DIR}/${server_output}"
echo "Created ${BUILD_DIR}/${bin_output}"
}
# Package for all platforms
echo "Starting packaging process for version: ${VERSION}"
# Linux packaging
package_for_platform "x86_64-unknown-linux-musl" "linux-x86_64"
# Windows packaging
package_for_platform "x86_64-pc-windows-gnu" "windows-x86_64"
echo "All packages created successfully in ${BUILD_DIR}/"