forked from kvcache-ai/Mooncake
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdependencies.sh
More file actions
executable file
·437 lines (376 loc) · 13.7 KB
/
dependencies.sh
File metadata and controls
executable file
·437 lines (376 loc) · 13.7 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
#!/bin/bash
# Copyright 2024 KVCache.AI
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Color definitions
GREEN="\033[0;32m"
BLUE="\033[0;34m"
YELLOW="\033[0;33m"
RED="\033[0;31m"
NC="\033[0m" # No Color
# Configuration
REPO_ROOT=`pwd`
GITHUB_PROXY=${GITHUB_PROXY:-"https://github.com"}
GOVER=1.25.9
# Function to print section headers
print_section() {
echo -e "\n${BLUE}=== $1 ===${NC}"
}
# Function to print success messages
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
# Function to print error messages and exit
print_error() {
echo -e "${RED}✗ ERROR: $1${NC}"
exit 1
}
# Function to check command success
check_success() {
if [ $? -ne 0 ]; then
print_error "$1"
fi
}
# Function to detect OS
detect_os() {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$(echo "$ID" | tr '[:upper:]' '[:lower:]')
OS_VERSION=$VERSION_ID
elif [ -f /etc/redhat-release ]; then
OS="centos"
else
print_error "Cannot detect OS. Supported OS: Ubuntu, Debian, CentOS, RHEL, Rocky, AlmaLinux, and openEuler."
fi
echo -e "${GREEN}Detected OS: $OS ${OS_VERSION:-unknown}${NC}"
}
if [ $(id -u) -ne 0 ]; then
print_error "Require root permission, try sudo ./dependencies.sh"
fi
# Parse command line arguments
SKIP_CONFIRM=false
INSTALL_SPDK=false
for arg in "$@"; do
case $arg in
-y|--yes)
SKIP_CONFIRM=true
;;
--with-spdk)
INSTALL_SPDK=true
;;
-h|--help)
echo -e "${YELLOW}Mooncake Dependencies Installer${NC}"
echo -e "Usage: ./dependencies.sh [OPTIONS]"
echo -e "\nOptions:"
echo -e " -y, --yes Skip confirmation and install all dependencies"
echo -e " --with-spdk Install SPDK for NVMe-oF support"
echo -e " -h, --help Show this help message and exit"
exit 0
;;
esac
done
# Print welcome message
echo -e "${YELLOW}Mooncake Dependencies Installer${NC}"
echo -e "This script will install all required dependencies for Mooncake."
echo -e "The following components will be installed:"
echo -e " - System packages (build tools, libraries)"
echo -e " - Git submodules (including pybind11 and yalantinglibs)"
echo -e " - Go $GOVER"
if [ "$INSTALL_SPDK" = true ]; then
echo -e " - SPDK (for NVMe-oF support)"
fi
echo
# Ask for confirmation unless -y flag is used
if [ "$SKIP_CONFIRM" = false ]; then
read -p "Do you want to continue? [Y/n] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]] && [[ ! $REPLY = "" ]]; then
echo -e "${YELLOW}Installation cancelled.${NC}"
exit 0
fi
fi
# Detect OS
detect_os
# Update package lists
print_section "Updating package lists"
if [ "$OS" = "ubuntu" ] || [ "$OS" = "debian" ]; then
apt-get update
check_success "Failed to update package lists"
elif [ "$OS" = "centos" ] || [ "$OS" = "rhel" ] || [ "$OS" = "rocky" ] || [ "$OS" = "almalinux" ] || [ "$OS" = "openeuler" ]; then
yum clean all
yum makecache
check_success "Failed to update package lists"
else
print_error "Unsupported OS: $OS"
fi
# Install system packages
print_section "Installing system packages"
echo -e "${YELLOW}This may take a few minutes...${NC}"
if [ "$OS" = "ubuntu" ] || [ "$OS" = "debian" ]; then
SYSTEM_PACKAGES="build-essential \
cmake \
ninja-build \
git \
wget \
unzip \
libibverbs-dev \
libgoogle-glog-dev \
libgtest-dev \
libjsoncpp-dev \
libunwind-dev \
libnuma-dev \
libpython3-dev \
libboost-all-dev \
libssl-dev \
libgrpc-dev \
libgrpc++-dev \
libprotobuf-dev \
libyaml-cpp-dev \
protobuf-compiler-grpc \
libcurl4-openssl-dev \
libhiredis-dev \
liburing-dev \
libjemalloc-dev \
libmsgpack-dev \
libzstd-dev \
libasio-dev \
libxxhash-dev \
pkg-config \
patchelf \
libc6-dev \
libc-bin"
apt-get install -y $SYSTEM_PACKAGES
check_success "Failed to install system packages"
elif [ "$OS" = "centos" ] || [ "$OS" = "rhel" ] || [ "$OS" = "rocky" ] || [ "$OS" = "almalinux" ] || [ "$OS" = "openeuler" ]; then
SYSTEM_PACKAGES="@development \
cmake \
git \
wget \
rdma-core-devel \
glog-devel \
gtest-devel \
jsoncpp-devel \
libunwind-devel \
numactl-devel \
python3-devel \
boost-devel \
openssl-devel \
grpc-devel \
protobuf-devel \
yaml-cpp-devel \
grpc-plugins \
libcurl-devel \
hiredis-devel \
liburing-devel \
jemalloc-devel \
pkgconf-pkg-config \
elfutils-libelf-devel \
patchelf \
xxhash-devel \
libbsd-devel"
yum install -y $SYSTEM_PACKAGES
check_success "Failed to install system packages"
else
print_error "Unsupported OS: $OS"
fi
print_success "System packages installed successfully"
# Initialize and update git submodules
print_section "Initializing Git Submodules"
# Check if .gitmodules exists
if [ -f "${REPO_ROOT}/.gitmodules" ]; then
echo "Enter repository root: ${REPO_ROOT}"
cd "${REPO_ROOT}"
check_success "Failed to change to repository root directory"
echo "Initializing git submodules..."
git submodule sync --recursive
check_success "Failed to sync git submodules"
git submodule update --init --recursive
check_success "Failed to initialize git submodules"
print_success "Git submodules initialized and updated successfully"
else
echo -e "${YELLOW}No .gitmodules file found. Skipping...${NC}"
exit 1
fi
# Build and install yalantinglibs from submodule
print_section "Installing yalantinglibs"
cd "${REPO_ROOT}/extern/yalantinglibs"
check_success "Failed to change to yalantinglibs submodule directory"
mkdir -p build
check_success "Failed to create build directory"
cd build
check_success "Failed to change to build directory"
echo "Configuring yalantinglibs..."
cmake .. -DBUILD_EXAMPLES=OFF -DBUILD_BENCHMARK=OFF -DBUILD_UNIT_TESTS=OFF
check_success "Failed to configure yalantinglibs"
echo "Building yalantinglibs (using $(nproc) cores)..."
cmake --build . -j$(nproc)
check_success "Failed to build yalantinglibs"
echo "Installing yalantinglibs..."
cmake --install .
check_success "Failed to install yalantinglibs"
print_success "yalantinglibs installed successfully"
cd "${REPO_ROOT}"
print_section "Verifying essential build tools"
# Verify getconf and ldd (required for glibc version detection in build_wheel.sh)
if [ "$OS" = "ubuntu" ] || [ "$OS" = "debian" ]; then
if ! command -v getconf >/dev/null 2>&1; then
print_error "getconf not found after installing system packages. This should not happen."
fi
if ! command -v ldd >/dev/null 2>&1; then
print_error "ldd not found after installing system packages. This should not happen."
fi
print_success "getconf found: $(getconf --version 2>&1 | head -1)"
print_success "ldd found: $(ldd --version 2>&1 | head -1)"
fi
print_section "Installing Go $GOVER"
USED_CN_MIRROR=false
install_go() {
ARCH=$(uname -m)
if [ "$ARCH" = "aarch64" ]; then
ARCH="arm64"
elif [ "$ARCH" = "x86_64" ]; then
ARCH="amd64"
else
echo "Unsupported architecture: $ARCH"
exit 1
fi
GO_TARBALL="go$GOVER.linux-$ARCH.tar.gz"
# Try multiple download mirrors with fallback
GO_DOWNLOAD_URLS=(
"https://go.dev/dl/${GO_TARBALL}"
"https://golang.google.cn/dl/${GO_TARBALL}"
"https://mirrors.aliyun.com/golang/${GO_TARBALL}"
)
DOWNLOAD_SUCCESS=false
for url in "${GO_DOWNLOAD_URLS[@]}"; do
echo "Downloading Go $GOVER from ${url}..."
if wget -q --show-progress --timeout=30 --tries=2 -O "${GO_TARBALL}" "${url}"; then
DOWNLOAD_SUCCESS=true
if [[ "$url" != "https://go.dev/dl/${GO_TARBALL}" ]]; then
USED_CN_MIRROR=true
fi
print_success "Downloaded Go $GOVER from ${url}"
break
else
echo -e "${YELLOW}Failed to download from ${url}, trying next mirror...${NC}"
rm -f "${GO_TARBALL}"
fi
done
if [ "$DOWNLOAD_SUCCESS" = false ]; then
print_error "Failed to download Go $GOVER from all mirrors"
fi
echo "Installing Go $GOVER..."
tar -C /usr/local -xzf "${GO_TARBALL}"
check_success "Failed to install Go $GOVER"
rm -f "${GO_TARBALL}"
check_success "Failed to clean up Go installation file"
print_success "Go $GOVER installed successfully"
}
if command -v go &> /dev/null; then
GO_VERSION=$(go version | awk '{print $3}')
if [[ "$GO_VERSION" == "go$GOVER" ]]; then
echo -e "${YELLOW}Go $GOVER is already installed. Skipping...${NC}"
else
echo -e "${YELLOW}Found Go $GO_VERSION. Will install Go $GOVER...${NC}"
install_go
fi
else
install_go
fi
# Add Go to PATH if not already there
if ! grep -q "export PATH=\$PATH:/usr/local/go/bin" ~/.bashrc; then
echo -e "${YELLOW}Adding Go to your PATH in ~/.bashrc${NC}"
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
echo -e "${YELLOW}Please run 'source ~/.bashrc' or start a new terminal to use Go${NC}"
fi
# Set GOPROXY only if Go download fell back to a CN mirror
if [ "$USED_CN_MIRROR" = true ] && [ -z "$GOPROXY" ]; then
export GOPROXY=https://goproxy.cn,https://goproxy.io,direct
echo -e "${YELLOW}Detected restricted network (Go was downloaded from a CN mirror).${NC}"
echo -e "${YELLOW}GOPROXY set to: ${GOPROXY}${NC}"
if ! grep -q "export GOPROXY=" ~/.bashrc; then
echo 'export GOPROXY=https://goproxy.cn,https://goproxy.io,direct' >> ~/.bashrc
echo -e "${YELLOW}GOPROXY added to ~/.bashrc for future sessions${NC}"
fi
elif [ -n "$GOPROXY" ]; then
echo -e "${GREEN}GOPROXY already set to: ${GOPROXY}${NC}"
fi
# Install SPDK if requested
if [ "$INSTALL_SPDK" = true ]; then
print_section "Installing SPDK"
cd "${REPO_ROOT}/extern"
check_success "Failed to change to extern directory"
# Remove existing SPDK if present
if [ -d "spdk" ]; then
echo -e "${YELLOW}SPDK directory already exists. Removing for fresh install...${NC}"
rm -rf spdk
check_success "Failed to remove existing SPDK directory"
fi
# Clone SPDK
echo "Cloning SPDK from ${GITHUB_PROXY}/spdk/spdk.git..."
git clone ${GITHUB_PROXY}/spdk/spdk.git
check_success "Failed to clone SPDK"
cd spdk
check_success "Failed to change to SPDK directory"
# Checkout specific version
echo "Checking out SPDK version v23.01.1..."
git checkout v23.01.1
check_success "Failed to checkout SPDK version v23.01.1"
# Initialize submodules
echo "Initializing SPDK submodules..."
git submodule update --init
check_success "Failed to initialize SPDK submodules"
# Install SPDK dependencies
echo "Installing SPDK dependencies..."
./scripts/pkgdep.sh
check_success "Failed to install SPDK dependencies"
# Configure SPDK with RDMA support
echo "Configuring SPDK with RDMA support..."
./configure --with-rdma
check_success "Failed to configure SPDK"
# Build SPDK
echo "Building SPDK (using $(nproc) cores)..."
make -j$(nproc)
check_success "Failed to build SPDK"
# Install SPDK
echo "Installing SPDK..."
make install
check_success "Failed to install SPDK"
# Copy DPDK libraries to system library path
if ls dpdk/build/lib/*.a >/dev/null 2>&1; then
echo "Copying DPDK libraries to /usr/local/lib..."
cp dpdk/build/lib/*.a /usr/local/lib/
check_success "Failed to copy DPDK libraries"
fi
print_success "SPDK installed successfully"
cd "${REPO_ROOT}"
fi
# Return to the repository root
cd "${REPO_ROOT}"
# Print summary
print_section "Installation Complete"
echo -e "${GREEN}All dependencies have been successfully installed!${NC}"
echo -e "The following components were installed:"
echo -e " ${GREEN}✓${NC} System packages"
echo -e " ${GREEN}✓${NC} yalantinglibs"
echo -e " ${GREEN}✓${NC} Git submodules"
echo -e " ${GREEN}✓${NC} Go $GOVER"
if [ "$INSTALL_SPDK" = true ]; then
echo -e " ${GREEN}✓${NC} SPDK (v23.01.1)"
fi
echo
echo -e "You can now build and run Mooncake."
echo -e "${YELLOW}Note: You may need to restart your terminal or run 'source ~/.bashrc' to use Go.${NC}"
if [ "$INSTALL_SPDK" = true ]; then
echo -e "${YELLOW}Note: SPDK requires hugepages and RDMA configuration. Please refer to SPDK documentation for setup.${NC}"
fi