Skip to content

Commit

Permalink
fix(static): fix builds by switching to spc-config (#1231)
Browse files Browse the repository at this point in the history
* chore: remove useless SPC workarounds

* use spc-config
  • Loading branch information
dunglas authored Dec 18, 2024
1 parent fbbc129 commit c0e0c2d
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions build-static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ fi

arch="$(uname -m)"
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
# FIXME: re-enable PHP errors when SPC will be compatible with PHP 8.4
spcCommand="php -ddisplay_errors=Off ./bin/spc"
md5binary="md5sum"
if [ "${os}" = "darwin" ]; then
os="mac"
Expand Down Expand Up @@ -114,10 +116,10 @@ else
extraOpts="${extraOpts} --no-strip"
fi

./bin/spc doctor --auto-fix
./bin/spc download --with-php="${PHP_VERSION}" --for-extensions="${PHP_EXTENSIONS}" --for-libs="${PHP_EXTENSION_LIBS}" --ignore-cache-sources=php-src --prefer-pre-built
${spcCommand} doctor --auto-fix
${spcCommand} download --with-php="${PHP_VERSION}" --for-extensions="${PHP_EXTENSIONS}" --for-libs="${PHP_EXTENSION_LIBS}" --ignore-cache-sources=php-src --prefer-pre-built
# shellcheck disable=SC2086
./bin/spc build --debug --enable-zts --build-embed ${extraOpts} "${PHP_EXTENSIONS}" --with-libs="${PHP_EXTENSION_LIBS}"
${spcCommand} build --debug --enable-zts --build-embed ${extraOpts} "${PHP_EXTENSIONS}" --with-libs="${PHP_EXTENSION_LIBS}"
fi

curlGitHubHeaders=(--header "X-GitHub-Api-Version: 2022-11-28")
Expand All @@ -144,7 +146,7 @@ cp -R include/wtr/watcher-c.h ../../buildroot/include/wtr/watcher-c.h
cd ../../

# See https://github.com/docker-library/php/blob/master/8.3/alpine3.20/zts/Dockerfile#L53-L55
CGO_CFLAGS="-DFRANKENPHP_VERSION=${FRANKENPHP_VERSION} -I${PWD}/buildroot/include/ $(./buildroot/bin/php-config --includes | sed s#-I/#-I"${PWD}"/buildroot/#g)"
CGO_CFLAGS="-DFRANKENPHP_VERSION=${FRANKENPHP_VERSION} -I${PWD}/buildroot/include/ $(${spcCommand} spc-config "${PHP_EXTENSIONS}" --with-libs="${PHP_EXTENSION_LIBS}" --includes)"
if [ -n "${DEBUG_SYMBOLS}" ]; then
CGO_CFLAGS="-g ${CGO_CFLAGS}"
else
Expand All @@ -159,12 +161,7 @@ elif [ "${os}" = "linux" ] && [ -z "${DEBUG_SYMBOLS}" ]; then
CGO_LDFLAGS="-Wl,-O1 -pie"
fi

# Temporary workaround for https://github.com/crazywhalecc/static-php-cli/issues/560
if [[ "${PHP_EXTENSIONS}" == *"pgsql"* ]]; then
CGO_LDFLAGS="${CGO_LDFLAGS} ${PWD}/buildroot/lib/libpgcommon.a ${PWD}/buildroot/lib/libpgport.a ${PWD}/buildroot/lib/libpq.a"
fi
CGO_LDFLAGS="${CGO_LDFLAGS} ${PWD}/buildroot/lib/libbrotlicommon.a ${PWD}/buildroot/lib/libbrotlienc.a ${PWD}/buildroot/lib/libbrotlidec.a ${PWD}/buildroot/lib/libwatcher-c.a $(./buildroot/bin/php-config --ldflags || true) $(./buildroot/bin/php-config --libs | sed -e 's/-lgcc_s//g' || true)"
CGO_LDFLAGS="${CGO_LDFLAGS} ${PWD}/buildroot/lib/libbrotlicommon.a ${PWD}/buildroot/lib/libbrotlienc.a ${PWD}/buildroot/lib/libbrotlidec.a ${PWD}/buildroot/lib/libwatcher-c.a $(${spcCommand} spc-config "${PHP_EXTENSIONS}" --with-libs="${PHP_EXTENSION_LIBS}" --libs)"
if [ "${os}" = "linux" ]; then
if echo "${PHP_EXTENSIONS}" | grep -qE "\b(intl|imagick|grpc|v8js|protobuf|mongodb|tbb)\b"; then
CGO_LDFLAGS="${CGO_LDFLAGS} -lstdc++"
Expand All @@ -173,11 +170,7 @@ fi

export CGO_LDFLAGS

#LIBPHP_VERSION="$(./buildroot/bin/php-config --version)"
# Temporary workaround for https://github.com/crazywhalecc/static-php-cli/issues/563
if [[ $(cat buildroot/include/php/main/php_version.h) =~ (define PHP_VERSION \"([0-9\.]+)) ]]; then
export LIBPHP_VERSION=${BASH_REMATCH[2]}
fi
LIBPHP_VERSION="$(./buildroot/bin/php-config --version)"

cd ../

Expand Down

0 comments on commit c0e0c2d

Please sign in to comment.