From d598959ed38f4d53bc2a0bc5cc5725bf42863757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sat, 2 Dec 2023 12:16:39 +0100 Subject: [PATCH] fixes and docs --- build-static.sh | 14 ++++++++------ docs/static.md | 17 ++++++++++++++--- static-builder.Dockerfile | 2 ++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/build-static.sh b/build-static.sh index e914d49e9b..15d1f20d4c 100755 --- a/build-static.sh +++ b/build-static.sh @@ -53,7 +53,9 @@ if [ "$CLEAN" ]; then fi # Build libphp if ncessary -if [ ! -f "dist/static-php-cli/buildroot/lib/libphp.a" ]; then +if [ -f "dist/static-php-cli/buildroot/lib/libphp.a" ]; then + cd dist/static-php-cli +else mkdir -p dist/ cd dist/ @@ -84,23 +86,23 @@ if [ ! -f "dist/static-php-cli/buildroot/lib/libphp.a" ]; then ./bin/spc fetch --with-php="$PHP_VERSION" --for-extensions="$PHP_EXTENSIONS" # shellcheck disable=SC2086 ./bin/spc build --enable-zts --build-embed $extraOpts "$PHP_EXTENSIONS" --with-libs="$PHP_EXTENSION_LIBS" - - cd ../.. fi -CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $(dist/static-php-cli/buildroot/bin/php-config --includes | sed s#-I/#-I"$PWD"/buildroot/#g)" +CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $(./buildroot/bin/php-config --includes | sed s#-I/#-I"$PWD"/buildroot/#g)" export CGO_CFLAGS if [ "$os" = "mac" ]; then export CGO_LDFLAGS="-framework CoreFoundation -framework SystemConfiguration" fi -CGO_LDFLAGS="$CGO_LDFLAGS $(dist/static-php-cli/buildroot/bin/php-config --ldflags) $(dist/static-php-cli/buildroot/bin/php-config --libs)" +CGO_LDFLAGS="$CGO_LDFLAGS $(./buildroot/bin/php-config --ldflags) $(./buildroot/bin/php-config --libs)" export CGO_LDFLAGS -LIBPHP_VERSION="$(dist/static-php-cli/buildroot/bin/php-config --version)" +LIBPHP_VERSION="$(./buildroot/bin/php-config --version)" export LIBPHP_VERSION +cd ../.. + # Embed PHP app, if any if [ -d "$EMBED" ]; then mv embed embed.bak diff --git a/docs/static.md b/docs/static.md index 11458cb9bf..f2c6636fbe 100644 --- a/docs/static.md +++ b/docs/static.md @@ -31,8 +31,6 @@ docker buildx bake --load --set static-builder.args.PHP_EXTENSIONS=opcache,pdo_s # ... ``` -See [the list of supported extensions](https://static-php.dev/en/guide/extensions.html). - To add libraries enabling additional functionality to the extensions you've enabled, you can pass use the `PHP_EXTENSION_LIBS` Docker ARG: ```console @@ -43,6 +41,8 @@ docker buildx bake \ static-builder ``` +See also: [customizing the build](#customizing-the-build) + ### GitHub Token If you hit the GitHub API rate limit, set a GitHub Personal Access Token in an environment variable named `GITHUB_TOKEN`: @@ -64,4 +64,15 @@ cd frankenphp Note: this script also works on Linux (and probably on other Unixes), and is used internally by the Docker based static builder we provide. -See [the list of supported extensions](https://static-php.dev/en/guide/extensions.html). +## Customizing The Build + +The following environment variables can be passed to `docker build` and to the `build-static.sh` +script to customize the static build: + +* `FRANKENPHP_VERSION`: the version of FrankenPHP to use +* `PHP_VERSION`: the version of PHP to use +* `PHP_EXTENSIONS`: the PHP extensions to build ([list of supported extensions](https://static-php.dev/en/guide/extensions.html)) +* `PHP_EXTENSION_LIBS`: extra libraries to build that add extra features to the extensions +* `EMBED`: path of the PHP application to embed in the binary +* `CLEAN`: when set, libphp and all its dependencies are built from scratch (no cache) +* `RELEASE`: (maintainers only) when set, the resulting binary will be uploaded on GitHub diff --git a/static-builder.Dockerfile b/static-builder.Dockerfile index 20a6b82a77..76f32ce163 100644 --- a/static-builder.Dockerfile +++ b/static-builder.Dockerfile @@ -5,6 +5,8 @@ ARG FRANKENPHP_VERSION='' ARG PHP_VERSION='' ARG PHP_EXTENSIONS='' ARG PHP_EXTENSION_LIBS='' +ARG CLEAN='' +ARG EMBED='' SHELL ["/bin/ash", "-eo", "pipefail", "-c"] RUN apk update; \