Skip to content

Commit 6949e35

Browse files
committed
fix issue of not allowing pybind off
1 parent ba49d9a commit 6949e35

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

install_executorch.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import subprocess
1616
import sys
1717
from contextlib import contextmanager
18-
from typing import List
18+
from dataclasses import dataclass
19+
from typing import List, Tuple
1920

2021
from install_requirements import (
2122
install_requirements,
@@ -169,13 +170,19 @@ def build_args_parser() -> argparse.ArgumentParser:
169170
return parser
170171

171172

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+
174178
# Flatten list of lists.
175179
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, []
178184

185+
cmake_args = []
179186
for pybind_arg in args.pybind:
180187
if pybind_arg not in VALID_PYBINDS:
181188
raise Exception(
@@ -186,7 +193,7 @@ def _list_pybind_defines(args) -> List[str]:
186193
else:
187194
cmake_args.append(f"-DEXECUTORCH_BUILD_{pybind_arg.upper()}=ON")
188195

189-
return cmake_args
196+
return False, cmake_args
190197

191198

192199
def main(args):
@@ -196,15 +203,23 @@ def main(args):
196203
parser = build_args_parser()
197204
args = parser.parse_args()
198205

199-
has_pybindings = False
200206
cmake_args = [os.getenv("CMAKE_ARGS", "")]
201207
use_pytorch_nightly = True
202208

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

209224
if args.clean:
210225
clean()
@@ -216,13 +231,6 @@ def main(args):
216231
# latest PT commit otherwise
217232
use_pytorch_nightly = False
218233

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-
226234
# Use ClangCL on Windows.
227235
# ClangCL is an alias to Clang that configures it to work in an MSVC-compatible
228236
# mode. Using it on Windows to avoid compiler compatibility issues for MSVC.
@@ -236,9 +244,6 @@ def main(args):
236244
#
237245

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

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

0 commit comments

Comments
 (0)