Skip to content

Commit 7d8c170

Browse files
committed
setup windows linking for llguidance; thanks @phil-scott-78
1 parent 3ec9fd4 commit 7d8c170

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

common/CMakeLists.txt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ if (LLAMA_LLGUIDANCE)
9696
include(ExternalProject)
9797
set(LLGUIDANCE_SRC ${CMAKE_BINARY_DIR}/llguidance/source)
9898
set(LLGUIDANCE_PATH ${LLGUIDANCE_SRC}/target/release)
99+
100+
# Set the correct library file extension based on platform
101+
if (WIN32)
102+
set(LLGUIDANCE_LIB_NAME "llguidance.lib")
103+
# Add Windows-specific libraries
104+
set(LLGUIDANCE_PLATFORM_LIBS
105+
ws2_32 # Windows Sockets API
106+
userenv # For GetUserProfileDirectoryW
107+
ntdll # For NT functions
108+
bcrypt # For BCryptGenRandom
109+
)
110+
else()
111+
set(LLGUIDANCE_LIB_NAME "libllguidance.a")
112+
set(LLGUIDANCE_PLATFORM_LIBS "")
113+
endif()
114+
99115
ExternalProject_Add(llguidance_ext
100116
GIT_REPOSITORY https://github.com/guidance-ai/llguidance
101117
# v0.6.12:
@@ -106,17 +122,18 @@ if (LLAMA_LLGUIDANCE)
106122
CONFIGURE_COMMAND ""
107123
BUILD_COMMAND cargo build --release
108124
INSTALL_COMMAND ""
109-
BUILD_BYPRODUCTS ${LLGUIDANCE_PATH}/libllguidance.a ${LLGUIDANCE_PATH}/llguidance.h
125+
BUILD_BYPRODUCTS ${LLGUIDANCE_PATH}/${LLGUIDANCE_LIB_NAME} ${LLGUIDANCE_PATH}/llguidance.h
110126
UPDATE_COMMAND ""
111127
)
112128
target_compile_definitions(${TARGET} PUBLIC LLAMA_USE_LLGUIDANCE)
113129

114130
add_library(llguidance STATIC IMPORTED)
115-
set_target_properties(llguidance PROPERTIES IMPORTED_LOCATION ${LLGUIDANCE_PATH}/libllguidance.a)
131+
set_target_properties(llguidance PROPERTIES IMPORTED_LOCATION ${LLGUIDANCE_PATH}/${LLGUIDANCE_LIB_NAME})
116132
add_dependencies(llguidance llguidance_ext)
117133

118134
target_include_directories(${TARGET} PRIVATE ${LLGUIDANCE_PATH})
119-
set(LLAMA_COMMON_EXTRA_LIBS ${LLAMA_COMMON_EXTRA_LIBS} llguidance)
135+
# Add platform libraries to the main target
136+
set(LLAMA_COMMON_EXTRA_LIBS ${LLAMA_COMMON_EXTRA_LIBS} llguidance ${LLGUIDANCE_PLATFORM_LIBS})
120137
endif ()
121138

122139
target_include_directories(${TARGET} PUBLIC .)

0 commit comments

Comments
 (0)