From 1a788f8ae6e394a6f9764dc0cb5e653f68d8b4d3 Mon Sep 17 00:00:00 2001 From: codingl2k1 Date: Sun, 2 Mar 2025 10:42:56 +0100 Subject: [PATCH 1/7] Try to fix windows build --- scripts/setup.sh | 8 ++++---- setup.py | 33 +++++++++++++++++---------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index ee4be550..2c5937b6 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -22,10 +22,10 @@ build_llamacpp() { cd build && \ cmake .. -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_LIBDIR=lib && \ cmake --build . --config Release && \ - cmake --install . --prefix ${PREFIX} && \ - cp common/libcommon.a ${LIB} && \ - cp examples/llava/libllava_static.a ${LIB}/libllava.a && \ - cd ${CWD} + cmake --install . --prefix ${PREFIX} + [[ -e common/libcommon.a ]] && cp common/libcommon.a ${LIB} + [[ -e common/Release/common.lib ]] && cp common/Release/common.lib ${LIB} + cd ${CWD} } get_llamacpp_shared() { diff --git a/setup.py b/setup.py index debad004..8b3d8614 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,6 @@ PLATFORM = platform.system() -WITH_DYLIB = os.getenv("WITH_DYLIB", False) LLAMACPP_INCLUDES_DIR = os.path.join(CWD, "src/llama.cpp/include") LLAMACPP_LIBS_DIR = os.path.join(CWD, "src/llama.cpp/lib") @@ -27,7 +26,9 @@ INCLUDE_DIRS = [ "src/pyllama", LLAMACPP_INCLUDES_DIR, - os.path.join(CWD, "thirdparty/llama.cpp"), # For including 'common/base64.hpp' in server/utils.hpp + os.path.join( + CWD, "thirdparty/llama.cpp" + ), # For including 'common/base64.hpp' in server/utils.hpp os.path.join(CWD, "thirdparty/llama.cpp/examples/server"), ] LIBRARY_DIRS = [ @@ -35,14 +36,14 @@ ] LIBRARIES = ["pthread"] - -if WITH_DYLIB: - EXTRA_OBJECTS.append(f"{LLAMACPP_LIBS_DIR}/libcommon.a") - LIBRARIES.extend( +if PLATFORM == "Windows": + EXTRA_OBJECTS.extend( [ - "common", - "ggml", - "llama", + f"{LLAMACPP_LIBS_DIR}/common.lib", + f"{LLAMACPP_LIBS_DIR}/llama.lib", + f"{LLAMACPP_LIBS_DIR}/ggml.lib", + f"{LLAMACPP_LIBS_DIR}/ggml-base.lib", + f"{LLAMACPP_LIBS_DIR}/ggml-cpu.lib", ] ) else: @@ -55,13 +56,13 @@ f"{LLAMACPP_LIBS_DIR}/libggml-cpu.a", ] ) - if PLATFORM == "Darwin": - EXTRA_OBJECTS.extend( - [ - f"{LLAMACPP_LIBS_DIR}/libggml-blas.a", - f"{LLAMACPP_LIBS_DIR}/libggml-metal.a", - ] - ) +if PLATFORM == "Darwin": + EXTRA_OBJECTS.extend( + [ + f"{LLAMACPP_LIBS_DIR}/libggml-blas.a", + f"{LLAMACPP_LIBS_DIR}/libggml-metal.a", + ] + ) INCLUDE_DIRS.append(os.path.join(CWD, "src/pyllama")) From b2ff3da69e36eb6dd9d3819a835601a0111e7b78 Mon Sep 17 00:00:00 2001 From: codingl2k1 Date: Sun, 2 Mar 2025 11:06:55 +0100 Subject: [PATCH 2/7] Fix --- Makefile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index ce800bda..89855cdb 100644 --- a/Makefile +++ b/Makefile @@ -23,18 +23,13 @@ endif all: build -build_llama_cpp: +build: @bash scripts/setup.sh - -build: build_llama_cpp - @git diff thirdparty > changes.diff - @python3 setup.py build_ext --inplace - - + python setup.py build_ext --inplace wheel: @echo "WITH_DYLIB=$(WITH_DYLIB)" - @python3 setup.py bdist_wheel + @python setup.py bdist_wheel ifeq ($(WITH_DYLIB),1) delocate-wheel -v dist/*.whl endif From d06da87684bf6cd398ff5252472fc6ca22b6680b Mon Sep 17 00:00:00 2001 From: codingl2k1 Date: Sun, 2 Mar 2025 11:27:31 +0100 Subject: [PATCH 3/7] Windows build without pthread --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8b3d8614..8e651d6a 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,6 @@ LIBRARY_DIRS = [ LLAMACPP_LIBS_DIR, ] -LIBRARIES = ["pthread"] if PLATFORM == "Windows": EXTRA_OBJECTS.extend( @@ -47,6 +46,7 @@ ] ) else: + LIBRARIES = ["pthread"] EXTRA_OBJECTS.extend( [ f"{LLAMACPP_LIBS_DIR}/libcommon.a", From aebfffb546e5bf13f4d57e3e2b1ea0bf5cbd2622 Mon Sep 17 00:00:00 2001 From: codingl2k1 Date: Sun, 2 Mar 2025 11:37:40 +0100 Subject: [PATCH 4/7] Fix --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8e651d6a..158ed7e5 100644 --- a/setup.py +++ b/setup.py @@ -34,6 +34,7 @@ LIBRARY_DIRS = [ LLAMACPP_LIBS_DIR, ] +LIBRARIES = [] if PLATFORM == "Windows": EXTRA_OBJECTS.extend( @@ -46,7 +47,7 @@ ] ) else: - LIBRARIES = ["pthread"] + LIBRARIES.extend(["pthread"]) EXTRA_OBJECTS.extend( [ f"{LLAMACPP_LIBS_DIR}/libcommon.a", From 45f1769bdf9de69b0b8d6f7add775446ac10bb7e Mon Sep 17 00:00:00 2001 From: codingl2k1 Date: Sun, 2 Mar 2025 11:56:18 +0100 Subject: [PATCH 5/7] Fix build --- setup.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/setup.py b/setup.py index 158ed7e5..8332354a 100644 --- a/setup.py +++ b/setup.py @@ -37,15 +37,7 @@ LIBRARIES = [] if PLATFORM == "Windows": - EXTRA_OBJECTS.extend( - [ - f"{LLAMACPP_LIBS_DIR}/common.lib", - f"{LLAMACPP_LIBS_DIR}/llama.lib", - f"{LLAMACPP_LIBS_DIR}/ggml.lib", - f"{LLAMACPP_LIBS_DIR}/ggml-base.lib", - f"{LLAMACPP_LIBS_DIR}/ggml-cpu.lib", - ] - ) + LIBRARIES.extend(["common", "llama", "ggml", "ggml-base", "ggml-cpu"]) else: LIBRARIES.extend(["pthread"]) EXTRA_OBJECTS.extend( From 789dbba383d460f5228807bb302cca005c5be6a5 Mon Sep 17 00:00:00 2001 From: codingl2k1 Date: Sun, 2 Mar 2025 13:30:14 +0100 Subject: [PATCH 6/7] Only build x64 for windows wheel --- .github/workflows/build-wheel.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-wheel.yaml b/.github/workflows/build-wheel.yaml index e5e12139..8fde084d 100644 --- a/.github/workflows/build-wheel.yaml +++ b/.github/workflows/build-wheel.yaml @@ -111,22 +111,22 @@ jobs: # Windows AMD64 - os: windows-latest - arch: auto + arch: AMD64 platform-id: win_amd64 python: 39 requires-python: ">=3.9,<3.10" - os: windows-latest - arch: auto + arch: AMD64 platform-id: win_amd64 python: 310 requires-python: ">=3.10,<3.11" - os: windows-latest - arch: auto + arch: AMD64 platform-id: win_amd64 python: 311 requires-python: ">=3.11,<3.12" - os: windows-latest - arch: auto + arch: AMD64 platform-id: win_amd64 python: 312 requires-python: ">=3.12,<3.13" From 545b5a9f0ef5154978b6a0370f3f8ca97b460b14 Mon Sep 17 00:00:00 2001 From: codingl2k1 Date: Sun, 2 Mar 2025 13:39:20 +0100 Subject: [PATCH 7/7] Fix build --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8332354a..5588e83d 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ LIBRARIES = [] if PLATFORM == "Windows": - LIBRARIES.extend(["common", "llama", "ggml", "ggml-base", "ggml-cpu"]) + LIBRARIES.extend(["common", "llama", "ggml", "ggml-base", "ggml-cpu", "Advapi32"]) else: LIBRARIES.extend(["pthread"]) EXTRA_OBJECTS.extend(