Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 74063fc

Browse files
committed
feat: pack cortex.llamacpp to cortex-cpp build
1 parent ab128f5 commit 74063fc

File tree

4 files changed

+127
-10
lines changed

4 files changed

+127
-10
lines changed

.github/workflows/cortex-cpp-quality-gate.yml

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,85 @@ jobs:
2222
matrix:
2323
include:
2424
- os: "linux"
25-
name: "amd64"
25+
name: "amd64-noavx"
2626
runs-on: "ubuntu-20-04"
27-
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}}"
27+
cmake-flags: "-DLLAMA_NATIVE=OFF"
28+
build-deps-cmake-flags: ""
29+
run-e2e: false
30+
ccache-dir: ''
31+
32+
- os: "linux"
33+
name: "amd64-vulkan"
34+
runs-on: "ubuntu-20-04-cuda-11-7"
35+
cmake-flags: "-DLLAMA_VULKAN=ON -DLLAMA_NATIVE=OFF"
36+
build-deps-cmake-flags: ""
37+
run-e2e: false
38+
ccache-dir: ''
39+
40+
- os: "linux"
41+
name: "amd64-noavx-cuda-11-7"
42+
runs-on: "ubuntu-20-04-cuda-11-7"
43+
cmake-flags: "-DCUDA_11_7=ON -DLLAMA_NATIVE=OFF -DLLAMA_CUDA=ON"
2844
build-deps-cmake-flags: ""
45+
run-e2e: false
2946
ccache-dir: ''
47+
48+
- os: "linux"
49+
name: "amd64-noavx-cuda-12-0"
50+
runs-on: "ubuntu-20-04-cuda-12-0"
51+
cmake-flags: "-DCUDA_12_0=ON -DLLAMA_NATIVE=OFF -DLLAMA_CUDA=ON"
52+
build-deps-cmake-flags: ""
53+
run-e2e: false
54+
ccache-dir: ''
55+
3056
- os: "mac"
3157
name: "amd64"
3258
runs-on: "macos-13"
33-
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}}"
59+
cmake-flags: ""
3460
build-deps-cmake-flags: ""
61+
run-e2e: false
3562
ccache-dir: ''
63+
3664
- os: "mac"
3765
name: "arm64"
3866
runs-on: "mac-silicon"
39-
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}} -DMAC_ARM64=ON"
67+
cmake-flags: "-DMAC_ARM64=ON"
4068
build-deps-cmake-flags: ""
69+
run-e2e: false
4170
ccache-dir: ''
71+
4272
- os: "windows"
43-
name: "amd64"
73+
name: "amd64-noavx"
74+
runs-on: "windows-cuda-11-7"
75+
cmake-flags: "-DLLAMA_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DLLAMA_BLAS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
76+
build-deps-cmake-flags: "-DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
77+
run-e2e: false
78+
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache'
79+
80+
- os: "windows"
81+
name: "amd64-vulkan"
82+
runs-on: "windows-cuda-12-0"
83+
cmake-flags: "-DLLAMA_VULKAN=ON -DLLAMA_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
84+
build-deps-cmake-flags: "-DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
85+
run-e2e: false
86+
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache'
87+
88+
- os: "windows"
89+
name: "amd64-noavx-cuda-12-0"
4490
runs-on: "windows-cuda-12-0"
45-
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}} -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
91+
cmake-flags: "-DLLAMA_NATIVE=OFF -DCUDA_12_0=ON -DLLAMA_BUILD_SERVER=ON -DLLAMA_CUDA=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
4692
build-deps-cmake-flags: "-DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
47-
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache'
93+
run-e2e: false
94+
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache'
95+
96+
- os: "windows"
97+
name: "amd64-noavx-cuda-11-7"
98+
runs-on: "windows-cuda-11-7"
99+
cmake-flags: "-DLLAMA_NATIVE=OFF -DCUDA_11_7=ON -DLLAMA_BUILD_SERVER=ON -DLLAMA_CUDA=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
100+
build-deps-cmake-flags: "-DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
101+
run-e2e: false
102+
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache'
103+
48104
steps:
49105
- name: Clone
50106
id: checkout

cortex-cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cmake_minimum_required(VERSION 3.5)
22

33
project(cortex-cpp C CXX)
4+
include(engines/cortex.llamacpp/engine.cmake)
45

56
# Build using CMAKE-JS
67
if(DEFINED CMAKE_JS_INC)

cortex-cpp/Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ endif
3838

3939
pre-package:
4040
ifeq ($(OS),Windows_NT)
41-
@powershell -Command "mkdir -p cortex-cpp;"
41+
@powershell -Command "mkdir -p cortex-cpp\engines\cortex.llamacpp\; cp build\engines\cortex.llamacpp\engine.dll cortex-cpp\engines\cortex.llamacpp\;"
4242
@powershell -Command "cp build\cortex-cpp.exe .\cortex-cpp\;"
4343
@powershell -Command "cp ..\.github\patches\windows\msvcp140.dll .\cortex-cpp\;"
4444
@powershell -Command "cp ..\.github\patches\windows\vcruntime140_1.dll .\cortex-cpp\;"
4545
@powershell -Command "cp ..\.github\patches\windows\vcruntime140.dll .\cortex-cpp\;"
4646
else ifeq ($(shell uname -s),Linux)
47-
@mkdir -p cortex-cpp; \
47+
@mkdir -p cortex-cpp/engines/cortex.llamacpp; \
48+
cp build/engines/cortex.llamacpp/libengine.so cortex-cpp/engines/cortex.llamacpp/; \
4849
cp build/cortex-cpp cortex-cpp/;
4950
else
50-
@mkdir -p cortex-cpp; \
51+
@mkdir -p cortex-cpp/engines/cortex.llamacpp; \
52+
cp build/engines/cortex.llamacpp/libengine.dylib cortex-cpp/engines/cortex.llamacpp/; \
5153
cp build/cortex-cpp cortex-cpp/;
5254
endif
5355

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# cortex.llamacpp release version
2+
set(VERSION 0.1.25)
3+
4+
set(ENGINE_VERSION v${VERSION})
5+
add_compile_definitions(CORTEX_LLAMACPP_VERSION="${VERSION}")
6+
7+
# MESSAGE("ENGINE_VERSION=" ${ENGINE_VERSION})
8+
9+
# Download library based on instructions
10+
if(UNIX AND NOT APPLE)
11+
if(CUDA_12_0)
12+
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-linux-amd64-noavx-cuda-12-0.tar.gz)
13+
elseif(CUDA_11_7)
14+
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-linux-amd64-noavx-cuda-11-7.tar.gz)
15+
elseif(LLAMA_VULKAN)
16+
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-linux-amd64-vulkan.tar.gz)
17+
set(ENGINE_VERSION v${VERSION})
18+
else()
19+
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-linux-amd64-noavx.tar.gz)
20+
endif()
21+
elseif(UNIX)
22+
if(MAC_ARM64)
23+
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-mac-arm64.tar.gz)
24+
else()
25+
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-mac-amd64.tar.gz)
26+
endif()
27+
else()
28+
if(CUDA_12_0)
29+
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-windows-amd64-noavx-cuda-12-0.tar.gz)
30+
elseif(CUDA_11_7)
31+
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-windows-amd64-noavx-cuda-11-7.tar.gz)
32+
elseif(LLAMA_VULKAN)
33+
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-windows-amd64-vulkan.tar.gz)
34+
set(ENGINE_VERSION v${VERSION})
35+
else()
36+
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-windows-amd64-noavx.tar.gz)
37+
endif()
38+
endif()
39+
40+
41+
set(LIBLLAMA_ENGINE_URL https://github.com/janhq/cortex.llamacpp/releases/download/${ENGINE_VERSION}/${LIBRARY_NAME})
42+
# MESSAGE("LIBLLAMA_ENGINE_URL="${LIBLLAMA_ENGINE_URL})
43+
# MESSAGE("LIBARRY_NAME=" ${LIBRARY_NAME})
44+
45+
set(LIBLLAMA_ENGINE_PATH ${CMAKE_BINARY_DIR}/engines/${LIBRARY_NAME})
46+
47+
# MESSAGE("CMAKE_BINARY_DIR = " ${CMAKE_BINARY_DIR})
48+
49+
file(DOWNLOAD ${LIBLLAMA_ENGINE_URL} ${LIBLLAMA_ENGINE_PATH} STATUS LIBLLAMA_ENGINE_DOWNLOAD_STATUS)
50+
list(GET LIBLLAMA_ENGINE_DOWNLOAD_STATUS 0 LIBLLAMA_ENGINE_DOWNLOAD_STATUS_NO)
51+
# MESSAGE("file = " ${CMAKE_BINARY_DIR}/engines/${LIBRARY_NAME})
52+
53+
if(LIBLLAMA_ENGINE_DOWNLOAD_STATUS_NO)
54+
message(STATUS "Pre-built library not downloaded. (${LIBLLAMA_ENGINE_DOWNLOAD_STATUS})")
55+
else()
56+
message(STATUS "Linking downloaded pre-built library.")
57+
file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/engines/${LIBRARY_NAME} DESTINATION ${CMAKE_BINARY_DIR}/engines/)
58+
endif()

0 commit comments

Comments
 (0)