Fix python compilation on OSX (#58)

* Fix python compilation on OSX

* Fix python compilation on OSX
This commit is contained in:
Jason
2022-07-29 16:54:20 +08:00
committed by GitHub
parent ac3fe67d4c
commit 4612159f99
2 changed files with 47 additions and 4 deletions

View File

@@ -15,6 +15,7 @@
#include <map>
#include <vector>
#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

View File

@@ -44,7 +44,8 @@ setup_configs = dict()
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 @@ if sys.argv[1] == "install" or sys.argv[1] == "bdist_wheel":
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 @@ if sys.argv[1] == "install" or sys.argv[1] == "bdist_wheel":
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: