-
Notifications
You must be signed in to change notification settings - Fork 77
Add Windows (CPU) build support #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Common Makefile definitions shared across subprojects | ||
| # This file should be included at the top of other Makefiles | ||
|
|
||
| # OS detection | ||
| ifeq ($(OS),Windows_NT) | ||
| DETECTED_OS := Windows | ||
| else | ||
| UNAME_S := $(shell uname -s) | ||
| ifeq ($(UNAME_S),Linux) | ||
| DETECTED_OS := Linux | ||
| endif | ||
| ifeq ($(UNAME_S),Darwin) | ||
| DETECTED_OS := macOS | ||
| endif | ||
| endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| model-cli | ||
| model-cli.exe | ||
| .idea/ | ||
| dist/ | ||
| dist/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,27 @@ | ||
| ifeq ($(OS),Windows_NT) | ||
| DETECTED_OS := Windows | ||
| else | ||
| UNAME_S := $(shell uname -s) | ||
| ifeq ($(UNAME_S),Linux) | ||
| DETECTED_OS := Linux | ||
| endif | ||
| ifeq ($(UNAME_S),Darwin) | ||
| DETECTED_OS := macOS | ||
| endif | ||
| endif | ||
| include ../Makefile.common | ||
|
|
||
| BUILD_DIR := build | ||
| INSTALL_DIR := install | ||
| NATIVE_DIR := native | ||
|
|
||
| .PHONY: build clean install-deps build-dir install-dir | ||
| # Vulkan SDK version for Windows | ||
| VULKAN_VERSION := 1.4.313.2 | ||
|
|
||
| # Architecture detection for Windows | ||
| ifeq ($(DETECTED_OS),Windows) | ||
| UNAME_M := $(shell uname -m) | ||
| ifeq ($(UNAME_M),x86_64) | ||
| DETECTED_ARCH := amd64 | ||
| else ifeq ($(UNAME_M),aarch64) | ||
| DETECTED_ARCH := arm64 | ||
| else ifeq ($(UNAME_M),arm64) | ||
| DETECTED_ARCH := arm64 | ||
| else | ||
| DETECTED_ARCH := amd64 | ||
| endif | ||
| endif | ||
|
|
||
| .PHONY: build clean install-deps install-deps-cuda install-deps-opencl build-dir install-dir | ||
|
|
||
| build: install-deps | ||
| ifeq ($(DETECTED_OS),macOS) | ||
|
|
@@ -48,8 +55,60 @@ else ifeq ($(DETECTED_OS),Linux) | |
| @echo "Linux build not implemented yet" | ||
| @exit 1 | ||
| else ifeq ($(DETECTED_OS),Windows) | ||
| @echo "Windows build not implemented yet" | ||
| @exit 1 | ||
| ifeq ($(DETECTED_ARCH),amd64) | ||
| @echo "Building for Windows AMD64 (CPU with Vulkan)..." | ||
| @echo "Configuring CMake..." | ||
| PATH="C:/Program Files/LLVM/bin;$$PATH" cmake -B $(BUILD_DIR) \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DGGML_NATIVE=OFF \ | ||
| -DGGML_OPENMP=OFF \ | ||
| -DDDLLAMA_BUILD_UTILS=ON \ | ||
| -GNinja \ | ||
| -DLLAMA_CURL=OFF \ | ||
| -DBUILD_SHARED_LIBS=ON \ | ||
| -DGGML_BACKEND_DL=ON \ | ||
| -DGGML_CPU_ALL_VARIANTS=ON \ | ||
| -DGGML_VULKAN=ON \ | ||
| "-DCMAKE_C_COMPILER=C:/Program Files/LLVM/bin/clang.exe" \ | ||
| "-DCMAKE_CXX_COMPILER=C:/Program Files/LLVM/bin/clang++.exe" \ | ||
| "-DCMAKE_RC_COMPILER=C:/Program Files/LLVM/bin/llvm-rc.exe" \ | ||
| -S $(NATIVE_DIR) | ||
| @echo "Building..." | ||
| PATH="C:/Program Files/LLVM/bin;$$PATH" cmake --build $(BUILD_DIR) --config Release | ||
|
Comment on lines
+61
to
+77
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The path to the LLVM toolchain is hardcoded. This can cause issues if LLVM is installed in a different location. It's better to define a variable for the LLVM path at the top of the file (e.g., |
||
| @echo "Installing..." | ||
| cmake --install $(BUILD_DIR) \ | ||
| --config Release \ | ||
| --prefix $(INSTALL_DIR) | ||
| @echo "Cleaning install directory..." | ||
| rm -f $(INSTALL_DIR)/bin/*.py | ||
| rm -rf $(INSTALL_DIR)/lib/cmake | ||
| rm -rf $(INSTALL_DIR)/lib/pkgconfig | ||
| rm -rf $(INSTALL_DIR)/include | ||
| @echo "Build complete! Binaries are in $(INSTALL_DIR)" | ||
|
Comment on lines
+82
to
+87
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block of code for cleaning the install directory is duplicated in the define WINDOWS_POST_INSTALL_CLEAN
@echo "Cleaning install directory..."
rm -f $(INSTALL_DIR)/bin/*.py
rm -rf $(INSTALL_DIR)/lib/cmake
rm -rf $(INSTALL_DIR)/lib/pkgconfig
rm -rf $(INSTALL_DIR)/include
@echo "Build complete! Binaries are in $(INSTALL_DIR)"
endefThen use |
||
| else | ||
| @echo "Building for Windows ARM64 (CPU)..." | ||
| @echo "Configuring CMake..." | ||
| cmake -B $(BUILD_DIR) \ | ||
| -G Ninja \ | ||
| -DCMAKE_C_COMPILER="C:/Program Files/LLVM/bin/clang.exe" \ | ||
| -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DGGML_NATIVE=OFF \ | ||
| -DLLAMA_CURL=OFF \ | ||
| -S $(NATIVE_DIR) | ||
|
Comment on lines
+91
to
+98
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the |
||
| @echo "Building..." | ||
| cmake --build $(BUILD_DIR) --config Release | ||
| @echo "Installing..." | ||
| cmake --install $(BUILD_DIR) \ | ||
| --config Release \ | ||
| --prefix $(INSTALL_DIR) | ||
| @echo "Cleaning install directory..." | ||
| rm -f $(INSTALL_DIR)/bin/*.py | ||
| rm -rf $(INSTALL_DIR)/lib/cmake | ||
| rm -rf $(INSTALL_DIR)/lib/pkgconfig | ||
| rm -rf $(INSTALL_DIR)/include | ||
| @echo "Build complete! Binaries are in $(INSTALL_DIR)" | ||
|
Comment on lines
+105
to
+110
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| endif | ||
| else | ||
| @echo "Unsupported OS: $(DETECTED_OS)" | ||
| @exit 1 | ||
|
|
@@ -68,8 +127,30 @@ else ifeq ($(DETECTED_OS),Linux) | |
| @echo "Linux dependency installation not implemented yet" | ||
| @exit 1 | ||
| else ifeq ($(DETECTED_OS),Windows) | ||
| @echo "Windows dependency installation not implemented yet" | ||
| @exit 1 | ||
| ifeq ($(DETECTED_ARCH),amd64) | ||
| @echo "Installing build dependencies for Windows AMD64 (CPU with Vulkan)..." | ||
| @echo "Installing Ninja..." | ||
| choco install ninja -y | ||
| @echo "Installing CMake..." | ||
| choco install cmake -y --installargs 'ADD_CMAKE_TO_PATH=System' | ||
| @echo "Installing LLVM (clang)..." | ||
| choco install llvm -y | ||
| @echo "Adding LLVM to system PATH..." | ||
| @powershell -Command "[System.Environment]::SetEnvironmentVariable('PATH', 'C:\\Program Files\\LLVM\\bin;' + [System.Environment]::GetEnvironmentVariable('PATH', 'Machine'), 'Machine')" || echo "LLVM PATH update attempted" | ||
| @if [ -d "/c/VulkanSDK/$(VULKAN_VERSION)" ]; then \ | ||
| echo "Vulkan SDK $(VULKAN_VERSION) already installed"; \ | ||
| else \ | ||
| echo "Installing Vulkan SDK $(VULKAN_VERSION)..."; \ | ||
| curl.exe -o "$$TEMP/VulkanSDK-Installer.exe" -L "https://sdk.lunarg.com/sdk/download/$(VULKAN_VERSION)/windows/vulkansdk-windows-X64-$(VULKAN_VERSION).exe"; \ | ||
| "$$TEMP/VulkanSDK-Installer.exe" --accept-licenses --default-answer --confirm-command install; \ | ||
| powershell -Command "[System.Environment]::SetEnvironmentVariable('VULKAN_SDK', 'C:\\VulkanSDK\\$(VULKAN_VERSION)', 'User')"; \ | ||
| powershell -Command "[System.Environment]::SetEnvironmentVariable('PATH', [System.Environment]::GetEnvironmentVariable('PATH', 'User') + ';C:\\VulkanSDK\\$(VULKAN_VERSION)\\bin', 'User')"; \ | ||
| echo "Vulkan SDK $(VULKAN_VERSION) installed. Please restart your shell for changes to take effect."; \ | ||
| fi | ||
|
Comment on lines
+139
to
+149
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The paths for LLVM and Vulkan SDK are hardcoded. This can lead to problems if the user has installed them in non-default locations. It would be more robust to use variables for these paths, with sensible defaults. For example: LLVM_INSTALL_PATH ?= C:\\Program Files\\LLVM
VULKAN_INSTALL_PATH ?= C:\\VulkanSDKThen use |
||
| else | ||
| @echo "Installing build dependencies for Windows ARM64 (CPU)..." | ||
| @echo "Ninja and LLVM should already be installed on ARM64 runners" | ||
| endif | ||
| else | ||
| @echo "Unsupported OS: $(DETECTED_OS)" | ||
| @exit 1 | ||
|
|
@@ -87,9 +168,9 @@ install-dir: | |
|
|
||
| help: | ||
| @echo "Available targets:" | ||
| @echo " build - Build llama.cpp (macOS only for now)" | ||
| @echo " install-deps - Install build dependencies" | ||
| @echo " build-dir - Print build directory path" | ||
| @echo " install-dir - Print install directory path" | ||
| @echo " clean - Clean build artifacts" | ||
| @echo " help - Show this help" | ||
| @echo " build - Build llama.cpp (macOS and Windows)" | ||
| @echo " install-deps - Install build dependencies (CPU with Vulkan for Windows AMD64)" | ||
| @echo " build-dir - Print build directory path" | ||
| @echo " install-dir - Print install directory path" | ||
| @echo " clean - Clean build artifacts" | ||
| @echo " help - Show this help" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current OS detection logic doesn't handle cases where
uname -sreturns something other thanLinuxorDarwin(e.g.,FreeBSD). In such cases,DETECTED_OSwill be empty, which could lead to confusing "Unsupported OS: " messages later. It would be better to use anif-else-ifstructure and set a default value forDETECTED_OSto provide a more informative message for unsupported systems.