Skip to content

Commit dc1ca98

Browse files
committed
Build pybindings and link in backends when building pip wheels
Always build the pybindings when building the pip wheel. Always link in XNNPACK. On macos, also link in MPS. Core ML can't build on the worker machine, though, because the version of macOS is too old; Core ML requires some features introduced in macOS 10.15.
1 parent d5cbc09 commit dc1ca98

File tree

5 files changed

+53
-12
lines changed

5 files changed

+53
-12
lines changed

.github/workflows/build-wheels-linux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
# "recursive" default to do less work, and to give the buck daemon fewer
5555
# files to look at.
5656
submodules: true
57+
env-var-script: build/packaging/env_var_script_linux.sh
5758
pre-script: ${{ matrix.pre-script }}
5859
post-script: ${{ matrix.post-script }}
5960
package-name: ${{ matrix.package-name }}

.github/workflows/build-wheels-m1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
# "recursive" default to do less work, and to give the buck daemon fewer
5555
# files to look at.
5656
submodules: true
57+
env-var-script: build/packaging/env_var_script_m1.sh
5758
pre-script: ${{ matrix.pre-script }}
5859
post-script: ${{ matrix.post-script }}
5960
package-name: ${{ matrix.package-name }}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# This file is sourced into the environment before building a pip wheel. It
8+
# should typically only contain shell variable assignments. Be sure to export
9+
# any variables so that subprocesses will see them.
10+
11+
# Enable pybindings so that users can execute ExecuTorch programs from python.
12+
export EXECUTORCH_BUILD_PYBIND=1
13+
14+
# Ensure that CMAKE_ARGS is defined before referencing it. Defaults to empty
15+
# if not defined.
16+
export CMAKE_ARGS="${CMAKE_ARGS:-}"
17+
18+
# Link the XNNPACK backend into the pybindings runtime so that users can execute
19+
# ExecuTorch programs that delegate to it.
20+
CMAKE_ARGS="${CMAKE_ARGS} -DEXECUTORCH_BUILD_XNNPACK=ON"

build/packaging/env_var_script_m1.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# This file is sourced into the environment before building a pip wheel. It
8+
# should typically only contain shell variable assignments. Be sure to export
9+
# any variables so that subprocesses will see them.
10+
11+
# Enable pybindings so that users can execute ExecuTorch programs from python.
12+
export EXECUTORCH_BUILD_PYBIND=1
13+
14+
# Ensure that CMAKE_ARGS is defined before referencing it. Defaults to empty
15+
# if not defined.
16+
export CMAKE_ARGS="${CMAKE_ARGS:-}"
17+
18+
# Link the XNNPACK backend into the pybindings runtime so that users can execute
19+
# ExecuTorch programs that delegate to it.
20+
CMAKE_ARGS="${CMAKE_ARGS} -DEXECUTORCH_BUILD_XNNPACK=ON"
21+
22+
# When building for macOS, link additional backends into the pybindings runtime.
23+
24+
# TODO(dbort): Core ML requires features only available in macOS 10.15, but the
25+
# build machine uses an older version.
26+
# CMAKE_ARGS="${CMAKE_ARGS} -DEXECUTORCH_BUILD_COREML=ON"
27+
28+
CMAKE_ARGS="${CMAKE_ARGS} -DEXECUTORCH_BUILD_MPS=ON"

setup.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ def _is_env_enabled(env_var: str, default: bool = False) -> bool:
8383
def pybindings(cls) -> bool:
8484
return cls._is_env_enabled("EXECUTORCH_BUILD_PYBIND", default=False)
8585

86-
@classmethod
87-
@property
88-
def xnnpack(cls) -> bool:
89-
return cls._is_env_enabled("EXECUTORCH_BUILD_XNNPACK", default=False)
90-
9186

9287
class _BaseExtension(Extension):
9388
"""A base class that maps an abstract source to an abstract destination."""
@@ -372,13 +367,9 @@ def run(self):
372367
"-DEXECUTORCH_BUILD_PYBIND=ON",
373368
]
374369
build_args += ["--target", "portable_lib"]
375-
if ShouldBuild.xnnpack:
376-
cmake_args += [
377-
"-DEXECUTORCH_BUILD_XNNPACK=ON",
378-
]
379-
# No target needed; the cmake arg will link xnnpack
380-
# into the portable_lib target.
381-
# TODO(dbort): Add MPS/CoreML backends when building on macos.
370+
# To link backends into the portable_lib target, callers should
371+
# add entries like `-DEXECUTORCH_BUILD_XNNPACK=ON` to the CMAKE_ARGS
372+
# environment variable.
382373

383374
# Allow adding extra cmake args through the environment. Used by some
384375
# tests and demos to expand the set of targets included in the pip

0 commit comments

Comments
 (0)