@@ -58,7 +58,20 @@ if [ -n "${DEBUG_SYMBOLS}" ]; then
5858fi
5959# php version to build
6060if [ -z " ${PHP_VERSION} " ]; then
61- export PHP_VERSION=" 8.4"
61+ get_latest_php_version () {
62+ input=" $1 "
63+ json=$( curl -s " https://www.php.net/releases/index.php?json&version=$input " )
64+ latest=$( echo " $json " | jq -r ' .version' )
65+
66+ if [[ " $latest " == " $input " * ]]; then
67+ echo " $latest "
68+ else
69+ echo " $input "
70+ fi
71+ }
72+
73+ PHP_VERSION=" $( get_latest_php_version " 8.4" ) "
74+ export PHP_VERSION
6275fi
6376# default extension set
6477defaultExtensions=" 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
117130 go clean -cache
118131fi
119132
120- cache_key=" ${PHP_VERSION} -${PHP_EXTENSIONS} -${PHP_EXTENSION_LIBS} "
133+ mkdir -p dist/
134+ cd dist/
121135
122- # Build libphp if necessary
123- if [ -f dist/cache_key ] && [ " $( cat dist/cache_key) " = " ${cache_key} " ] && [ -f " dist/static-php-cli/buildroot/lib/libphp.a" ]; then
124- cd dist/static-php-cli
125-
126- if [ -f " ./spc" ]; then
127- spcCommand=" ./spc"
128- elif [ -f " bin/spc" ]; then
129- spcCommand=" ./bin/spc"
136+ if type " brew" > /dev/null 2>&1 ; then
137+ if ! type " composer" > /dev/null; then
138+ packages=" composer"
130139 fi
131- else
132- mkdir -p dist/
133- cd dist/
134- echo -n " ${cache_key} " > cache_key
135-
136- if type " brew" > /dev/null 2>&1 ; then
137- if ! type " composer" > /dev/null; then
138- packages=" composer"
139- fi
140- if ! type " go" > /dev/null 2>&1 ; then
141- packages=" ${packages} go"
142- fi
143- if [ -n " ${RELEASE} " ] && ! type " gh" > /dev/null 2>&1 ; then
144- packages=" ${packages} gh"
145- fi
146-
147- if [ -n " ${packages} " ]; then
148- # shellcheck disable=SC2086
149- brew install --formula --quiet ${packages}
150- fi
140+ if ! type " go" > /dev/null 2>&1 ; then
141+ packages=" ${packages} go"
151142 fi
152-
153- if [ " ${SPC_REL_TYPE} " = " binary" ] && [[ ! " ${arch} " =~ arm ]]; then
154- mkdir -p static-php-cli/
155- cd static-php-cli/
156- curl -o spc -fsSL " https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-${arch} "
157- chmod +x spc
158- spcCommand=" ./spc"
159- elif [ -d " static-php-cli/src" ]; then
160- cd static-php-cli/
161- git pull
162- composer install --no-dev -a
163- spcCommand=" ./bin/spc"
164- else
165- git clone --depth 1 https://github.com/crazywhalecc/static-php-cli --branch main
166- cd static-php-cli/
167- composer install --no-dev -a
168- spcCommand=" ./bin/spc"
143+ if [ -n " ${RELEASE} " ] && ! type " gh" > /dev/null 2>&1 ; then
144+ packages=" ${packages} gh"
169145 fi
170146
171- # extensions to build
172- if [ -z " ${PHP_EXTENSIONS} " ]; then
173- # enable EMBED mode, first check if project has dumped extensions
174- if [ -n " ${EMBED} " ] && [ -f " ${EMBED} /composer.json" ] && [ -f " ${EMBED} /composer.lock" ] && [ -f " ${EMBED} /vendor/installed.json" ]; then
175- cd " ${EMBED} "
176- # read the extensions using spc dump-extensions
177- PHP_EXTENSIONS=$( ${spcCommand} dump-extensions " ${EMBED} " --format=text --no-dev --no-ext-output=" ${defaultExtensions} " )
178- else
179- PHP_EXTENSIONS=" ${defaultExtensions} "
180- fi
147+ if [ -n " ${packages} " ]; then
148+ # shellcheck disable=SC2086
149+ brew install --formula --quiet ${packages}
181150 fi
182- # additional libs to build
183- if [ -z " ${PHP_EXTENSION_LIBS} " ]; then
184- PHP_EXTENSION_LIBS=" ${defaultExtensionLibs} "
151+ fi
152+
153+ if [ " ${SPC_REL_TYPE} " = " binary" ]; then
154+ mkdir -p static-php-cli/
155+ cd static-php-cli/
156+ if [[ " ${arch} " =~ " arm" ]]; then
157+ dl_arch=" aarch64"
158+ else
159+ dl_arch=" ${arch} "
185160 fi
186- # The Brotli library must always be built as it is required by http://github.com/dunglas/caddy-cbrotli
187- if ! echo " ${PHP_EXTENSION_LIBS} " | grep -q " \bbrotli\b" ; then
188- PHP_EXTENSION_LIBS=" ${PHP_EXTENSION_LIBS} ,brotli"
161+ curl -o spc -fsSL " https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-${dl_arch} "
162+ chmod +x spc
163+ spcCommand=" ./spc"
164+ elif [ -d " static-php-cli/src" ]; then
165+ cd static-php-cli/
166+ git pull
167+ composer install --no-dev -a --no-interaction
168+ spcCommand=" ./bin/spc"
169+ else
170+ git clone --depth 1 https://github.com/crazywhalecc/static-php-cli --branch main
171+ cd static-php-cli/
172+ composer install --no-dev -a --no-interaction
173+ spcCommand=" ./bin/spc"
174+ fi
175+
176+ # Extensions to build
177+ if [ -z " ${PHP_EXTENSIONS} " ]; then
178+ # enable EMBED mode, first check if project has dumped extensions
179+ if [ -n " ${EMBED} " ] && [ -f " ${EMBED} /composer.json" ] && [ -f " ${EMBED} /composer.lock" ] && [ -f " ${EMBED} /vendor/installed.json" ]; then
180+ cd " ${EMBED} "
181+ # read the extensions using spc dump-extensions
182+ PHP_EXTENSIONS=$( ${spcCommand} dump-extensions " ${EMBED} " --format=text --no-dev --no-ext-output=" ${defaultExtensions} " )
183+ else
184+ PHP_EXTENSIONS=" ${defaultExtensions} "
189185 fi
190- # The mimalloc library must be built if MIMALLOC is true
191- if [ -n " ${MIMALLOC} " ]; then
192- if ! echo " ${PHP_EXTENSION_LIBS} " | grep -q " \bmimalloc\b" ; then
193- PHP_EXTENSION_LIBS=" ${PHP_EXTENSION_LIBS} ,mimalloc"
194- fi
186+ fi
187+
188+ # Additional libraries to build
189+ if [ -z " ${PHP_EXTENSION_LIBS} " ]; then
190+ PHP_EXTENSION_LIBS=" ${defaultExtensionLibs} "
191+ fi
192+
193+ # The Brotli library must always be built as it is required by http://github.com/dunglas/caddy-cbrotli
194+ if ! echo " ${PHP_EXTENSION_LIBS} " | grep -q " \bbrotli\b" ; then
195+ PHP_EXTENSION_LIBS=" ${PHP_EXTENSION_LIBS} ,brotli"
196+ fi
197+
198+ # The mimalloc library must be built if MIMALLOC is true
199+ if [ -n " ${MIMALLOC} " ]; then
200+ if ! echo " ${PHP_EXTENSION_LIBS} " | grep -q " \bmimalloc\b" ; then
201+ PHP_EXTENSION_LIBS=" ${PHP_EXTENSION_LIBS} ,mimalloc"
195202 fi
203+ fi
196204
205+ # Build libphp if necessary
206+ cache_key=" ${PHP_VERSION} -${PHP_EXTENSIONS} -${PHP_EXTENSION_LIBS} "
207+ if [ -f ../cache_key ] && [ " $( cat ../cache_key) " = " ${cache_key} " ] && [ -f " buildroot/lib/libphp.a" ]; then
208+ echo " Hit cache, skipping libphp build."
209+ else
197210 ${spcCommand} doctor --auto-fix
198211 # shellcheck disable=SC2086
199212 ${spcCommand} download --with-php=" ${PHP_VERSION} " --for-extensions=" ${PHP_EXTENSIONS} " --for-libs=" ${PHP_EXTENSION_LIBS} " ${SPC_OPT_DOWNLOAD_ARGS}
200213 # shellcheck disable=SC2086
201214 ${spcCommand} build --enable-zts --build-embed ${SPC_OPT_BUILD_ARGS} " ${PHP_EXTENSIONS} " --with-libs=" ${PHP_EXTENSION_LIBS} "
215+
216+ echo -n " ${cache_key} " > ../cache_key
202217fi
203218
204219if ! type " go" > /dev/null 2>&1 ; then
0 commit comments