Skip to content

Commit 4ca3367

Browse files
committed
Ship libpng and zlib with package on linux
1 parent 45feac1 commit 4ca3367

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

setup.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,12 @@ def get_extensions():
154154
extension(
155155
'torchvision._C',
156156
sources,
157-
libraries= libraries,
157+
libraries=libraries,
158158
library_dirs=third_party_search_directories,
159159
include_dirs=include_dirs + third_party_search_directories,
160160
define_macros=define_macros,
161161
extra_compile_args=extra_compile_args,
162+
runtime_library_dirs=['lib']
162163
)
163164
]
164165
if compile_cpp_tests:
@@ -210,6 +211,7 @@ def run(self):
210211
# It's an old-style class in Python 2.7...
211212
distutils.command.clean.clean.run(self)
212213

214+
213215
def throw_of_failure(command):
214216
ret = os.system(command)
215217
if ret != 0:
@@ -222,22 +224,31 @@ def build_deps():
222224
cpu_count = multiprocessing.cpu_count()
223225
os.chdir("third_party/zlib/")
224226
throw_of_failure('cmake .')
225-
throw_of_failure("cmake --build . --parallel {}".format(cpu_count))
227+
throw_of_failure("cmake --build . -- -j {}".format(cpu_count))
226228
os.chdir(this_dir)
227229

228230
zlib_path = os.path.join(this_dir, "third_party/zlib")
229-
libpng_cmake_options="-DPNG_BUILD_ZLIB=ON -DPNG_STATIC=OFF -DZLIB_INCLUDE_DIR:PATH={zlib_path} -DZLIB_LIBRARY:FILEPATH={zlib_path}/libz.so".format(zlib_path=zlib_path)
231+
libpng_cmake_options = "-DPNG_BUILD_ZLIB=ON -DPNG_STATIC=OFF -DZLIB_INCLUDE_DIR:PATH={zlib_path} -DZLIB_LIBRARY:FILEPATH={zlib_path}/libz.so".format(zlib_path=zlib_path)
230232
os.chdir("third_party/libpng/")
231233
os.system('cmake {} .'.format(libpng_cmake_options))
232-
throw_of_failure("cmake --build . --parallel {}".format(cpu_count))
234+
throw_of_failure("cmake --build . -- -j {}".format(cpu_count))
233235
os.chdir(this_dir)
234236

235237

236-
237238
def build_ext_with_dependencies(self):
238239
build_deps()
239240
return BuildExtension.with_options(no_python_abi_suffix=True)(self)
240241

242+
243+
data_files = []
244+
if sys.platform.startswith('linux'):
245+
data_files = [
246+
('torchvision/lib', [
247+
'third_party/zlib/libz.so',
248+
'third_party/libpng/libpng.so'])
249+
]
250+
251+
241252
setup(
242253
# Metadata
243254
name=package_name,
@@ -261,5 +272,6 @@ def build_ext_with_dependencies(self):
261272
cmdclass={
262273
'build_ext': build_ext_with_dependencies,
263274
'clean': clean,
264-
}
275+
},
276+
data_files=data_files
265277
)

0 commit comments

Comments
 (0)