Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
# Cross-platform cargo configuration
# No hardcoded target - let cargo detect the platform automatically

# GLIBC compatibility for static linking on Linux
# When building on systems with glibc 2.38+, the C++ dependencies (protobuf, onnxruntime)
# will use new __isoc23_* symbols. We need to provide wrappers for older glibc compatibility.

[target.x86_64-unknown-linux-gnu]
rustflags = [
# These link args will be used if we provide wrapper functions
# See build.rs for the actual wrapper implementation
]

[env]
# Disable fortify source to avoid additional glibc symbol dependencies
CFLAGS = "-D_FORTIFY_SOURCE=0"
CXXFLAGS = "-D_FORTIFY_SOURCE=0"

77 changes: 62 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
MACOSX_DEPLOYMENT_TARGET: 13.4

jobs:
# Rust code quality checks
Expand Down Expand Up @@ -63,10 +64,22 @@ jobs:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install PHP
- name: Install LLVM 17
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 17
sudo apt-get install -y libclang-17-dev
echo "LIBCLANG_PATH=/usr/lib/llvm-17/lib" >> $GITHUB_ENV
echo "LLVM_CONFIG_PATH=/usr/lib/llvm-17/bin/llvm-config" >> $GITHUB_ENV
echo "/usr/lib/llvm-17/bin" >> $GITHUB_PATH

- name: Install PHP 8.4
run: |
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update
sudo apt-get install -y php php-dev php-cli php-json
sudo apt-get install -y php8.4 php8.4-dev php8.4-cli
php -v

- name: Cache cargo registry
uses: actions/cache@v4
Expand Down Expand Up @@ -95,6 +108,13 @@ jobs:
- name: Run PHP tests
run: php -d 'extension=target/debug/libllm.so' tests/run_tests.php

- name: Install cargo-php
run: |
LIBCLANG_PATH=$LIBCLANG_PATH \
LLVM_CONFIG_PATH=$LLVM_CONFIG_PATH \
PATH="/usr/lib/llvm-17/bin:$PATH" \
cargo install cargo-php

- name: Generate stubs
run: cargo php stubs --stdout > php/llm.php

Expand All @@ -112,79 +132,106 @@ jobs:

# Build and test on macOS
macos:
name: macOS Build & Test
runs-on: macos-latest
name: macOS Build & Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: rust-quality
strategy:
fail-fast: false
matrix:
os: [macos-15, macos-15-intel] # macos-15 = ARM64 (Apple Silicon), macos-15-intel = Intel x86_64
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Detect architecture and set Homebrew prefix
run: |
echo "Architecture: $(uname -m)"
HOMEBREW_PREFIX=$(brew --prefix)
echo "HOMEBREW_PREFIX=$HOMEBREW_PREFIX" >> $GITHUB_ENV
echo "Homebrew prefix: $HOMEBREW_PREFIX"

- name: Install PHP 8.4
run: |
brew tap shivammathur/php
brew install shivammathur/php/php@8.4
brew link --overwrite --force shivammathur/php/php@8.4
php -v

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install LLVM 17
run: |
brew install llvm@17
echo "LIBCLANG_PATH=/opt/homebrew/opt/llvm@17/lib" >> $GITHUB_ENV
echo "LLVM_CONFIG_PATH=/opt/homebrew/opt/llvm@17/bin/llvm-config" >> $GITHUB_ENV
echo "/opt/homebrew/opt/llvm@17/bin" >> $GITHUB_PATH
echo "LIBCLANG_PATH=$HOMEBREW_PREFIX/opt/llvm@17/lib" >> $GITHUB_ENV
echo "LLVM_CONFIG_PATH=$HOMEBREW_PREFIX/opt/llvm@17/bin/llvm-config" >> $GITHUB_ENV
echo "$HOMEBREW_PREFIX/opt/llvm@17/bin" >> $GITHUB_PATH

- name: Verify LLVM installation
run: |
echo "LIBCLANG_PATH: $LIBCLANG_PATH"
echo "LLVM_CONFIG_PATH: $LLVM_CONFIG_PATH"
ls -la /opt/homebrew/opt/llvm@17/lib || ls -la /usr/local/opt/llvm@17/lib || echo "LLVM lib path check"
ls -la $HOMEBREW_PREFIX/opt/llvm@17/lib || echo "LLVM lib path check failed"
which llvm-config

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-${{ matrix.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-${{ matrix.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-${{ matrix.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}


- name: Run cargo clippy (macOS)
run: |
LIBCLANG_PATH=$LIBCLANG_PATH \
LLVM_CONFIG_PATH=$LLVM_CONFIG_PATH \
PATH="/opt/homebrew/opt/llvm@17/bin:$PATH" \
PATH="$HOMEBREW_PREFIX/opt/llvm@17/bin:$PATH" \
cargo clippy --all-targets --all-features -- -D warnings

- name: Build extension (debug)
run: |
LIBCLANG_PATH=$LIBCLANG_PATH \
LLVM_CONFIG_PATH=$LLVM_CONFIG_PATH \
PATH="/opt/homebrew/opt/llvm@17/bin:$PATH" \
PATH="$HOMEBREW_PREFIX/opt/llvm@17/bin:$PATH" \
cargo build --verbose

- name: Build extension (release)
run: |
LIBCLANG_PATH=$LIBCLANG_PATH \
LLVM_CONFIG_PATH=$LLVM_CONFIG_PATH \
PATH="/opt/homebrew/opt/llvm@17/bin:$PATH" \
PATH="$HOMEBREW_PREFIX/opt/llvm@17/bin:$PATH" \
cargo build --release --verbose

- name: Run PHP tests
run: php -d 'extension=target/debug/libllm.dylib' tests/run_tests.php

- name: Install cargo-php
run: |
LIBCLANG_PATH=$LIBCLANG_PATH \
LLVM_CONFIG_PATH=$LLVM_CONFIG_PATH \
PATH="$HOMEBREW_PREFIX/opt/llvm@17/bin:$PATH" \
cargo install cargo-php

- name: Generate stubs
run: |
LIBCLANG_PATH=$LIBCLANG_PATH \
LLVM_CONFIG_PATH=$LLVM_CONFIG_PATH \
PATH="/opt/homebrew/opt/llvm@17/bin:$PATH" \
PATH="$HOMEBREW_PREFIX/opt/llvm@17/bin:$PATH" \
cargo php stubs --stdout > php/llm.php


- name: Verify stubs generated
run: |
if [ ! -f php/llm.php ]; then
Expand Down
Loading