-
Notifications
You must be signed in to change notification settings - Fork 651
Expand file tree
/
Copy pathclean_distribution.sh
More file actions
executable file
·90 lines (77 loc) · 3.06 KB
/
clean_distribution.sh
File metadata and controls
executable file
·90 lines (77 loc) · 3.06 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
#!/bin/bash
# Copyright 2025 The TensorFlow Quantum Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =============================================================================
# Summary: bundle external shared libraries into the final TFQ wheel.
# Run this script with the option "-h" to get a usage summary.
#
# This uses auditwheel to "repair" the wheel: copy external shared libraries
# into the wheel itself and modify the RPATH entries such that these libraries
# will be picked up at runtime. This accomplishes a similar result as if the
# libraries had been statically linked.
set -eu -o pipefail
function quit() {
printf 'Error: %b\n' "$*" >&2
exit 1
}
# Find the top of the local TFQ git tree. Do it early in case this fails.
thisdir=$(dirname "${BASH_SOURCE[0]:?}")
repo_dir=$(git -C "${thisdir}" rev-parse --show-toplevel 2> /dev/null) || \
quit "This script must be run from inside the TFQ git tree."
# Default values for variables that can be changed via command line flags.
docker_image="quay.io/pypa/manylinux_2_34_x86_64"
platform="manylinux_2_17_x86_64"
py_version=$(python3 --version | cut -d' ' -f2 | cut -d. -f1,2)
action="repair"
usage="Usage: ${0} [OPTIONS] /path/to/wheel.whl
Run auditwheel on the given wheel file. Available options:
Configuration options:
-m IMG Use manylinux Docker image IMG (default: ${docker_image})
-p X.Y Use Python version X.Y (default: ${py_version})
-t TAG Pass --plat TAG to auditwheel (default: ${platform})
General options:
-h Show this help message and exit
-s Run 'auditwheel show', not repair (default: run 'auditwheel repair')"
while getopts "hm:p:st:" opt; do
case "${opt}" in
h) echo "${usage}"; exit 0 ;;
m) docker_image="${OPTARG}" ;;
p) py_version="${OPTARG}" ;;
s) action="show" ;;
t) platform="${OPTARG}" ;;
*) quit "${usage}" ;;
esac
done
shift $((OPTIND -1))
if (( $# < 1 )); then
quit "Must provide at least one argument.\n\n${usage}"
fi
wheel_path="$(cd "$(dirname "${1}")" && pwd)/$(basename "${1}")"
wheel_name="$(basename "${1}")"
auditwheel_args=()
if [[ "${action}" == "repair" ]]; then
auditwheel_args+=(
"--exclude" "libtensorflow_framework.so.2"
"--plat" "${platform}"
"-w" "/tfq/wheelhouse"
)
fi
echo "Running 'auditwheel ${action}' in Docker with image ${docker_image}"
docker run -it --rm --network host \
-w /tfq \
-v "${repo_dir}":/tfq \
-v "${wheel_path}":"/tmp/${wheel_name}" \
"${docker_image}" \
auditwheel "${action}" "${auditwheel_args[@]}" "/tmp/${wheel_name}"
echo "Done. New wheel file written to ${repo_dir}/wheelhouse"