From 4612159f995d605337daa69cdb3dda5a578485e6 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 29 Jul 2022 16:54:20 +0800 Subject: [PATCH] Fix python compilation on OSX (#58) * Fix python compilation on OSX * Fix python compilation on OSX --- csrcs/fastdeploy/fastdeploy_runtime.h | 10 ++++++- setup.py | 41 +++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/csrcs/fastdeploy/fastdeploy_runtime.h b/csrcs/fastdeploy/fastdeploy_runtime.h index 32ca7ab106..1dc5da099c 100644 --- a/csrcs/fastdeploy/fastdeploy_runtime.h +++ b/csrcs/fastdeploy/fastdeploy_runtime.h @@ -15,6 +15,7 @@ #include #include + #include "fastdeploy/backends/backend.h" #include "fastdeploy/utils/perf.h" @@ -152,7 +153,14 @@ struct FASTDEPLOY_DECL Runtime { RuntimeOption option; + ~Runtime() { + if (backend_ != nullptr) { + delete backend_; + backend_ = nullptr; + } + } + private: - BaseBackend* backend_; + BaseBackend* backend_ = nullptr; }; } // namespace fastdeploy diff --git a/setup.py b/setup.py index 7c549fe604..fcaaa9f376 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,8 @@ setup_configs["ENABLE_PADDLE_FRONTEND"] = os.getenv("ENABLE_PADDLE_FRONTEND", "ON") setup_configs["ENABLE_ORT_BACKEND"] = os.getenv("ENABLE_ORT_BACKEND", "ON") -setup_configs["ENABLE_PADDLE_BACKEND"] = os.getenv("ENABLE_PADDLE_BACKEND", "OFF") +setup_configs["ENABLE_PADDLE_BACKEND"] = os.getenv("ENABLE_PADDLE_BACKEND", + "OFF") setup_configs["BUILD_DEMO"] = os.getenv("BUILD_DEMO", "ON") setup_configs["ENABLE_VISION"] = os.getenv("ENABLE_VISION", "ON") setup_configs["ENABLE_TRT_BACKEND"] = os.getenv("ENABLE_TRT_BACKEND", "OFF") @@ -370,8 +371,8 @@ def run(self): path = os.path.relpath( os.path.join(root, d), ".setuptools-cmake-build/third_libs/install") - rpaths.append("$ORIGIN/" + os.path.join( - "libs/third_libs", path)) + rpaths.append("$ORIGIN/" + os.path.join("libs/third_libs", + path)) rpaths = ":".join(rpaths) command = "patchelf --set-rpath '{}' ".format(rpaths) + pybind_so_file # The sw_64 not suppot patchelf, so we just disable that. @@ -379,6 +380,40 @@ def run(self): assert os.system( command) == 0, "patchelf {} failed, the command: {}".format( command, pybind_so_file) + elif platform.system().lower() == "darwin": + pre_commands = [ + "install_name_tool -delete_rpath '@loader_path/libs' " + + pybind_so_file + ] + commands = [ + "install_name_tool -id '@loader_path/libs' " + pybind_so_file + ] + commands.append("install_name_tool -add_rpath '@loader_path/libs' " + + pybind_so_file) + for root, dirs, files in os.walk( + ".setuptools-cmake-build/third_libs/install"): + for d in dirs: + if d == "lib": + path = os.path.relpath( + os.path.join(root, d), + ".setuptools-cmake-build/third_libs/install") + pre_commands.append( + "install_name_tool -delete_rpath '@loader_path/{}' ". + format(os.path.join("libs/third_libs", + path)) + pybind_so_file) + commands.append( + "install_name_tool -add_rpath '@loader_path/{}' ". + format(os.path.join("libs/third_libs", + path)) + pybind_so_file) + for command in pre_commands: + try: + os.system(command) + except: + print("Skip execute command: " + command) + for command in commands: + assert os.system( + command) == 0, "command execute failed! command: {}".format( + command) all_files = get_all_files("fastdeploy/libs") for f in all_files: