Skip to content

Commit 0cc9b0c

Browse files
pierreduphenderkes
authored andcommitted
fix: build-static.sh (php#1474)
* Fixes build-static script * Add composer to gnu image * Fix syntax
1 parent 5f0647c commit 0cc9b0c

File tree

1 file changed

+68
-62
lines changed

1 file changed

+68
-62
lines changed

build-static.sh

Lines changed: 68 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -117,82 +117,88 @@ if [ -n "${CLEAN}" ]; then
117117
go clean -cache
118118
fi
119119

120-
mkdir -p dist/
121-
cd dist/
120+
cache_key="${PHP_VERSION}-${PHP_EXTENSIONS}-${PHP_EXTENSION_LIBS}"
122121

123-
if type "brew" >/dev/null 2>&1; then
124-
if ! type "composer" >/dev/null; then
125-
packages="composer"
126-
fi
127-
if ! type "go" >/dev/null 2>&1; then
128-
packages="${packages} go"
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"
129130
fi
130-
if [ -n "${RELEASE}" ] && ! type "gh" >/dev/null 2>&1; then
131-
packages="${packages} gh"
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
132151
fi
133152

134-
if [ -n "${packages}" ]; then
135-
# shellcheck disable=SC2086
136-
brew install --formula --quiet ${packages}
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"
137169
fi
138-
fi
139170

140-
if [ "${SPC_REL_TYPE}" = "binary" ]; then
141-
mkdir static-php-cli/
142-
cd static-php-cli/
143-
curl -o spc -fsSL "https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-$(uname -m)"
144-
chmod +x spc
145-
spcCommand="./spc"
146-
elif [ -d "static-php-cli/src" ]; then
147-
cd static-php-cli/
148-
git pull
149-
composer install --no-dev -a --no-interaction
150-
spcCommand="./bin/spc"
151-
else
152-
git clone --depth 1 https://github.com/crazywhalecc/static-php-cli --branch main
153-
cd static-php-cli/
154-
composer install --no-dev -a --no-interaction
155-
spcCommand="./bin/spc"
156-
fi
157-
158-
# extensions to build
159-
if [ -z "${PHP_EXTENSIONS}" ]; then
160-
# enable EMBED mode, first check if project has dumped extensions
161-
if [ -n "${EMBED}" ] && [ -f "${EMBED}/composer.json" ] && [ -f "${EMBED}/composer.lock" ] && [ -f "${EMBED}/vendor/installed.json" ]; then
162-
cd "${EMBED}"
163-
# read the extensions using spc dump-extensions
164-
PHP_EXTENSIONS=$(${spcCommand} dump-extensions "${EMBED}" --format=text --no-dev --no-ext-output="${defaultExtensions}")
165-
else
166-
PHP_EXTENSIONS="${defaultExtensions}"
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
167181
fi
168-
fi
169-
# additional libs to build
170-
if [ -z "${PHP_EXTENSION_LIBS}" ]; then
171-
PHP_EXTENSION_LIBS="${defaultExtensionLibs}"
172-
fi
173-
# The Brotli library must always be built as it is required by http://github.com/dunglas/caddy-cbrotli
174-
if ! echo "${PHP_EXTENSION_LIBS}" | grep -q "\bbrotli\b"; then
175-
PHP_EXTENSION_LIBS="${PHP_EXTENSION_LIBS},brotli"
176-
fi
177-
# The mimalloc library must be built if MIMALLOC is true
178-
if [ -n "${MIMALLOC}" ]; then
179-
if ! echo "${PHP_EXTENSION_LIBS}" | grep -q "\bmimalloc\b"; then
180-
PHP_EXTENSION_LIBS="${PHP_EXTENSION_LIBS},mimalloc"
182+
# additional libs to build
183+
if [ -z "${PHP_EXTENSION_LIBS}" ]; then
184+
PHP_EXTENSION_LIBS="${defaultExtensionLibs}"
185+
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"
189+
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
181195
fi
182-
fi
183196

184-
# Build libphp if necessary
185-
cache_key="${PHP_VERSION}-${PHP_EXTENSIONS}-${PHP_EXTENSION_LIBS}"
186-
if [ -f ../cache_key ] && [ "$(cat ../cache_key)" = "${cache_key}" ] && [ -f "buildroot/lib/libphp.a" ]; then
187-
echo "Hit cache, skipping libphp build."
188-
else
189197
${spcCommand} doctor --auto-fix
190198
# shellcheck disable=SC2086
191199
${spcCommand} download --with-php="${PHP_VERSION}" --for-extensions="${PHP_EXTENSIONS}" --for-libs="${PHP_EXTENSION_LIBS}" ${SPC_OPT_DOWNLOAD_ARGS}
192200
# shellcheck disable=SC2086
193201
${spcCommand} build --enable-zts --build-embed ${SPC_OPT_BUILD_ARGS} "${PHP_EXTENSIONS}" --with-libs="${PHP_EXTENSION_LIBS}"
194-
195-
echo -n "${cache_key}" >../cache_key
196202
fi
197203

198204
if ! type "go" >/dev/null 2>&1; then

0 commit comments

Comments
 (0)