From f2c4eab4f3a2135eaeddf8c10cf664ee54d03559 Mon Sep 17 00:00:00 2001 From: PurHur Date: Tue, 19 May 2026 08:35:25 +0000 Subject: [PATCH] Pre-install LLVM 9 in 22.04 dev Docker image (#237) Bake the bundled LLVM 9 toolchain into /opt/llvm9 at image build time so container CI finds JIT/AOT dependencies without re-downloading on every run. Resolve PHP_COMPILER_LLVM_PATH from bind-mounted .llvm, env, or /opt/llvm9. Co-authored-by: Cursor --- .dockerignore | 7 +++++++ Docker/dev/ubuntu-22.04/Dockerfile | 12 +++++++++++- Makefile | 2 +- README.md | 6 +++++- script/ci-local.sh | 10 ++++++---- script/install-llvm9.sh | 2 +- script/php-env.sh | 20 +++++++++++++++----- 7 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..e4291f25 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.git +.llvm +vendor +node_modules +*.o +*.a +build/ diff --git a/Docker/dev/ubuntu-22.04/Dockerfile b/Docker/dev/ubuntu-22.04/Dockerfile index fb4f9397..7618d2c1 100644 --- a/Docker/dev/ubuntu-22.04/Dockerfile +++ b/Docker/dev/ubuntu-22.04/Dockerfile @@ -9,13 +9,23 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ software-properties-common gnupg \ && add-apt-repository -y ppa:ondrej/php \ && apt-get update && apt-get install -y --no-install-recommends \ - git curl unzip ca-certificates \ + git curl unzip ca-certificates dpkg \ php8.2-cli php8.2-mbstring php8.2-xml php8.2-ffi php8.2-posix php8.2-phar \ php8.2-tokenizer php8.2-dom php8.2-xmlwriter \ build-essential clang llvm-14-dev libjansson4 \ && rm -rf /var/lib/apt/lists/* \ && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +# Pre-install LLVM 9 toolchain for JIT/AOT CI (#237). Build from repo root: +# docker build -f Docker/dev/ubuntu-22.04/Dockerfile -t php-compiler:22.04-dev . +COPY script/install-llvm9.sh /tmp/install-llvm9.sh +RUN chmod +x /tmp/install-llvm9.sh \ + && PHP_COMPILER_LLVM_INSTALL_DIR=/opt/llvm9 /tmp/install-llvm9.sh \ + && rm -f /tmp/install-llvm9.sh + +ENV PHP_COMPILER_LLVM_PATH=/opt/llvm9 +ENV LD_LIBRARY_PATH=/opt/llvm9 + WORKDIR /compiler CMD ["/bin/bash"] diff --git a/Makefile b/Makefile index dbe5a751..b652ee3c 100755 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ LOCAL_DEV_IMAGE ?= php-compiler:22.04-dev .PHONY: docker-build-22 docker-build-22: - docker build -t $(LOCAL_DEV_IMAGE) -t $(PHP_COMPILER_DEV_IMAGE) Docker/dev/ubuntu-22.04 + docker build -f Docker/dev/ubuntu-22.04/Dockerfile -t $(LOCAL_DEV_IMAGE) -t $(PHP_COMPILER_DEV_IMAGE) . # Run full local CI inside Docker (mount repo; harness hosts may need: tar | docker run -i …) .PHONY: test-docker diff --git a/README.md b/README.md index cee3f897..4a6d20d9 100755 --- a/README.md +++ b/README.md @@ -93,12 +93,16 @@ Docker is optional on a normal dev machine. On **Runforge / harness hosts** (no ### Container development (PHP 8.2, Ubuntu 22.04) -Build the dev image once: +Build the dev image once (from the repository root; LLVM 9 is baked into `/opt/llvm9`): ```console make docker-build-22 +# equivalent: +docker build -f Docker/dev/ubuntu-22.04/Dockerfile -t php-compiler:22.04-dev . ``` +When you bind-mount the repo, a host `.llvm/` directory (if present) overrides the image toolchain; otherwise `PHP_COMPILER_LLVM_PATH` defaults to `/opt/llvm9` and JIT/AOT tests run without re-downloading. + Run the full local CI suite inside the container (same as `./script/ci-local.sh` on the host): ```console diff --git a/script/ci-local.sh b/script/ci-local.sh index d54238d2..ecde508c 100755 --- a/script/ci-local.sh +++ b/script/ci-local.sh @@ -17,8 +17,10 @@ fi "${COMPOSER[@]}" install --no-interaction --ignore-platform-reqs 2>/dev/null || true chmod +x script/install-llvm9.sh script/apply-patches.sh 2>/dev/null || true -if [[ -x script/install-llvm9.sh ]]; then - script/install-llvm9.sh || true +if [[ -z "${PHP_COMPILER_LLVM_PATH:-}" || ! -f "${PHP_COMPILER_LLVM_PATH}/libLLVM-9.so.1" ]]; then + if [[ -x script/install-llvm9.sh ]]; then + script/install-llvm9.sh || true + fi fi if [[ -x script/apply-patches.sh ]]; then script/apply-patches.sh || true @@ -27,9 +29,9 @@ fi "$PHP_BIN" "${PHP_OPTS[@]}" script/capability-matrix.php --check "$PHP_BIN" "${PHP_OPTS[@]}" script/bootstrap-inventory.php --check -LLVM_DIR="$(cd "$(dirname "$0")/.." && pwd)/.llvm" +LLVM_DIR="${PHP_COMPILER_LLVM_PATH:-$(cd "$(dirname "$0")/.." && pwd)/.llvm}" if [[ -f "$LLVM_DIR/libLLVM-9.so.1" ]]; then - echo "LLVM 9 found: JIT compliance, AOT fixtures (simple_web_*, static_web), and ExampleWebAotTest will run." + echo "LLVM 9 found at $LLVM_DIR: JIT compliance, AOT fixtures (simple_web_*, static_web), and ExampleWebAotTest will run." else echo "LLVM 9 missing: @group llvm tests (JIT, AOT, web AOT) are skipped. Run: script/install-llvm9.sh" fi diff --git a/script/install-llvm9.sh b/script/install-llvm9.sh index 07f5bb07..2631dbea 100755 --- a/script/install-llvm9.sh +++ b/script/install-llvm9.sh @@ -2,7 +2,7 @@ # Fetch libLLVM-9, clang-9, linker, and crt bits for AOT/JIT on hosts with only LLVM 17+. set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" -LLVM_DIR="$ROOT/.llvm" +LLVM_DIR="${PHP_COMPILER_LLVM_INSTALL_DIR:-$ROOT/.llvm}" DEB_BASE="http://deb.debian.org/debian/pool/main/l/llvm-toolchain-9" BINUTILS_BASE="http://deb.debian.org/debian/pool/main/b/binutils" GCC9_BASE="http://deb.debian.org/debian/pool/main/g/gcc-9" diff --git a/script/php-env.sh b/script/php-env.sh index 8cf49889..93e5421d 100644 --- a/script/php-env.sh +++ b/script/php-env.sh @@ -20,12 +20,22 @@ if ! command -v "$PHP_BIN" >/dev/null 2>&1; then done fi export PHP_COMPILER_EXT_DIR="${PHP_COMPILER_EXT_DIR:-/usr/lib/php/20220829}" -LLVM_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/.llvm" -if [[ -f "$LLVM_DIR/libLLVM-9.so.1" ]]; then - export LD_LIBRARY_PATH="$LLVM_DIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" - export PATH="$LLVM_DIR${PATH:+:$PATH}" - export PHP_COMPILER_LLVM_PATH="$LLVM_DIR" +_REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +_REPO_LLVM="$_REPO_ROOT/.llvm" +_LLVM_DIR="" +if [[ -f "$_REPO_LLVM/libLLVM-9.so.1" ]]; then + _LLVM_DIR="$_REPO_LLVM" +elif [[ -n "${PHP_COMPILER_LLVM_PATH:-}" && -f "${PHP_COMPILER_LLVM_PATH}/libLLVM-9.so.1" ]]; then + _LLVM_DIR="$PHP_COMPILER_LLVM_PATH" +elif [[ -f /opt/llvm9/libLLVM-9.so.1 ]]; then + _LLVM_DIR=/opt/llvm9 fi +if [[ -n "$_LLVM_DIR" ]]; then + export LD_LIBRARY_PATH="$_LLVM_DIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" + export PATH="$_LLVM_DIR${PATH:+:$PATH}" + export PHP_COMPILER_LLVM_PATH="$_LLVM_DIR" +fi +unset _REPO_ROOT _REPO_LLVM _LLVM_DIR EXT_DIR="$PHP_COMPILER_EXT_DIR" PHP_OPTS=() if [[ -d "$EXT_DIR" ]]; then