This is an automated email from the ASF dual-hosted git repository.
junrushao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-ffi.git
The following commit(s) were added to refs/heads/main by this push:
new a06d0df [Fix] Remove python lib during building torch c dlpack ext
(#210)
a06d0df is described below
commit a06d0dfa2df9bbc3921d6ba6e6a67dd98ac5510a
Author: Yaoyao Ding <[email protected]>
AuthorDate: Thu Oct 30 17:13:13 2025 -0400
[Fix] Remove python lib during building torch c dlpack ext (#210)
This PR removes the following ldflags when building torch-c-dlpack ext
on linux platform.
```
-L <python-lib-dir> -lpython3
```
to fix https://github.com/apache/tvm-ffi/actions/runs/18935308302
After some trial-and-error, what I've observed:
- on linux, we don't need to link `libtorch_python`, thus there is no
need to link `python.so`
- on macos and windows, both require `libtorch_python`, otherwise there
will be some symbols related to pybind11 not found => raise error. To
link `libtorch_python`, we need python's shared library on these two
platforms.
After this PR:
https://github.com/yaoyaoding/tvm-ffi/actions/runs/18954559833/job/54127883692
---
python/tvm_ffi/utils/_build_optional_torch_c_dlpack.py | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/python/tvm_ffi/utils/_build_optional_torch_c_dlpack.py
b/python/tvm_ffi/utils/_build_optional_torch_c_dlpack.py
index 0c0724c..77900ff 100644
--- a/python/tvm_ffi/utils/_build_optional_torch_c_dlpack.py
+++ b/python/tvm_ffi/utils/_build_optional_torch_c_dlpack.py
@@ -34,6 +34,7 @@ import torch.utils.cpp_extension
# Important: to avoid cyclic dependency, we avoid import tvm_ffi names at top
level here.
IS_WINDOWS = sys.platform == "win32"
+IS_DARWIN = sys.platform == "darwin"
cpp_source = """
#include <dlpack/dlpack.h>
@@ -769,7 +770,7 @@ def main() -> None: # noqa: PLR0912, PLR0915
python_lib = f"python{sys.version_info.major}.lib"
python_libdir_list = [
sysconfig.get_config_var("LIBDIR"),
- sysconfig.get_path("include"),
+ str(Path(sys.base_exec_prefix) / "libs"),
]
if (
sysconfig.get_path("include") is not None
@@ -781,13 +782,13 @@ def main() -> None: # noqa: PLR0912, PLR0915
for python_libdir in python_libdir_list:
if python_libdir and (Path(python_libdir) /
python_lib).exists():
ldflags.append(f"/LIBPATH:{python_libdir.replace(':',
'$:')}")
- ldflags.append(python_lib)
break
- else:
+
+ if IS_DARWIN:
python_libdir = sysconfig.get_config_var("LIBDIR")
if python_libdir:
- ldflags.append(f"-L{python_libdir}")
py_version = f"python{sysconfig.get_python_version()}"
+ ldflags.append(f"-L{python_libdir}")
ldflags.append(f"-l{py_version}")
# generate ninja build file