Skip to content

Commit 40fc354

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 40fc354

File tree

7 files changed

+46
-11
lines changed

7 files changed

+46
-11
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
use_buildx: true
104104
run: ""
105105
- name: AMD64 native on OSX
106-
os: macos-13
106+
os: macos-15
107107
arch: x86_64
108108
use_buildx: false
109109
run: ./build-osx
@@ -557,7 +557,7 @@ jobs:
557557
- artifact_suffix: ubuntu-22.04-arm64
558558
asset_name_suffix: linux-arm64.tar.gz
559559
asset_content_type: application/gzip
560-
- artifact_suffix: macos-13-x86_64
560+
- artifact_suffix: macos-15-x86_64
561561
asset_name_suffix: macos-x86_64.tar.gz
562562
asset_content_type: application/gzip
563563
- artifact_suffix: macos-14-arm64
@@ -811,7 +811,7 @@ jobs:
811811
arch: aarch
812812
delimiter: "_"
813813
distro: 10
814-
- artifact: artifact-macos-13-x86_64
814+
- artifact: artifact-macos-15-x86_64
815815
type: arc
816816
arch: x86_64
817817
delimiter: "-"

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
arch: amd64
3131
build_type: jammy
3232
- job_name: 'Build static on amd64 OSX'
33-
os: macos-13
33+
os: macos-15
3434
use_docker: false
3535
script_name: ./build-osx
3636
arch: amd64

build-alpine

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ install_deps() {
2222
ln -s /usr/bin/objcopy "/usr/bin/${arch}-alpine-linux-musl-objcopy"
2323
export CROSS_COMPILE="/usr/bin/${arch}-alpine-linux-musl-"
2424

25-
apk add curl git autoconf bison re2c pkgconf zlib-dev zstd-dev openssl-libs-static openssl-dev zlib-static zlib-dev gnu-libiconv-dev
25+
apk add curl git autoconf bison re2c pkgconf zlib-dev zstd-dev openssl-libs-static openssl-dev zlib-static zlib-dev gnu-libiconv-dev clang-dev llvm-dev
2626

2727
install_curl
2828

@@ -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: 13 additions & 1 deletion
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="0dc6b881ea6cb10cd53c5a754d08b76ace5a9657"
1718
SKIP_SYSTEM_DEPS="$2"
1819
BUILD_DEV="$3"
1920
BUILD_STATIC=1 # Always build static but dev
@@ -79,7 +80,18 @@ else
7980
fi
8081
cd ..
8182

82-
cd ..
83+
# llm
84+
git clone https://github.com/manticoresoftware/llm-php-ext.git llm
85+
cd llm && git checkout "$LLM_REV"
86+
if [ "$(uname)" == "Darwin" ]; then
87+
# macOS: Use LLVM 17 from Homebrew
88+
LLVM_PREFIX="$(brew --prefix llvm@17 2>/dev/null || echo /opt/homebrew/opt/llvm@17)"
89+
LIBCLANG_PATH="$LLVM_PREFIX/lib"
90+
LLVM_CONFIG_PATH="$LLVM_PREFIX/bin/llvm-config"
91+
LLVM_PATH="$LLVM_PREFIX/bin"
92+
export LIBCLANG_PATH="$LIBCLANG_PATH" LLVM_CONFIG_PATH="$LLVM_CONFIG_PATH" PATH="$LLVM_PATH:$PATH"
93+
fi
94+
cd ../..
8395

8496
BUILD_EXTRA=()
8597
if [[ "$BUILD_DEV" == "1" ]]; then

build-linux

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ set -xe
1717

1818
install_deps() {
1919
sudo apt-get update -y
20-
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
20+
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 wget
21+
# Install LLVM 17 directly from apt.llvm.org
22+
wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/llvm-archive-keyring.gpg
23+
echo "deb [signed-by=/usr/share/keyrings/llvm-archive-keyring.gpg] http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" | sudo tee /etc/apt/sources.list.d/llvm.list > /dev/null
24+
sudo apt-get update -y
25+
sudo apt-get install -y clang-17 lldb-17 lld-17 clangd-17 clang-tidy-17 clang-format-17 clang-tools-17 llvm-17-dev libomp-17-dev libc++-17-dev libc++abi-17-dev libclang-common-17-dev libclang-17-dev libclang-cpp17-dev || echo "LLVM 17 packages not all available, continuing..."
26+
27+
install_rust
2128
}
2229

2330
install_dev_deps() {
2431
sudo apt-get install -y libonig-dev libgmp-dev libxml2-dev
2532
}
2633

27-
export -f install_deps install_dev_deps
34+
export -f install_deps install_dev_deps install_rust
2835
. build-bash-base.sh "$@"
2936

3037

@@ -47,6 +54,7 @@ ENABLE_STATIC=yes
4754
--with-rdkafka \
4855
--enable-jchash \
4956
--enable-simdjson \
57+
--enable-llm \
5058
--with-openssl --with-zlib --with-zip --with-iconv \
5159
--enable-filter \
5260
--with-curl \

build-osx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
# you can find it at https://www.php.net/license/3_01.txt
88

99
set -e
10+
. helper.sh
11+
1012
install_deps() {
11-
brew install bash curl autoconf automake bison re2c zstd git openssl zlib cmake libzip librdkafka libiconv
13+
brew install bash curl autoconf automake bison re2c zstd git openssl zlib cmake libzip librdkafka libiconv llvm@17
1214

1315
OPENSSL_PREFIX="$(brew --prefix openssl)"
1416
LIBRDKAFKA_PREFIX="$(brew --prefix librdkafka)"
@@ -21,13 +23,15 @@ install_deps() {
2123
export CPPFLAGS="-I${OPENSSL_PREFIX}/include -I${LIBRDKAFKA_PREFIX}/include -I${ICONV_PREFIX}/include"
2224

2325
export PKG_CONFIG_PATH="${OPENSSL_PREFIX}/lib/pkgconfig"
26+
27+
install_rust
2428
}
2529

2630
install_dev_deps() {
2731
brew install libxml2 oniguruma libgmp
2832
}
2933

30-
export -f install_deps install_dev_deps
34+
export -f install_deps install_dev_deps install_rust
3135
. ./build-bash-base.sh "$@"
3236

3337
hide_dynamic_libs() {
@@ -95,6 +99,7 @@ chmod +x configure
9599
--with-rdkafka \
96100
--enable-jchash \
97101
--enable-simdjson \
102+
--enable-llm \
98103
--with-openssl --with-zlib --with-zip --with-iconv=$(brew --prefix libiconv) \
99104
--enable-filter \
100105
--with-curl \

helper.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
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+
}
10+
411
install_curl() {
512
test -d curl-8.0.0 && rm -fr "$_"
613
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)