-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·256 lines (214 loc) · 6.22 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·256 lines (214 loc) · 6.22 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
#!/bin/bash
# FastTD3 C++ Build Script
# This script automates the build process with different configurations
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to detect OS
detect_os() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo "linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
echo "windows"
else
echo "unknown"
fi
}
# Function to check dependencies
check_dependencies() {
print_status "Checking dependencies..."
local missing_deps=()
if ! command_exists cmake; then
missing_deps+=("cmake")
fi
if ! command_exists make; then
missing_deps+=("make")
fi
if [[ ${#missing_deps[@]} -gt 0 ]]; then
print_error "Missing dependencies: ${missing_deps[*]}"
print_status "Please install the missing dependencies and try again."
exit 1
fi
print_success "All dependencies found!"
}
# Function to setup environment
setup_environment() {
print_status "Setting up build environment..."
local os=$(detect_os)
# Check for LibTorch
if [[ -z "$CMAKE_PREFIX_PATH" ]]; then
print_warning "CMAKE_PREFIX_PATH not set. Please set it to your LibTorch installation path."
print_status "Example: export CMAKE_PREFIX_PATH=/path/to/libtorch:\$CMAKE_PREFIX_PATH"
# Try to find LibTorch in common locations
local libtorch_paths=(
"/usr/local/libtorch"
"/opt/libtorch"
"$HOME/libtorch"
"$HOME/.local/libtorch"
)
for path in "${libtorch_paths[@]}"; do
if [[ -d "$path" ]]; then
print_status "Found LibTorch at: $path"
export CMAKE_PREFIX_PATH="$path:$CMAKE_PREFIX_PATH"
break
fi
done
fi
# Create build directory
mkdir -p build
cd build
}
# Function to build project
build_project() {
local build_type=${1:-Release}
local enable_tests=${2:-false}
local enable_cuda=${3:-false}
print_status "Building FastTD3 (${build_type})..."
# Configure with CMake
local cmake_args=(
"-DCMAKE_BUILD_TYPE=${build_type}"
"-DCMAKE_CXX_STANDARD=17"
"-DCMAKE_CXX_STANDARD_REQUIRED=ON"
)
if [[ "$enable_tests" == "true" ]]; then
cmake_args+=("-DBUILD_TESTS=ON")
fi
if [[ "$enable_cuda" == "true" ]]; then
cmake_args+=("-DUSE_CUDA=ON")
fi
cmake "${cmake_args[@]}" ..
# Build
local jobs=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
make -j"$jobs"
print_success "Build completed successfully!"
}
# Function to run tests
run_tests() {
if [[ -f "fast_td3_tests" ]]; then
print_status "Running tests..."
./fast_td3_tests
print_success "Tests completed!"
else
print_warning "Test executable not found. Build with tests enabled first."
fi
}
# Function to clean build
clean_build() {
print_status "Cleaning build directory..."
rm -rf build/*
print_success "Build directory cleaned!"
}
# Function to show help
show_help() {
echo "FastTD3 C++ Build Script"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " -d, --debug Build in debug mode"
echo " -t, --tests Build with tests enabled"
echo " -c, --cuda Build with CUDA support"
echo " -r, --run-tests Run tests after building"
echo " --clean Clean build directory"
echo " --check-deps Check dependencies only"
echo ""
echo "Examples:"
echo " $0 # Build in release mode"
echo " $0 -d # Build in debug mode"
echo " $0 -t -r # Build with tests and run them"
echo " $0 -c # Build with CUDA support"
echo " $0 --clean # Clean build directory"
}
# Main script
main() {
local build_type="Release"
local enable_tests=false
local enable_cuda=false
local run_tests_after=false
local clean_only=false
local check_deps_only=false
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_help
exit 0
;;
-d|--debug)
build_type="Debug"
shift
;;
-t|--tests)
enable_tests=true
shift
;;
-c|--cuda)
enable_cuda=true
shift
;;
-r|--run-tests)
run_tests_after=true
shift
;;
--clean)
clean_only=true
shift
;;
--check-deps)
check_deps_only=true
shift
;;
*)
print_error "Unknown option: $1"
show_help
exit 1
;;
esac
done
# Check dependencies
check_dependencies
if [[ "$check_deps_only" == "true" ]]; then
exit 0
fi
# Clean if requested
if [[ "$clean_only" == "true" ]]; then
clean_build
exit 0
fi
# Setup environment
setup_environment
# Build project
build_project "$build_type" "$enable_tests" "$enable_cuda"
# Run tests if requested
if [[ "$run_tests_after" == "true" ]]; then
run_tests
fi
print_success "FastTD3 C++ build completed successfully!"
print_status "You can now run: ./fast_td3 --help"
}
# Run main function with all arguments
main "$@"