Skip to content

Commit

Permalink
Extend setup cmake ability (#3349)
Browse files Browse the repository at this point in the history
Summary:
For executorch users, we see a common pattern that they have to:

```bash
bash install_requirements.sh --pybind xnnpack

cmake -S . -Bcmake-out ...

cmake --build ...
```

This is repeating cmake build twice, the first one is inside setup.py.

Here I'm adding a way to allow setup.py to install the libraries seperately, by passing `CMAKE_ARGS` and `CMAKE_BUILD_ARGS` into setup.py, through `install_requirements.sh`.

After this change, user can do:

```bash
export CMAKE_ARGS="-DCMAKE_INSTALL_PREFIX=<install dir> \
  -DEXECUTORCH_BUILD_OPTIMIZED=ON \
  ..."

export CMAKE_BUILD_ARGS="--target install"

bash install_requirements.sh --pybind xnnpack
```

Then we should be able to find `libxnnpack.a` `liboptimized_ops_lib.a` etc under install dir.

Pull Request resolved: #3349

Reviewed By: mikekgfb

Differential Revision: D56560786

Pulled By: larryliu0820

fbshipit-source-id: fb6cd230df2317067f07ae0f1e72d0596b7b454b
  • Loading branch information
larryliu0820 authored and facebook-github-bot committed Apr 25, 2024
1 parent 319a4f2 commit 8ec0af9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion install_requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fi

# Parse options.
EXECUTORCH_BUILD_PYBIND=OFF
CMAKE_ARGS=""

for arg in "$@"; do
case $arg in
Expand Down Expand Up @@ -110,4 +109,5 @@ $PIP_EXECUTABLE install --extra-index-url "${TORCH_NIGHTLY_URL}" \

EXECUTORCH_BUILD_PYBIND="${EXECUTORCH_BUILD_PYBIND}" \
CMAKE_ARGS="${CMAKE_ARGS}" \
CMAKE_BUILD_ARGS="${CMAKE_BUILD_ARGS}" \
$PIP_EXECUTABLE install . --no-build-isolation -v
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,14 @@ def run(self):
if "CMAKE_ARGS" in os.environ:
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]

# Allow adding extra build args through the environment. Used by some
# tests and demos to expand the set of targets included in the pip
# package.
if "CMAKE_BUILD_ARGS" in os.environ:
build_args += [
item for item in os.environ["CMAKE_BUILD_ARGS"].split(" ") if item
]

# Put the cmake cache under the temp directory, like
# "pip-out/temp.<plat>/cmake-out".
cmake_cache_dir = os.path.join(repo_root, self.build_temp, "cmake-out")
Expand Down

0 comments on commit 8ec0af9

Please sign in to comment.