Skip to content

Commit 2aebd33

Browse files
authored
Add standalone_crt/ to be part of the wheel package, when available. (#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.
1 parent 98ecefb commit 2aebd33

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

python/setup.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,22 @@ def get_lib_path():
4949
if not CONDA_BUILD:
5050
lib_path = libinfo["find_lib_path"]()
5151
libs = [lib_path[0]]
52-
if libs[0].find("runtime") == -1:
52+
if "runtime" not in libs[0]:
5353
for name in lib_path[1:]:
54-
if name.find("runtime") != -1:
54+
if "runtime" in name:
5555
libs.append(name)
5656
break
57+
58+
# Add standalone_crt, if present
59+
for name in lib_path:
60+
candidate_path = os.path.join(os.path.dirname(name), "standalone_crt")
61+
if os.path.isdir(candidate_path):
62+
libs.append(candidate_path)
63+
break
64+
5765
else:
5866
libs = None
67+
5968
return libs, version
6069

6170

@@ -154,9 +163,16 @@ def is_pure(self):
154163
if wheel_include_libs:
155164
with open("MANIFEST.in", "w") as fo:
156165
for path in LIB_LIST:
157-
shutil.copy(path, os.path.join(CURRENT_DIR, "tvm"))
158-
_, libname = os.path.split(path)
159-
fo.write("include tvm/%s\n" % libname)
166+
if os.path.isfile(path):
167+
shutil.copy(path, os.path.join(CURRENT_DIR, "tvm"))
168+
_, libname = os.path.split(path)
169+
fo.write(f"include tvm/{libname}%s")
170+
171+
if os.path.isdir(path):
172+
_, libname = os.path.split(path)
173+
shutil.copytree(path, os.path.join(CURRENT_DIR, "tvm", libname))
174+
fo.write(f"recursive-include tvm/{libname} *\n")
175+
160176
setup_kwargs = {"include_package_data": True}
161177

162178
if include_libs:
@@ -206,4 +222,10 @@ def get_package_data_files():
206222
os.remove("MANIFEST.in")
207223
for path in LIB_LIST:
208224
_, libname = os.path.split(path)
209-
os.remove("tvm/%s" % libname)
225+
path_to_be_removed = f"tvm/{libname}"
226+
227+
if os.path.isfile(path_to_be_removed):
228+
os.remove(path_to_be_removed)
229+
230+
if os.path.isdir(path_to_be_removed):
231+
shutil.rmtree(path_to_be_removed)

0 commit comments

Comments
 (0)