diff --git a/build-static.sh b/build-static.sh index 930b0781a3..4de0255275 100755 --- a/build-static.sh +++ b/build-static.sh @@ -58,7 +58,20 @@ if [ -n "${DEBUG_SYMBOLS}" ]; then fi # php version to build if [ -z "${PHP_VERSION}" ]; then - export PHP_VERSION="8.4" + get_latest_php_version() { + input="$1" + json=$(curl -s "https://www.php.net/releases/index.php?json&version=$input") + latest=$(echo "$json" | jq -r '.version') + + if [[ "$latest" == "$input"* ]]; then + echo "$latest" + else + echo "$input" + fi + } + + PHP_VERSION="$(get_latest_php_version "8.4")" + export PHP_VERSION fi # default extension set defaultExtensions="apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,ftp,gd,gmp,gettext,iconv,igbinary,imagick,intl,ldap,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,parallel,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,protobuf,readline,redis,session,shmop,simplexml,soap,sockets,sodium,sqlite3,ssh2,sysvmsg,sysvsem,sysvshm,tidy,tokenizer,xlswriter,xml,xmlreader,xmlwriter,zip,zlib,yaml,zstd" @@ -117,88 +130,90 @@ if [ -n "${CLEAN}" ]; then go clean -cache fi -cache_key="${PHP_VERSION}-${PHP_EXTENSIONS}-${PHP_EXTENSION_LIBS}" +mkdir -p dist/ +cd dist/ -# Build libphp if necessary -if [ -f dist/cache_key ] && [ "$(cat dist/cache_key)" = "${cache_key}" ] && [ -f "dist/static-php-cli/buildroot/lib/libphp.a" ]; then - cd dist/static-php-cli - - if [ -f "./spc" ]; then - spcCommand="./spc" - elif [ -f "bin/spc" ]; then - spcCommand="./bin/spc" +if type "brew" >/dev/null 2>&1; then + if ! type "composer" >/dev/null; then + packages="composer" fi -else - mkdir -p dist/ - cd dist/ - echo -n "${cache_key}" >cache_key - - if type "brew" >/dev/null 2>&1; then - if ! type "composer" >/dev/null; then - packages="composer" - fi - if ! type "go" >/dev/null 2>&1; then - packages="${packages} go" - fi - if [ -n "${RELEASE}" ] && ! type "gh" >/dev/null 2>&1; then - packages="${packages} gh" - fi - - if [ -n "${packages}" ]; then - # shellcheck disable=SC2086 - brew install --formula --quiet ${packages} - fi + if ! type "go" >/dev/null 2>&1; then + packages="${packages} go" fi - - if [ "${SPC_REL_TYPE}" = "binary" ] && [[ ! "${arch}" =~ arm ]]; then - mkdir -p static-php-cli/ - cd static-php-cli/ - curl -o spc -fsSL "https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-${arch}" - chmod +x spc - spcCommand="./spc" - elif [ -d "static-php-cli/src" ]; then - cd static-php-cli/ - git pull - composer install --no-dev -a - spcCommand="./bin/spc" - else - git clone --depth 1 https://github.com/crazywhalecc/static-php-cli --branch main - cd static-php-cli/ - composer install --no-dev -a - spcCommand="./bin/spc" + if [ -n "${RELEASE}" ] && ! type "gh" >/dev/null 2>&1; then + packages="${packages} gh" fi - # extensions to build - if [ -z "${PHP_EXTENSIONS}" ]; then - # enable EMBED mode, first check if project has dumped extensions - if [ -n "${EMBED}" ] && [ -f "${EMBED}/composer.json" ] && [ -f "${EMBED}/composer.lock" ] && [ -f "${EMBED}/vendor/installed.json" ]; then - cd "${EMBED}" - # read the extensions using spc dump-extensions - PHP_EXTENSIONS=$(${spcCommand} dump-extensions "${EMBED}" --format=text --no-dev --no-ext-output="${defaultExtensions}") - else - PHP_EXTENSIONS="${defaultExtensions}" - fi + if [ -n "${packages}" ]; then + # shellcheck disable=SC2086 + brew install --formula --quiet ${packages} fi - # additional libs to build - if [ -z "${PHP_EXTENSION_LIBS}" ]; then - PHP_EXTENSION_LIBS="${defaultExtensionLibs}" +fi + +if [ "${SPC_REL_TYPE}" = "binary" ]; then + mkdir -p static-php-cli/ + cd static-php-cli/ + if [[ "${arch}" =~ "arm" ]]; then + dl_arch="aarch64" + else + dl_arch="${arch}" fi - # The Brotli library must always be built as it is required by http://github.com/dunglas/caddy-cbrotli - if ! echo "${PHP_EXTENSION_LIBS}" | grep -q "\bbrotli\b"; then - PHP_EXTENSION_LIBS="${PHP_EXTENSION_LIBS},brotli" + curl -o spc -fsSL "https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-${dl_arch}" + chmod +x spc + spcCommand="./spc" +elif [ -d "static-php-cli/src" ]; then + cd static-php-cli/ + git pull + composer install --no-dev -a --no-interaction + spcCommand="./bin/spc" +else + git clone --depth 1 https://github.com/crazywhalecc/static-php-cli --branch main + cd static-php-cli/ + composer install --no-dev -a --no-interaction + spcCommand="./bin/spc" +fi + +# Extensions to build +if [ -z "${PHP_EXTENSIONS}" ]; then + # enable EMBED mode, first check if project has dumped extensions + if [ -n "${EMBED}" ] && [ -f "${EMBED}/composer.json" ] && [ -f "${EMBED}/composer.lock" ] && [ -f "${EMBED}/vendor/installed.json" ]; then + cd "${EMBED}" + # read the extensions using spc dump-extensions + PHP_EXTENSIONS=$(${spcCommand} dump-extensions "${EMBED}" --format=text --no-dev --no-ext-output="${defaultExtensions}") + else + PHP_EXTENSIONS="${defaultExtensions}" fi - # The mimalloc library must be built if MIMALLOC is true - if [ -n "${MIMALLOC}" ]; then - if ! echo "${PHP_EXTENSION_LIBS}" | grep -q "\bmimalloc\b"; then - PHP_EXTENSION_LIBS="${PHP_EXTENSION_LIBS},mimalloc" - fi +fi + +# Additional libraries to build +if [ -z "${PHP_EXTENSION_LIBS}" ]; then + PHP_EXTENSION_LIBS="${defaultExtensionLibs}" +fi + +# The Brotli library must always be built as it is required by http://github.com/dunglas/caddy-cbrotli +if ! echo "${PHP_EXTENSION_LIBS}" | grep -q "\bbrotli\b"; then + PHP_EXTENSION_LIBS="${PHP_EXTENSION_LIBS},brotli" +fi + +# The mimalloc library must be built if MIMALLOC is true +if [ -n "${MIMALLOC}" ]; then + if ! echo "${PHP_EXTENSION_LIBS}" | grep -q "\bmimalloc\b"; then + PHP_EXTENSION_LIBS="${PHP_EXTENSION_LIBS},mimalloc" fi +fi +# Build libphp if necessary +cache_key="${PHP_VERSION}-${PHP_EXTENSIONS}-${PHP_EXTENSION_LIBS}" +if [ -f ../cache_key ] && [ "$(cat ../cache_key)" = "${cache_key}" ] && [ -f "buildroot/lib/libphp.a" ]; then + echo "Hit cache, skipping libphp build." +else ${spcCommand} doctor --auto-fix # shellcheck disable=SC2086 ${spcCommand} download --with-php="${PHP_VERSION}" --for-extensions="${PHP_EXTENSIONS}" --for-libs="${PHP_EXTENSION_LIBS}" ${SPC_OPT_DOWNLOAD_ARGS} # shellcheck disable=SC2086 ${spcCommand} build --enable-zts --build-embed ${SPC_OPT_BUILD_ARGS} "${PHP_EXTENSIONS}" --with-libs="${PHP_EXTENSION_LIBS}" + + echo -n "${cache_key}" >../cache_key fi if ! type "go" >/dev/null 2>&1; then diff --git a/static-builder-gnu.Dockerfile b/static-builder-gnu.Dockerfile index 9288a62018..f7224114d7 100644 --- a/static-builder-gnu.Dockerfile +++ b/static-builder-gnu.Dockerfile @@ -94,6 +94,9 @@ RUN yum install -y \ else \ GO_ARCH="amd64" ; \ fi ; \ + curl -o jq -fsSL https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-${GO_ARCH} && \ + chmod +x jq && \ + mv jq /usr/local/bin/jq && \ curl -o go.tgz -fsSL https://go.dev/dl/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \ rm -rf /usr/local/go && \ tar -C /usr/local -xzf go.tgz && \