|
12 | 12 | # docker build \ |
13 | 13 | # --build-arg BASE_IMAGE=playground-php-wasm:compile-extension-php8-4-jspi \ |
14 | 14 | # --build-arg HOST_PHP_VERSION=8.4 \ |
| 15 | +# --build-arg HOST_PHP_API_VERSION=20240924 \ |
15 | 16 | # -t playground-php-wasm-ext-rust:8.4-jspi \ |
16 | 17 | # -f Dockerfile.rust . |
17 | 18 |
|
18 | 19 | ARG BASE_IMAGE=playground-php-wasm:compile-extension-php8-4-jspi |
19 | 20 | ARG HOST_PHP_VERSION=8.4 |
20 | | - |
21 | | -# Stage providing a host PHP CLI binary. ext-php-rs's build.rs shells |
22 | | -# out to `php` to detect the PHP version (PHP_VERSION_ID drives the cfg |
23 | | -# flags such as php74, php80, and php85). The wasm-targeted PHP install in |
24 | | -# /usr/local has no CLI binary (--disable-cli), so copy a matching CLI from |
25 | | -# the official PHP image for the target version. |
26 | | -FROM php:${HOST_PHP_VERSION}-cli AS host-php-cli |
27 | | - |
28 | | -RUN set -eux; \ |
29 | | - mkdir -p /opt/host-php/libdeps; \ |
30 | | - ldd /usr/local/bin/php \ |
31 | | - | awk '($2 == "=>") { print $3 } ($1 ~ /^\//) { print $1 }' \ |
32 | | - | grep -v '^$' \ |
33 | | - | sort -u \ |
34 | | - | while read -r lib; do cp -L "$lib" /opt/host-php/libdeps/; done |
| 21 | +ARG HOST_PHP_API_VERSION=20240924 |
35 | 22 |
|
36 | 23 | FROM ${BASE_IMAGE} |
37 | | - |
38 | | -COPY --from=host-php-cli /usr/local/bin/php /opt/host-php/bin/php |
39 | | -COPY --from=host-php-cli /usr/local/lib/php /opt/host-php/lib/php |
40 | | -COPY --from=host-php-cli /usr/local/etc/php /opt/host-php/etc/php |
41 | | -COPY --from=host-php-cli /usr/local/include/php /opt/host-php/include/php |
42 | | -COPY --from=host-php-cli /opt/host-php/libdeps /opt/host-php/libdeps |
| 24 | +ARG HOST_PHP_VERSION=8.4 |
| 25 | +ARG HOST_PHP_API_VERSION=20240924 |
43 | 26 |
|
44 | 27 | ENV RUSTUP_HOME=/root/rustup \ |
45 | 28 | CARGO_HOME=/root/cargo \ |
46 | 29 | PATH=/root/cargo/bin:/root/rustup/bin:/usr/local/bin:/usr/bin:/bin \ |
47 | | - LD_LIBRARY_PATH=/opt/host-php/libdeps:/opt/host-php/lib |
| 30 | + HOST_PHP_VERSION=${HOST_PHP_VERSION} \ |
| 31 | + HOST_PHP_API_VERSION=${HOST_PHP_API_VERSION} |
48 | 32 |
|
49 | 33 | RUN apt-get update && apt-get install -y --no-install-recommends \ |
50 | 34 | curl ca-certificates build-essential \ |
51 | 35 | libclang-dev clang llvm-dev pkg-config libxml2 libonig5 libsqlite3-0 \ |
52 | 36 | libargon2-1 libssl3 zlib1g libreadline8 \ |
53 | | - && rm -rf /var/lib/apt/lists/* \ |
54 | | - && /opt/host-php/bin/php -v \ |
55 | | - && ln -sf /opt/host-php/bin/php /usr/local/bin/php-host |
| 37 | + && rm -rf /var/lib/apt/lists/* |
| 38 | + |
| 39 | +# ext-php-rs shells out to `php -i` for version, debug, and ZTS metadata. The |
| 40 | +# wasm-targeted PHP install in /usr/local has no CLI binary (--disable-cli), and |
| 41 | +# copying a host PHP binary across Debian generations makes this layer depend on |
| 42 | +# incompatible shared libraries. Keep the build contract narrow: report only the |
| 43 | +# phpinfo keys ext-php-rs reads, while `PHP_CONFIG` continues to point at the |
| 44 | +# wasm PHP install for headers and include paths. |
| 45 | +RUN set -eux; \ |
| 46 | + printf '%s\n' \ |
| 47 | + '#!/usr/bin/env bash' \ |
| 48 | + 'set -euo pipefail' \ |
| 49 | + 'if [ "${1:-}" != "-i" ]; then' \ |
| 50 | + ' echo "php-host-info only supports php -i for ext-php-rs build metadata" >&2' \ |
| 51 | + ' exit 1' \ |
| 52 | + 'fi' \ |
| 53 | + 'cat <<INFO' \ |
| 54 | + 'PHP Version => ${HOST_PHP_VERSION}' \ |
| 55 | + 'PHP API => ${HOST_PHP_API_VERSION}' \ |
| 56 | + 'Debug Build => no' \ |
| 57 | + 'Thread Safety => disabled' \ |
| 58 | + 'INFO' \ |
| 59 | + > /usr/local/bin/php-host-info; \ |
| 60 | + chmod +x /usr/local/bin/php-host-info; \ |
| 61 | + /usr/local/bin/php-host-info -i | grep -q "PHP API => ${HOST_PHP_API_VERSION}" |
56 | 62 |
|
57 | | -# ext-php-rs's build.rs needs a host `php` executable to query include paths |
58 | | -# from `php-config`. The wasm-targeted PHP install in /usr/local does not ship |
59 | | -# a CLI binary (--disable-cli). We install Debian's host php-cli purely so the |
60 | | -# build script's PHP shells out can run; bindgen still uses |
61 | | -# /usr/local/bin/php-config (from PATH order) for headers — which IS the wasm |
62 | | -# PHP install. Set PHP_CONFIG explicitly to make this contract obvious. |
| 63 | +# Set PHP_CONFIG explicitly so bindgen uses the wasm PHP headers from the |
| 64 | +# Playground compile-extension image, not any host PHP package that apt may |
| 65 | +# provide as a transitive dependency. |
63 | 66 | ENV PHP_CONFIG=/usr/local/bin/php-config \ |
64 | | - PHP=/opt/host-php/bin/php |
| 67 | + PHP=/usr/local/bin/php-host-info |
65 | 68 |
|
66 | 69 | RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \ |
67 | 70 | | sh -s -- -y --default-toolchain stable --profile minimal \ |
|
0 commit comments