Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ configuration path cannot exist and it has no scan directory, so no system
at install time. The informational build strings in
`include/php/main/build-defs.h` and `include/php/gmp.h` carry the same
placeholder. `include/php/` also carries the library headers the PHP
headers include: `gmp.h`, `sodium.h` with `sodium/`, and, from PHP 8.5, the
lexbor URL headers under `lexbor/`, so an extension can build against
`ext/gmp`, `ext/sodium`, or the `ext/uri` WHATWG parser with `phpize` alone.
headers include: `gmp.h`, `sodium.h` with `sodium/`, simdjson's `simdjson.h`
beside the `ext/simdjson` bindings header, and, from PHP 8.5, the lexbor URL
headers under `lexbor/`, so an extension can build against `ext/gmp`,
`ext/sodium`, `ext/simdjson`, or the `ext/uri` WHATWG parser with `phpize`
alone.

Releases published before shared extensions contain only `bin/php`, `LICENSE`,
and `NOTICE`, with every module compiled in.
Expand Down
31 changes: 21 additions & 10 deletions scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ cp -R "$BUILDROOT/lib/php/build" "$PACKAGE/lib/php/build"
install -m 0644 "$PROJECT_ROOT/LICENSE" "$PACKAGE/LICENSE"
install -m 0644 "$PROJECT_ROOT/NOTICE" "$PACKAGE/NOTICE"

# Library headers the installed PHP headers include are staged under include/php,
# which php-config --includes names.
KIT_INCLUDE="$PACKAGE/include/php"

# Stage one library header and every header of that library it reaches through
# "<prefix>..." includes, keeping the library's own layout under include/php.
stage_header_closure() {
Expand All @@ -73,24 +77,24 @@ stage_header_closure() {
while ((${#queue[@]})); do
header="${queue[0]}"
queue=("${queue[@]:1}")
[[ -f "$PACKAGE/include/php/$header" ]] && continue
[[ -f "$KIT_INCLUDE/$header" ]] && continue
require_file "$source_root/$header"
mkdir -p "$(dirname "$PACKAGE/include/php/$header")"
install -m 0644 "$source_root/$header" "$PACKAGE/include/php/$header"
mkdir -p "$(dirname "$KIT_INCLUDE/$header")"
install -m 0644 "$source_root/$header" "$KIT_INCLUDE/$header"
while IFS= read -r included; do
queue+=("$included")
done < <(sed -nE "s|^[[:space:]]*#[[:space:]]*include[[:space:]]*[\"<](${prefix}[^\">]+)[\">].*|\\1|p" \
"$source_root/$header")
done
}

# The installed PHP headers include three libraries the binary links statically but
# the build kit does not carry: ext/gmp includes <gmp.h>, ext/sodium includes
# <sodium.h>, and ext/uri's WHATWG parser includes lexbor's URL headers, which
# php-src compiles in but does not install. Each is staged under include/php,
# which php-config --includes names, in the library's own layout, so an extension
# that includes those PHP headers builds against the libraries this binary links.
KIT_INCLUDE="$PACKAGE/include/php"
# The installed PHP headers include four libraries the binary links but the build
# kit does not carry: ext/gmp includes <gmp.h>, ext/sodium includes <sodium.h>,
# ext/uri's WHATWG parser includes lexbor's URL headers, which php-src compiles in
# but does not install, and ext/simdjson's bindings header includes "simdjson.h",
# the library header the extension compiles but does not install. Each is staged
# in the library's own layout, so an extension that includes those PHP headers
# builds against the libraries this release was built with.
if [[ -f "$KIT_INCLUDE/ext/gmp/php_gmp_int.h" ]]; then
require_file "$BUILDROOT/include/gmp.h"
install -m 0644 "$BUILDROOT/include/gmp.h" "$KIT_INCLUDE/gmp.h"
Expand Down Expand Up @@ -120,6 +124,13 @@ fi
if [[ -f "$KIT_INCLUDE/ext/uri/uri_parser_whatwg.h" ]]; then
stage_header_closure "$BUILD_DIR/source/php-src/ext/lexbor" "lexbor/" lexbor/url/url.h
fi
if [[ -f "$KIT_INCLUDE/ext/simdjson/src/simdjson_bindings_defs.h" ]]; then
# The bindings header includes "simdjson.h" from its own folder, so the
# amalgamated library header is staged beside it.
require_file "$BUILD_DIR/source/php-src/ext/simdjson/src/simdjson.h"
install -m 0644 "$BUILD_DIR/source/php-src/ext/simdjson/src/simdjson.h" \
"$KIT_INCLUDE/ext/simdjson/src/simdjson.h"
fi

# Ship exactly the listed shared extensions: a missing or unlisted .so means
# the build and the list the gate verified have drifted apart.
Expand Down
15 changes: 14 additions & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ printf 'dnl fixture\n' > "$FIXTURE_ROOT/lib/php/build/phpize.m4"
# PHP headers that include library headers the kit must carry, the libraries'
# installed headers, and lexbor's source tree, of which only the URL closure ships.
mkdir -p "$FIXTURE_ROOT/include/php/ext/gmp" "$FIXTURE_ROOT/include/php/ext/sodium" \
"$FIXTURE_ROOT/include/php/ext/uri" "$FIXTURE_ROOT/include/sodium"
"$FIXTURE_ROOT/include/php/ext/uri" "$FIXTURE_ROOT/include/php/ext/simdjson/src" \
"$FIXTURE_ROOT/include/sodium"
printf '#include <gmp.h>\n' > "$FIXTURE_ROOT/include/php/ext/gmp/php_gmp_int.h"
printf '#include <sodium.h>\n' > "$FIXTURE_ROOT/include/php/ext/sodium/php_libsodium.h"
printf '#include "lexbor/url/url.h"\n' > "$FIXTURE_ROOT/include/php/ext/uri/uri_parser_whatwg.h"
printf '#include "simdjson.h"\n' > "$FIXTURE_ROOT/include/php/ext/simdjson/src/simdjson_bindings_defs.h"
printf '#include <stddef.h>\n#define __GMP_CFLAGS "-I%s/include"\n' "$FIXTURE_ROOT" > "$FIXTURE_ROOT/include/gmp.h"
printf '#include "sodium/core.h"\n' > "$FIXTURE_ROOT/include/sodium.h"
printf '#include "export.h"\n' > "$FIXTURE_ROOT/include/sodium/core.h"
Expand All @@ -81,6 +83,9 @@ printf '#include "lexbor/core/base.h"\n#include <lexbor/url/base.h>\n' > "$FIXTU
printf '#include "lexbor/core/base.h"\n' > "$FIXTURE_LEXBOR/url/base.h"
printf '#include <string.h>\n' > "$FIXTURE_LEXBOR/core/base.h"
printf '#include "lexbor/core/base.h"\n' > "$FIXTURE_LEXBOR/html/parser.h"
FIXTURE_SIMDJSON="$FIXTURE_BUILD/source/php-src/ext/simdjson/src"
mkdir -p "$FIXTURE_SIMDJSON"
printf '#define SIMDJSON_H\n' > "$FIXTURE_SIMDJSON/simdjson.h"
printf 'fixture\n' > "$FIXTURE_ROOT/modules/demo_on.so"
printf 'fixture\n' > "$FIXTURE_ROOT/modules/demo_off.so"
printf 'demo_on on\ndemo_off off zend requires=demo_on\n' > "$FIXTURE_BUILD/shared-extensions.txt"
Expand All @@ -96,6 +101,7 @@ for member in \
./include/php/sodium/core.h ./include/php/sodium/export.h \
./include/php/lexbor/url/url.h ./include/php/lexbor/url/base.h \
./include/php/lexbor/core/base.h \
./include/php/ext/simdjson/src/simdjson.h \
./lib/php/build/phpize.m4 \
./lib/php/extensions/demo_off.so ./lib/php/extensions/demo_on.so \
./share/php-bin/manifest.json ./LICENSE ./NOTICE
Expand Down Expand Up @@ -172,6 +178,13 @@ if "$SCRIPT_DIR/package.sh" "$FIXTURE_ROOT/bin/php" 8.4.99 2> "$SCRATCH_DIR/miss
fi
grep -Fq 'lexbor/core/base.h' "$SCRATCH_DIR/missing-header.log"
mv "$SCRATCH_DIR/base.h" "$FIXTURE_LEXBOR/core/base.h"
mv "$FIXTURE_SIMDJSON/simdjson.h" "$SCRATCH_DIR/simdjson.h"
if "$SCRIPT_DIR/package.sh" "$FIXTURE_ROOT/bin/php" 8.4.99 2> "$SCRATCH_DIR/missing-simdjson.log"; then
echo "Expected packaging to reject a missing simdjson header." >&2
exit 1
fi
grep -Fq "Required file not found: $FIXTURE_SIMDJSON/simdjson.h" "$SCRATCH_DIR/missing-simdjson.log"
mv "$SCRATCH_DIR/simdjson.h" "$FIXTURE_SIMDJSON/simdjson.h"

# A library header that cannot be copied stops packaging too.
mkdir -p "$SCRATCH_DIR/failing-install"
Expand Down
Loading