Skip to content

Commit 938920c

Browse files
authored
Merge pull request #12020 from typhoonzero/fix_mac_whl_packaging
fix mac build and whl pkg
2 parents 26ae611 + 81d3829 commit 938920c

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ if(ANDROID OR IOS)
103103
add_definitions(-DPADDLE_MOBILE_INFERENCE)
104104
endif()
105105

106+
if (APPLE OR WIN32)
107+
set(WITH_MKL OFF CACHE STRING
108+
"Disable MKL for building on mac and windows" FORCE)
109+
endif()
110+
106111
set(THIRD_PARTY_PATH "${CMAKE_BINARY_DIR}/third_party" CACHE STRING
107112
"A path setting third party libraries download & build directories.")
108113

paddle/contrib/inference/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ cc_library(paddle_inference_api
4949
# Here the shared library doesn't depend on other fluid libraries, or double free will occur.
5050
cc_library(paddle_inference_api_shared SHARED
5151
SRCS paddle_inference_api.cc paddle_inference_api_impl.cc)
52+
add_dependencies(paddle_inference_api_shared ${FLUID_CORE_MODULES} ${GLOB_OP_LIB})
5253
set_target_properties(paddle_inference_api_shared PROPERTIES OUTPUT_NAME paddle_inference_api)
54+
5355
if(NOT APPLE)
5456
set(LINK_FLAGS "-fPIC -fvisibility=hidden")
5557
set_target_properties(paddle_inference_api_shared PROPERTIES LINK_FLAGS "${LINK_FLAGS}")

python/setup.py.in

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,15 @@ if '${WITH_MKL}' == 'ON':
156156
shutil.copy('${MKLML_IOMP_LIB}', libs_path)
157157
package_data['paddle.libs']+=['libmklml_intel.so','libiomp5.so']
158158
if '${WITH_MKLDNN}' == 'ON':
159+
# TODO(typhoonzero): use install_name_tool to patch mkl libs once
160+
# we can support mkl on mac.
161+
#
159162
# change rpath of libmkldnn.so.0, add $ORIGIN/ to it.
160163
# The reason is that all thirdparty libraries in the same directory,
161164
# thus, libmkldnn.so.0 will find libmklml_intel.so and libiomp5.so.
162165
command = "patchelf --set-rpath '$ORIGIN/' ${MKLDNN_SHARED_LIB}"
163166
if os.system(command) != 0:
164-
raise Exception("patchelf --set-rpath for libmkldnn.so.0 fails")
167+
raise Exception("patch libmkldnn.so failed, command: %s" % command)
165168
package_data['paddle.libs']+=['libmkldnn.so.0']
166169
shutil.copy('${MKLDNN_SHARED_LIB}', libs_path)
167170
# remove unused paddle/libs/__init__.py
@@ -172,9 +175,12 @@ package_dir['paddle.libs']=libs_path
172175
# The reason is that libwarpctc.so, libiomp5.so etc are in paddle.libs, and
173176
# core.so is in paddle.fluid, thus paddle/fluid/../libs will pointer to above libraries.
174177
# This operation will fix https://github.com/PaddlePaddle/Paddle/issues/3213
175-
command = "patchelf --set-rpath '$ORIGIN/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/core.so"
178+
if "@APPLE@" == "1":
179+
command = "install_name_tool -id \"@loader_path/../libs/\" ${PADDLE_BINARY_DIR}/python/paddle/fluid/core.so"
180+
else:
181+
command = "patchelf --set-rpath '$ORIGIN/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/core.so"
176182
if os.system(command) != 0:
177-
raise Exception("patchelf --set-rpath for core.so fails")
183+
raise Exception("patch core.so failed, command: %s" % command)
178184

179185
setup(name='${PACKAGE_NAME}',
180186
version='${PADDLE_VERSION}',

0 commit comments

Comments
 (0)