15
15
import subprocess
16
16
import sys
17
17
from contextlib import contextmanager
18
- from typing import List
18
+ from dataclasses import dataclass
19
+ from typing import List , Tuple
19
20
20
21
from install_requirements import (
21
22
install_requirements ,
@@ -169,13 +170,19 @@ def build_args_parser() -> argparse.ArgumentParser:
169
170
return parser
170
171
171
172
172
- def _list_pybind_defines (args ) -> List [str ]:
173
- cmake_args = []
173
+ # Returns (wants_off, wanted_pybindings)
174
+ def _list_pybind_defines (args ) -> Tuple [bool , List [str ]]:
175
+ if args .pybind is None :
176
+ return False , []
177
+
174
178
# Flatten list of lists.
175
179
args .pybind = list (itertools .chain (* args .pybind ))
176
- if ("off" in args .pybind ) and (len (args .pybind ) != 1 ):
177
- raise Exception (f"Cannot combine `off` with other pybinds: { args .pybind } " )
180
+ if "off" in args .pybind :
181
+ if len (args .pybind ) != 1 :
182
+ raise Exception (f"Cannot combine `off` with other pybinds: { args .pybind } " )
183
+ return True , []
178
184
185
+ cmake_args = []
179
186
for pybind_arg in args .pybind :
180
187
if pybind_arg not in VALID_PYBINDS :
181
188
raise Exception (
@@ -186,7 +193,7 @@ def _list_pybind_defines(args) -> List[str]:
186
193
else :
187
194
cmake_args .append (f"-DEXECUTORCH_BUILD_{ pybind_arg .upper ()} =ON" )
188
195
189
- return cmake_args
196
+ return False , cmake_args
190
197
191
198
192
199
def main (args ):
@@ -196,15 +203,23 @@ def main(args):
196
203
parser = build_args_parser ()
197
204
args = parser .parse_args ()
198
205
199
- has_pybindings = False
200
206
cmake_args = [os .getenv ("CMAKE_ARGS" , "" )]
201
207
use_pytorch_nightly = True
202
208
203
- if args .pybind :
204
- pybind_defines = _list_pybind_defines (args )
209
+ has_pybindings = False
210
+ wants_pybindings_off , pybind_defines = _list_pybind_defines (args )
211
+ if not wants_pybindings_off :
212
+ has_pybindings = True
205
213
if len (pybind_defines ) > 0 :
206
- has_pybindings = True
214
+ # If the user explicitly provides a list of bindings, just use them
207
215
cmake_args += pybind_defines
216
+ else :
217
+ # If the user has not set pybindings off but also has not provided
218
+ # a list, then turn on xnnpack by default
219
+ cmake_args .append ("-DEXECUTORCH_BUILD_XNNPACK=ON" )
220
+
221
+ if has_pybindings :
222
+ cmake_args .append ("-DEXECUTORCH_BUILD_PYBIND=ON" )
208
223
209
224
if args .clean :
210
225
clean ()
@@ -216,13 +231,6 @@ def main(args):
216
231
# latest PT commit otherwise
217
232
use_pytorch_nightly = False
218
233
219
- # If --pybind is not set explicitly for backends (e.g., --pybind xnnpack)
220
- # or is not turned off explicitly (--pybind off)
221
- # then install XNNPACK by default.
222
- if not has_pybindings :
223
- has_pybindings = True
224
- cmake_args .append ("-DEXECUTORCH_BUILD_XNNPACK=ON" )
225
-
226
234
# Use ClangCL on Windows.
227
235
# ClangCL is an alias to Clang that configures it to work in an MSVC-compatible
228
236
# mode. Using it on Windows to avoid compiler compatibility issues for MSVC.
@@ -236,9 +244,6 @@ def main(args):
236
244
#
237
245
238
246
# Set environment variables
239
- if has_pybindings :
240
- cmake_args .append ("-DEXECUTORCH_BUILD_PYBIND=ON" )
241
-
242
247
os .environ ["CMAKE_ARGS" ] = " " .join (cmake_args )
243
248
244
249
# Check if the required submodules are present and update them if not
0 commit comments