Skip to content

Commit f9a6274

Browse files
committed
Build boost from source to match gtsam version. Exclude libgtsam and libboost from the wheel to avoid conflicts with gtsam. Share gtsam symbols with gtdynamics.
1 parent 8467700 commit f9a6274

File tree

5 files changed

+51
-10
lines changed

5 files changed

+51
-10
lines changed

.github/scripts/cibw_before_all_linux.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,29 @@ echo "Installing base system dependencies..."
1818
dnf install -y \
1919
wget curl git \
2020
tinyxml2-devel \
21-
ruby \
22-
boost-devel
21+
ruby
2322

2423
echo "CMake version:"
2524
cmake --version
2625

2726

27+
# Build Boost 1.87.0 from source (must match the version used by gtsam-develop on PyPI)
28+
echo "Building Boost 1.87.0 from source..."
29+
cd /tmp
30+
wget https://archives.boost.io/release/1.87.0/source/boost_1_87_0.tar.gz --quiet
31+
tar -xzf boost_1_87_0.tar.gz
32+
cd boost_1_87_0
33+
34+
BOOST_PREFIX="${INSTALL_PREFIX}/boost"
35+
./bootstrap.sh --prefix=${BOOST_PREFIX}
36+
./b2 install --prefix=${BOOST_PREFIX} --with=all -d0
37+
cd /tmp && rm -rf boost_1_87_0*
38+
39+
export BOOST_ROOT="${BOOST_PREFIX}"
40+
export BOOST_INCLUDEDIR="${BOOST_PREFIX}/include"
41+
export BOOST_LIBRARYDIR="${BOOST_PREFIX}/lib"
42+
43+
2844
# Install Gazebo dependencies for SDFormat
2945
echo "Installing Gazebo dependencies..."
3046
cd /tmp
@@ -98,8 +114,11 @@ git clone --depth 1 https://github.com/borglab/gtsam.git ${INSTALL_PREFIX}/gtsam
98114
# gtsam_current symlink will be created by before-build after GTSAM is built
99115
cat > ${INSTALL_PREFIX}/env.sh << EOF
100116
export INSTALL_PREFIX="${INSTALL_PREFIX}"
117+
export BOOST_ROOT="${BOOST_PREFIX}"
118+
export BOOST_INCLUDEDIR="${BOOST_PREFIX}/include"
119+
export BOOST_LIBRARYDIR="${BOOST_PREFIX}/lib"
101120
export CMAKE_PREFIX_PATH="${INSTALL_PREFIX}/gtsam_current:${INSTALL_PREFIX}/gz-cmake4:${INSTALL_PREFIX}/gz-utils:${INSTALL_PREFIX}/gz-math:${INSTALL_PREFIX}/sdformat:\${CMAKE_PREFIX_PATH}"
102-
export LD_LIBRARY_PATH="${INSTALL_PREFIX}/gtsam_current/lib:${INSTALL_PREFIX}/sdformat/lib:${INSTALL_PREFIX}/gz-utils/lib:${INSTALL_PREFIX}/gz-math/lib:\${LD_LIBRARY_PATH}"
121+
export LD_LIBRARY_PATH="${BOOST_PREFIX}/lib:${INSTALL_PREFIX}/gtsam_current/lib:${INSTALL_PREFIX}/sdformat/lib:${INSTALL_PREFIX}/gz-utils/lib:${INSTALL_PREFIX}/gz-math/lib:\${LD_LIBRARY_PATH}"
103122
EOF
104123

105124
echo "before-all completed successfully!"

.github/scripts/cibw_before_all_macos.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,21 @@ fi
1919

2020
# Install Base System Dependencies via Homebrew
2121
echo "Installing base system dependencies..."
22-
brew install boost cmake wget git
22+
brew install cmake wget git
23+
24+
# Build Boost 1.87.0 from source (must match the version used by gtsam-develop on PyPI)
25+
echo "Building Boost 1.87.0 from source..."
26+
cd /tmp
27+
wget https://archives.boost.io/release/1.87.0/source/boost_1_87_0.tar.gz --quiet
28+
tar -xzf boost_1_87_0.tar.gz
29+
cd boost_1_87_0
30+
31+
BOOST_PREFIX="${INSTALL_PREFIX}/boost"
32+
./bootstrap.sh --prefix=${BOOST_PREFIX}
33+
./b2 install --prefix=${BOOST_PREFIX} --with=all -d0 \
34+
cxxflags="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}" \
35+
linkflags="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"
36+
cd /tmp && rm -rf boost_1_87_0*
2337

2438
# Install SDFormat via Homebrew
2539
brew tap osrf/simulation
@@ -31,8 +45,6 @@ echo "Cloning GTSAM source (develop branch)..."
3145
git clone --depth 1 https://github.com/borglab/gtsam.git ${INSTALL_PREFIX}/gtsam_source
3246

3347
# Write environment file for before-build scripts
34-
BOOST_PREFIX=$(brew --prefix boost)
35-
3648
cat > ${INSTALL_PREFIX}/env.sh << EOF
3749
export INSTALL_PREFIX="${INSTALL_PREFIX}"
3850
export BOOST_ROOT="${BOOST_PREFIX}"

.github/scripts/cibw_before_build_linux.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ cmake ${GTSAM_SOURCE} \
5353
-DGTSAM_PYTHON_VERSION=${PYTHON_VERSION} \
5454
-DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXE} \
5555
-DGTSAM_ALLOW_DEPRECATED_SINCE_V43=OFF \
56+
-DBOOST_ROOT=${BOOST_ROOT} \
5657
-DCMAKE_CXX_FLAGS="-faligned-new -Wno-error=free-nonheap-object"
5758

5859
cmake --build . --config Release -j${NUM_CORES}

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,24 @@ manylinux-x86_64-image = "quay.io/pypa/manylinux_2_34_x86_64"
7676
manylinux-aarch64-image = "quay.io/pypa/manylinux_2_34_aarch64"
7777
before-all = "bash {project}/.github/scripts/cibw_before_all_linux.sh"
7878
before-build = "bash {project}/.github/scripts/cibw_before_build_linux.sh {project}"
79-
repair-wheel-command = "LD_LIBRARY_PATH=/opt/gtdynamics-deps/gtd_current/lib:/opt/gtdynamics-deps/gtsam_current/lib:/opt/gtdynamics-deps/sdformat/lib:/opt/gtdynamics-deps/gz-utils/lib:/opt/gtdynamics-deps/gz-math/lib:$LD_LIBRARY_PATH auditwheel repair -w {dest_dir} {wheel}"
79+
repair-wheel-command = "LD_LIBRARY_PATH=/opt/gtdynamics-deps/gtd_current/lib:/opt/gtdynamics-deps/gtsam_current/lib:/opt/gtdynamics-deps/boost/lib:/opt/gtdynamics-deps/sdformat/lib:/opt/gtdynamics-deps/gz-utils/lib:/opt/gtdynamics-deps/gz-math/lib:$LD_LIBRARY_PATH auditwheel repair -w {dest_dir} {wheel} --exclude 'libgtsam*' --exclude 'libmetis-gtsam*' --exclude 'libcephes-gtsam*' --exclude 'libboost_*'"
8080

8181
[tool.cibuildwheel.linux.environment]
8282
INSTALL_PREFIX = "/opt/gtdynamics-deps"
8383
GTSAM_DIR = "/opt/gtdynamics-deps/gtsam_current/lib/cmake/GTSAM"
8484
CMAKE_PREFIX_PATH = "/opt/gtdynamics-deps/gtsam_current:/opt/gtdynamics-deps/gz-cmake4:/opt/gtdynamics-deps/gz-utils:/opt/gtdynamics-deps/gz-math:/opt/gtdynamics-deps/sdformat"
85-
LD_LIBRARY_PATH = "/opt/gtdynamics-deps/gtd_current/lib:/opt/gtdynamics-deps/gtsam_current/lib:/opt/gtdynamics-deps/sdformat/lib:/opt/gtdynamics-deps/gz-utils/lib:/opt/gtdynamics-deps/gz-math/lib"
85+
LD_LIBRARY_PATH = "/opt/gtdynamics-deps/gtd_current/lib:/opt/gtdynamics-deps/gtsam_current/lib:/opt/gtdynamics-deps/boost/lib:/opt/gtdynamics-deps/sdformat/lib:/opt/gtdynamics-deps/gz-utils/lib:/opt/gtdynamics-deps/gz-math/lib"
8686
Python_EXECUTABLE = "$(which python)"
8787
PYTHON_EXECUTABLE = "$(which python)"
8888

8989
[tool.cibuildwheel.macos]
9090
before-all = "bash {project}/.github/scripts/cibw_before_all_macos.sh"
9191
before-build = "bash {project}/.github/scripts/cibw_before_build_macos.sh {project}"
92-
repair-wheel-command = "DYLD_LIBRARY_PATH=$HOME/opt/gtdynamics-deps/gtd_current/lib:$HOME/opt/gtdynamics-deps/gtsam_current/lib:$DYLD_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}"
92+
repair-wheel-command = "DYLD_LIBRARY_PATH=$HOME/opt/gtdynamics-deps/gtd_current/lib:$HOME/opt/gtdynamics-deps/gtsam_current/lib:$HOME/opt/gtdynamics-deps/boost/lib:$DYLD_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel} --exclude libgtsam --exclude libmetis-gtsam --exclude libcephes-gtsam --exclude libboost_serialization --exclude libboost_filesystem --exclude libboost_thread --exclude libboost_atomic --exclude libboost_chrono --exclude libboost_date_time --exclude libboost_regex --exclude libboost_timer --exclude libboost_system --exclude libboost_container"
9393

9494
[tool.cibuildwheel.macos.environment]
9595
MACOSX_DEPLOYMENT_TARGET = "$MACOSX_DEPLOYMENT_TARGET"
9696
INSTALL_PREFIX = "$HOME/opt/gtdynamics-deps"
9797
GTSAM_DIR = "$HOME/opt/gtdynamics-deps/gtsam_current/lib/cmake/GTSAM"
9898
CMAKE_PREFIX_PATH = "$HOME/opt/gtdynamics-deps/gtsam_current"
99-
DYLD_LIBRARY_PATH = "$HOME/opt/gtdynamics-deps/gtd_current/lib:$HOME/opt/gtdynamics-deps/gtsam_current/lib"
99+
DYLD_LIBRARY_PATH = "$HOME/opt/gtdynamics-deps/gtd_current/lib:$HOME/opt/gtdynamics-deps/gtsam_current/lib:$HOME/opt/gtdynamics-deps/boost/lib"

python/gtdynamics/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Python needs to know about gtsam base classes before it can import module classes
22
# Else will throw cryptic "referenced unknown base type" error.
3+
# Load gtsam with RTLD_GLOBAL so that libgtsam's symbols (and pybind11 type
4+
# registrations) from the gtsam-develop wheel are visible to the gtdynamics
5+
# native extension, which links against the same library but doesn't bundle it.
6+
import sys
7+
import os
8+
9+
_old_dlopen_flags = sys.getdlopenflags()
10+
sys.setdlopenflags(os.RTLD_GLOBAL | os.RTLD_NOW)
311
import gtsam
12+
sys.setdlopenflags(_old_dlopen_flags)
413

514
from gtdynamics.gtdynamics import *
615

0 commit comments

Comments
 (0)