Skip to content

Commit 5c3e5a5

Browse files
committed
ci: automate library bundling in ROCm build workflow
Replace manual copying of ROCm libraries and shared objects with an automated CMake-based bundling step using GET_RUNTIME_DEPENDENCIES. This ensures all linked libraries (e.g., libamdhip64, librocm_sysdeps) are recursively detected and bundled into build/bin, filtering out system libs like libc.so, while improving portability and reducing maintenance for dependency management.
1 parent 57413ad commit 5c3e5a5

File tree

1 file changed

+43
-38
lines changed

1 file changed

+43
-38
lines changed

.github/workflows/build.yml

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -647,51 +647,56 @@ jobs:
647647
- name: Build
648648
run: cmake --build build --config ${{ matrix.build }} -j $(nproc)
649649

650-
- name: Copy ROCm core libs to build directory
650+
# Copy Backend ROCm Folders ---
651+
- name: Copy ROCm Backend Data
651652
run: |
652653
build_bin_path="build/bin"
653-
rocm_bin_path="/opt/rocm/bin"
654654
rocm_lib_path="/opt/rocm/lib"
655655
656-
# Copy rocblas/library folder
657-
rocblas_lib_path="$rocm_lib_path/rocblas/library"
658-
if [ -d "$rocblas_lib_path" ]; then
659-
dest_rocblas_path="$build_bin_path/rocblas/library"
660-
mkdir -p "$(dirname "$dest_rocblas_path")"
661-
cp -r "$rocblas_lib_path" "$(dirname "$dest_rocblas_path")/"
662-
echo "Copied: rocblas/library"
656+
# These CANNOT be auto-detected by CMake because they aren't linked libraries.
657+
if [ -d "$rocm_lib_path/rocblas/library" ]; then
658+
mkdir -p "$build_bin_path/rocblas/library"
659+
cp -r "$rocm_lib_path/rocblas/library" "$(dirname "$build_bin_path/rocblas/library")/"
663660
fi
664-
665-
# Copy hipblaslt/library folder
666-
hipblaslt_lib_path="$rocm_lib_path/hipblaslt/library"
667-
if [ -d "$hipblaslt_lib_path" ]; then
668-
dest_hipblaslt_path="$build_bin_path/hipblaslt/library"
669-
mkdir -p "$(dirname "$dest_hipblaslt_path")"
670-
cp -r "$hipblaslt_lib_path" "$(dirname "$dest_hipblaslt_path")/"
671-
echo "Copied: hipblaslt/library"
661+
if [ -d "$rocm_lib_path/hipblaslt/library" ]; then
662+
mkdir -p "$build_bin_path/hipblaslt/library"
663+
cp -r "$rocm_lib_path/hipblaslt/library" "$(dirname "$build_bin_path/hipblaslt/library")/"
672664
fi
673-
674-
# Copy required shared libraries
675-
# We use generic wildcards to catch versioned .so files
676-
echo "Copying shared libraries..."
677-
cp -v $rocm_lib_path/libhipblas.so* "$build_bin_path/" 2>/dev/null || true
678-
cp -v $rocm_lib_path/librocblas.so* "$build_bin_path/" 2>/dev/null || true
679-
cp -v $rocm_lib_path/libamdhip64.so* "$build_bin_path/" 2>/dev/null || true
680-
cp -v $rocm_lib_path/librocsolver.so* "$build_bin_path/" 2>/dev/null || true
681-
cp -v $rocm_lib_path/libroctx64.so* "$build_bin_path/" 2>/dev/null || true
682-
cp -v $rocm_lib_path/libhipblaslt.so* "$build_bin_path/" 2>/dev/null || true
683-
cp -v $rocm_lib_path/libamd_comgr.so* "$build_bin_path/" 2>/dev/null || true
684-
cp -v $rocm_lib_path/libhsa-runtime64.so* "$build_bin_path/" 2>/dev/null || true
685-
686-
# Copy LLVM runtime libs often needed
687-
cp -v $rocm_lib_path/llvm/lib/libLLVM.so* "$build_bin_path/" 2>/dev/null || true
688-
cp -v $rocm_lib_path/llvm/lib/libclang-cpp.so* "$build_bin_path/" 2>/dev/null || true
689665
690-
- name: Copy libs to build directory
691-
run: |
692-
build_bin_path="build/bin"
693-
echo "Copying built project libraries..."
694-
find build \( -name "libwhisper.so*" -o -name "libggml*.so*" \) -exec cp -vP {} "$build_bin_path/" \;
666+
# Auto-Bundle All Linked Libraries ---
667+
- name: Bundle Linked Libraries (Auto-Magic)
668+
run: |
669+
# Create the CMake script on the fly
670+
cat << 'EOF' > bundle_libs.cmake
671+
file(GET_RUNTIME_DEPENDENCIES
672+
EXECUTABLES ${APP}
673+
RESOLVED_DEPENDENCIES_VAR resolved_deps
674+
UNRESOLVED_DEPENDENCIES_VAR unresolved_deps
675+
DIRECTORIES
676+
"/opt/rocm/lib"
677+
"/opt/rocm/lib/rocm_sysdeps/lib"
678+
"/usr/lib/llvm-18/lib"
679+
"/usr/lib/x86_64-linux-gnu"
680+
)
681+
682+
# Filter out system libraries we should NOT bundle
683+
set(SKIP_REGEX "^(libc\.so|libm\.so|libdl\.so|librt\.so|libpthread\.so|libstdc\+\+|libgcc_s|ld-linux)")
684+
685+
foreach(lib ${resolved_deps})
686+
get_filename_component(name ${lib} NAME)
687+
if(NOT name MATCHES "${SKIP_REGEX}")
688+
message(STATUS "Bundling: ${name}")
689+
file(COPY ${lib} DESTINATION "build/bin")
690+
endif()
691+
endforeach()
692+
EOF
693+
694+
# Run the script targeting whisper-cli
695+
# This recursively finds libamdhip64, librocm_sysdeps, libomp, libSDL2, etc.
696+
cmake -DAPP="build/bin/whisper-cli" -P bundle_libs.cmake
697+
698+
# Fix permissions
699+
chmod +x build/bin/*.so*
695700
696701
- name: Set RPATH for portable distribution
697702
run: |

0 commit comments

Comments
 (0)