-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathllama_build_only.bat
More file actions
152 lines (129 loc) · 5.77 KB
/
llama_build_only.bat
File metadata and controls
152 lines (129 loc) · 5.77 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
145
146
147
148
149
150
151
152
@echo off
setlocal EnableExtensions
rem ==========================================================
rem Llama.cpp Community Build Script (Windows 10/11)
rem Checks prerequisites, installs if needed, and builds llama.cpp
rem developed by SAmedia / py-sandy / Sandra Weidmann
rem license: GPLv3
rem ==========================================================
pushd "%~dp0"
set "VSPATH="
if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
for /f "usebackq tokens=*" %%i in (`
"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ^
-latest -products * ^
-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ^
-property installationPath
`) do set "VSPATH=%%i"
)
echo [INFO] Visual Studio found at: %VSPATH%
rem --- trying first vcvars64.bat ---
if exist "%VSPATH%\VC\Auxiliary\Build\vcvars64.bat" (
call "%VSPATH%\VC\Auxiliary\Build\vcvars64.bat" || goto :err
) else (
rem --- then try VsDevCmd.bat ---
if exist "%VSPATH%\Common7\Tools\VsDevCmd.bat" (
call "%VSPATH%\Common7\Tools\VsDevCmd.bat" -arch=x64 -host_arch=x64 || goto :err
) else (
echo [ERROR] Even vcvars64.bat nor VsDevCmd.bat was found!
goto :err
)
)
rem --- change to script folder ---
pushd "%~dp0" || goto :err
rem --- clone llama.cpp repo ---
if not exist "llama.cpp\.git" (
git clone https://github.com/ggml-org/llama.cpp.git || goto :err
)
rem --- change to llama.cpp ---
pushd "llama.cpp" || goto :err
rem --- prepare vcpkg ---
set "VCPKG_ROOT=%CD%\vcpkg"
if not exist "%VCPKG_ROOT%\." (
git clone https://github.com/microsoft/vcpkg.git "%VCPKG_ROOT%" || goto :err
call "%VCPKG_ROOT%\bootstrap-vcpkg.bat" || goto :err
)
"%VCPKG_ROOT%\vcpkg.exe" install curl:x64-windows || goto :err
set "BUILD_DIR=%CD%\build"
set "LOGFILE=%CD%\build_log.txt"
echo [BUILD] %DATE% %TIME% :: Configure + Build (Ninja) > "%LOGFILE%"
echo [INFO] CMake configure is starting ...
rem --- CMake Build ---
cmake -S . -B "%BUILD_DIR%" -G Ninja ^
-DGGML_CUDA=ON ^
-DGGML_CUDA_GRAPHS=ON ^
-DGGML_CUDA_FA_ALL_QUANTS=ON ^
-DLLAMA_CURL=ON ^
-DCMAKE_CUDA_ARCHITECTURES=native ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_TOOLCHAIN_FILE="%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake" ^
-DVCPKG_TARGET_TRIPLET=x64-windows ^
-DCMAKE_CXX_FLAGS="/W0" >> "%LOGFILE%" 2>&1 || goto :err
echo [INFO] Build is starting...please wait...it can take some minutes...
call :START_NINJA_PROGRESS "Build (Ninja)"
cmake --build "%BUILD_DIR%" -j %NUMBER_OF_PROCESSORS% >> "%LOGFILE%" 2>&1 || goto :err
rem --- finished ---
popd
popd
echo.
echo [INFO] Build done successfully!
echo [LOG] Details: "%LOGFILE%"
pause
exit /b 0
:err
echo.
echo [ERROR] Error at build or dependencies. See log: "%LOGFILE%"
pause
exit /b 1
:START_NINJA_PROGRESS
setlocal EnableExtensions DisableDelayedExpansion
set "___P_TITLE=%~1"
if "%___P_TITLE%"=="" set "___P_TITLE=Ninja Build"
rem Fallback if LOGFILE is not set.
set "___P_LOG=%LOGFILE%"
if not defined ___P_LOG set "___P_LOG=%CD%\build_log.txt"
rem Handover to PowerShell via environment variables (reliable, no argument parsing).
set "PS_NINJA_TITLE=%___P_TITLE%"
set "PS_NINJA_LOG=%___P_LOG%"
rem Background PowerShell: waits for ninja.exe, reads the log tail, shows % + bar on ONE line.
start "" /b powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$ErrorActionPreference='SilentlyContinue';" ^
"$title=$env:PS_NINJA_TITLE; $log=[Environment]::ExpandEnvironmentVariables($env:PS_NINJA_LOG);" ^
"$reNinja=[regex]'^\s*\[(\d+)/(\d+)\]'; $reCMake=[regex]'^\s*\[\s*(\d{1,3})%\s*\]';" ^
"$spin=@('|','/','-','\'); $i=0; $lastPct=$null; $done=$null; $total=$null;" ^
"Write-Host '';" ^
"$row=[Console]::CursorTop - 1;" ^
"for($w=0; $w -lt 240 -and -not (Get-Process -Name 'ninja' -ErrorAction SilentlyContinue); $w++){ Start-Sleep -Milliseconds 250 }" ^
"while(Get-Process -Name 'ninja' -ErrorAction SilentlyContinue){" ^
" $found=$false;" ^
" if (Test-Path $log){" ^
" try{ $tail = Get-Content -Path $log -Tail 1000 -ErrorAction Stop } catch { $tail=@() }" ^
" foreach($ln in $tail){" ^
" if($reNinja.IsMatch($ln)){" ^
" $m=$reNinja.Match($ln); $done=[int]$m.Groups[1].Value; $total=[int]$m.Groups[2].Value; if($total -gt 0){ $lastPct=[math]::Floor(100*$done/$total); $found=$true }" ^
" } elseif($reCMake.IsMatch($ln)){" ^
" $m=$reCMake.Match($ln); $lastPct=[int]$m.Groups[1].Value; $done=$null; $total=$null; $found=$true" ^
" }" ^
" }" ^
" }" ^
" $w=[Console]::WindowWidth;" ^
" if($w -lt 20){ $w=80 }" ^
" if($lastPct -ne $null){" ^
" $maxBar=[math]::Min(40,[math]::Max(10,$w-($title.Length+18))); " ^
" $fill=[math]::Floor($maxBar*$lastPct/100);" ^
" $bar=('#'*$fill).PadRight($maxBar,'-');" ^
" $ct= if($done -ne $null -and $total -ne $null) { ' ' + $done + '/' + $total } else { '' };" ^
" $txt='['+$lastPct+'%] '+$bar+$ct;" ^
" } else {" ^
" $txt='['+$spin[$i %% $spin.Length]+'] running...'; $i++" ^
" }" ^
" $line=$title+' '+$txt; if($line.Length -ge $w){ $line=$line.Substring(0,$w-1) }" ^
" [Console]::SetCursorPosition(0,$row);" ^
" [Console]::Write($line.PadRight($w-1));" ^
" [Console]::Title=$line;" ^
" Start-Sleep -Milliseconds 250" ^
"}" ^
"$w=[Console]::WindowWidth; if($w -lt 20){ $w=80 };" ^
"$doneLine=$title+' [done]'; if($doneLine.Length -ge $w){ $doneLine=$doneLine.Substring(0,$w-1) };" ^
"[Console]::SetCursorPosition(0,$row); [Console]::Write($doneLine.PadRight($w-1)); [Console]::Title=$title+' [done]';"
endlocal & exit /b 0