Skip to content

Commit f4dc4b8

Browse files
committed
build: integrate llguidance as an external project
1 parent f19655c commit f4dc4b8

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

common/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ add_library(${TARGET} STATIC
6363
console.h
6464
json-schema-to-grammar.cpp
6565
json.hpp
66+
llguidance.cpp
6667
log.cpp
6768
log.h
6869
minja.hpp
@@ -89,6 +90,32 @@ if (LLAMA_CURL)
8990
set(LLAMA_COMMON_EXTRA_LIBS ${LLAMA_COMMON_EXTRA_LIBS} ${CURL_LIBRARY})
9091
endif ()
9192

93+
if (LLAMA_LLGUIDANCE)
94+
include(ExternalProject)
95+
set(LLGUIDANCE_SRC ${CMAKE_BINARY_DIR}/llguidance/source)
96+
set(LLGUIDANCE_PATH ${LLGUIDANCE_SRC}/target/release)
97+
ExternalProject_Add(llguidance_ext
98+
GIT_REPOSITORY https://github.com/guidance-ai/llguidance
99+
GIT_TAG 0cbe6b3a6ee72e5726c76f13fe67e21a5895f679
100+
PREFIX ${CMAKE_BINARY_DIR}/llguidance
101+
SOURCE_DIR ${LLGUIDANCE_SRC}
102+
BUILD_IN_SOURCE TRUE
103+
CONFIGURE_COMMAND ""
104+
BUILD_COMMAND cargo build --release
105+
INSTALL_COMMAND ""
106+
BUILD_BYPRODUCTS ${LLGUIDANCE_PATH}/libllguidance.a ${LLGUIDANCE_PATH}/llguidance.h
107+
UPDATE_COMMAND ""
108+
)
109+
target_compile_definitions(${TARGET} PUBLIC LLAMA_USE_LLGUIDANCE)
110+
111+
add_library(llguidance STATIC IMPORTED)
112+
set_target_properties(llguidance PROPERTIES IMPORTED_LOCATION ${LLGUIDANCE_PATH}/libllguidance.a)
113+
add_dependencies(llguidance llguidance_ext)
114+
115+
target_include_directories(${TARGET} PRIVATE ${LLGUIDANCE_PATH})
116+
set(LLAMA_COMMON_EXTRA_LIBS ${LLAMA_COMMON_EXTRA_LIBS} llguidance)
117+
endif ()
118+
92119
target_include_directories(${TARGET} PUBLIC .)
93120
target_compile_features (${TARGET} PUBLIC cxx_std_17)
94121
target_link_libraries (${TARGET} PRIVATE ${LLAMA_COMMON_EXTRA_LIBS} PUBLIC llama Threads::Threads)

0 commit comments

Comments
 (0)