From 02783250555b52515b627148bd998221334bd770 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Fri, 24 Jul 2020 11:22:39 +0800 Subject: [PATCH] fix(python/import/macos): fix some macos user import crash GitOrigin-RevId: b701710b743d1384606a9d6bdbd62e4a1ddcc4d3 --- python_module/CMakeLists.txt | 1 + scripts/whl/macos/macos_build_whl.sh | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/python_module/CMakeLists.txt b/python_module/CMakeLists.txt index 2789d01ad..e98421397 100644 --- a/python_module/CMakeLists.txt +++ b/python_module/CMakeLists.txt @@ -68,6 +68,7 @@ add_custom_target(version_ld SOURCES ${VERSION_SCRIPT}) set_target_properties(mgb PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/megengine/_internal) if (APPLE) target_link_libraries(mgb megbrain megdnn) + set_target_properties(mgb PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") else() target_link_libraries(mgb megbrain megdnn -Wl,--version-script=${VERSION_SCRIPT}) endif() diff --git a/scripts/whl/macos/macos_build_whl.sh b/scripts/whl/macos/macos_build_whl.sh index 105fe931d..c430e29f7 100755 --- a/scripts/whl/macos/macos_build_whl.sh +++ b/scripts/whl/macos/macos_build_whl.sh @@ -65,17 +65,15 @@ function config_python_env() { fi echo ${ver} + #config a dir to trick cmake find a null pythonlib + PYTHON_LIBRARY=${PYTHON_DIR}lib/ if [ "$1" = "3.5.9" ]; then - PYTHON_LIBRARY=${PYTHON_DIR}lib/libpython3.5m.dylib PYTHON_INCLUDE_DIR=${PYTHON_DIR}include/python3.5m elif [ "$1" = "3.6.10" ]; then - PYTHON_LIBRARY=${PYTHON_DIR}lib/libpython3.6m.dylib PYTHON_INCLUDE_DIR=${PYTHON_DIR}include/python3.6m elif [ "$1" = "3.7.7" ]; then - PYTHON_LIBRARY=${PYTHON_DIR}lib/libpython3.7m.dylib PYTHON_INCLUDE_DIR=${PYTHON_DIR}include/python3.7m elif [ "$1" = "3.8.3" ]; then - PYTHON_LIBRARY=${PYTHON_DIR}lib/libpython3.8.dylib PYTHON_INCLUDE_DIR=${PYTHON_DIR}include/python3.8 else echo "ERR: DO NOT SUPPORT PYTHON VERSION" @@ -91,7 +89,7 @@ function do_build() { config_python_env ${ver} #check env - if [ ! -f "$PYTHON_LIBRARY" ]; then + if [ ! -d "$PYTHON_LIBRARY" ]; then echo "ERR: can not find $PYTHON_LIBRARY , Invalid python package" err_env fi @@ -131,7 +129,16 @@ function do_build() { llvm-strip -s _mgb.so cd ${BUILD_DIR}/staging ${PYTHON_DIR}/bin/python3 setup.py bdist_wheel - cp ${BUILD_DIR}/staging/dist/Meg*.whl ${MACOS_WHL_HOME}/ + cd ${BUILD_DIR}/staging/dist/ + org_whl_name=`ls Meg*.whl` + index=`awk -v a="${org_whl_name}" -v b="-macosx" 'BEGIN{print index(a,b)}'` + #compat for osx version from 10.5(Leopard) + #FIXME: same no need at -macosx-version-min=10.5 for build so + compat_whl_name=`echo ${org_whl_name} |cut -b -$index`macosx_10_5_x86_64.whl + echo "org whl name: ${org_whl_name}" + echo "comapt whl name: ${compat_whl_name}" + cp ${BUILD_DIR}/staging/dist/Meg*.whl ${MACOS_WHL_HOME}/${compat_whl_name} + cd ${SRC_DIR} echo "" echo "##############################################################################################" -- GitLab