Skip to content

New pip build system #2499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ cmake-android-out/
cmake-ios-out/
ethos-u-scratch/
executorch.egg-info
pip-out/
__pycache__/
build/lib/
exir/_serialize/scalar_type.fbs
exir/_serialize/program.fbs
sdk/bundled_program/serialize/bundled_program_schema.fbs
sdk/bundled_program/serialize/scalar_type.fbs
Comment on lines -10 to -13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice finding we probably don't want to ignore all these

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We needed to before this, because setup.py copied them directly into the source tree.


# Any exported models and profiling outputs
*.pte
Expand Down
42 changes: 42 additions & 0 deletions build/pip_data_bin_init.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file should be written to the wheel package as
# `executorch/data/bin/__init__.py`.
#
# Setuptools will expect to be able to say something like `from
# executorch.data.bin import mybin; mybin()` for each entry listed in the
# [project.scripts] section of pyproject.toml. This file makes the `mybin()`
# function execute the binary at `executorch/data/bin/mybin` and exit with that
# binary's exit status.

import subprocess
import os
import sys
import types

# This file should live in the target `bin` directory.
_bin_dir = os.path.join(os.path.dirname(__file__))

def _find_executable_files_under(dir):
"""Lists all executable files in the given directory."""
bin_names = []
for filename in os.listdir(dir):
filepath = os.path.join(dir, filename)
if os.path.isfile(filepath) and os.access(filepath, os.X_OK):
bin_names.append(filename)
return bin_names

# The list of binaries to create wrapper functions for.
_bin_names = _find_executable_files_under(_bin_dir)

# We'll define functions named after each binary. Make them importable.
__all__ = _bin_names

def _run(name):
"""Runs the named binary, which should live under _bin_dir.

Exits the current process with the return code of the subprocess.
"""
raise SystemExit(subprocess.call([os.path.join(_bin_dir, name)] + sys.argv[1:], close_fds=False))

# Define a function named after each of the binaries.
for bin_name in _bin_names:
exec(f"def {bin_name}(): _run('{bin_name}')")
25 changes: 0 additions & 25 deletions docs/source/getting-started-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,37 +111,12 @@ Follow these steps:
source .executorch/bin/activate
```

1. Install [Cmake](https://cmake.org/download)

```bash
conda install cmake
```

Alternatively:

```bash
pip install cmake
```

1. Install ExecuTorch and dependencies:

```bash
./install_requirements.sh
```

**Optional:** Install ExecuTorch as an editable installation:
```bash
pip install --editable . --config-settings editable_mode=strict --no-build-isolation
```

1. Expose FlatBuffers compiler:

ExecuTorch uses `flatc` to export models and builds it from sources at
`third-party/flatbuffers`. Make it available by adding it to the `$PATH` environment variable,
as prompted by the previous step, or exporting as `$FLATC_EXECUTABLE`
enironment variable.
Run `./build/install_flatc.sh` to make sure `flatc` is installed correctly.

You have successfully set up your environment to work with ExecuTorch. The next
step is to generate a sample ExecuTorch program.

Expand Down
16 changes: 7 additions & 9 deletions install_requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ for arg in "$@"; do
;;
coreml|mps|xnnpack)
if [[ "$EXECUTORCH_BUILD_PYBIND" == "ON" ]]; then
CMAKE_ARGS="$CMAKE_ARGS -DEXECUTORCH_BUILD_${arg^^}=ON"
arg_upper="$(echo "${arg}" | tr '[:lower:]' '[:upper:]')"
CMAKE_ARGS="$CMAKE_ARGS -DEXECUTORCH_BUILD_${arg_upper}=ON"
else
echo "Error: $arg must follow --pybind"
exit 1
Expand Down Expand Up @@ -65,6 +66,7 @@ EXIR_REQUIREMENTS=(

# pip packages needed for development.
DEVEL_REQUIREMENTS=(
cmake # For building binary targets.
setuptools # For building the pip package.
tomli # Imported by extract_sources.py when using python < 3.11.
wheel # For building the pip package archive.
Expand Down Expand Up @@ -94,13 +96,9 @@ pip install --extra-index-url "${TORCH_NIGHTLY_URL}" \
"${REQUIREMENTS_TO_INSTALL[@]}"

#
# Install executorch pip package.
# Install executorch pip package. This also makes `flatc` available on the path.
#

EXECUTORCH_BUILD_PYBIND="$EXECUTORCH_BUILD_PYBIND" \
CMAKE_ARGS="$CMAKE_ARGS" \
CMAKE_BUILD_PARALLEL_LEVEL=9 \
pip install . --no-build-isolation -v

# Install flatc dependency
bash build/install_flatc.sh
EXECUTORCH_BUILD_PYBIND="${EXECUTORCH_BUILD_PYBIND}" \
CMAKE_ARGS="${CMAKE_ARGS}" \
pip install . --no-build-isolation -v
18 changes: 15 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,27 @@ dependencies=[
"ruamel.yaml",
"sympy",
"tabulate",
"tomli",
"zstd",
]

# Tell setuptools to generate commandline wrappers for tools that we install
# under data/bin in the pip package. This will put these commands on the user's
# path.
[project.scripts]
flatc = "executorch.data.bin:flatc"

[tool.setuptools.package-data]
"*" = ["*.fbs", "*.yaml"]
# TODO(dbort): Prune /test[s]/ dirs, /third-party/ dirs, yaml files that we
# don't need.
"*" = [
# Some backends like XNNPACK need their .fbs files.
"*.fbs",
# Some kernel libraries need their .yaml files.
"*.yaml",
]

[tool.setuptools.exclude-package-data]
"*" = ["*.pyc"]

[tool.usort]
# Do not try to put "first-party" imports in their own section.
first_party_detection = false
2 changes: 2 additions & 0 deletions sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ ExternalProject_Add(
SOURCE_DIR ${CMAKE_SOURCE_DIR}/third-party/flatcc
BINARY_DIR ${CMAKE_BINARY_DIR}/_host_build
CMAKE_CACHE_ARGS -DFLATCC_TEST:BOOL=OFF -DFLATCC_REFLECTION:BOOL=OFF
# See above comment about POSITION_INDEPENDENT_CODE.
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
INSTALL_COMMAND "" # Prevent the install step, modify as needed
)

Expand Down
Loading