44# This source code is licensed under the BSD-style license found in the
55# LICENSE file in the root directory of this source tree.
66
7- import distutils . sysconfig
7+
88import os
9- import platform
10- import subprocess
11- import sys
129from pathlib import Path
1310
14- from setuptools .command .build_ext import build_ext
15-
1611
17- __all__ = [
18- "get_ext_modules" ,
19- "CMakeBuild" ,
20- ]
12+ __all__ = ["get_ext_modules" ]
2113
2214
2315_THIS_DIR = Path (__file__ ).parent .resolve ()
@@ -38,96 +30,5 @@ def _get_build(var, default=False):
3830 return False
3931
4032
41- _BUILD_S3 = _get_build ("BUILD_S3" , False )
42- _USE_SYSTEM_AWS_SDK_CPP = _get_build ("USE_SYSTEM_AWS_SDK_CPP" , False )
43- _USE_SYSTEM_PYBIND11 = _get_build ("USE_SYSTEM_PYBIND11" , False )
44- _USE_SYSTEM_LIBS = _get_build ("USE_SYSTEM_LIBS" , False )
45-
46-
47- try :
48- # Use the pybind11 from third_party
49- if not (_USE_SYSTEM_PYBIND11 or _USE_SYSTEM_LIBS ):
50- sys .path .insert (0 , str (_ROOT_DIR / "third_party/pybind11/" ))
51- from pybind11 .setup_helpers import Pybind11Extension
52- except ImportError :
53- from setuptools import Extension as Pybind11Extension
54-
55-
5633def get_ext_modules ():
57- if _BUILD_S3 :
58- return [Pybind11Extension (name = "torchdata._torchdata" , sources = [])]
59- else :
60- return []
61-
62-
63- class CMakeBuild (build_ext ):
64- def run (self ):
65- try :
66- subprocess .check_output (["cmake" , "--version" ])
67- except OSError :
68- raise RuntimeError ("CMake is not available." ) from None
69- super ().run ()
70-
71- def build_extension (self , ext ):
72- # Because the following `cmake` command will build all of `ext_modules`` at the same time,
73- # we would like to prevent multiple calls to `cmake`.
74- # Therefore, we call `cmake` only for `torchdata._torchdata`,
75- # in case `ext_modules` contains more than one module.
76- if ext .name != "torchdata._torchdata" :
77- return
78-
79- extdir = os .path .abspath (os .path .dirname (self .get_ext_fullpath (ext .name )))
80-
81- # required for auto-detection of auxiliary "native" libs
82- if not extdir .endswith (os .path .sep ):
83- extdir += os .path .sep
84-
85- debug = int (os .environ .get ("DEBUG" , 0 )) if self .debug is None else self .debug
86- cfg = "Debug" if debug else "Release"
87-
88- cmake_args = [
89- f"-DCMAKE_BUILD_TYPE={ cfg } " ,
90- f"-DCMAKE_INSTALL_PREFIX={ extdir } " ,
91- f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={ extdir } " ,
92- f"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY={ extdir } " , # For Windows
93- f"-DPython_INCLUDE_DIR={ distutils .sysconfig .get_python_inc ()} " ,
94- f"-DBUILD_S3:BOOL={ 'ON' if _BUILD_S3 else 'OFF' } " ,
95- f"-DUSE_SYSTEM_AWS_SDK_CPP:BOOL={ 'ON' if _USE_SYSTEM_AWS_SDK_CPP else 'OFF' } " ,
96- f"-DUSE_SYSTEM_PYBIND11:BOOL={ 'ON' if _USE_SYSTEM_PYBIND11 else 'OFF' } " ,
97- f"-DUSE_SYSTEM_LIBS:BOOL={ 'ON' if _USE_SYSTEM_LIBS else 'OFF' } " ,
98- ]
99-
100- build_args = ["--config" , cfg ]
101-
102- # Default to Ninja
103- if "CMAKE_GENERATOR" not in os .environ or platform .system () == "Windows" :
104- cmake_args += ["-GNinja" ]
105- if platform .system () == "Windows" :
106- python_version = sys .version_info
107- cmake_args += [
108- "-DCMAKE_C_COMPILER=cl" ,
109- "-DCMAKE_CXX_COMPILER=cl" ,
110- f"-DPYTHON_VERSION={ python_version .major } .{ python_version .minor } " ,
111- ]
112-
113- # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
114- # across all generators.
115- if "CMAKE_BUILD_PARALLEL_LEVEL" not in os .environ :
116- # self.parallel is a Python 3 only way to set parallel jobs by hand
117- # using -j in the build_ext call, not supported by pip or PyPA-build.
118- if hasattr (self , "parallel" ) and self .parallel :
119- # CMake 3.12+ only.
120- build_args += [f"-j{ self .parallel } " ]
121-
122- if not os .path .exists (self .build_temp ):
123- os .makedirs (self .build_temp )
124-
125- subprocess .check_call (["cmake" , str (_ROOT_DIR )] + cmake_args , cwd = self .build_temp )
126- subprocess .check_call (["cmake" , "--build" , "." ] + build_args , cwd = self .build_temp )
127-
128- def get_ext_filename (self , fullname ):
129- ext_filename = super ().get_ext_filename (fullname )
130- ext_filename_parts = ext_filename .split ("." )
131- without_abi = ext_filename_parts [:- 2 ] + ext_filename_parts [- 1 :]
132- ext_filename = "." .join (without_abi )
133- return ext_filename
34+ return []
0 commit comments