Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python compilation on OSX #58

Merged
merged 3 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion csrcs/fastdeploy/fastdeploy_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <map>
#include <vector>

#include "fastdeploy/backends/backend.h"
#include "fastdeploy/utils/perf.h"

Expand Down Expand Up @@ -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
41 changes: 38 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -370,15 +371,49 @@ 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.
if platform.machine() != 'sw_64' and platform.machine() != 'mips64':
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:
Expand Down