|
1 | 1 | import os |
| 2 | +import sys |
2 | 3 | import shutil |
3 | 4 | import struct |
4 | 5 | from subprocess import run |
5 | 6 |
|
6 | 7 | from setuptools import Extension, find_packages |
7 | 8 | from setuptools.dist import Distribution |
| 9 | +from setuptools.command.build_ext import build_ext |
8 | 10 | from pathlib import Path |
9 | 11 | from io import BytesIO |
10 | 12 | from zipfile import ZipFile |
|
92 | 94 | runtime_library_dirs = None |
93 | 95 | extra_link_args = None |
94 | 96 | elif platform.system() == 'Darwin': |
95 | | - runtime_library_dirs = None |
96 | | - extra_link_args = [f'-Wl,-rpath,@loader_path/dxfeed/core', f'-Wl,-rpath,.', f'-Wl,-rpath,{str(capi_bin_dir)}'] |
97 | | - capi_full_library_file_path = capi_bin_dir / capi_library_file_name |
98 | | - run(('install_name_tool', '-id', f'@rpath/{capi_library_file_name}', str(capi_full_library_file_path))) |
| 97 | + runtime_library_dirs = ['.', str(capi_bin_dir)] |
| 98 | + extra_link_args = None # [f'-Wl,-rpath,@loader_path/dxfeed/core', f'-Wl,-rpath,.', f'-Wl,-rpath,{str(capi_bin_dir)}'] |
| 99 | + # capi_full_library_file_path = capi_bin_dir / capi_library_file_name |
| 100 | + # run(('install_name_tool', '-id', f'@rpath/{capi_library_file_name}', str(capi_full_library_file_path))) |
99 | 101 | else: |
100 | | - runtime_library_dirs = ["$ORIGIN", '.', str(capi_bin_dir)] |
| 102 | + runtime_library_dirs = ['$ORIGIN', '.', str(capi_bin_dir)] |
101 | 103 | extra_link_args = None |
102 | 104 |
|
103 | 105 | capi_include_dirs = [str(capi_include_dir)] |
|
122 | 124 | extensions = cythonize(extensions, language_level=3) |
123 | 125 |
|
124 | 126 |
|
| 127 | +class custom_build_ext(build_ext): |
| 128 | + """ |
| 129 | + Add appropriate rpath linker flags (necessary on mac) |
| 130 | + """ |
| 131 | + |
| 132 | + def finalize_options(self): |
| 133 | + super().finalize_options() |
| 134 | + # Special treatment of rpath in case of OSX, to work around python |
| 135 | + # distutils bug 36353. This constructs proper rpath arguments for clang. |
| 136 | + # See https://bugs.python.org/issue36353 |
| 137 | + # Workaround from https://github.com/python/cpython/pull/12418 |
| 138 | + if sys.platform[:6] == "darwin": |
| 139 | + for path in self.rpath: |
| 140 | + for ext in self.extensions: |
| 141 | + ext.extra_link_args.append("-Wl,-rpath," + path) |
| 142 | + self.rpath[:] = [] |
| 143 | + |
| 144 | + |
125 | 145 | def build(setup_kwargs): |
126 | 146 | setup_kwargs.update({ |
| 147 | + 'cmdclass': {'build_ext': custom_build_ext}, |
127 | 148 | 'ext_modules': extensions, |
128 | 149 | 'zip_safe': False, |
129 | 150 | 'packages': find_packages(), |
|
0 commit comments