15
15
import subprocess
16
16
import sys
17
17
from contextlib import contextmanager
18
+ from typing import List
18
19
19
20
from install_requirements import (
20
21
install_requirements ,
@@ -168,28 +169,24 @@ def build_args_parser() -> argparse.ArgumentParser:
168
169
return parser
169
170
170
171
171
- def handle_pybind (args , cmake_args , executorch_build_pybind ):
172
+ def _list_pybind_defines (args ) -> List [str ]:
173
+ cmake_args = []
172
174
# Flatten list of lists.
173
175
args .pybind = list (itertools .chain (* args .pybind ))
174
- if "off" in args .pybind :
175
- if len (args .pybind ) != 1 :
176
- raise Exception (f"Cannot combine `off` with other pybinds: { args .pybind } " )
177
- executorch_build_pybind = "OFF"
178
- else :
179
- for pybind_arg in args .pybind :
180
- if pybind_arg not in VALID_PYBINDS :
181
- raise Exception (
182
- f"Unrecognized pybind argument { pybind_arg } ; valid options are: { ', ' .join (VALID_PYBINDS )} "
183
- )
184
- if pybind_arg == "training" :
185
- cmake_args += " -DEXECUTORCH_BUILD_EXTENSION_TRAINING=ON"
186
- os .environ ["EXECUTORCH_BUILD_TRAINING" ] = "ON"
187
- elif pybind_arg == "mps" :
188
- cmake_args += " -DEXECUTORCH_BUILD_MPS=ON"
189
- else :
190
- cmake_args += f" -DEXECUTORCH_BUILD_{ pybind_arg .upper ()} =ON"
191
- executorch_build_pybind = "ON"
192
- return executorch_build_pybind , cmake_args
176
+ if ("off" in args .pybind ) and (len (args .pybind ) != 1 ):
177
+ raise Exception (f"Cannot combine `off` with other pybinds: { args .pybind } " )
178
+
179
+ for pybind_arg in args .pybind :
180
+ if pybind_arg not in VALID_PYBINDS :
181
+ raise Exception (
182
+ f"Unrecognized pybind argument { pybind_arg } ; valid options are: { ', ' .join (VALID_PYBINDS )} "
183
+ )
184
+ if pybind_arg == "training" :
185
+ cmake_args .append ("-DEXECUTORCH_BUILD_EXTENSION_TRAINING=ON" )
186
+ else :
187
+ cmake_args .append (f"-DEXECUTORCH_BUILD_{ pybind_arg .upper ()} =ON" )
188
+
189
+ return cmake_args
193
190
194
191
195
192
def main (args ):
@@ -199,14 +196,15 @@ def main(args):
199
196
parser = build_args_parser ()
200
197
args = parser .parse_args ()
201
198
202
- EXECUTORCH_BUILD_PYBIND = ""
203
- CMAKE_ARGS = os .getenv ("CMAKE_ARGS" , "" )
199
+ has_pybindings = False
200
+ cmake_args = [ os .getenv ("CMAKE_ARGS" , "" )]
204
201
use_pytorch_nightly = True
205
202
206
203
if args .pybind :
207
- EXECUTORCH_BUILD_PYBIND , CMAKE_ARGS = handle_pybind (
208
- args , CMAKE_ARGS , EXECUTORCH_BUILD_PYBIND
209
- )
204
+ pybind_defines = _list_pybind_defines (args )
205
+ if len (pybind_defines ) > 0 :
206
+ has_pybindings = True
207
+ cmake_args += pybind_defines
210
208
211
209
if args .clean :
212
210
clean ()
@@ -221,15 +219,15 @@ def main(args):
221
219
# If --pybind is not set explicitly for backends (e.g., --pybind xnnpack)
222
220
# or is not turned off explicitly (--pybind off)
223
221
# then install XNNPACK by default.
224
- if EXECUTORCH_BUILD_PYBIND == "" :
225
- EXECUTORCH_BUILD_PYBIND = "ON"
226
- CMAKE_ARGS += " -DEXECUTORCH_BUILD_XNNPACK=ON"
222
+ if not has_pybindings :
223
+ has_pybindings = True
224
+ cmake_args . append ( " -DEXECUTORCH_BUILD_XNNPACK=ON")
227
225
228
226
# Use ClangCL on Windows.
229
227
# ClangCL is an alias to Clang that configures it to work in an MSVC-compatible
230
228
# mode. Using it on Windows to avoid compiler compatibility issues for MSVC.
231
229
if os .name == "nt" :
232
- CMAKE_ARGS += " -T ClangCL"
230
+ cmake_args . append ( " -T ClangCL")
233
231
234
232
#
235
233
# Install executorch pip package. This also makes `flatc` available on the path.
@@ -238,8 +236,10 @@ def main(args):
238
236
#
239
237
240
238
# Set environment variables
241
- os .environ ["EXECUTORCH_BUILD_PYBIND" ] = EXECUTORCH_BUILD_PYBIND
242
- os .environ ["CMAKE_ARGS" ] = CMAKE_ARGS
239
+ if has_pybindings :
240
+ cmake_args .append ("-DEXECUTORCH_BUILD_PYBIND=ON" )
241
+
242
+ os .environ ["CMAKE_ARGS" ] = " " .join (cmake_args )
243
243
244
244
# Check if the required submodules are present and update them if not
245
245
check_and_update_submodules ()
0 commit comments