Skip to content

[Bug] DSO path finding should not depend on hardcoded paths #250

@junrushao

Description

@junrushao

Current path finding for libtvm_ffi.so and libtvm_ffi_testing.so heavily depends on hardcoded paths. More concretely, assuming build/lib as part of the path for editable development.

dll_path: list[Path] = [ffi_dir / "lib"]
dll_path.append(ffi_dir / ".." / ".." / "build" / "lib")
# in source build from parent if needed
dll_path.append(ffi_dir / ".." / ".." / ".." / "build" / "lib")

However, this is not an optimal strategy for editable builds, because:

  1. build directory could be different than build/, e.g. build-release, build/release, etc.
  2. the actual .so files are actually installed into Python's site-packages directory by scikit-build-core. The .so files can get outdated or mismatch inside build/

Let's switch to a more standard practice in this case for both apache-tvm-ffi and the example extension in my_ffi_extension under examples/packaging, by using the snippet below:

import importlib.metadata as im

def find_files(
  package: str,  # pass in `__package__`
  stem: str  # pass in `tvm_ffi`, so that it finds `lib{stem}.so`, `lib{stem}.so`, `{stem}.dll`
):
    owners: list[str] = im.packages_distributions().get(package)
    pkg = owners[0] if owners else package.replace("_", "-")
    for pth in im.files(pkg):
        print("File: ", pth.locate())
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions