Skip to content

Commit 949e43f

Browse files
[libshortfin] Clean up a few CI related items. (#163)
* Disables ASAN ODR check properly (had syntax error in env var). * Builds non-debug Python. * Sets up LSAN suppressions to account for non-debug Python intentional leaks. * Has CMake fetch the correct nanobind vs relying on pip (had another incident of mismatched version). * Added options SHORTFIN_BUILD_STATIC=OFF, SHORTFIN_BUILD_DYNAMIC=ON, and SHORTFIN_LINK_DYNAMIC to control variants of libraries produced and linked to (disabling static in most configs saves a lot of build time). * Run pytest with `-s` (stream output) option. For some reason, some of the subprocess tests are otherwise not working right on GHA runners. It looks like there may be some malformed I/O somewhere that gets less reliable with redirection. This isn't solved but does increase the chance of passing.
1 parent 08c69aa commit 949e43f

8 files changed

+109
-78
lines changed

.github/workflows/ci_linux_x64-libshortfin.yml

+5
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ jobs:
9494
-DCMAKE_C_COMPILER=clang-18 \
9595
-DCMAKE_CXX_COMPILER=clang++-18 \
9696
-DCMAKE_LINKER_TYPE=LLD \
97+
-DSHORTFIN_BUNDLE_DEPS=ON \
9798
-DCMAKE_PREFIX_PATH=${{ env.IREE_REPO_DIR }}/build/lib/cmake/IREE \
9899
-DSHORTFIN_BUILD_PYTHON_BINDINGS=ON \
99100
..
@@ -111,12 +112,16 @@ jobs:
111112
run: |
112113
mkdir ${{ env.LIBSHORTFIN_DIR }}/build-host-only
113114
cd ${{ env.LIBSHORTFIN_DIR }}/build-host-only
115+
# In this configuration, also build static+dynamic in order to verify
116+
# that path structurally works.
114117
cmake -GNinja \
115118
-DCMAKE_C_COMPILER=clang-18 \
116119
-DCMAKE_CXX_COMPILER=clang++-18 \
117120
-DCMAKE_LINKER_TYPE=LLD \
118121
-DCMAKE_PREFIX_PATH=${{ env.IREE_REPO_DIR }}/build/lib/cmake/IREE \
119122
-DSHORTFIN_BUILD_PYTHON_BINDINGS=ON \
120123
-DSHORTFIN_HAVE_AMDGPU=OFF \
124+
-DSHORTFIN_BUILD_STATIC=ON \
125+
-DSHORTFIN_BUILD_DYNAMIC=ON \
121126
..
122127
cmake --build . --target all

.github/workflows/ci_linux_x64_asan-libshortfin.yml

+12-9
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ env:
2323
PYENV_ROOT: ${{ github.workspace }}/pyenv
2424
PYENV_REF: 9ecd803bffaffb949fbdd8c70cb086227f6a3202 # v2.4.10
2525
PYTHON_VER: 3.12.3
26-
CACHE_ASAN_VER: 1
26+
CACHE_ASAN_VER: 2
2727
CACHE_DEPS_VER: 1
2828
IREE_SOURCE_DIR: ${{ github.workspace }}/iree
2929
LIBSHORTFIN_DIR: ${{ github.workspace }}/libshortfin/
3030

31-
3231
jobs:
3332
setup-python-asan:
3433
name: Setup Python ASan
3534
runs-on: ubuntu-24.04
35+
env:
36+
# The Python build process leaks. Here we just disable leak checking vs
37+
# being more precise.
38+
ASAN_OPTIONS: detect_leaks=0
3639

3740
steps:
3841
- name: Cache Python ASan
@@ -64,15 +67,18 @@ jobs:
6467
cd ${{ env.PYENV_ROOT }}
6568
src/configure && make -C src
6669
export PATH=${{ env.PYENV_ROOT }}/bin:$PATH && eval "$(pyenv init -)"
67-
CC=clang-18 CXX=clang++-18 LDFLAGS="-lstdc++" PYTHON_CONFIGURE_OPTS="--with-address-sanitizer" pyenv install -v -g ${{ env.PYTHON_VER }}
68-
pyenv global ${{ env.PYTHON_VER }}-debug
70+
CC=clang-18 CXX=clang++-18 LDFLAGS="-lstdc++" PYTHON_CONFIGURE_OPTS="--with-address-sanitizer" pyenv install -v ${{ env.PYTHON_VER }}
71+
pyenv global ${{ env.PYTHON_VER }}
6972
7073
7174
build-and-test:
7275
name: Build and test libshortfin
7376
needs: [setup-python-asan]
7477
runs-on: ubuntu-24.04
75-
78+
env:
79+
# TODO(#151): Don't ignore ODR violations
80+
ASAN_OPTIONS: detect_odr_violation=0
81+
LSAN_OPTIONS: suppressions=${{ github.workspace }}/libshortfin/build_tools/python_lsan_suppressions.txt
7682
steps:
7783
- name: Install dependencies
7884
run: |
@@ -135,9 +141,6 @@ jobs:
135141
key: ${{ steps.cache-python-deps-restore.outputs.cache-primary-key }}
136142

137143
- name: Build libshortfin
138-
env:
139-
# TODO(#151): Don't ignore ODR violations
140-
ASAN_OPTIONS=detect_odr_violation: 0
141144
run: |
142145
eval "$(pyenv init -)"
143146
mkdir ${{ env.LIBSHORTFIN_DIR }}/build
@@ -168,4 +171,4 @@ jobs:
168171
run: |
169172
eval "$(pyenv init -)"
170173
cd ${{ env.LIBSHORTFIN_DIR }}
171-
pytest -m "not requires_amd_gpu"
174+
pytest -m "not requires_amd_gpu" -s

libshortfin/CMakeLists.txt

+19-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ project(
1818
VERSION 0.9
1919
LANGUAGES C CXX)
2020

21+
include(CMakeDependentOption)
22+
2123
set(SOVERSION 1)
2224

2325
set(CMAKE_C_STANDARD 11)
@@ -34,10 +36,26 @@ endif()
3436
# build options
3537
option(SHORTFIN_BUILD_PYTHON_BINDINGS "Builds Python Bindings" OFF)
3638
option(SHORTFIN_BUILD_TESTS "Builds C++ tests" ON)
37-
option(SHORTFIN_BUNDLE_DEPS "Download dependencies instead of using system libraries" OFF)
39+
option(SHORTFIN_BUNDLE_DEPS "Download dependencies instead of using system libraries" ON)
3840

3941
set(SHORTFIN_IREE_SOURCE_DIR "" CACHE FILEPATH "Path to IREE source")
4042

43+
# Options for building static or dynamic libraries.
44+
option(SHORTFIN_BUILD_STATIC "Builds static libraries" OFF)
45+
option(SHORTFIN_BUILD_DYNAMIC "Builds dynamic libraries" ON)
46+
cmake_dependent_option(SHORTFIN_LINK_DYNAMIC "Links internal binaries against static libshortfin.a" ON "SHORTFIN_BUILD_DYNAMIC" OFF)
47+
if(NOT SHORTFIN_BUILD_STATIC AND NOT SHORTFIN_BUILD_DYNAMIC)
48+
message(FATAL_ERROR "One of SHORTFIN_BUILD_STATIC or SHORTFIN_BUILD_DYNAMIC must be ON")
49+
endif()
50+
message(STATUS "Shortfin build static = ${SHORTFIN_BUILD_STATIC}, dynamic = ${SHORTFIN_BUILD_DYNAMIC}")
51+
if(SHORTFIN_LINK_DYNAMIC)
52+
message(STATUS "Dynamic linking to shortfin")
53+
set(SHORTFIN_LINK_LIBRARY_NAME "shortfin")
54+
else()
55+
message(STATUS "Static linking to shortfin-static")
56+
set(SHORTFIN_LINK_LIBRARY_NAME "shortfin-static")
57+
endif()
58+
4159
# Enabling ASAN. Note that this will work best if building in a completely
4260
# bundled fashion and with an ASAN rigged CPython. Otherwise, various LD_PRELOAD
4361
# hacks are needed. This is merely a develope convenience: people are more

libshortfin/bindings/python/CMakeLists.txt

+8-9
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
# build. - _shortfin_tracing.lib: Native library with tracing enabled (TODO). -
1111
# Others.
1212

13-
# Detect the installed nanobind package and import it into CMake
14-
execute_process(
15-
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
16-
OUTPUT_STRIP_TRAILING_WHITESPACE
17-
OUTPUT_VARIABLE nanobind_ROOT)
18-
find_package(nanobind CONFIG REQUIRED)
13+
# nanobind
14+
FetchContent_Declare(
15+
nanobind
16+
GIT_REPOSITORY https://github.com/wjakob/nanobind.git
17+
GIT_TAG 9641bb7151f04120013b812789b3ebdfa7e7324f # 2.1.0
18+
)
19+
FetchContent_MakeAvailable(nanobind)
1920

2021
nanobind_add_module(shortfin_python_extension NB_STATIC LTO
2122
array_binding.cc
@@ -26,9 +27,7 @@ set_target_properties(shortfin_python_extension
2627
PROPERTIES OUTPUT_NAME "_shortfin_default/lib")
2728

2829
target_link_libraries(shortfin_python_extension
29-
# TODO: This should be configurable as to whether we link to the static
30-
# or dynamic version.
31-
PRIVATE shortfin
30+
PRIVATE ${SHORTFIN_LINK_LIBRARY_NAME}
3231
)
3332

3433
nanobind_add_stub(

libshortfin/build_tools/cmake/shortfin_library.cmake

+63-57
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,24 @@ function(shortfin_public_library)
2424
"COMPONENTS"
2525
${ARGN}
2626
)
27-
shortfin_components_to_static_libs(_STATIC_COMPONENTS ${_RULE_COMPONENTS})
28-
shortfin_components_to_dynamic_libs(_DYLIB_COMPONENTS ${_RULE_COMPONENTS})
29-
# Static library.
30-
add_library("${_RULE_NAME}-static" STATIC)
31-
target_link_libraries(
32-
"${_RULE_NAME}-static" PUBLIC ${_STATIC_COMPONENTS}
33-
)
27+
if(SHORTFIN_BUILD_STATIC)
28+
# Static library.
29+
shortfin_components_to_static_libs(_STATIC_COMPONENTS ${_RULE_COMPONENTS})
30+
add_library("${_RULE_NAME}-static" STATIC)
31+
target_link_libraries(
32+
"${_RULE_NAME}-static" PUBLIC ${_STATIC_COMPONENTS}
33+
)
34+
endif()
3435

35-
# Dylib library.
36-
add_library("${_RULE_NAME}" SHARED)
37-
target_compile_definitions("${_RULE_NAME}" INTERFACE _SHORTFIN_USING_DYLIB)
38-
target_link_libraries(
39-
"${_RULE_NAME}" PUBLIC ${_DYLIB_COMPONENTS}
40-
)
36+
if(SHORTFIN_BUILD_DYNAMIC)
37+
# Dylib library.
38+
shortfin_components_to_dynamic_libs(_DYLIB_COMPONENTS ${_RULE_COMPONENTS})
39+
add_library("${_RULE_NAME}" SHARED)
40+
target_compile_definitions("${_RULE_NAME}" INTERFACE _SHORTFIN_USING_DYLIB)
41+
target_link_libraries(
42+
"${_RULE_NAME}" PUBLIC ${_DYLIB_COMPONENTS}
43+
)
44+
endif()
4145
endfunction()
4246

4347
function(shortfin_cc_component)
@@ -48,50 +52,52 @@ function(shortfin_cc_component)
4852
"HDRS;SRCS;DEPS;COMPONENTS"
4953
${ARGN}
5054
)
51-
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
52-
set(_STATIC_OBJECTS_NAME "${_RULE_NAME}.objects")
53-
set(_DYLIB_OBJECTS_NAME "${_RULE_NAME}.dylib.objects")
54-
55-
shortfin_components_to_static_libs(_STATIC_COMPONENTS ${_RULE_COMPONENTS})
56-
shortfin_components_to_dynamic_libs(_DYLIB_COMPONENTS ${_RULE_COMPONENTS})
57-
58-
# Static object library.
59-
add_library(${_STATIC_OBJECTS_NAME} OBJECT)
60-
target_sources(${_STATIC_OBJECTS_NAME}
61-
PRIVATE
62-
${_RULE_SRCS}
63-
${_RULE_HDRS}
64-
)
65-
target_compile_options(${_STATIC_OBJECTS_NAME} PRIVATE ${SHORTFIN_DEFAULT_COPTS})
66-
target_link_libraries(${_STATIC_OBJECTS_NAME}
67-
PUBLIC
68-
_shortfin_defs
69-
${_STATIC_COMPONENTS}
70-
${_RULE_DEPS}
71-
)
55+
if(SHORTFIN_BUILD_STATIC)
56+
# Static object library.
57+
set(_STATIC_OBJECTS_NAME "${_RULE_NAME}.objects")
58+
shortfin_components_to_static_libs(_STATIC_COMPONENTS ${_RULE_COMPONENTS})
59+
add_library(${_STATIC_OBJECTS_NAME} OBJECT)
60+
target_sources(${_STATIC_OBJECTS_NAME}
61+
PRIVATE
62+
${_RULE_SRCS}
63+
${_RULE_HDRS}
64+
)
65+
target_compile_options(${_STATIC_OBJECTS_NAME} PRIVATE ${SHORTFIN_DEFAULT_COPTS})
66+
target_link_libraries(${_STATIC_OBJECTS_NAME}
67+
PUBLIC
68+
_shortfin_defs
69+
${_STATIC_COMPONENTS}
70+
${_RULE_DEPS}
71+
)
72+
endif()
7273

73-
# Dylib object library.
74-
add_library(${_DYLIB_OBJECTS_NAME} OBJECT)
75-
target_sources(${_DYLIB_OBJECTS_NAME}
76-
PRIVATE
77-
${_RULE_SRCS}
78-
${_RULE_HDRS}
79-
)
80-
target_compile_options(${_DYLIB_OBJECTS_NAME} PRIVATE ${SHORTFIN_DEFAULT_COPTS})
81-
target_link_libraries(${_DYLIB_OBJECTS_NAME}
82-
PUBLIC
83-
_shortfin_defs
84-
${_DYLIB_COMPONENTS}
85-
${_RULE_DEPS}
86-
)
87-
set_target_properties(
88-
${_DYLIB_OBJECTS_NAME} PROPERTIES
89-
CXX_VISIBILITY_PRESET hidden
90-
C_VISIBILITY_PRESET hidden
91-
VISIBILITY_INLINES_HIDDEN ON
92-
)
93-
target_compile_definitions(${_DYLIB_OBJECTS_NAME}
94-
PRIVATE _SHORTFIN_BUILDING_DYLIB)
74+
if(SHORTFIN_BUILD_DYNAMIC)
75+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
76+
set(_DYLIB_OBJECTS_NAME "${_RULE_NAME}.dylib.objects")
77+
shortfin_components_to_dynamic_libs(_DYLIB_COMPONENTS ${_RULE_COMPONENTS})
78+
# Dylib object library.
79+
add_library(${_DYLIB_OBJECTS_NAME} OBJECT)
80+
target_sources(${_DYLIB_OBJECTS_NAME}
81+
PRIVATE
82+
${_RULE_SRCS}
83+
${_RULE_HDRS}
84+
)
85+
target_compile_options(${_DYLIB_OBJECTS_NAME} PRIVATE ${SHORTFIN_DEFAULT_COPTS})
86+
target_link_libraries(${_DYLIB_OBJECTS_NAME}
87+
PUBLIC
88+
_shortfin_defs
89+
${_DYLIB_COMPONENTS}
90+
${_RULE_DEPS}
91+
)
92+
set_target_properties(
93+
${_DYLIB_OBJECTS_NAME} PROPERTIES
94+
CXX_VISIBILITY_PRESET hidden
95+
C_VISIBILITY_PRESET hidden
96+
VISIBILITY_INLINES_HIDDEN ON
97+
)
98+
target_compile_definitions(${_DYLIB_OBJECTS_NAME}
99+
PRIVATE _SHORTFIN_BUILDING_DYLIB)
100+
endif()
95101
endfunction()
96102

97103
function(shortfin_components_to_static_libs out_static_libs)
@@ -122,7 +128,7 @@ function(shortfin_gtest_test)
122128
add_executable(${_RULE_NAME} ${_RULE_SRCS})
123129
target_link_libraries(${_RULE_NAME} PRIVATE
124130
${_RULE_DEPS}
125-
shortfin
131+
${SHORTFIN_LINK_LIBRARY_NAME}
126132
GTest::gmock
127133
GTest::gtest_main
128134
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
leak:PyUnicode_New
2+
leak:_PyUnicodeWriter_Finish

libshortfin/pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ requires = [
33
"cmake>=3.29",
44
"setuptools>=61.0",
55
"wheel",
6-
"nanobind>=2.0",
76
"ninja",
87
]
98
build-backend = "setuptools.build_meta"

libshortfin/requirements-tests.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
nanobind==2.1.0
21
pytest
32
requests
43
fastapi

0 commit comments

Comments
 (0)