Skip to content

Commit 89daa25

Browse files
authored
llguidance build fixes for Windows (#11664)
* setup windows linking for llguidance; thanks @phil-scott-78 * add build instructions for windows and update script link * change VS Community link from DE to EN * whitespace fix
1 parent 300907b commit 89daa25

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

common/CMakeLists.txt

+20-3
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 .)

docs/build.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ cmake --build build --config Release
4646
```
4747
4848
- Building for Windows (x86, x64 and arm64) with MSVC or clang as compilers:
49-
- Install Visual Studio 2022, e.g. via the [Community Edition](https://visualstudio.microsoft.com/de/vs/community/). In the installer, select at least the following options (this also automatically installs the required additional tools like CMake,...):
49+
- Install Visual Studio 2022, e.g. via the [Community Edition](https://visualstudio.microsoft.com/vs/community/). In the installer, select at least the following options (this also automatically installs the required additional tools like CMake,...):
5050
- Tab Workload: Desktop-development with C++
5151
- Tab Components (select quickly via search): C++-_CMake_ Tools for Windows, _Git_ for Windows, C++-_Clang_ Compiler for Windows, MS-Build Support for LLVM-Toolset (clang)
5252
- Please remember to always use a Developer Command Prompt / PowerShell for VS2022 for git, build, test

docs/llguidance.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ cmake -B build -DLLAMA_LLGUIDANCE=ON
1313
make -C build -j
1414
```
1515

16+
For Windows use `cmake --build build --config Release` instead of `make`.
17+
1618
This requires the Rust compiler and the `cargo` tool to be [installed](https://www.rust-lang.org/tools/install).
1719

1820
## Interface
1921

2022
There are no new command-line arguments or modifications to `common_params`. When enabled, grammars starting with `%llguidance` are passed to LLGuidance instead of the [current](../grammars/README.md) llama.cpp grammars. Additionally, JSON Schema requests (e.g., using the `-j` argument in `llama-cli`) are also passed to LLGuidance.
2123

22-
For your existing GBNF grammars, you can use [gbnf_to_lark.py script](https://github.com/guidance-ai/llguidance/blob/main/scripts/gbnf_to_lark.py) to convert them to LLGuidance Lark-like format.
24+
For your existing GBNF grammars, you can use [gbnf_to_lark.py script](https://github.com/guidance-ai/llguidance/blob/main/python/llguidance/gbnf_to_lark.py) to convert them to LLGuidance Lark-like format.
2325

2426
## Performance
2527

0 commit comments

Comments
 (0)