Skip to content

Commit d93d371

Browse files
[libshortfin] Python build ergonomics. (#177)
* Move bindings/python -> python * Rework setup.py so that it can be the main driver for Python based dev: * Add env vars SHORTFIN_IREE_SOURCE_DIR, SHORTFIN_ENABLE_ASAN, SHORTFIN_DEV_MODE, SHORTFIN_RUN_CTESTS * Update README with python based dev flow commands * Change build dir to build/cmake (from build/b) * Removes a redundant build of IREE in the main CI (was not doing anything in bundled mode). With this, I can change my dev process to be entirely based on `pip install` with a fully editable build and the ability to manipulate cmake post build. This better aligns with how users will consume it.
1 parent e52b086 commit d93d371

18 files changed

+128
-118
lines changed

.github/workflows/ci_linux_x64-libshortfin.yml

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,6 @@ jobs:
5757
git submodule update --init --depth 1 -- third_party/googletest
5858
git submodule update --init --depth 1 -- third_party/hip-build-deps/
5959
60-
- name: Build IREE runtime
61-
run: |
62-
mkdir ${{ env.IREE_REPO_DIR }}/build
63-
cd ${{ env.IREE_REPO_DIR }}/build
64-
cmake -GNinja \
65-
-DCMAKE_C_COMPILER=clang-18 \
66-
-DCMAKE_CXX_COMPILER=clang++-18 \
67-
-DIREE_ENABLE_LLD=ON \
68-
-DIREE_ERROR_ON_MISSING_SUBMODULES=OFF \
69-
-DIREE_HAL_DRIVER_DEFAULTS=OFF \
70-
-DIREE_HAL_DRIVER_LOCAL_SYNC=ON \
71-
-DIREE_HAL_DRIVER_LOCAL_TASK=ON \
72-
-DIREE_HAL_DRIVER_HIP=ON \
73-
-DIREE_BUILD_COMPILER=OFF \
74-
-DIREE_BUILD_SAMPLES=OFF \
75-
-DIREE_BUILD_TESTS=OFF \
76-
..
77-
cmake --build . --target all
78-
7960
- name: Setup Python
8061
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
8162
with:
@@ -97,7 +78,7 @@ jobs:
9778
-DCMAKE_CXX_COMPILER=clang++-18 \
9879
-DCMAKE_LINKER_TYPE=LLD \
9980
-DSHORTFIN_BUNDLE_DEPS=ON \
100-
-DCMAKE_PREFIX_PATH=${{ env.IREE_REPO_DIR }}/build/lib/cmake/IREE \
81+
-DSHORTFIN_IREE_SOURCE_DIR=${{ env.IREE_REPO_DIR }} \
10182
-DSHORTFIN_BUILD_PYTHON_BINDINGS=ON \
10283
..
10384
cmake --build . --target all
@@ -120,7 +101,7 @@ jobs:
120101
-DCMAKE_C_COMPILER=clang-18 \
121102
-DCMAKE_CXX_COMPILER=clang++-18 \
122103
-DCMAKE_LINKER_TYPE=LLD \
123-
-DCMAKE_PREFIX_PATH=${{ env.IREE_REPO_DIR }}/build/lib/cmake/IREE \
104+
-DSHORTFIN_IREE_SOURCE_DIR=${{ env.IREE_REPO_DIR }} \
124105
-DSHORTFIN_BUILD_PYTHON_BINDINGS=ON \
125106
-DSHORTFIN_HAVE_AMDGPU=OFF \
126107
-DSHORTFIN_BUILD_STATIC=ON \

.github/workflows/ci_linux_x64_asan-libshortfin.yml

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,27 +147,13 @@ jobs:
147147
- name: Build libshortfin
148148
run: |
149149
eval "$(pyenv init -)"
150-
mkdir ${{ env.LIBSHORTFIN_DIR }}/build
151-
cd ${{ env.LIBSHORTFIN_DIR }}/build
152-
cmake -GNinja \
153-
-DCMAKE_BUILD_TYPE=Debug \
154-
-DCMAKE_C_COMPILER=clang-18 \
155-
-DCMAKE_CXX_COMPILER=clang++-18 \
156-
-DCMAKE_LINKER_TYPE=LLD \
157-
-DSHORTFIN_BUNDLE_DEPS=ON \
158-
-DSHORTFIN_IREE_SOURCE_DIR=${{ env.IREE_SOURCE_DIR }} \
159-
-DSHORTFIN_BUILD_PYTHON_BINDINGS=ON \
160-
-DSHORTFIN_ENABLE_ASAN=ON \
161-
..
162-
cmake --build . --target all
150+
cd ${{ env.LIBSHORTFIN_DIR }}
151+
SHORTFIN_IREE_SOURCE_DIR="${{ env.IREE_SOURCE_DIR }}" \
152+
SHORTFIN_ENABLE_ASAN=ON \
153+
SHORTFIN_DEV_MODE=ON \
154+
SHORTFIN_RUN_CTESTS=ON \
163155
pip install -v -e .
164156
165-
- name: Run ctest
166-
if: ${{ !cancelled() }}
167-
run: |
168-
cd ${{ env.LIBSHORTFIN_DIR }}/build
169-
ctest --timeout 30 --output-on-failure
170-
171157
- name: Run pytest
172158
if: ${{ !cancelled() }}
173159
env:

libshortfin/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# https://llvm.org/LICENSE.txt for license information. SPDX-License-Identifier:
55
# Apache-2.0 WITH LLVM-exception
66

7-
cmake_minimum_required(VERSION 3.28)
7+
cmake_minimum_required(VERSION 3.29)
88

99
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
1010
message(
@@ -138,7 +138,7 @@ if (NOT SHORTFIN_IREE_SOURCE_DIR AND SHORTFIN_BUNDLE_DEPS)
138138
)
139139
FetchContent_GetProperties(iree)
140140
if(NOT iree_POPULATED)
141-
FetchContent_Populate(iree)
141+
FetchContent_MakeAvailable(iree)
142142
endif()
143143
set(SHORTFIN_IREE_SOURCE_DIR ${iree_SOURCE_DIR})
144144
endif()
@@ -184,7 +184,7 @@ add_subdirectory(src)
184184

185185
if(SHORTFIN_BUILD_PYTHON_BINDINGS)
186186
find_package(Python 3.8 COMPONENTS Interpreter Development.Module REQUIRED)
187-
add_subdirectory(bindings/python)
187+
add_subdirectory(python)
188188
set(SHORTFIN_PYTHON_CPP_PREBUILT "TRUE") # See setup.py.
189189
configure_file(setup.py setup.py @ONLY)
190190
configure_file(pyproject.toml pyproject.toml COPYONLY)

libshortfin/README.md

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,19 @@
11
# libshortfin - SHARK C++ inference library
22

3-
## Dev Builds
4-
5-
Library dependencies:
6-
7-
* [spdlog](https://github.com/gabime/spdlog)
8-
* [xtensor](https://github.com/xtensor-stack/xtensor)
9-
* [iree runtime](https://github.com/iree-org/iree)
10-
11-
On recent Ubuntu, the primary dependencies can be satisfied via:
12-
13-
```
14-
apt install libspdlog-dev libxtensor-dev
15-
```
16-
17-
CMake must be told how to find the IREE runtime, either from a distribution
18-
tarball, or local build/install dir. For a local build directory, pass:
19-
20-
```
21-
# Assumes that the iree-build directory is adjacent to this repo.
22-
-DCMAKE_PREFIX_PATH=$(pwd)/../../iree-build/lib/cmake/IREE
23-
```
24-
25-
One liner recommended CMake command (note that CMAKE_LINKER_TYPE requires
26-
cmake>=3.29):
3+
## Native Dev Builds
274

285
```
296
cmake -GNinja -S. -Bbuild \
307
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
31-
-DCMAKE_LINKER_TYPE=LLD \
32-
-DCMAKE_PREFIX_PATH=$(pwd)/../../iree-build/lib/cmake/IREE
8+
-DCMAKE_LINKER_TYPE=LLD
339
```
3410

35-
## Building Python Bindings
11+
## Python Dev Builds
3612

3713
If using a Python based development flow, there are two options:
3814

39-
1. `pip install -v .` to build and install the library (TODO: Not yet implemented).
40-
2. Build with cmake and `-DSHORTFIN_BUILD_PYTHON_BINDINGS=ON` and then
15+
1. `pip install -e` based.
16+
2. Build with cmake as above and `-DSHORTFIN_BUILD_PYTHON_BINDINGS=ON` and then
4117
from the `build/` directory, run `pip install -v -e .` to create an
4218
editable install that will update as you build the C++ project.
4319

@@ -46,6 +22,34 @@ recommended. Your python install should track any source file changes or
4622
builds without further interaction. Re-installing will be necessary if package
4723
structure changes significantly.
4824

25+
For pure Python based dev, everything can be done from pip:
26+
27+
```
28+
# Install build system pre-reqs (since we are building in dev mode, this
29+
# is not done for us). See source of truth in pyproject.toml:
30+
pip install setuptools wheel
31+
32+
# Optionally install cmake and ninja if you don't have them or need a newer
33+
# version. If doing heavy development in Python, it is strongly recommended
34+
# to install these natively on your system as it will make it easier to
35+
# switch Python interpreters and build options (and the launcher in debug/asan
36+
# builds of Python is much slower). Note CMakeLists.txt for minimum CMake
37+
# version, which is usually quite recent.
38+
pip install cmake ninja
39+
40+
# Optional env vars:
41+
# SHORTFIN_IREE_SOURCE_DIR=$(pwd)/../../iree
42+
# Note that the `--no-build-isolation` flag is useful in development setups
43+
# because it does not create an intermediate venv that will keep later
44+
# invocations of cmake/ninja from working at the command line. If just doing
45+
# a one-shot build, it can be ommitted.
46+
SHORTFIN_DEV_MODE=ON pip install --no-build-isolation -v -e .
47+
48+
Once built the first time, `cmake`, `ninja`, and `ctest` commands can be run
49+
directly from `build/cmake` and changes will apply directly to the next
50+
process launch.
51+
```
52+
4953
## Running Tests
5054

5155
The project uses a combination of ctest for native C++ tests and pytest. Much
File renamed without changes.

0 commit comments

Comments
 (0)