Skip to content

Commit

Permalink
Fix python compilation on OSX (#58)
Browse files Browse the repository at this point in the history
* Fix python compilation on OSX

* Fix python compilation on OSX
  • Loading branch information
jiangjiajun authored Jul 29, 2022
1 parent ac3fe67 commit 4612159
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
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

0 comments on commit 4612159

Please sign in to comment.