From 518d4187e02971921d9122e580151feebde1bfbe Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Thu, 5 Sep 2024 12:57:30 +0300 Subject: [PATCH 1/8] feat: Adding Windows ARM64 packages --- .github/workflows/release-python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-python.yml b/.github/workflows/release-python.yml index 27491a3..897b93f 100644 --- a/.github/workflows/release-python.yml +++ b/.github/workflows/release-python.yml @@ -58,7 +58,7 @@ jobs: CIBW_BUILD: "cp${{matrix.python}}-*" CIBW_SKIP: "pp* *musllinux*" CIBW_ARCHS_MACOS: "arm64 x86_64" - CIBW_ARCHS_WINDOWS: "AMD64" + CIBW_ARCHS_WINDOWS: "AMD64 ARM64" CIBW_ARCHS_LINUX: "x86_64 aarch64" CIBW_BEFORE_BUILD: "make lib" CIBW_TEST_REQUIRES: "pytest>=6.0.0 huggingface_hub" From 2560becf7c38986faf0f962c1008c12c445654cd Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Thu, 5 Sep 2024 14:02:49 +0300 Subject: [PATCH 2/8] chore: Updating make lib to account for arch --- Makefile | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0d57120..f58f231 100644 --- a/Makefile +++ b/Makefile @@ -38,11 +38,20 @@ ifeq ($(findstring x86_64,$(ARCH)),x86_64) IS_X86 = true endif +CMAKE_ARCH_FLAG = "" + +# Add architecture flag based on the target platform +ifeq ($(findstring win_arm64,$(ARCH)),win_arm64) + CMAKE_ARCH_FLAG = "-A ARM64" +else ifeq ($(findstring win_amd64,$(ARCH)),win_amd64) + CMAKE_ARCH_FLAG = "-A x64" +endif + lib: rm -rf build && mkdir build @if [ "$(IS_X86)" = "true" ]; then \ - arch -x86_64 /bin/bash -c "cd build && cmake ${CMAKE_FLAGS} -DGGML_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DGGML_RPC=ON -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DBUILD_SHARED_LIBS=OFF .. && cmake --build . --config Release"; \ + arch -x86_64 /bin/bash -c "cd build && cmake ${CMAKE_FLAGS} ${CMAKE_ARCH_FLAG} -DGGML_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DGGML_RPC=ON -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DBUILD_SHARED_LIBS=OFF .. && cmake --build . --config Release"; \ else \ - cd build && cmake ${CMAKE_FLAGS} -DGGML_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DGGML_RPC=ON -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DBUILD_SHARED_LIBS=OFF .. && cmake --build . --config Release; \ + cd build && cmake ${CMAKE_FLAGS} ${CMAKE_ARCH_FLAG} -DGGML_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DGGML_RPC=ON -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DBUILD_SHARED_LIBS=OFF .. && cmake --build . --config Release; \ fi #-j $(sysctl -n hw.logicalcpu) \ No newline at end of file From dd9162c66cdee407b95cf6e521fffe7f0bb7ea81 Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Thu, 5 Sep 2024 14:21:27 +0300 Subject: [PATCH 3/8] chore: Reducing scope of build to test out wind arm64 --- .github/workflows/release-python.yml | 4 ++-- Makefile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release-python.yml b/.github/workflows/release-python.yml index 897b93f..59e5db1 100644 --- a/.github/workflows/release-python.yml +++ b/.github/workflows/release-python.yml @@ -17,7 +17,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - os: [windows-latest,macos-latest,ubuntu-latest] #, windows-latest, macos-latest, macos-14, ubuntu-latest, + os: [windows-latest] #,macos-latest,ubuntu-latest] #, windows-latest, macos-latest, macos-14, ubuntu-latest, python: [38,39,310,311,312] steps: - name: Dependencies @@ -58,7 +58,7 @@ jobs: CIBW_BUILD: "cp${{matrix.python}}-*" CIBW_SKIP: "pp* *musllinux*" CIBW_ARCHS_MACOS: "arm64 x86_64" - CIBW_ARCHS_WINDOWS: "AMD64 ARM64" + CIBW_ARCHS_WINDOWS: "ARM64" CIBW_ARCHS_LINUX: "x86_64 aarch64" CIBW_BEFORE_BUILD: "make lib" CIBW_TEST_REQUIRES: "pytest>=6.0.0 huggingface_hub" diff --git a/Makefile b/Makefile index f58f231..08c921c 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,6 @@ ifeq ($(findstring x86_64,$(ARCH)),x86_64) endif CMAKE_ARCH_FLAG = "" - # Add architecture flag based on the target platform ifeq ($(findstring win_arm64,$(ARCH)),win_arm64) CMAKE_ARCH_FLAG = "-A ARM64" @@ -48,6 +47,7 @@ else ifeq ($(findstring win_amd64,$(ARCH)),win_amd64) endif lib: + @echo "Building for $(ARCH)" rm -rf build && mkdir build @if [ "$(IS_X86)" = "true" ]; then \ arch -x86_64 /bin/bash -c "cd build && cmake ${CMAKE_FLAGS} ${CMAKE_ARCH_FLAG} -DGGML_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DGGML_RPC=ON -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DBUILD_SHARED_LIBS=OFF .. && cmake --build . --config Release"; \ From 2176751cce29fc57e5b6045588d043e8fffbfc5f Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Thu, 5 Sep 2024 14:28:43 +0300 Subject: [PATCH 4/8] chore: Leaving just cp39 for test --- .github/workflows/release-python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-python.yml b/.github/workflows/release-python.yml index 59e5db1..915f479 100644 --- a/.github/workflows/release-python.yml +++ b/.github/workflows/release-python.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: os: [windows-latest] #,macos-latest,ubuntu-latest] #, windows-latest, macos-latest, macos-14, ubuntu-latest, - python: [38,39,310,311,312] + python: [39] # 38,310,311,312 steps: - name: Dependencies if: matrix.os == 'ubuntu-latest' From 93a2ca023275927a8f11edec1b6677098557fab5 Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Thu, 5 Sep 2024 14:36:03 +0300 Subject: [PATCH 5/8] chore: Checking $(PROCESSOR_ARCHITECTURE) on win --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 08c921c..f123b0f 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ else ifeq ($(findstring win_amd64,$(ARCH)),win_amd64) endif lib: - @echo "Building for $(ARCH)" + @echo "Building for $(PROCESSOR_ARCHITECTURE)" rm -rf build && mkdir build @if [ "$(IS_X86)" = "true" ]; then \ arch -x86_64 /bin/bash -c "cd build && cmake ${CMAKE_FLAGS} ${CMAKE_ARCH_FLAG} -DGGML_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DGGML_RPC=ON -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DBUILD_SHARED_LIBS=OFF .. && cmake --build . --config Release"; \ From 33b01a3de346258e51df10b452d843b0e5917abf Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Thu, 5 Sep 2024 14:44:12 +0300 Subject: [PATCH 6/8] chore: Checking cross-compile with CIBW_ARCHS and _PYTHON_HOST_PLATFORM --- Makefile | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f123b0f..526fe44 100644 --- a/Makefile +++ b/Makefile @@ -46,8 +46,35 @@ else ifeq ($(findstring win_amd64,$(ARCH)),win_amd64) CMAKE_ARCH_FLAG = "-A x64" endif +# Function to detect target architecture +define detect_arch +$(shell \ + if [ -n "$$CIBW_ARCHS" ]; then \ + case "$$CIBW_ARCHS" in \ + *arm64*|*aarch64*) echo "arm64" ;; \ + *x86_64*|*AMD64*) echo "x86_64" ;; \ + *) echo "unknown" ;; \ + esac; \ + elif [ -n "$$_PYTHON_HOST_PLATFORM" ]; then \ + case "$$_PYTHON_HOST_PLATFORM" in \ + *arm64*|*aarch64*) echo "arm64" ;; \ + *x86_64*) echo "x86_64" ;; \ + *) echo "unknown" ;; \ + esac; \ + else \ + case "$$(uname -m)" in \ + arm64|aarch64) echo "arm64" ;; \ + x86_64|amd64) echo "x86_64" ;; \ + *) echo "unknown" ;; \ + esac; \ + fi \ +) +endef + +TARGET_ARCH := $(call detect_arch) + lib: - @echo "Building for $(PROCESSOR_ARCHITECTURE)" + @echo "Building for $(TARGET_ARCH)" rm -rf build && mkdir build @if [ "$(IS_X86)" = "true" ]; then \ arch -x86_64 /bin/bash -c "cd build && cmake ${CMAKE_FLAGS} ${CMAKE_ARCH_FLAG} -DGGML_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DGGML_RPC=ON -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DBUILD_SHARED_LIBS=OFF .. && cmake --build . --config Release"; \ From 25d37303fcbca4f5c3b8cb7c801521c527eb86a9 Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Thu, 5 Sep 2024 15:01:26 +0300 Subject: [PATCH 7/8] chore: Using some tricks to detect cross-compile --- Makefile | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 526fe44..8487091 100644 --- a/Makefile +++ b/Makefile @@ -40,41 +40,14 @@ endif CMAKE_ARCH_FLAG = "" # Add architecture flag based on the target platform -ifeq ($(findstring win_arm64,$(ARCH)),win_arm64) +ifeq ($(findstring arm64,$(SETUPTOOLS_EXT_SUFFIX)),arm64) CMAKE_ARCH_FLAG = "-A ARM64" -else ifeq ($(findstring win_amd64,$(ARCH)),win_amd64) +else CMAKE_ARCH_FLAG = "-A x64" endif -# Function to detect target architecture -define detect_arch -$(shell \ - if [ -n "$$CIBW_ARCHS" ]; then \ - case "$$CIBW_ARCHS" in \ - *arm64*|*aarch64*) echo "arm64" ;; \ - *x86_64*|*AMD64*) echo "x86_64" ;; \ - *) echo "unknown" ;; \ - esac; \ - elif [ -n "$$_PYTHON_HOST_PLATFORM" ]; then \ - case "$$_PYTHON_HOST_PLATFORM" in \ - *arm64*|*aarch64*) echo "arm64" ;; \ - *x86_64*) echo "x86_64" ;; \ - *) echo "unknown" ;; \ - esac; \ - else \ - case "$$(uname -m)" in \ - arm64|aarch64) echo "arm64" ;; \ - x86_64|amd64) echo "x86_64" ;; \ - *) echo "unknown" ;; \ - esac; \ - fi \ -) -endef - -TARGET_ARCH := $(call detect_arch) - lib: - @echo "Building for $(TARGET_ARCH)" + @echo "Building for $(CMAKE_ARCH_FLAG)" rm -rf build && mkdir build @if [ "$(IS_X86)" = "true" ]; then \ arch -x86_64 /bin/bash -c "cd build && cmake ${CMAKE_FLAGS} ${CMAKE_ARCH_FLAG} -DGGML_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DGGML_RPC=ON -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DBUILD_SHARED_LIBS=OFF .. && cmake --build . --config Release"; \ From b2652723e1fbf77fcab03a0eb40ef0ab202ddc69 Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Thu, 5 Sep 2024 15:36:33 +0300 Subject: [PATCH 8/8] chore: Adding MSBuild for arm64 --- .github/workflows/release-python.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/release-python.yml b/.github/workflows/release-python.yml index 915f479..ac3a97a 100644 --- a/.github/workflows/release-python.yml +++ b/.github/workflows/release-python.yml @@ -50,6 +50,12 @@ jobs: if: matrix.os == 'windows-latest' run: | echo "SHARED_LIB_PATH=../../build/Release" >> $GITHUB_ENV + - name: Setup MSBuild + if: matrix.os == 'windows-latest' + uses: microsoft/setup-msbuild@v2 + with: + vs-version: 'latest' # Or specify a specific version like '17.0' + msbuild-architecture: 'arm64' # Crucial to target ARM64 tools - name: Build wheels run: | make python-cidist