Skip to content

Commit

Permalink
Add standalone_crt/ to be part of the wheel package, when available. (#…
Browse files Browse the repository at this point in the history
…9005)

* When using a packaged TVM such as tlcpack, it is impossible to run
  `tvm.micro.get_standalone_crt_dir()`, because the subtree
  `standalone_crt/` is not available.

* This patch adds `standalone_crt/` as `data_files`, so that they
  can be picked up by _ffi.libinfo.find_lib_path() and therefore
  be found when `tvm.micro.get_standalone_crt_dir()` is invoked.
  • Loading branch information
leandron committed Sep 15, 2021
1 parent 98ecefb commit 2aebd33
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,22 @@ def get_lib_path():
if not CONDA_BUILD:
lib_path = libinfo["find_lib_path"]()
libs = [lib_path[0]]
if libs[0].find("runtime") == -1:
if "runtime" not in libs[0]:
for name in lib_path[1:]:
if name.find("runtime") != -1:
if "runtime" in name:
libs.append(name)
break

# Add standalone_crt, if present
for name in lib_path:
candidate_path = os.path.join(os.path.dirname(name), "standalone_crt")
if os.path.isdir(candidate_path):
libs.append(candidate_path)
break

else:
libs = None

return libs, version


Expand Down Expand Up @@ -154,9 +163,16 @@ def is_pure(self):
if wheel_include_libs:
with open("MANIFEST.in", "w") as fo:
for path in LIB_LIST:
shutil.copy(path, os.path.join(CURRENT_DIR, "tvm"))
_, libname = os.path.split(path)
fo.write("include tvm/%s\n" % libname)
if os.path.isfile(path):
shutil.copy(path, os.path.join(CURRENT_DIR, "tvm"))
_, libname = os.path.split(path)
fo.write(f"include tvm/{libname}%s")

if os.path.isdir(path):
_, libname = os.path.split(path)
shutil.copytree(path, os.path.join(CURRENT_DIR, "tvm", libname))
fo.write(f"recursive-include tvm/{libname} *\n")

setup_kwargs = {"include_package_data": True}

if include_libs:
Expand Down Expand Up @@ -206,4 +222,10 @@ def get_package_data_files():
os.remove("MANIFEST.in")
for path in LIB_LIST:
_, libname = os.path.split(path)
os.remove("tvm/%s" % libname)
path_to_be_removed = f"tvm/{libname}"

if os.path.isfile(path_to_be_removed):
os.remove(path_to_be_removed)

if os.path.isdir(path_to_be_removed):
shutil.rmtree(path_to_be_removed)

0 comments on commit 2aebd33

Please sign in to comment.