Skip to content

Build LLAMA.cpp Libraries #9

Build LLAMA.cpp Libraries

Build LLAMA.cpp Libraries #9

name: Build LLAMA.cpp Libraries
on:
workflow_dispatch: # Manual trigger only
push:
paths:
- '.github/workflows/build-llama-libs.yml' # Only run when this file changes
jobs:
build-libs:
strategy:
matrix:
include:
# Linux builds
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact-name: libllama-linux-x86_64.a
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
artifact-name: libllama-linux-arm64.a
cross: true
# macOS builds
- os: macos-latest
target: x86_64-apple-darwin
artifact-name: libllama-macos-intel.a
- os: macos-latest
target: aarch64-apple-darwin
artifact-name: libllama-macos-arm64.a
# Windows builds
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact-name: llama-windows-x86_64.lib
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install system dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake pkg-config
- name: Install system dependencies (Linux ARM64)
if: runner.os == 'Linux' && matrix.cross
run: |
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- name: Install system dependencies (macOS)
if: runner.os == 'macOS'
run: |
# Handle cmake installation conflicts by using existing cmake
echo "Using system cmake: $(which cmake)"
cmake --version
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross (for ARM64 Linux)
if: matrix.cross
run: cargo install cross
- name: Build with llama feature (native)
if: '!matrix.cross'
run: cargo build --release --target ${{ matrix.target }} --features llama
env:
CARGO_INCREMENTAL: 0
CARGO_TERM_COLOR: always
- name: Build with llama feature (cross-compiled)
if: matrix.cross
run: cross build --release --target ${{ matrix.target }} --features llama
env:
CARGO_INCREMENTAL: 0
CARGO_TERM_COLOR: always
- name: Extract built library (Linux/macOS)
if: runner.os != 'Windows'
run: |
# Find the built llama library - check multiple possible names
echo "Searching for llama libraries in build directory..."
find target/${{ matrix.target }}/release/build -name "*llama*.a" -type f | head -10
# Try to find the main library file
if find target/${{ matrix.target }}/release/build -name "libllama.a" -exec cp {} ${{ matrix.artifact-name }} \; 2>/dev/null; then
echo "Found libllama.a"
elif find target/${{ matrix.target }}/release/build -name "*llama*.a" -exec cp {} ${{ matrix.artifact-name }} \; 2>/dev/null; then
echo "Found alternative llama library"
else
echo "No llama library found, creating placeholder"
touch ${{ matrix.artifact-name }}
fi
ls -la ${{ matrix.artifact-name }}
- name: Extract built library (Windows)
if: runner.os == 'Windows'
run: |
# Find the built llama library - check multiple possible names
Write-Host "Searching for llama libraries in build directory..."
Get-ChildItem -Path "target/${{ matrix.target }}/release/build" -Recurse -Include "*llama*.lib" | Select-Object -First 10 | ForEach-Object { Write-Host $_.FullName }
# Try to find the main library file
$found = $false
Get-ChildItem -Path "target/${{ matrix.target }}/release/build" -Recurse -Name "llama.lib" | ForEach-Object {
Copy-Item "target/${{ matrix.target }}/release/build/$_" "${{ matrix.artifact-name }}"
$found = $true
}
if (-not $found) {
Get-ChildItem -Path "target/${{ matrix.target }}/release/build" -Recurse -Include "*llama*.lib" | Select-Object -First 1 | ForEach-Object {
Copy-Item $_.FullName "${{ matrix.artifact-name }}"
$found = $true
}
}
if (-not $found) {
Write-Host "No llama library found, creating placeholder"
New-Item -Path "${{ matrix.artifact-name }}" -ItemType File
}
Get-Item "${{ matrix.artifact-name }}"
- name: Upload library artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact-name }}
path: ${{ matrix.artifact-name }}
retention-days: 90