Skip to content

Commit

Permalink
fix copy onednnl 6
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielNSD committed Oct 31, 2024
1 parent dd83249 commit cb7c1b8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 17 deletions.
38 changes: 21 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,33 @@ endif()
# TODO: find a better way to get these libraries version number (they can change between builds)
if(APPLE)
# Copy required dylibs to the build directory and adjust LC_LOAD_DYLIB path
add_custom_command(TARGET metaltranslate POST_BUILD
COMMAND ICU_UC_LIB_NAME=$(otool -L ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib | grep 'libicuuc' | sed -E 's|.*(libicuuc[^ ]*).*|\1|')
COMMAND ICU_DATA_LIB_NAME=$(otool -L ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib | grep 'libicudata' | sed -E 's|.*(libicudata[^ ]*).*|\1|')
COMMAND DNNL_LIB_NAME=$(otool -L ${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib | grep 'libdnnl' | sed -E 's|.*(libdnnl[^ ]*).*|\1|')
# add_custom_command(TARGET metaltranslate POST_BUILD
# COMMAND ICU_UC_LIB_NAME=$(otool -L ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib | grep 'libicuuc' | sed -E 's|.*(libicuuc[^ ]*).*|\1|')
# COMMAND ICU_DATA_LIB_NAME=$(otool -L ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib | grep 'libicudata' | sed -E 's|.*(libicudata[^ ]*).*|\1|')
# COMMAND DNNL_LIB_NAME=$(otool -L ${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib | grep 'libdnnl' | sed -E 's|.*(libdnnl[^ ]*).*|\1|')

COMMAND echo 'Extracted ICU UC library name: ${ICU_UC_LIB_NAME}'
COMMAND echo 'Extracted ICU DATA library name: ${ICU_DATA_LIB_NAME}'
COMMAND echo 'Extracted DNNL library name: ${DNNL_LIB_NAME}'
# COMMAND echo 'Extracted ICU UC library name: ${ICU_UC_LIB_NAME}'
# COMMAND echo 'Extracted ICU DATA library name: ${ICU_DATA_LIB_NAME}'
# COMMAND echo 'Extracted DNNL library name: ${DNNL_LIB_NAME}'


COMMAND install_name_tool -change ${ONEDNN_ROOT}/lib/${DNNL_LIB_NAME} @rpath/libdnnl.3.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib # change lib path of ctranslate2 lib
COMMAND install_name_tool -change ${ICU_LIBRARY_DIR}/${ICU_UC_LIB_NAME} @rpath/libicuuc.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib
COMMAND install_name_tool -change ${ICU_LIBRARY_DIR}/${ICU_DATA_LIB_NAME} @rpath/libicudata.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib
COMMAND install_name_tool -change ${ICU_LIBRARY_DIR}/${ICU_UC_LIB_NAME} @rpath/libicuuc.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib
# COMMAND install_name_tool -change ${ONEDNN_ROOT}/lib/${DNNL_LIB_NAME} @rpath/libdnnl.3.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib # change lib path of ctranslate2 lib
# COMMAND install_name_tool -change ${ICU_LIBRARY_DIR}/${ICU_UC_LIB_NAME} @rpath/libicuuc.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib
# COMMAND install_name_tool -change ${ICU_LIBRARY_DIR}/${ICU_DATA_LIB_NAME} @rpath/libicudata.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib
# COMMAND install_name_tool -change ${ICU_LIBRARY_DIR}/${ICU_UC_LIB_NAME} @rpath/libicuuc.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib

# copy files to build directory
COMMAND ${CMAKE_COMMAND} -E copy ${ONEDNN_ROOT}/lib/libdnnl.3.dylib $<TARGET_FILE_DIR:metaltranslate>
COMMAND ${CMAKE_COMMAND} -E copy ${ICU_LIBRARY_DIR}/libicuuc.dylib $<TARGET_FILE_DIR:metaltranslate>
COMMAND ${CMAKE_COMMAND} -E copy ${ICU_LIBRARY_DIR}/libicudata.dylib $<TARGET_FILE_DIR:metaltranslate>
# # copy files to build directory
# COMMAND ${CMAKE_COMMAND} -E copy ${ONEDNN_ROOT}/lib/libdnnl.3.dylib $<TARGET_FILE_DIR:metaltranslate>
# COMMAND ${CMAKE_COMMAND} -E copy ${ICU_LIBRARY_DIR}/libicuuc.dylib $<TARGET_FILE_DIR:metaltranslate>
# COMMAND ${CMAKE_COMMAND} -E copy ${ICU_LIBRARY_DIR}/libicudata.dylib $<TARGET_FILE_DIR:metaltranslate>


COMMENT "Adjusting LC_LOAD_DYLIB path for libdnnl"
)
# COMMENT "Adjusting LC_LOAD_DYLIB path for libdnnl"
# )
add_custom_command(TARGET metaltranslate POST_BUILD
COMMAND ${CMAKE_COMMAND} -E env EXTERNAL_INSTALL_LOCATION=${EXTERNAL_INSTALL_LOCATION} ONEDNN_ROOT=${ONEDNN_ROOT} ICU_LIBRARY_DIR=${ICU_LIBRARY_DIR} ./post_build_script.sh $<TARGET_FILE_DIR:metaltranslate>
COMMENT "Running post-build script to adjust LC_LOAD_DYLIB paths and copy files"
)
elseif(UNIX)
add_custom_command(TARGET metaltranslate POST_BUILD

Expand Down
22 changes: 22 additions & 0 deletions post_built_mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Extract library names
ICU_UC_LIB_NAME=$(otool -L "${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib" | grep 'libicuuc' | sed -E 's|.*(libicuuc[^ ]*).*|\1|')
ICU_DATA_LIB_NAME=$(otool -L "${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib" | grep 'libicudata' | sed -E 's|.*(libicudata[^ ]*).*|\1|')
DNNL_LIB_NAME=$(otool -L "${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib" | grep 'libdnnl' | sed -E 's|.*(libdnnl[^ ]*).*|\1|')

# Echo extracted library names for logging
echo "Extracted ICU UC library name: ${ICU_UC_LIB_NAME}"
echo "Extracted ICU DATA library name: ${ICU_DATA_LIB_NAME}"
echo "Extracted DNNL library name: ${DNNL_LIB_NAME}"

# Modify install paths using install_name_tool
install_name_tool -change "${ONEDNN_ROOT}/lib/${DNNL_LIB_NAME}" @rpath/libdnnl.3.dylib "${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib"
install_name_tool -change "${ICU_LIBRARY_DIR}/${ICU_UC_LIB_NAME}" @rpath/libicuuc.dylib "${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib"
install_name_tool -change "${ICU_LIBRARY_DIR}/${ICU_DATA_LIB_NAME}" @rpath/libicudata.dylib "${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib"
install_name_tool -change "${ICU_LIBRARY_DIR}/${ICU_UC_LIB_NAME}" @rpath/libicuuc.dylib "${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib"

# Copy necessary files to build directory
cp "${ONEDNN_ROOT}/lib/libdnnl.3.dylib" "$1"
cp "${ICU_LIBRARY_DIR}/libicuuc.dylib" "$1"
cp "${ICU_LIBRARY_DIR}/libicudata.dylib" "$1"

0 comments on commit cb7c1b8

Please sign in to comment.