Skip to content

Commit e736e78

Browse files
committed
Revert "Statically linking zlib and libpng"
This reverts commit f7bc8a4.
1 parent 0033a3a commit e736e78

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

setup.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ def get_extensions():
9393
extra_compile_args = {}
9494
third_party_search_directories = []
9595

96-
extra_objects = []
97-
if sys.platform.startswith('linux') or sys.platform.startswith("darwin"):
96+
runtime_library_dirs = None
97+
if sys.platform.startswith('linux') or sys.platform.startswith('darwin'):
9898
sources = sources + source_image_cpu
9999
libraries.append('png')
100100
third_party_search_directories.append(os.path.join(cwd, "third_party/libpng"))
101-
extra_objects = ['third_party/zlib/libz.a', 'third_party/libpng/libpng.a']
101+
runtime_library_dirs = ['lib']
102102

103103
extension = CppExtension
104104

@@ -116,6 +116,7 @@ def get_extensions():
116116

117117
define_macros = []
118118

119+
extra_compile_args = {}
119120
if (torch.cuda.is_available() and CUDA_HOME is not None) or os.getenv('FORCE_CUDA', '0') == '1':
120121
extension = CUDAExtension
121122
sources += source_cuda
@@ -160,7 +161,7 @@ def get_extensions():
160161
include_dirs=include_dirs + third_party_search_directories,
161162
define_macros=define_macros,
162163
extra_compile_args=extra_compile_args,
163-
extra_objects=extra_objects
164+
runtime_library_dirs=runtime_library_dirs
164165
)
165166
]
166167
if compile_cpp_tests:
@@ -230,11 +231,11 @@ def build_deps():
230231

231232
zlib_path = os.path.join(this_dir, "third_party/zlib")
232233
if sys.platform.startswith("linux"):
233-
libpng_cmake_options = "-DPNG_BUILD_ZLIB=ON -DPNG_STATIC=ON -DZLIB_INCLUDE_DIR:PATH={zlib_path} -DZLIB_LIBRARY:FILEPATH={zlib_path}/libz.so".format(zlib_path=zlib_path)
234+
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)
234235
if sys.platform.startswith("darwin"):
235-
libpng_cmake_options = "-DPNG_BUILD_ZLIB=ON -DPNG_STATIC=ON -DZLIB_INCLUDE_DIR:PATH={zlib_path} -DZLIB_LIBRARY:FILEPATH={zlib_path}/libz.dylib".format(zlib_path=zlib_path)
236+
libpng_cmake_options = "-DPNG_BUILD_ZLIB=ON -DPNG_STATIC=OFF -DZLIB_INCLUDE_DIR:PATH={zlib_path} -DZLIB_LIBRARY:FILEPATH={zlib_path}/libz.dylib".format(zlib_path=zlib_path)
236237
os.chdir("third_party/libpng/")
237-
os.system('cmake -DCMAKE_C_FLAGS="-fPIC" {} .'.format(libpng_cmake_options))
238+
os.system('cmake {} .'.format(libpng_cmake_options))
238239
throw_of_failure("cmake --build . -- -j {}".format(cpu_count))
239240
os.chdir(this_dir)
240241

@@ -244,6 +245,22 @@ def build_ext_with_dependencies(self):
244245
return BuildExtension.with_options(no_python_abi_suffix=True)(self)
245246

246247

248+
data_files = []
249+
if sys.platform.startswith('linux'):
250+
data_files = [
251+
('torchvision/lib', [
252+
'third_party/zlib/libz.so',
253+
'third_party/libpng/libpng.so'])
254+
]
255+
256+
if sys.platform.startswith('darwin'):
257+
data_files = [
258+
('torchvision/lib', [
259+
'third_party/zlib/libz.dylib',
260+
'third_party/libpng/libpng.dylib'])
261+
]
262+
263+
247264
setup(
248265
# Metadata
249266
name=package_name,
@@ -268,4 +285,5 @@ def build_ext_with_dependencies(self):
268285
'build_ext': build_ext_with_dependencies,
269286
'clean': clean,
270287
},
288+
data_files=data_files
271289
)

0 commit comments

Comments
 (0)