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