Skip to content

Commit 6b3cbaf

Browse files
Fix for wheel build (#74)
1 parent c6a9309 commit 6b3cbaf

1 file changed

Lines changed: 4 additions & 65 deletions

File tree

setup.py

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
6767
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
6868
f"-DPYTHON_EXECUTABLE={sys.executable}",
6969
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
70+
f"-DTORCH_CMAKE_PREFIX_PATH={torch.utils.cmake_prefix_path}",
7071
]
7172
build_args = []
7273
# Adding CMake arguments set as environment variable
@@ -149,69 +150,6 @@ def build_extension(self, ext: CMakeExtension) -> None:
149150
check=True)
150151

151152

152-
def build_custom_kernels():
153-
compiled_lib_filename = "libCustomOps.so"
154-
c_source_base_subdir = "csrc"
155-
custom_ops_module_subdir = "custom_ops"
156-
build_artefacts_subdir = "build"
157-
python_package_name = "arctic_inference" # Your package directory name
158-
159-
try:
160-
project_root_dir = Path(__file__).resolve().parent
161-
except NameError:
162-
project_root_dir = Path.cwd()
163-
164-
cpp_custom_ops_source_dir = project_root_dir / c_source_base_subdir / custom_ops_module_subdir
165-
build_output_dir = cpp_custom_ops_source_dir / build_artefacts_subdir
166-
target_so_path_in_package_source = project_root_dir / python_package_name / compiled_lib_filename
167-
168-
target_so_path_in_package_source.parent.mkdir(parents=True, exist_ok=True)
169-
build_output_dir.mkdir(parents=True, exist_ok=True)
170-
171-
torch_cmake_prefix = torch.utils.cmake_prefix_path
172-
cmake_configure_command = [
173-
"cmake", f"-DTORCH_CMAKE_PREFIX_PATH={torch_cmake_prefix}", ".."
174-
]
175-
subprocess.run(cmake_configure_command,
176-
cwd=build_output_dir,
177-
check=True,
178-
capture_output=True)
179-
180-
num_cpu_cores = os.cpu_count() or 1
181-
make_build_command = ["make", f"-j{num_cpu_cores}"]
182-
subprocess.run(make_build_command,
183-
cwd=build_output_dir,
184-
check=True,
185-
capture_output=True)
186-
187-
compiled_library_file_path = build_output_dir / compiled_lib_filename
188-
189-
if not compiled_library_file_path.exists():
190-
raise FileNotFoundError(
191-
f"Compiled library {compiled_library_file_path.resolve()} not found after build."
192-
)
193-
194-
if target_so_path_in_package_source.exists(
195-
) or target_so_path_in_package_source.is_symlink():
196-
try:
197-
target_so_path_in_package_source.unlink(missing_ok=True)
198-
except TypeError:
199-
if target_so_path_in_package_source.exists(
200-
) or target_so_path_in_package_source.is_symlink():
201-
target_so_path_in_package_source.unlink()
202-
except OSError as e:
203-
if target_so_path_in_package_source.is_dir():
204-
shutil.rmtree(target_so_path_in_package_source)
205-
else:
206-
raise OSError(
207-
f"Error removing {target_so_path_in_package_source.resolve()}: {e}"
208-
) from e
209-
210-
shutil.copy2(compiled_library_file_path, target_so_path_in_package_source)
211-
212-
return compiled_lib_filename
213-
214-
215153
class CompileGrpc(_build_py):
216154
"""Custom build command to compile .proto files before building."""
217155

@@ -227,8 +165,9 @@ def run(self):
227165
setup(
228166
ext_modules=[
229167
CMakeExtension("arctic_inference.common.suffix_cache._C",
230-
"csrc/suffix_cache")
168+
"csrc/suffix_cache"),
169+
CMakeExtension("arctic_inference.custom_ops",
170+
"csrc/custom_ops"),
231171
],
232172
cmdclass={"build_ext": CMakeBuild, 'build_py': CompileGrpc},
233-
package_data={"arctic_inference": [build_custom_kernels()]},
234173
)

0 commit comments

Comments
 (0)