Skip to content

Commit 8786f77

Browse files
authored
[wip] Build wheels with debug info (#770)
Co-authored-by: driazati <[email protected]>
1 parent b0f4e2a commit 8786f77

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,4 @@ node_modules
8585

8686
# Analytics cache folder
8787
cache/
88+
.vscode/

manywheel/build_common.sh

+28
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
set -ex
55
SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
66

7+
78
# Require only one python installation
89
if [[ -z "$DESIRED_PYTHON" ]]; then
910
echo "Need to set DESIRED_PYTHON env variable"
@@ -141,6 +142,7 @@ fi
141142
echo "Calling setup.py bdist at $(date)"
142143
time CMAKE_ARGS=${CMAKE_ARGS[@]} \
143144
EXTRA_CAFFE2_CMAKE_FLAGS=${EXTRA_CAFFE2_CMAKE_FLAGS[@]} \
145+
BUILD_LIBTORCH_CPU_WITH_DEBUG=1 \
144146
python setup.py bdist_wheel -d /tmp/$WHEELHOUSE_DIR
145147
echo "Finished setup.py bdist at $(date)"
146148

@@ -344,6 +346,32 @@ for pkg in /$WHEELHOUSE_DIR/torch*linux*.whl /$LIBTORCH_HOUSE_DIR/libtorch*.zip;
344346
done
345347
fi
346348

349+
pushd "$PREFIX/lib"
350+
351+
# Duplicate library into debug lib
352+
cp libtorch_cpu.so libtorch_cpu.so.dbg
353+
354+
# Keep debug symbols on debug lib
355+
strip --only-keep-debug libtorch_cpu.so.dbg
356+
357+
# Remove debug info from release lib
358+
strip --strip-debug libtorch_cpu.so
359+
360+
objcopy libtorch_cpu.so --add-gnu-debuglink=libtorch_cpu.so.dbg
361+
362+
# Zip up debug info
363+
mkdir -p /tmp/debug
364+
mv libtorch_cpu.so.dbg /tmp/debug/libtorch_cpu.so.dbg
365+
CRC32=$(objcopy --dump-section .gnu_debuglink=>(tail -c4 | od -t x4 -An | xargs echo) libtorch_cpu.so)
366+
367+
pushd /tmp
368+
PKG_NAME=$(basename "$pkg" | sed 's/\.whl$//g')
369+
zip /tmp/debug-whl-libtorch-"$PKG_NAME"-"$CRC32".zip /tmp/debug/libtorch_cpu.so.dbg
370+
cp /tmp/debug-whl-libtorch-"$PKG_NAME"-"$CRC32".zip "$PYTORCH_FINAL_PACKAGE_DIR"
371+
popd
372+
373+
popd
374+
347375
# zip up the wheel back
348376
zip -rq $(basename $pkg) $PREIX*
349377

0 commit comments

Comments
 (0)