Specify the paths of system tools when building Apple framework (#22056)

### Description
<!-- Describe your changes. -->

Specify the path of `ar`, `ld` and `libtool` when building apple
framework.


### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->

Sometimes non-system executables will comes before the system-provided
ones. This PR intends to prevent it from happening.
This commit is contained in:
Chester Liu 2024-09-23 17:19:30 +08:00 committed by GitHub
parent b636b275aa
commit 9b37b3ea44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -352,12 +352,12 @@ if(onnxruntime_BUILD_APPLE_FRAMEWORK)
# make both maccatalyst and other builds do the same thing.
set(CUR_TARGET_CMAKE_SOURCE_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_LIB}.dir)
add_custom_command(TARGET onnxruntime POST_BUILD
COMMAND ar -t $<TARGET_FILE:${_LIB}> | grep "\.o$" > ${_LIB}.object_file_list.txt
COMMAND /usr/bin/ar -t $<TARGET_FILE:${_LIB}> | grep "\.o$" > ${_LIB}.object_file_list.txt
COMMAND ${CMAKE_COMMAND} -E env python3 ${CMAKE_CURRENT_SOURCE_DIR}/maccatalyst_prepare_objects_for_prelink.py ${CUR_TARGET_CMAKE_SOURCE_LIB_DIR} ${CUR_STATIC_LIB_OBJ_DIR} ${CUR_STATIC_LIB_OBJ_DIR}/${_LIB}.object_file_list.txt
WORKING_DIRECTORY ${CUR_STATIC_LIB_OBJ_DIR})
else()
add_custom_command(TARGET onnxruntime POST_BUILD
COMMAND ar ARGS -x $<TARGET_FILE:${_LIB}>
COMMAND /usr/bin/ar ARGS -x $<TARGET_FILE:${_LIB}>
WORKING_DIRECTORY ${CUR_STATIC_LIB_OBJ_DIR})
endif()
endif()
@ -378,12 +378,12 @@ if(onnxruntime_BUILD_APPLE_FRAMEWORK)
# do the pre-link with `ld -r` to create a single relocatable object with correct symbol visibility
add_custom_command(TARGET onnxruntime POST_BUILD
COMMAND ld ARGS -r -o ${STATIC_LIB_DIR}/prelinked_objects.o */*.o ../*.a
COMMAND /usr/bin/ld ARGS -r -o ${STATIC_LIB_DIR}/prelinked_objects.o */*.o ../*.a
WORKING_DIRECTORY ${STATIC_LIB_TEMP_DIR})
# create the static library
add_custom_command(TARGET onnxruntime POST_BUILD
COMMAND libtool -static -o ${STATIC_FRAMEWORK_DIR}/onnxruntime prelinked_objects.o
COMMAND /usr/bin/libtool -static -o ${STATIC_FRAMEWORK_DIR}/onnxruntime prelinked_objects.o
WORKING_DIRECTORY ${STATIC_LIB_DIR})
# Assemble the other pieces of the static framework