Skip to content

Commit 5501b06

Browse files
committed
fix issue of not allowing pybind off
1 parent ba49d9a commit 5501b06

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

install_executorch.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import subprocess
1616
import sys
1717
from contextlib import contextmanager
18-
from typing import List
18+
from typing import List, Tuple
1919

2020
from install_requirements import (
2121
install_requirements,
@@ -169,13 +169,19 @@ def build_args_parser() -> argparse.ArgumentParser:
169169
return parser
170170

171171

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+
174177
# Flatten list of lists.
175178
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, []
178183

184+
cmake_args = []
179185
for pybind_arg in args.pybind:
180186
if pybind_arg not in VALID_PYBINDS:
181187
raise Exception(
@@ -186,7 +192,7 @@ def _list_pybind_defines(args) -> List[str]:
186192
else:
187193
cmake_args.append(f"-DEXECUTORCH_BUILD_{pybind_arg.upper()}=ON")
188194

189-
return cmake_args
195+
return False, cmake_args
190196

191197

192198
def main(args):
@@ -196,15 +202,23 @@ def main(args):
196202
parser = build_args_parser()
197203
args = parser.parse_args()
198204

199-
has_pybindings = False
200205
cmake_args = [os.getenv("CMAKE_ARGS", "")]
201206
use_pytorch_nightly = True
202207

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
205212
if len(pybind_defines) > 0:
206-
has_pybindings = True
213+
# If the user explicitly provides a list of bindings, just use them
207214
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")
208222

209223
if args.clean:
210224
clean()
@@ -216,13 +230,6 @@ def main(args):
216230
# latest PT commit otherwise
217231
use_pytorch_nightly = False
218232

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-
226233
# Use ClangCL on Windows.
227234
# ClangCL is an alias to Clang that configures it to work in an MSVC-compatible
228235
# mode. Using it on Windows to avoid compiler compatibility issues for MSVC.
@@ -236,9 +243,6 @@ def main(args):
236243
#
237244

238245
# Set environment variables
239-
if has_pybindings:
240-
cmake_args.append("-DEXECUTORCH_BUILD_PYBIND=ON")
241-
242246
os.environ["CMAKE_ARGS"] = " ".join(cmake_args)
243247

244248
# Check if the required submodules are present and update them if not

0 commit comments

Comments
 (0)