Skip to content

Commit 550e00c

Browse files
committed
feat: add llm-php-ext build support across platforms
- Add Rust toolchain installation via rustup - Install cargo-php for building PHP extensions - Clone and build llm-php-ext with static linking - Enable llm extension in PHP configure for Alpine, Linux, and OSX
1 parent defbddd commit 550e00c

5 files changed

Lines changed: 41 additions & 3 deletions

File tree

build-alpine

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ install_deps() {
3131
install_zlib
3232

3333
install_rdkafka
34+
35+
install_rust
3436
}
3537

3638
install_dev_deps() {
@@ -39,7 +41,7 @@ install_dev_deps() {
3941
install_libxml2
4042
}
4143

42-
export -f install_deps install_dev_deps
44+
export -f install_deps install_dev_deps install_rust
4345
. build-bash-base.sh "$@"
4446

4547
if [ "$BUILD_DEV" -eq 1 ]; then
@@ -61,6 +63,7 @@ ENABLE_STATIC=yes
6163
--with-rdkafka \
6264
--enable-jchash \
6365
--enable-simdjson \
66+
--enable-llm \
6467
--with-openssl --with-zlib --with-zip \
6568
--enable-filter \
6669
--with-curl \

build-bash-base.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ SWOOLE_REV="3e1a1f89930ba0bbea1f5ee31bcd0ee701a87aab"
1414
RDKAFKA_REV="53398031f1cd96e437e9705b67b4dc19d955acb6"
1515
JCHASH_REV="8ed50cc8c211effe1c214eae1e3240622e0f11b0"
1616
SIMDJSON_REV="9a2745669fea733a40f9443b1a793846d0759b89"
17+
LLM_REV="5d31060ec962d4b13b3e429cbfe4aaca38711047"
1718
SKIP_SYSTEM_DEPS="$2"
1819
BUILD_DEV="$3"
1920
BUILD_STATIC=1 # Always build static but dev
@@ -79,6 +80,25 @@ else
7980
fi
8081
cd ..
8182

83+
# llm
84+
git clone https://github.com/manticoresoftware/llm-php-ext.git llm
85+
cd llm && git checkout "$LLM_REV"
86+
cd ..
87+
88+
# Build llm extension statically
89+
cd ext/llm
90+
if [ "$(uname)" == "Darwin" ]; then
91+
# macOS: Use LLVM 17 from Homebrew
92+
LIBCLANG_PATH="/opt/homebrew/opt/llvm@17/lib"
93+
LLVM_CONFIG_PATH="/opt/homebrew/opt/llvm@17/bin/llvm-config"
94+
LLVM_PATH="/opt/homebrew/opt/llvm@17/bin"
95+
LIBCLANG_PATH="$LIBCLANG_PATH" LLVM_CONFIG_PATH="$LLVM_CONFIG_PATH" PATH="$LLVM_PATH:$PATH" cargo build --release --features static
96+
else
97+
# Linux
98+
cargo build --release --features static
99+
fi
100+
cd ../..
101+
82102
cd ..
83103

84104
BUILD_EXTRA=()

build-linux

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ set -xe
1818
install_deps() {
1919
sudo apt-get update -y
2020
sudo apt-get install -y curl build-essential autoconf automake bison re2c libzstd-dev pkg-config git libssl-dev zlib1g-dev libzip-dev libonig-dev cmake libcurl4-openssl-dev libzip-dev librdkafka-dev libiconv-hook-dev
21+
22+
install_rust
2123
}
2224

2325
install_dev_deps() {
2426
sudo apt-get install -y libonig-dev libgmp-dev libxml2-dev
2527
}
2628

27-
export -f install_deps install_dev_deps
29+
export -f install_deps install_dev_deps install_rust
2830
. build-bash-base.sh "$@"
2931

3032

@@ -47,6 +49,7 @@ ENABLE_STATIC=yes
4749
--with-rdkafka \
4850
--enable-jchash \
4951
--enable-simdjson \
52+
--enable-llm \
5053
--with-openssl --with-zlib --with-zip --with-iconv \
5154
--enable-filter \
5255
--with-curl \

build-osx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ install_deps() {
2121
export CPPFLAGS="-I${OPENSSL_PREFIX}/include -I${LIBRDKAFKA_PREFIX}/include -I${ICONV_PREFIX}/include"
2222

2323
export PKG_CONFIG_PATH="${OPENSSL_PREFIX}/lib/pkgconfig"
24+
25+
install_rust
2426
}
2527

2628
install_dev_deps() {
2729
brew install libxml2 oniguruma libgmp
2830
}
2931

30-
export -f install_deps install_dev_deps
32+
export -f install_deps install_dev_deps install_rust
3133
. ./build-bash-base.sh "$@"
3234

3335
hide_dynamic_libs() {
@@ -95,6 +97,7 @@ chmod +x configure
9597
--with-rdkafka \
9698
--enable-jchash \
9799
--enable-simdjson \
100+
--enable-llm \
98101
--with-openssl --with-zlib --with-zip --with-iconv=$(brew --prefix libiconv) \
99102
--enable-filter \
100103
--with-curl \

helper.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#!/usr/bin/env bash
22
set -ex
33

4+
install_rust() {
5+
# Install Rust toolchain
6+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
7+
# Source cargo environment
8+
. "$HOME/.cargo/env"
9+
# Install cargo-php for building PHP extensions
10+
cargo install cargo-php --locked
11+
}
12+
413
install_curl() {
514
test -d curl-8.0.0 && rm -fr "$_"
615
curl -sSL https://github.com/curl/curl/releases/download/curl-8_0_0/curl-8.0.0.tar.gz | tar -xzf -

0 commit comments

Comments
 (0)