@@ -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,91 +130,90 @@ if [ -n "${CLEAN}" ]; then
117130 go clean -cache
118131fi
119132
120- cache_key=" ${PHP_VERSION} -${PHP_EXTENSIONS} -${PHP_EXTENSION_LIBS} "
121-
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
133+ mkdir -p dist/
134+ cd dist/
125135
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-
132- PHP_EXTENSIONS=" ${defaultExtensions} "
133- PHP_EXTENSION_LIBS=" ${defaultExtensionLibs} "
134- else
135- mkdir -p dist/
136- cd dist/
137- echo -n " ${cache_key} " > cache_key
138-
139- if type " brew" > /dev/null 2>&1 ; then
140- if ! type " composer" > /dev/null; then
141- packages=" composer"
142- fi
143- if ! type " go" > /dev/null 2>&1 ; then
144- packages=" ${packages} go"
145- fi
146- if [ -n " ${RELEASE} " ] && ! type " gh" > /dev/null 2>&1 ; then
147- packages=" ${packages} gh"
148- fi
149-
150- if [ -n " ${packages} " ]; then
151- # shellcheck disable=SC2086
152- brew install --formula --quiet ${packages}
153- fi
140+ if ! type " go" > /dev/null 2>&1 ; then
141+ packages=" ${packages} go"
154142 fi
155-
156- if [ " ${SPC_REL_TYPE} " = " binary" ] && [[ ! " ${arch} " =~ arm ]]; then
157- mkdir -p static-php-cli/
158- cd static-php-cli/
159- curl -o spc -fsSL " https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-${arch} "
160- chmod +x spc
161- spcCommand=" ./spc"
162- elif [ -d " static-php-cli/src" ]; then
163- cd static-php-cli/
164- git pull
165- composer install --no-dev -a
166- spcCommand=" ./bin/spc"
167- else
168- git clone --depth 1 https://github.com/crazywhalecc/static-php-cli --branch main
169- cd static-php-cli/
170- composer install --no-dev -a
171- spcCommand=" ./bin/spc"
143+ if [ -n " ${RELEASE} " ] && ! type " gh" > /dev/null 2>&1 ; then
144+ packages=" ${packages} gh"
172145 fi
173146
174- # extensions to build
175- if [ -z " ${PHP_EXTENSIONS} " ]; then
176- # enable EMBED mode, first check if project has dumped extensions
177- if [ -n " ${EMBED} " ] && [ -f " ${EMBED} /composer.json" ] && [ -f " ${EMBED} /composer.lock" ] && [ -f " ${EMBED} /vendor/installed.json" ]; then
178- cd " ${EMBED} "
179- # read the extensions using spc dump-extensions
180- PHP_EXTENSIONS=$( ${spcCommand} dump-extensions " ${EMBED} " --format=text --no-dev --no-ext-output=" ${defaultExtensions} " )
181- else
182- PHP_EXTENSIONS=" ${defaultExtensions} "
183- fi
147+ if [ -n " ${packages} " ]; then
148+ # shellcheck disable=SC2086
149+ brew install --formula --quiet ${packages}
184150 fi
185- # additional libs to build
186- if [ -z " ${PHP_EXTENSION_LIBS} " ]; then
187- 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} "
188160 fi
189- # The Brotli library must always be built as it is required by http://github.com/dunglas/caddy-cbrotli
190- if ! echo " ${PHP_EXTENSION_LIBS} " | grep -q " \bbrotli\b" ; then
191- 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} "
192185 fi
193- # The mimalloc library must be built if MIMALLOC is true
194- if [ -n " ${MIMALLOC} " ]; then
195- if ! echo " ${PHP_EXTENSION_LIBS} " | grep -q " \bmimalloc\b" ; then
196- PHP_EXTENSION_LIBS=" ${PHP_EXTENSION_LIBS} ,mimalloc"
197- 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"
198202 fi
203+ fi
199204
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
200210 ${spcCommand} doctor --auto-fix
201211 # shellcheck disable=SC2086
202212 ${spcCommand} download --with-php=" ${PHP_VERSION} " --for-extensions=" ${PHP_EXTENSIONS} " --for-libs=" ${PHP_EXTENSION_LIBS} " ${SPC_OPT_DOWNLOAD_ARGS}
203213 # shellcheck disable=SC2086
204214 ${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
205217fi
206218
207219if ! type " go" > /dev/null 2>&1 ; then
0 commit comments