Skip to content

Commit

Permalink
Modularize CMake Build [5B/N] (#3451)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebookresearch/FBGEMM#550

- Set RPATh to be just `$ORIGIN`

Pull Request resolved: #3451

Reviewed By: spcyppt

Differential Revision: D66842181

Pulled By: q10

fbshipit-source-id: 6e9af4dbc0f7b3c62d7d0673a51aef95c7845ed9
  • Loading branch information
q10 authored and facebook-github-bot committed Dec 6, 2024
1 parent e58c49f commit 9d78337
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
20 changes: 12 additions & 8 deletions .github/scripts/fbgemm_gpu_postbuild.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
echo "################################################################################"
echo "[CMAKE] Running post-build script ..."

# Print directory
pwd
TARGET=$1
SET_RPATH_TO_ORIGIN=$2
echo "Target file: ${TARGET}"

# List all generated .SO files
find . -name '*.so'

# Remove errant RPATHs from the .SO
# Set or remove RPATHs for the .SO
# https://github.com/pytorch/FBGEMM/issues/3098
# https://github.com/NixOS/patchelf/issues/453
find . -name '*.so' -print0 | xargs -0 patchelf --remove-rpath
if [ "${SET_RPATH_TO_ORIGIN}" != "" ]; then
echo "Resetting RPATH to \$ORIGIN ..."
patchelf --force-rpath --set-rpath "\$ORIGIN" "${TARGET}" || exit 1
else
echo "Removing all RPATHs ..."
patchelf --remove-rpath "${TARGET}" || exit 1
fi

echo "[CMAKE] Removed errant RPATHs"
readelf -d "${TARGET}" | grep -i rpath
echo "################################################################################"
19 changes: 12 additions & 7 deletions cmake/modules/GpuCppLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,21 @@ function(gpu_cpp_library)
# Post-Build Steps
############################################################################

# NOTE: Fix this in future PR
if (args_DEPS)
# Only set this if the library has dependencies that we also build,
# otherwise we will hit the following error:
# `No valid ELF RPATH or RUNPATH entry exists in the file`
set(set_rpath_to_origin 1)
endif()

# Add a post-build step to remove errant RPATHs from the .SO
# add_custom_target(${lib_name}_postbuild ALL
# DEPENDS
# WORKING_DIRECTORY ${OUTPUT_DIR}
# COMMAND bash ${FBGEMM}/.github/scripts/fbgemm_gpu_postbuild.bash)
add_custom_target(${lib_name}_postbuild ALL
DEPENDS
WORKING_DIRECTORY ${OUTPUT_DIR}
COMMAND bash ${FBGEMM}/.github/scripts/fbgemm_gpu_postbuild.bash $<TARGET_FILE:${lib_name}> ${set_rpath_to_origin})

# # Set the post-build steps to run AFTER the build completes
# add_dependencies(${lib_name}_postbuild ${lib_name})
# Set the post-build steps to run AFTER the build completes
add_dependencies(${lib_name}_postbuild ${lib_name})

############################################################################
# Set the Output Variable(s)
Expand Down

0 comments on commit 9d78337

Please sign in to comment.