Skip to content

Commit 17797ce

Browse files
committed
feat: add dependencies install script.
1 parent ad66008 commit 17797ce

File tree

2 files changed

+106
-6
lines changed

2 files changed

+106
-6
lines changed

setup.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def check_and_install_pre_commit():
445445
print("Run 'pre-commit install' failed. Please install pre-commit: pip install pre-commit")
446446
exit(0)
447447

448-
def run_git_command(command, cwd=None, check=True):
448+
def run_shell_command(command, cwd=None, check=True):
449449
try:
450450
subprocess.run(command, cwd=cwd, check=check, shell=True, capture_output=True, text=True)
451451
return True
@@ -492,15 +492,15 @@ def apply_patch_safely(patch_file_path, repo_path):
492492

493493
if has_uncommitted_changes(repo_path):
494494
print(f"⚠️ Uncommitted changes detected. Running `git reset --hard` for {repo_path}")
495-
if not run_git_command("git reset --hard", cwd=repo_path):
495+
if not run_shell_command("git reset --hard", cwd=repo_path):
496496
print("❌ Failed to reset changes!")
497497
return False
498498

499499
print(f"🛠️ Apply patch: {patch_file_path}")
500-
apply_success = run_git_command(f"git apply --check {patch_file_path}", cwd=repo_path, check=False)
500+
apply_success = run_shell_command(f"git apply --check {patch_file_path}", cwd=repo_path, check=False)
501501

502502
if apply_success:
503-
if not run_git_command(f"git apply {patch_file_path}", cwd=repo_path):
503+
if not run_shell_command(f"git apply {patch_file_path}", cwd=repo_path):
504504
print("❌ apply patch fail!")
505505
apply_success = False
506506

@@ -512,7 +512,7 @@ def apply_patch_safely(patch_file_path, repo_path):
512512
print(f" cd {repo_path} && git apply {patch_file_path}")
513513
return False
514514

515-
def apply_patch():
515+
def pre_build():
516516
if os.path.exists("third_party/custom_patch"):
517517
script_path = os.path.dirname(os.path.abspath(__file__))
518518
mooncake_repo_path = os.path.join(script_path, "third_party/Mooncake")
@@ -521,6 +521,9 @@ def apply_patch():
521521
cpprestsdk_repo_path = os.path.join(script_path, "third_party/cpprestsdk")
522522
if not apply_patch_safely("../custom_patch/cpprestsdk.patch", cpprestsdk_repo_path):
523523
exit(0)
524+
if not run_shell_command("sh third_party/dependencies.sh", cwd=script_path):
525+
print("❌ Failed to reset changes!")
526+
exit(0)
524527

525528
if __name__ == "__main__":
526529
device = 'a2' # default
@@ -537,9 +540,10 @@ def apply_patch():
537540
del sys.argv[idx]
538541
del sys.argv[idx]
539542
if '--dry_run' not in sys.argv:
540-
apply_patch()
543+
pre_build()
541544
else:
542545
sys.argv.remove("--dry_run")
546+
543547
if '--install-xllm-kernels' in sys.argv:
544548
idx = sys.argv.index('--install-xllm-kernels')
545549
if idx + 1 < len(sys.argv):

third_party/dependencies.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
3+
# Color definitions
4+
GREEN="\033[0;32m"
5+
BLUE="\033[0;34m"
6+
YELLOW="\033[0;33m"
7+
RED="\033[0;31m"
8+
NC="\033[0m" # No Color
9+
10+
# Configuration
11+
REPO_ROOT=`pwd`
12+
13+
# Function to print section headers
14+
print_section() {
15+
echo -e "\n${BLUE}=== $1 ===${NC}"
16+
}
17+
18+
# Function to print success messages
19+
print_success() {
20+
echo -e "${GREEN}$1${NC}"
21+
}
22+
23+
# Function to print error messages and exit
24+
print_error() {
25+
echo -e "${RED}✗ ERROR: $1${NC}"
26+
exit 1
27+
}
28+
29+
# Function to check command success
30+
check_success() {
31+
if [ $? -ne 0 ]; then
32+
print_error "$1"
33+
fi
34+
}
35+
36+
if [ $(id -u) -ne 0 ]; then
37+
print_error "Require root permission, try sudo ./dependencies.sh"
38+
fi
39+
40+
41+
# Install yalantinglibs
42+
print_section "Installing yalantinglibs"
43+
44+
# Check if thirdparties directory exists
45+
if [ ! -d "${REPO_ROOT}/third_party/Mooncake/thirdparties" ]; then
46+
mkdir -p "${REPO_ROOT}/third_party/Mooncake/thirdparties"
47+
check_success "Failed to create Mooncake/thirdparties directory"
48+
fi
49+
50+
# Change to thirdparties directory
51+
cd "${REPO_ROOT}/third_party/Mooncake/thirdparties"
52+
check_success "Failed to change to Mooncake/thirdparties directory"
53+
54+
# Check if yalantinglibs is already installed
55+
if [ -d "yalantinglibs" ]; then
56+
echo -e "${YELLOW}yalantinglibs directory already exists. Removing for fresh install...${NC}"
57+
rm -rf yalantinglibs
58+
check_success "Failed to remove existing yalantinglibs directory"
59+
fi
60+
61+
# Clone yalantinglibs
62+
echo "Cloning yalantinglibs from https://github.com/alibaba/yalantinglibs.git"
63+
git clone https://github.com/alibaba/yalantinglibs.git
64+
check_success "Failed to clone yalantinglibs"
65+
66+
# Build and install yalantinglibs
67+
cd yalantinglibs
68+
check_success "Failed to change to yalantinglibs directory"
69+
70+
# Checkout version 0.5.5
71+
echo "Checking out yalantinglibs version 0.5.5..."
72+
git checkout 0.5.5
73+
check_success "Failed to checkout yalantinglibs version 0.5.5"
74+
75+
mkdir -p build
76+
check_success "Failed to create build directory"
77+
78+
cd build
79+
check_success "Failed to change to build directory"
80+
81+
echo "Configuring yalantinglibs..."
82+
cmake .. -DBUILD_EXAMPLES=OFF -DBUILD_BENCHMARK=OFF -DBUILD_UNIT_TESTS=OFF -DYLT_ENABLE_IBV=ON
83+
check_success "Failed to configure yalantinglibs"
84+
85+
echo "Building yalantinglibs (using $(nproc) cores)..."
86+
cmake --build . -j$(nproc)
87+
check_success "Failed to build yalantinglibs"
88+
89+
echo "Installing yalantinglibs..."
90+
cmake --install .
91+
check_success "Failed to install yalantinglibs"
92+
93+
sed -i '54s/target_link_libraries(${ylt_target_name} -libverbs)/target_link_libraries(${ylt_target_name} INTERFACE -libverbs)/' /usr/local/lib/cmake/yalantinglibs/config.cmake
94+
95+
print_success "yalantinglibs installed successfully"
96+

0 commit comments

Comments
 (0)