-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathbuild-wheel.sh
More file actions
executable file
·138 lines (113 loc) · 4.5 KB
/
Copy pathbuild-wheel.sh
File metadata and controls
executable file
·138 lines (113 loc) · 4.5 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
#!/usr/bin/env bash
# Internal script to build a wheel from a Drake installation.
set -eu -o pipefail
if [[ "$(uname)" == "Darwin" ]]; then
HOMEBREW="$(brew --prefix)"
# Use GNU 'cp' on macOS so we have a consistent CLI.
cp()
{
gcp "$@"
}
fi
# Helper function to change the RPATH of libraries. The first argument is the
# (origin-relative) new RPATH to be added. Remaining arguments are libraries to
# be modified. Note that existing RPATH(s) are removed (except for homebrew
# RPATHs on macOS).
chrpath()
{
rpath=$1
shift 1
for lib in "$@"; do
if [[ "$(uname)" == "Linux" ]]; then
patchelf --remove-rpath "$lib"
patchelf --set-rpath "\$ORIGIN/$rpath" "$lib"
else
strip_rpath \
--exclude="$HOMEBREW" \
"$lib"
install_name_tool -add_rpath "@loader_path/$rpath" "$lib"
fi
done
}
# Helper function to copy the imported copyright text into the wheel's
# documentation.
copy_license()
{
package_name=$1
mkdir -p ${WHEEL_DIR}/pydrake/doc/${package_name}
cp -t ${WHEEL_DIR}/pydrake/doc/${package_name}/ \
/tmp/drake-wheel-build/drake-wheel-licenses/${package_name}/copyright
}
###############################################################################
# Activate Drake's virtual environment, which provides some of the tools that
# we need to build the wheels.
. /tmp/drake-wheel-build/drake-src/venv/bin/activate
readonly WHEEL_DIR=/tmp/drake-wheel-build/drake-wheel
readonly WHEEL_SHARE_DIR=${WHEEL_DIR}/pydrake/share
# TODO(mwoehlke-kitware) Most of this should move to Bazel.
mkdir -p ${WHEEL_DIR}/drake
mkdir -p ${WHEEL_DIR}/pydrake/lib
mkdir -p ${WHEEL_DIR}/pydrake/share/drake
cd ${WHEEL_DIR}
cp -r -t ${WHEEL_DIR}/drake \
/tmp/drake-wheel-build/drake-dist/lib/python*/site-packages/drake/*
cp -r -t ${WHEEL_DIR}/pydrake \
/tmp/drake-wheel-build/drake-dist/share/doc \
/tmp/drake-wheel-build/drake-dist/lib/python*/site-packages/pydrake/*
cp -r -t ${WHEEL_DIR}/pydrake/lib \
/tmp/drake-wheel-build/drake-dist/lib/libdrake*.so
# MOSEK's published wheels declare an upper bound on their supported Python
# version, which is currently Python < 3.15. When that changes to a larger
# version number, we should bump this up to match, and also grep tools/wheel
# for other mentions of MOSEK version bounds and fix those as well.
PYTHON_MINOR=$(python -c "import sys; print(sys.version_info.minor)")
MOSEK_ENABLED=1
[ ${PYTHON_MINOR} -ge 15 ] && MOSEK_ENABLED=
if [[ "$(uname)" == "Darwin" && -n "${MOSEK_ENABLED}" ]]; then
# MOSEK is "sort of" third party, but is procured as part of Drake's build
# and ends up in /tmp/drake-wheel-build/drake-dist/. It should end up in
# the same place as libdrake.so.
cp -r -t ${WHEEL_DIR}/pydrake/lib \
/tmp/drake-wheel-build/drake-dist/lib/libmosek* \
/tmp/drake-wheel-build/drake-dist/lib/libtbb*
fi
if [[ "$(uname)" == "Linux" ]]; then
cp -r -t ${WHEEL_DIR}/pydrake \
/tmp/drake-wheel-build/drake-wheel-content/*
fi
# Copy the license files from third party dependencies we vendor.
if [[ "$(uname)" == "Linux" ]]; then
# The drake/tools/wheel/test/tests/libs-test.py must be kept in sync with
# this list. To maintain that correspondence, the _ALLOWED_LIBS entry seen
# in that test program is added as comment to the end of each line below.
copy_license gcc # libgfortran, libgomp, libquadmath
fi
cp -r -t ${WHEEL_SHARE_DIR}/drake \
/tmp/drake-wheel-build/drake-dist/share/drake/.drake-find_resource-sentinel \
/tmp/drake-wheel-build/drake-dist/share/drake/package.xml \
/tmp/drake-wheel-build/drake-dist/share/drake/examples \
/tmp/drake-wheel-build/drake-dist/share/drake/geometry \
/tmp/drake-wheel-build/drake-dist/share/drake/multibody \
/tmp/drake-wheel-build/drake-dist/share/drake/tutorials
if [[ "$(uname)" == "Linux" ]]; then
export LD_LIBRARY_PATH=${WHEEL_DIR}/pydrake/lib
fi
chrpath lib pydrake/*.so
chrpath ../lib pydrake/*/*.so
if [[ "$(uname)" == "Darwin" ]]; then
change_lpath \
--old='@loader_path/../../../' \
--new='@rpath/' \
pydrake/*.so
change_lpath \
--old='@loader_path/../../../../' \
--new='@rpath/' \
pydrake/*/*.so
fi
python -m build --wheel
if [[ "$(uname)" == "Darwin" ]]; then
delocate-wheel -w wheelhouse -v dist/drake*.whl
else
GLIBC_VERSION=$(ldd --version | sed -n '1{s/.* //;s/[.]/_/p}')
auditwheel repair --plat manylinux_${GLIBC_VERSION}_$(arch) dist/drake*.whl
fi