Skip to content

Commit 8bcd224

Browse files
authored
feat: add llm-php-ext build support across platforms and update php version to 8.4.17 (#78)
1 parent defbddd commit 8bcd224

10 files changed

Lines changed: 93 additions & 58 deletions

File tree

.github/workflows/release.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313
env:
1414
APP_NAME: 'manticore-executor'
1515
DOCKER_TAG: 'manticoresearch/manticore-executor'
16-
PHP_VERSION: '8.3.15'
16+
PHP_VERSION: '8.4.17'
1717
MAINTAINER: 'Manticore'
1818
DESC: 'Custom built PHP executor for Manticore.'
1919
EXTRA_NAME: 'manticore-extra'
@@ -103,12 +103,12 @@ jobs:
103103
use_buildx: true
104104
run: ""
105105
- name: AMD64 native on OSX
106-
os: macos-13
106+
os: macos-15-intel
107107
arch: x86_64
108108
use_buildx: false
109109
run: ./build-osx
110110
- name: ARM64 native on OSX
111-
os: macos-14
111+
os: macos-15
112112
arch: arm64
113113
use_buildx: false
114114
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
env:
99
APP_NAME: 'manticore-executor'
10-
PHP_VERSION: '8.3.15'
10+
PHP_VERSION: '8.4.17'
1111
MAINTAINER: 'Manticore'
1212
DESC: 'Custom built PHP executor for Manticore.'
1313

@@ -30,13 +30,13 @@ jobs:
3030
arch: amd64
3131
build_type: jammy
3232
- job_name: 'Build static on amd64 OSX'
33-
os: macos-13
33+
os: macos-15-intel
3434
use_docker: false
3535
script_name: ./build-osx
3636
arch: amd64
3737
build_type: osx
3838
- job_name: 'Build static on arm64 OSX'
39-
os: macos-14
39+
os: macos-15
4040
use_docker: false
4141
script_name: ./build-osx
4242
arch: arm64
@@ -52,7 +52,7 @@ jobs:
5252
run: ${{ matrix.script_name }} ${{ env.PHP_VERSION }}
5353
- name: Build binary using Docker
5454
if: ${{ matrix.use_docker == true }}
55-
run: docker run -v ${PWD}:/src -w /src alpine:3.17 sh -c "apk add sudo bash; ${{ matrix.script_name }} ${{ env.PHP_VERSION }}"
55+
run: docker run -v ${PWD}:/src -w /src alpine:3.21 sh -c "apk add sudo bash; ${{ matrix.script_name }} ${{ env.PHP_VERSION }}"
5656
- name: Create artifact
5757
run: |
5858
os="${{ runner.os }}"

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
FROM alpine:3.17
1+
FROM alpine:3.21
22
ARG BUILD_DEV=0
33

44
# Install the manticore-executor binary
55
COPY . /src
66
RUN apk add bash && \
77
cd /src && \
8-
./build-alpine 8.4.2 0 $BUILD_DEV && \
8+
./build-alpine 8.4.17 0 $BUILD_DEV && \
99
mv build/dist/bin/php /usr/bin/manticore-executor && \
1010
ln -s /usr/bin/manticore-executor /usr/bin/php && \
1111
cd ../..

Dockerfile-dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RUN apt-get update -y && \
66
COPY ./build-linux ./build-linux
77
COPY ./build-bash-base.sh ./build-bash-base.sh
88
COPY ./helper.sh ./helper.sh
9-
RUN ./build-linux 8.4.2 0 0 && \
9+
RUN ./build-linux 8.4.17 0 0 && \
1010
cp build/dist/bin/php /usr/bin/manticore-executor && \
1111
rm -fr build
1212

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Manticore Executor is a custom built PHP binary which:
2828

2929
By default, we disable all extensions and enable only those required to run our scripts.
3030

31-
We build executor from `PHP 8.4.2` with the following extensions enabled and compiled into the executable statically:
31+
We build executor from `PHP 8.4.17` with the following extensions enabled and compiled into the executable statically:
3232

3333
* pcntl
3434
* posix
@@ -83,10 +83,10 @@ Several scripts used to build the final package:
8383
* `build-linux`
8484
* `build-osx`
8585

86-
The scripts accept a version of PHP as a parameter. The current version is `8.4.2`. To build the binary, you should run the following example:
86+
The scripts accept a version of PHP as a parameter. The current version is `8.4.17`. To build the binary, you should run the following example:
8787

8888
```bash
89-
./build-linux "8.4.2"
89+
./build-linux "8.4.17"
9090
```
9191

92-
The command above will build the package on Linux with **PHP** `8.4.2`. Once it's done, you can find your binary in folder `dist/bin`.
92+
The command above will build the package on Linux with **PHP** `8.4.17`. Once it's done, you can find your binary in folder `dist/bin`.

build-alpine

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ 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 php84 php84-dev curl git autoconf bison re2c pkgconf zlib-dev zstd-static zstd-dev openssl-libs-static openssl-dev zlib-static zlib-dev gnu-libiconv-dev clang-dev llvm-dev
26+
27+
# Create symlinks for php84 to be accessible as php
28+
ln -sf /usr/bin/php84 /usr/bin/php
29+
ln -sf /usr/bin/php-config84 /usr/bin/php-config
30+
ln -sf /usr/bin/phpize84 /usr/bin/phpize
2631

2732
install_curl
2833

@@ -31,6 +36,8 @@ install_deps() {
3136
install_zlib
3237

3338
install_rdkafka
39+
40+
install_rust
3441
}
3542

3643
install_dev_deps() {
@@ -39,7 +46,7 @@ install_dev_deps() {
3946
install_libxml2
4047
}
4148

42-
export -f install_deps install_dev_deps
49+
export -f install_deps install_dev_deps install_rust
4350
. build-bash-base.sh "$@"
4451

4552
if [ "$BUILD_DEV" -eq 1 ]; then
@@ -61,6 +68,7 @@ ENABLE_STATIC=yes
6168
--with-rdkafka \
6269
--enable-jchash \
6370
--enable-simdjson \
71+
--enable-llm \
6472
--with-openssl --with-zlib --with-zip \
6573
--enable-filter \
6674
--with-curl \
@@ -77,3 +85,8 @@ fix_static_linking
7785

7886
make LDFLAGS=$MAKE_LDFLAGS -j8
7987
make install-cli
88+
89+
# Remove php84 that was used for building before installing php
90+
apk del php84 php84-dev
91+
rm -f /usr/bin/php /usr/bin/php-config /usr/bin/phpize
92+

build-bash-base.sh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
set -e
99

1010
PHP_VERSION="$1"
11-
ZSTD_REV="2dfcd6524ccdcef6dfdaa97d7f3716b866885093"
12-
DS_REV="da4d2f2a2c0f3732b34562636849c5e52e79e6c3"
13-
SWOOLE_REV="3e1a1f89930ba0bbea1f5ee31bcd0ee701a87aab"
11+
ZSTD_REV="d6d26eb805058fc672686715a7b5e39d8f65dd36"
12+
DS_REV="118c06b8863386ceada4238f3cec18ab84c9efb7"
13+
SWOOLE_REV="d611ff3ca60e8c9425b2e2e3ba1a9004faab64f5"
1414
RDKAFKA_REV="53398031f1cd96e437e9705b67b4dc19d955acb6"
15+
1516
JCHASH_REV="8ed50cc8c211effe1c214eae1e3240622e0f11b0"
1617
SIMDJSON_REV="9a2745669fea733a40f9443b1a793846d0759b89"
18+
LLM_REV="8ef13fa0911de91fddebe0bde48ba7569a055482"
1719
SKIP_SYSTEM_DEPS="$2"
1820
BUILD_DEV="$3"
1921
BUILD_STATIC=1 # Always build static but dev
@@ -79,7 +81,22 @@ else
7981
fi
8082
cd ..
8183

82-
cd ..
84+
# llm
85+
git clone https://github.com/manticoresoftware/llm-php-ext.git llm
86+
cd llm && git checkout "$LLM_REV"
87+
if [ "$(uname)" == "Darwin" ]; then
88+
# macOS: Use LLVM 17 from Homebrew
89+
LLVM_PREFIX="$(brew --prefix llvm@17 2>/dev/null || echo /opt/homebrew/opt/llvm@17)"
90+
LIBCLANG_PATH="$LLVM_PREFIX/lib"
91+
LLVM_CONFIG_PATH="$LLVM_PREFIX/bin/llvm-config"
92+
LLVM_PATH="$LLVM_PREFIX/bin"
93+
# Ensure PHP is still accessible by appending LLVM to PATH instead of prepending
94+
export LIBCLANG_PATH="$LIBCLANG_PATH" LLVM_CONFIG_PATH="$LLVM_CONFIG_PATH" PATH="$PATH:$LLVM_PATH"
95+
# Verify PHP is accessible
96+
echo "Verifying PHP is accessible for ext-php-rs build..."
97+
which php && php --version || echo "WARNING: php not found in PATH!"
98+
fi
99+
cd ../..
83100

84101
BUILD_EXTRA=()
85102
if [[ "$BUILD_DEV" == "1" ]]; then
@@ -102,7 +119,7 @@ if [[ "$BUILD_DEV" == "1" ]]; then
102119
# "--enable-memprof"
103120
# "--enable-memprof-debug"
104121
#
105-
# It does not work with PHP 8.4.2
122+
# It does not work with PHP 8.4.17
106123
# "--enable-tideways-xhprof"
107124
# "--enable-xdebug"
108125
)

build-linux

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,24 @@ 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 software-properties-common
21+
sudo add-apt-repository ppa:ondrej/php -y
22+
sudo apt-get update -y
23+
sudo apt-get install -y php8.4 php8.4-dev php8.4-cli build-essential clang libclang-dev pkg-config curl autoconf automake bison re2c libzstd-dev git libssl-dev zlib1g-dev libzip-dev libonig-dev cmake libcurl4-openssl-dev librdkafka-dev libiconv-hook-dev wget
24+
# Install LLVM 17 directly from apt.llvm.org
25+
wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/llvm-archive-keyring.gpg
26+
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
27+
sudo apt-get update -y
28+
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..."
29+
30+
install_rust
2131
}
2232

2333
install_dev_deps() {
2434
sudo apt-get install -y libonig-dev libgmp-dev libxml2-dev
2535
}
2636

27-
export -f install_deps install_dev_deps
37+
export -f install_deps install_dev_deps install_rust
2838
. build-bash-base.sh "$@"
2939

3040

@@ -47,6 +57,7 @@ ENABLE_STATIC=yes
4757
--with-rdkafka \
4858
--enable-jchash \
4959
--enable-simdjson \
60+
--enable-llm \
5061
--with-openssl --with-zlib --with-zip --with-iconv \
5162
--enable-filter \
5263
--with-curl \
@@ -59,3 +70,7 @@ ENABLE_STATIC=yes
5970

6071
make -j8
6172
make install-cli
73+
74+
# Remove php84 that was used for building before installing php
75+
sudo apt-get remove -y php8.4-dev php8.4-cli php8.4
76+

build-osx

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@
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 tap shivammathur/php
14+
brew install shivammathur/php/php@8.4 bash curl autoconf automake bison re2c zstd git openssl zlib cmake libzip librdkafka libiconv llvm@17
15+
brew link --overwrite --force shivammathur/php/php@8.4
16+
17+
# Add PHP to PATH - include both versioned path and brew bin directory
18+
PHP_PREFIX="$(brew --prefix shivammathur/php/php@8.4)"
19+
BREW_PREFIX="$(brew --prefix)"
20+
export PATH="${PHP_PREFIX}/bin:${BREW_PREFIX}/bin:${PATH}"
1221

1322
OPENSSL_PREFIX="$(brew --prefix openssl)"
1423
LIBRDKAFKA_PREFIX="$(brew --prefix librdkafka)"
@@ -21,42 +30,17 @@ install_deps() {
2130
export CPPFLAGS="-I${OPENSSL_PREFIX}/include -I${LIBRDKAFKA_PREFIX}/include -I${ICONV_PREFIX}/include"
2231

2332
export PKG_CONFIG_PATH="${OPENSSL_PREFIX}/lib/pkgconfig"
33+
34+
install_rust
2435
}
2536

2637
install_dev_deps() {
2738
brew install libxml2 oniguruma libgmp
2839
}
2940

30-
export -f install_deps install_dev_deps
41+
export -f install_deps install_dev_deps install_rust
3142
. ./build-bash-base.sh "$@"
3243

33-
hide_dynamic_libs() {
34-
! which brew && return
35-
for lib in "$@"; do
36-
LIB_PATH=$(brew --prefix "$lib")
37-
if ls "$LIB_PATH"/lib/*.dylib; then
38-
for f in "$LIB_PATH"/lib/*.dylib; do
39-
mv "$f" "$f.bak"
40-
done
41-
fi
42-
done
43-
}
44-
45-
restore_dynamic_libs() {
46-
! which brew && return
47-
for lib in "$@"; do
48-
LIB_PATH=$(brew --prefix "$lib")
49-
if ls "$LIB_PATH"/lib/*.dylib.bak; then
50-
for f in "$LIB_PATH"/lib/*.dylib.bak; do
51-
mv "$f" "${f%*.bak}"
52-
done
53-
fi
54-
done
55-
}
56-
57-
# Leave only static libs on
58-
hide_dynamic_libs zstd zlib
59-
6044
MAKE_LDFLAGS=
6145
ENABLE_SHARED=yes
6246
ENABLE_STATIC=no
@@ -95,6 +79,7 @@ chmod +x configure
9579
--with-rdkafka \
9680
--enable-jchash \
9781
--enable-simdjson \
82+
--enable-llm \
9883
--with-openssl --with-zlib --with-zip --with-iconv=$(brew --prefix libiconv) \
9984
--enable-filter \
10085
--with-curl \
@@ -109,5 +94,3 @@ make LDFLAGS=$MAKE_LDFLAGS -j8
10994
make install-cli
11095
strip dist/bin/php
11196

112-
# Return skipped dynamic libs
113-
restore_dynamic_libs zstd zlib

helper.sh

Lines changed: 9 additions & 2 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 -
@@ -64,7 +71,7 @@ build_dev_conf() {
6471
git checkout 68eb143bd5700a6fe041826118aeb9a13a3fcef3
6572
cd ..
6673

67-
# It does not work with PHP 8.4.2
74+
# It does not work with PHP 8.4.17
6875
# git clone https://github.com/tideways/php-xhprof-extension.git tideways_xhprof && cd "$_"
6976
# git checkout 7877082945fcccced12676749676af1736a00f65
7077
# cd ..
@@ -84,4 +91,4 @@ fix_static_linking() {
8491
sed -ie 's/PHP_INI_ENTRY("openssl.cafile", NULL, PHP_INI_PERDIR, NULL)/PHP_INI_ENTRY("openssl.cafile", "\/etc\/ssl\/cert.pem", PHP_INI_PERDIR, NULL)/g' ext/openssl/openssl.c
8592
sed -ie 's/-export-dynamic//g' Makefile
8693
sed -ie 's/-o $(SAPI_CLI_PATH)/-all-static -o $(SAPI_CLI_PATH)/g' Makefile
87-
}
94+
}

0 commit comments

Comments
 (0)