Skip to content

Commit ec84989

Browse files
committed
Build ext-quiche
1 parent 8e1c0e0 commit ec84989

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

compile.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ EXT_RDKAFKA_VERSION="6.0.4"
4545
EXT_ZSTD_VERSION="0.15.2"
4646
EXT_GRPC_VERSION="1.76.0"
4747
EXT_VANILLAGENERATOR_VERSION="abd059fd2ca79888aab3b9c5070d83ceea55fada"
48+
# ext-quiche is a Rust cdylib (built with cargo, not PHP autoconf). Pin to a
49+
# branch name (e.g. "master"), tag, or 40-char commit SHA — the build step
50+
# below switches between `git checkout` and tarball download accordingly.
51+
EXT_QUICHE_VERSION="master"
4852

4953
EXT_IGBINARY_VERSION_PHP85="3.2.17RC1"
5054

@@ -160,6 +164,7 @@ COMPILE_DEBUG="no"
160164
HAVE_VALGRIND="--without-valgrind"
161165
HAVE_OPCACHE="yes"
162166
HAVE_XDEBUG="yes"
167+
HAVE_QUICHE="yes"
163168
FSANITIZE_OPTIONS=""
164169
FLAGS_LTO=""
165170
HAVE_OPCACHE_JIT="no"
@@ -524,6 +529,10 @@ if [ "$DO_STATIC" == "yes" ]; then
524529
write_out "warning" "Xdebug cannot be built in static mode"
525530
HAVE_XDEBUG="no"
526531
fi
532+
if [ "$HAVE_QUICHE" == "yes" ]; then
533+
write_out "warning" "ext-quiche is a cdylib and cannot be built into a static PHP"
534+
HAVE_QUICHE="no"
535+
fi
527536
fi
528537

529538
if [ "$TOOLCHAIN_PREFIX" != "" ]; then
@@ -1863,6 +1872,86 @@ if [[ "$HAVE_XDEBUG" == "yes" ]]; then
18631872
write_out INFO "Xdebug is included, but disabled by default. To enable it, change 'xdebug.mode' in your php.ini file."
18641873
fi
18651874

1875+
#
1876+
# ext-quiche — a PHP-callable QUIC server built on top of tokio-quiche.
1877+
# Unlike the other extensions in this script it is a Rust crate, not a
1878+
# PHP autoconf module, so it is built with `cargo` and the resulting
1879+
# cdylib is dropped into PHP's extension directory. We do this AFTER
1880+
# `make install` so we can use the freshly-built `php-config` to learn
1881+
# the canonical extension dir.
1882+
#
1883+
if [[ "$HAVE_QUICHE" == "yes" ]]; then
1884+
if ! type cargo >> "$DIR/install.log" 2>&1; then
1885+
write_out "WARNING" "ext-quiche skipped: 'cargo' (Rust toolchain) not found in PATH. Install rustup if you want this extension."
1886+
elif [[ "$IS_CROSSCOMPILE" == "yes" ]] || [[ "$COMPILE_FOR_ANDROID" == "yes" ]] || [[ "$IS_WINDOWS" == "yes" ]]; then
1887+
write_out "WARNING" "ext-quiche skipped: cross-compile / Android / Windows targets are not supported by the boring-sys dependency"
1888+
else
1889+
write_library "ext-quiche" "$EXT_QUICHE_VERSION"
1890+
EXT_QUICHE_DIR="$BUILD_DIR/ext-quiche"
1891+
rm -rf "$EXT_QUICHE_DIR" 2>> "$DIR/install.log"
1892+
1893+
write_download
1894+
# A 40-char hex string is treated as a commit SHA → git clone+checkout.
1895+
# Anything else is treated as a tag/branch name → tarball download
1896+
# (faster and keeps the cache friendly), with a git-clone fallback for
1897+
# branches that don't have a stable archive URL.
1898+
if [[ "$EXT_QUICHE_VERSION" =~ ^[0-9a-f]{40}$ ]] || [[ "$EXT_QUICHE_VERSION" == "master" ]] || [[ "$EXT_QUICHE_VERSION" == "main" ]]; then
1899+
git clone --quiet "https://github.com/NetherGamesMC/ext-quiche.git" "$EXT_QUICHE_DIR" >> "$DIR/install.log" 2>&1 || {
1900+
write_error "ext-quiche: git clone failed; see install.log"
1901+
exit 1
1902+
}
1903+
(cd "$EXT_QUICHE_DIR" && git checkout --quiet "$EXT_QUICHE_VERSION") >> "$DIR/install.log" 2>&1 || {
1904+
write_error "ext-quiche: failed to check out $EXT_QUICHE_VERSION"
1905+
exit 1
1906+
}
1907+
else
1908+
mkdir -p "$EXT_QUICHE_DIR"
1909+
download_github_src "NetherGamesMC/ext-quiche" "$EXT_QUICHE_VERSION" "ext-quiche" \
1910+
| tar -zx --strip-components=1 -C "$EXT_QUICHE_DIR" >> "$DIR/install.log" 2>&1 || {
1911+
write_error "ext-quiche: tarball download/extract failed"
1912+
exit 1
1913+
}
1914+
fi
1915+
1916+
write_compile
1917+
# `cargo build --release` produces target/release/libext_quiche.{so,dylib}.
1918+
# Use --jobs to honour the user's -j setting; fall back to cargo's default
1919+
# parallelism if THREADS is unset.
1920+
CARGO_JOBS_FLAG=""
1921+
if [ -n "$THREADS" ]; then
1922+
CARGO_JOBS_FLAG="--jobs $THREADS"
1923+
fi
1924+
(cd "$EXT_QUICHE_DIR" && cargo build --release $CARGO_JOBS_FLAG) >> "$DIR/install.log" 2>&1 || {
1925+
write_error "ext-quiche: cargo build failed; see install.log"
1926+
exit 1
1927+
}
1928+
1929+
write_install
1930+
PHP_EXT_DIR=$("$INSTALL_DIR/bin/php-config" --extension-dir 2>> "$DIR/install.log")
1931+
if [ -z "$PHP_EXT_DIR" ] || [ ! -d "$PHP_EXT_DIR" ]; then
1932+
write_error "ext-quiche: could not resolve PHP extension dir from php-config"
1933+
exit 1
1934+
fi
1935+
1936+
# Linux → libext_quiche.so, macOS → libext_quiche.dylib. PHP loads either
1937+
# but php.ini uses one filename, so we install both as ext_quiche.so.
1938+
if [ -f "$EXT_QUICHE_DIR/target/release/libext_quiche.so" ]; then
1939+
cp "$EXT_QUICHE_DIR/target/release/libext_quiche.so" "$PHP_EXT_DIR/ext_quiche.so" >> "$DIR/install.log" 2>&1
1940+
elif [ -f "$EXT_QUICHE_DIR/target/release/libext_quiche.dylib" ]; then
1941+
cp "$EXT_QUICHE_DIR/target/release/libext_quiche.dylib" "$PHP_EXT_DIR/ext_quiche.so" >> "$DIR/install.log" 2>&1
1942+
else
1943+
write_error "ext-quiche: built artifact not found in $EXT_QUICHE_DIR/target/release/"
1944+
exit 1
1945+
fi
1946+
1947+
echo "" >> "$INSTALL_DIR/bin/php.ini"
1948+
echo "; ext-quiche — QUIC server bindings (Rust cdylib)" >> "$INSTALL_DIR/bin/php.ini"
1949+
echo "extension=ext_quiche.so" >> "$INSTALL_DIR/bin/php.ini"
1950+
1951+
write_done
1952+
fi
1953+
fi
1954+
18661955

18671956
cd "$DIR"
18681957
if [ "$DO_CLEANUP" == "yes" ]; then

0 commit comments

Comments
 (0)