Skip to content

Commit e5f42d2

Browse files
committed
Fix OSS CI: clang-format + jinja2cpp install-export leak
- jinja_chat_formatter.cpp: apply clang-format (lintrunner CLANGFORMAT). - extension/llm/runner/CMakeLists.txt: scope the private jinja2cpp dependency to $<BUILD_INTERFACE:...> so it is not propagated into the installed ExecuTorchTargets export. jinja2cpp is a FetchContent static library that is not installed, so leaking it made downstream find_package(executorch) consumers (the example runners) fail to link with -ljinja2cpp. Also drop the formatter source when jinja2cpp is not built.
1 parent 7141b95 commit e5f42d2

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

‎extension/llm/runner/CMakeLists.txt‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ executorch_load_build_variables()
3131
# build llm runner library
3232
list(TRANSFORM _extension_llm_runner__srcs PREPEND "${EXECUTORCH_ROOT}/")
3333

34+
# The Jinja chat formatter requires jinja2cpp. When jinja2cpp is not built (for
35+
# example a runner build that does not add the chat_template subdirectory), drop
36+
# the source so extension_llm_runner has no dependency on jinja2cpp at all.
37+
if(NOT TARGET jinja2cpp)
38+
list(FILTER _extension_llm_runner__srcs EXCLUDE REGEX
39+
"extension/llm/runner/jinja_chat_formatter\\.cpp$"
40+
)
41+
endif()
42+
3443
add_library(extension_llm_runner STATIC ${_extension_llm_runner__srcs})
3544

3645
# include sampler
@@ -54,11 +63,20 @@ endif()
5463
list(APPEND runner_deps kernels_util_all_deps)
5564

5665
target_link_libraries(extension_llm_runner PUBLIC ${runner_deps})
57-
target_link_libraries(extension_llm_runner PRIVATE $<LINK_ONLY:jinja2cpp>)
58-
target_include_directories(
59-
extension_llm_runner
60-
PRIVATE $<TARGET_PROPERTY:jinja2cpp,INTERFACE_INCLUDE_DIRECTORIES>
61-
)
66+
# jinja2cpp is a private, build-tree-only dependency of the Jinja chat formatter.
67+
# It is a FetchContent static library that is not installed, so it must NOT leak
68+
# into the installed ExecuTorchTargets export -- otherwise downstream
69+
# find_package(executorch) consumers fail to link with `-ljinja2cpp`.
70+
# BUILD_INTERFACE keeps the dependency local to this build tree.
71+
if(TARGET jinja2cpp)
72+
target_link_libraries(
73+
extension_llm_runner PRIVATE $<BUILD_INTERFACE:jinja2cpp>
74+
)
75+
target_include_directories(
76+
extension_llm_runner
77+
PRIVATE $<TARGET_PROPERTY:jinja2cpp,INTERFACE_INCLUDE_DIRECTORIES>
78+
)
79+
endif()
6280
set_target_properties(
6381
extension_llm_runner PROPERTIES POSITION_INDEPENDENT_CODE ON
6482
)

‎extension/llm/runner/jinja_chat_formatter.cpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,13 @@ jinja2::Value toStableValue(
166166
string_store.emplace_back(view->begin(), view->end());
167167
return jinja2::Value(nonstd::string_view(string_store.back()));
168168
}
169-
// getPtr<GenericMap> is checked before isMap()/asMap() so asMap() is only used
170-
// on an owning (non-Generic) map.
169+
// getPtr<GenericMap> is checked before isMap()/asMap() so asMap() is only
170+
// used on an owning (non-Generic) map.
171171
if (const auto* generic_map = value.getPtr<jinja2::GenericMap>()) {
172172
jinja2::ValuesMap owned;
173173
for (const auto& key : generic_map->GetKeys()) {
174-
owned[key] = toStableValue(generic_map->GetValueByName(key), string_store);
174+
owned[key] =
175+
toStableValue(generic_map->GetValueByName(key), string_store);
175176
}
176177
return jinja2::Value(std::move(owned));
177178
}

0 commit comments

Comments
 (0)