From 7d8c170cf55527dd9ee073292c74db70300e1cda Mon Sep 17 00:00:00 2001 From: "Michal Moskal (from Dev Box)" Date: Tue, 4 Feb 2025 11:31:04 -0800 Subject: [PATCH 1/4] setup windows linking for llguidance; thanks @phil-scott-78 --- common/CMakeLists.txt | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index e61015d2a..a09109431 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -96,6 +96,22 @@ if (LLAMA_LLGUIDANCE) include(ExternalProject) set(LLGUIDANCE_SRC ${CMAKE_BINARY_DIR}/llguidance/source) set(LLGUIDANCE_PATH ${LLGUIDANCE_SRC}/target/release) + + # Set the correct library file extension based on platform + if (WIN32) + set(LLGUIDANCE_LIB_NAME "llguidance.lib") + # Add Windows-specific libraries + set(LLGUIDANCE_PLATFORM_LIBS + ws2_32 # Windows Sockets API + userenv # For GetUserProfileDirectoryW + ntdll # For NT functions + bcrypt # For BCryptGenRandom + ) + else() + set(LLGUIDANCE_LIB_NAME "libllguidance.a") + set(LLGUIDANCE_PLATFORM_LIBS "") + endif() + ExternalProject_Add(llguidance_ext GIT_REPOSITORY https://github.com/guidance-ai/llguidance # v0.6.12: @@ -106,17 +122,18 @@ if (LLAMA_LLGUIDANCE) CONFIGURE_COMMAND "" BUILD_COMMAND cargo build --release INSTALL_COMMAND "" - BUILD_BYPRODUCTS ${LLGUIDANCE_PATH}/libllguidance.a ${LLGUIDANCE_PATH}/llguidance.h + BUILD_BYPRODUCTS ${LLGUIDANCE_PATH}/${LLGUIDANCE_LIB_NAME} ${LLGUIDANCE_PATH}/llguidance.h UPDATE_COMMAND "" ) target_compile_definitions(${TARGET} PUBLIC LLAMA_USE_LLGUIDANCE) add_library(llguidance STATIC IMPORTED) - set_target_properties(llguidance PROPERTIES IMPORTED_LOCATION ${LLGUIDANCE_PATH}/libllguidance.a) + set_target_properties(llguidance PROPERTIES IMPORTED_LOCATION ${LLGUIDANCE_PATH}/${LLGUIDANCE_LIB_NAME}) add_dependencies(llguidance llguidance_ext) target_include_directories(${TARGET} PRIVATE ${LLGUIDANCE_PATH}) - set(LLAMA_COMMON_EXTRA_LIBS ${LLAMA_COMMON_EXTRA_LIBS} llguidance) + # Add platform libraries to the main target + set(LLAMA_COMMON_EXTRA_LIBS ${LLAMA_COMMON_EXTRA_LIBS} llguidance ${LLGUIDANCE_PLATFORM_LIBS}) endif () target_include_directories(${TARGET} PUBLIC .) From 274c0ecd846ca67fee4410b78657902787bed026 Mon Sep 17 00:00:00 2001 From: "Michal Moskal (from Dev Box)" Date: Tue, 4 Feb 2025 11:31:28 -0800 Subject: [PATCH 2/4] add build instructions for windows and update script link --- docs/llguidance.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/llguidance.md b/docs/llguidance.md index 792d20704..cda787b14 100644 --- a/docs/llguidance.md +++ b/docs/llguidance.md @@ -13,13 +13,15 @@ cmake -B build -DLLAMA_LLGUIDANCE=ON make -C build -j ``` +For Windows use `cmake --build build --config Release` instead of `make`. + This requires the Rust compiler and the `cargo` tool to be [installed](https://www.rust-lang.org/tools/install). ## Interface 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. -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. +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. ## Performance From 73befb530614f4c9735170ed41ba42c63ace7a46 Mon Sep 17 00:00:00 2001 From: "Michal Moskal (from Dev Box)" Date: Tue, 4 Feb 2025 11:31:46 -0800 Subject: [PATCH 3/4] change VS Community link from DE to EN --- docs/build.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/build.md b/docs/build.md index dd6495028..c22199c19 100644 --- a/docs/build.md +++ b/docs/build.md @@ -46,7 +46,7 @@ cmake --build build --config Release ``` - Building for Windows (x86, x64 and arm64) with MSVC or clang as compilers: - - 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,...): + - 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,...): - Tab Workload: Desktop-development with C++ - 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) - Please remember to always use a Developer Command Prompt / PowerShell for VS2022 for git, build, test From 1f9316651fc220e8348dea0d0879a98a4e8d0e52 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Tue, 4 Feb 2025 11:40:21 -0800 Subject: [PATCH 4/4] whitespace fix --- common/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index a09109431..c2b4aa7d0 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -101,7 +101,7 @@ if (LLAMA_LLGUIDANCE) if (WIN32) set(LLGUIDANCE_LIB_NAME "llguidance.lib") # Add Windows-specific libraries - set(LLGUIDANCE_PLATFORM_LIBS + set(LLGUIDANCE_PLATFORM_LIBS ws2_32 # Windows Sockets API userenv # For GetUserProfileDirectoryW ntdll # For NT functions