forked from unitreerobotics/unitree_sdk2
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·93 lines (79 loc) · 2.78 KB
/
build.sh
File metadata and controls
executable file
·93 lines (79 loc) · 2.78 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
#!/bin/bash
set -e
# Detect architecture
ARCH=$(uname -m)
if [ "$ARCH" = "x86_64" ]; then
LIB_ARCH="x86_64"
PLATFORM_TAG="linux_x86_64"
elif [ "$ARCH" = "aarch64" ]; then
LIB_ARCH="aarch64"
PLATFORM_TAG="linux_aarch64"
else
echo "Unsupported architecture: $ARCH"
exit 1
fi
echo "Building for $ARCH"
# Clean and build SDKs
mkdir -p build
# Build for Python 3.8, 3.10, and 3.11
for PYTHON_VER in "3.8" "3.10" "3.11"; do
echo "Building Unitree SDK for Python $PYTHON_VER..."
BUILD_DIR="build_py${PYTHON_VER//.}"
mkdir -p $BUILD_DIR && cd $BUILD_DIR
# Set Python-specific configuration
if [ "$PYTHON_VER" = "3.10" ] || [ "$PYTHON_VER" = "3.11" ]; then
# For Python 3.10/3.11 built from source
cmake .. \
-DBUILD_PYTHON_BINDING=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_BUILD_RPATH_USE_ORIGIN=ON \
-DCMAKE_INSTALL_RPATH='$ORIGIN' \
-DPYTHON_EXECUTABLE=/usr/local/bin/python$PYTHON_VER \
-DPYTHON_INCLUDE_DIR=/usr/local/include/python$PYTHON_VER \
-DPYTHON_LIBRARY=/usr/local/lib/libpython$PYTHON_VER.so
else
# For system Python 3.8
cmake .. \
-DBUILD_PYTHON_BINDING=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_BUILD_RPATH_USE_ORIGIN=ON \
-DCMAKE_INSTALL_RPATH='$ORIGIN' \
-DPYTHON_EXECUTABLE=/usr/bin/python$PYTHON_VER
fi
make -j$(nproc)
cd ..
# Copy Python binding for this version
find $BUILD_DIR -name "unitree_interface.cpython-*.so" -exec cp {} unitree_interface/ \;
# Copy third-party libraries (only once)
if [ "$PYTHON_VER" = "3.8" ]; then
cp thirdparty/lib/$LIB_ARCH/*.so* unitree_interface/ 2>/dev/null || true
# Create versioned symlinks for FastRTPS libraries
cd unitree_interface
if [ -f libfastrtps.so ]; then
ln -sf libfastrtps.so libfastrtps.so.2.13
fi
if [ -f libfastcdr.so ]; then
ln -sf libfastcdr.so libfastcdr.so.2
fi
cd ..
fi
# Build wheel for this Python version
python$PYTHON_VER -m build --wheel
# Get Python version tag
PYTHON_TAG=$(python$PYTHON_VER -c "import sys; print(f'cp{sys.version_info.major}{sys.version_info.minor}')")
echo "Using Python tag: $PYTHON_TAG"
# Rename wheel
cd dist
for wheel in *.whl; do
if [[ "$wheel" == *"-py3-none-any.whl" ]]; then
new_name="${wheel/-py3-none-any.whl/-$PYTHON_TAG-$PYTHON_TAG-$PLATFORM_TAG.whl}"
mv "$wheel" "$new_name"
echo "Built wheel: $new_name"
fi
done
cd ..
done
# Fix RPATH for all .so files
for so in unitree_interface/*.so*; do
patchelf --set-rpath '$ORIGIN' "$so" 2>/dev/null || true
done