-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsmart_build.py
More file actions
126 lines (97 loc) · 3.51 KB
/
smart_build.py
File metadata and controls
126 lines (97 loc) · 3.51 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
#!/usr/bin/env python3
"""
Smart build script
Automatically handles version compatibility and dependency detection
"""
import subprocess
import sys
import os
import platform
def get_macos_deployment_target():
"""Get appropriate macOS deployment target"""
if sys.platform != "darwin":
return None
try:
result = subprocess.run(["sw_vers", "-productVersion"], capture_output=True, text=True, check=True)
macos_version = result.stdout.strip()
major_version = macos_version.split(".")[0]
# Set deployment target to current version
deployment_target = f"{major_version}.0"
print(f"Detected macOS version: {macos_version}, set deployment target: {deployment_target}")
return deployment_target
except Exception as e:
print(f"Failed to detect macOS version, using default: {e}")
return "14.0"
def check_dependency(module_name):
"""Check if a Python module is installed"""
try:
__import__(module_name)
return True
except ImportError:
return False
def fix_pybind11():
"""Fix pybind11 installation"""
print("Checking pybind11...")
subprocess.run([sys.executable, "scripts/fix_pybind11.py"], check=True)
def build_with_flags():
"""Build according to dependencies"""
# Fix pybind11
fix_pybind11()
# Check ML dependencies
xgboost_available = check_dependency("xgboost")
lightgbm_available = check_dependency("lightgbm")
print(f"XGBoost available: {xgboost_available}")
print(f"LightGBM available: {lightgbm_available}")
# Build CMake args
cmake_args = ["-G", "Ninja"]
# Add pybind11 path
try:
import pybind11
pybind11_dir = pybind11.get_cmake_dir()
cmake_args.extend([f"-Dpybind11_DIR={pybind11_dir}"])
print(f"Set pybind11 path: {pybind11_dir}")
except Exception as e:
print(f"Warning: failed to set pybind11 path: {e}")
# Enable GLCache if XGBoost is available
if xgboost_available:
cmake_args.extend(["-DENABLE_GLCACHE=ON"])
print("Enable GLCache (requires XGBoost)")
# Enable LRB and 3LCache if LightGBM is available
if lightgbm_available:
cmake_args.extend(["-DENABLE_LRB=ON", "-DENABLE_3L_CACHE=ON"])
print("Enable LRB and 3LCache (requires LightGBM)")
# Set macOS deployment target
deployment_target = get_macos_deployment_target()
if deployment_target:
cmake_args.extend([f"-DCMAKE_OSX_DEPLOYMENT_TARGET={deployment_target}"])
# Build commands
build_dir = "src/libCacheSim/build"
source_dir = "."
# Clean build directory
if os.path.exists(build_dir):
print("Cleaning build directory...")
subprocess.run(["rm", "-rf", build_dir], check=True)
# Run CMake configure
cmake_cmd = ["cmake", "-S", source_dir, "-B", build_dir] + cmake_args
print(f"Running: {' '.join(cmake_cmd)}")
subprocess.run(cmake_cmd, check=True)
# Run build
build_cmd = ["cmake", "--build", build_dir]
print(f"Running: {' '.join(build_cmd)}")
subprocess.run(build_cmd, check=True)
print("✓ Build completed!")
def main():
print("=== libCacheSim Smart Build ===")
print(f"Platform: {platform.platform()}")
print(f"Python: {sys.version}")
print()
try:
build_with_flags()
except subprocess.CalledProcessError as e:
print(f"✗ Build failed: {e}")
sys.exit(1)
except Exception as e:
print(f"✗ Build exception: {e}")
sys.exit(1)
if __name__ == "__main__":
main()