forked from chendan555/llamafile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-server.bat
More file actions
144 lines (125 loc) · 4.11 KB
/
Copy pathbuild-server.bat
File metadata and controls
144 lines (125 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
echo ============================================
echo llama.cpp Build Script (server only)
echo ============================================
echo.
:: ===== Configuration =====
set "WORK_DIR=%~dp0"
set "TOOLS_DIR=%WORK_DIR%tools"
set "SRC_DIR=%WORK_DIR%\llama.cpp"
set "CMAKE_MIN_VERSION=3.24"
:: ===== Check for system CMake =====
echo [0/3] Checking CMake...
set "CMAKE_MIN_VERSION=3.24"
set "SYS_CMAKE_VER="
where.exe cmake >nul 2>&1
if %errorlevel% neq 0 goto :cmake_no_system
for /f "delims=" %%p in ('where.exe cmake 2^>nul') do (
"%%p" --version > "%TEMP%\cmake-ver.txt" 2>&1
for /f "tokens=3" %%v in ('findstr /B "cmake version" "%TEMP%\cmake-ver.txt"') do set "SYS_CMAKE_VER=%%v"
del /q "%TEMP%\cmake-ver.txt" 2>nul
goto :cmake_ver_check
)
:cmake_ver_check
if defined SYS_CMAKE_VER (
echo 发现系统 CMake !SYS_CMAKE_VER!
powershell -Command "if ([version]'!SYS_CMAKE_VER!' -ge [version]'!CMAKE_MIN_VERSION!') { exit 0 } else { exit 1 }"
if !errorlevel! equ 0 (
echo 版本满足要求(!CMAKE_MIN_VERSION!+),使用系统 CMake
set "USE_SYSTEM_CMAKE=1"
goto :cmake_done
) else (
echo 版本低于 !CMAKE_MIN_VERSION!,将使用 bundled CMake
goto :cmake_bundled
)
) else (
echo 无法解析系统 CMake 版本号,将使用 bundled CMake
goto :cmake_bundled
)
:cmake_no_system
echo 系统未安装 CMake,将使用 bundled CMake
:cmake_bundled
if exist "%TOOLS_DIR%\cmake\bin\cmake.exe" (
echo 使用 bundled CMake
) else if exist "%TOOLS_DIR%\cmake.zip" (
echo 解压 cmake.zip...
powershell -Command "Expand-Archive -Path '%TOOLS_DIR%\cmake.zip' -DestinationPath '%TOOLS_DIR%' -Force"
for /d %%i in ("%TOOLS_DIR%\cmake-*-windows*") do (
if not exist "%TOOLS_DIR%\cmake" rename "%%i" cmake
)
echo CMake 就绪
) else (
echo 下载 CMake...
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%CMAKE_URL%' -OutFile '%TOOLS_DIR%\cmake.zip' -UseBasicParsing"
echo 解压 CMake...
powershell -Command "Expand-Archive -Path '%TOOLS_DIR%\cmake.zip' -DestinationPath '%TOOLS_DIR%' -Force"
for /d %%i in ("%TOOLS_DIR%\cmake-*-windows*") do (
if not exist "%TOOLS_DIR%\cmake" rename "%%i" cmake
)
echo CMake 就绪
)
:cmake_done
:: ===== Set PATH to build tools =====
:: Always add w64devkit to PATH for gcc/g++
set "PATH=%TOOLS_DIR%\w64devkit\bin;%PATH%"
if not defined USE_SYSTEM_CMAKE (
set "PATH=%TOOLS_DIR%\cmake\bin;%PATH%"
if not exist "%TOOLS_DIR%\cmake\bin\cmake.exe" (
for /d %%i in ("%TOOLS_DIR%\cmake-*-windows*") do set "PATH=%%i\bin;%PATH%"
)
)
cd /d "%SRC_DIR%"
:: ===== Clean old build artifacts =====
if exist "CMakeCache.txt" (
echo Cleaning old build cache...
del /q CMakeCache.txt 2>nul
rmdir /s /q CMakeFiles 2>nul
)
:: ===== CMake configure =====
echo [1/2] CMake configure...
echo AVX=ON, AVX2=ON, AVX512=OFF, NATIVE=OFF (server only)
cmake . -G "MinGW Makefiles" ^
-DLLAMA_CURL=OFF ^
-DCMAKE_CXX_COMPILER=g++ ^
-DCMAKE_C_COMPILER=gcc ^
-DLLAMA_BUILD_TESTS=OFF ^
-DLLAMA_BUILD_COMMON=ON ^
-DLLAMA_BUILD_APP=OFF ^
-DLLAMA_BUILD_EXAMPLES=OFF ^
-DLLAMA_BUILD_TOOLS=ON ^
-DLLAMA_BUILD_SERVER=ON ^
-DGGML_AVX=ON ^
-DGGML_AVX2=ON ^
-DGGML_AVX512=OFF ^
-DGGML_NATIVE=OFF ^
-DGGML_F16C=ON ^
-DGGML_FMA=ON ^
-DGGML_BMI2=ON
if errorlevel 1 (
echo CMake configure failed!
pause
exit /b 1
)
echo CMake configure done.
:: ===== Build =====
echo.
echo [2/2] Building llama-server only (8 threads, ~10-20 min)...
echo.
cmake --build . --config Release --target llama-server -j 8
if errorlevel 1 (
echo.
echo Build failed! Check errors above.
pause
exit /b 1
)
echo.
echo ============================================
echo Build complete!
echo Output: %SRC_DIR%\bin\
echo Executables:
dir /b "%SRC_DIR%\bin\*.exe" 2>nul | %SystemRoot%\System32\find.exe /c /v ""
echo ============================================
echo.
pause