From c1662257fd2a1d15d1923779cdd817dc9f6c2b4c Mon Sep 17 00:00:00 2001 From: Andriy Kravchenko Date: Wed, 21 Oct 2026 12:49:17 -0700 Subject: [PATCH 1/5] Enable bundled GD with JPEG and FreeType configure options --- .github/workflows/continuous-integration.yml | 6 ++ .../BundledPhpExtensionsRepository.php | 22 ++++++- test/assets/check-bundled-gd.php | 63 +++++++++++++++++++ test/install-bundled-gd.php | 41 ++++++++++++ .../BundledPhpExtensionsRepositoryTest.php | 35 +++++++++++ 5 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 test/assets/check-bundled-gd.php create mode 100644 test/install-bundled-gd.php diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index b68467b9..b60d77e8 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -141,10 +141,12 @@ jobs: libexif-dev \ libgd-dev \ libpng-dev \ + libjpeg-dev \ libtiff-dev \ libfreetype-dev \ libfreetype6 \ libfontconfig1-dev \ + fonts-dejavu-core \ libgmp-dev \ libssl-dev \ libsodium-dev \ @@ -199,6 +201,10 @@ jobs: run: sudo php test/install-bundled-php-exts.php php-config env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Test bundled GD image formats and FreeType rendering + run: sudo php test/install-bundled-gd.php php-config /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} end-to-end-tests: runs-on: ubuntu-latest diff --git a/src/ComposerIntegration/BundledPhpExtensionsRepository.php b/src/ComposerIntegration/BundledPhpExtensionsRepository.php index f285b90a..72eb88a6 100644 --- a/src/ComposerIntegration/BundledPhpExtensionsRepository.php +++ b/src/ComposerIntegration/BundledPhpExtensionsRepository.php @@ -38,6 +38,7 @@ class BundledPhpExtensionsRepository extends ArrayRepository * os-families?: non-empty-list, * type?: ExtensionType, * priority?: int, + * configure-options?: list, * }> */ private static array $bundledPhpExtensions = [ @@ -69,7 +70,22 @@ class BundledPhpExtensionsRepository extends ArrayRepository 'lib-ffi' => '*', ], ], - // ['name' => 'gd'], // build failure - ext/gd/gd.c:79:11: fatal error: ft2build.h: No such file or directory + [ + 'name' => 'gd', + 'require' => ['php' => '>= 7.4.0'], + 'configure-options' => [ + [ + 'name' => 'with-jpeg', + 'description' => 'Enable JPEG support in bundled GD', + 'needs-value' => false, + ], + [ + 'name' => 'with-freetype', + 'description' => 'Enable FreeType support in bundled GD', + 'needs-value' => false, + ], + ], + ], ['name' => 'gettext'], ['name' => 'gmp'], ['name' => 'iconv'], @@ -259,6 +275,10 @@ static function (string $target, string $constraint) use ($extension, $versionPa $phpExt['priority'] = $extension['priority']; } + if (array_key_exists('configure-options', $extension)) { + $phpExt['configure-options'] = $extension['configure-options']; + } + $package->setPhpExt($phpExt); return $package; diff --git a/test/assets/check-bundled-gd.php b/test/assets/check-bundled-gd.php new file mode 100644 index 00000000..dac1f4fc --- /dev/null +++ b/test/assets/check-bundled-gd.php @@ -0,0 +1,63 @@ + true, 'JPEG Support' => $configured, 'FreeType Support' => $configured] as $feature => $expected) { + if ($info[$feature] !== $expected) { + throw new RuntimeException('Unexpected GD capability: ' . $feature); + } +} + +$image = imagecreatetruecolor(80, 40); +if ($image === false) { + throw new RuntimeException('Could not create an image'); +} + +$background = imagecolorallocate($image, 20, 40, 60); +imagefill($image, 0, 0, $background); + +foreach ($configured ? ['png', 'jpeg'] : ['png'] as $format) { + ob_start(); + $written = $format === 'png' ? imagepng($image) : imagejpeg($image); + $encoded = ob_get_clean(); + if (! $written || $encoded === false) { + throw new RuntimeException('Could not encode ' . $format); + } + + $decoded = imagecreatefromstring($encoded); + if ($decoded === false || imagesx($decoded) !== 80 || imagesy($decoded) !== 40) { + throw new RuntimeException('Could not round-trip ' . $format); + } + + if ($format === 'png' && imagecolorat($decoded, 0, 0) !== $background) { + throw new RuntimeException('PNG round-trip changed the pixel colour'); + } +} + +if ($configured) { + $font = $argv[2] ?? ''; + if (! is_file($font)) { + throw new RuntimeException('Missing TrueType test font: ' . $font); + } + + $foreground = imagecolorallocate($image, 255, 255, 255); + if (imagettftext($image, 16, 0, 5, 25, $foreground, $font, 'GD') === false) { + throw new RuntimeException('FreeType could not render text'); + } + + $rendered = false; + for ($x = 0; $x < 80; $x++) { + for ($y = 0; $y < 40; $y++) { + $rendered = $rendered || imagecolorat($image, $x, $y) !== $background; + } + } + + if (! $rendered) { + throw new RuntimeException('FreeType did not draw any pixels'); + } +} + +echo 'GD ' . ($configured ? 'JPEG/FreeType' : 'default') . ' checks passed.' . PHP_EOL; diff --git a/test/install-bundled-gd.php b/test/install-bundled-gd.php new file mode 100644 index 00000000..bda635ac --- /dev/null +++ b/test/install-bundled-gd.php @@ -0,0 +1,41 @@ + ' . PHP_EOL; + exit(1); +} + +$phpBinaryPath = PhpBinaryPath::fromPhpConfigExecutable($phpConfigPath); + +foreach (['default' => [], 'configured' => ['--with-jpeg', '--with-freetype']] as $variant => $options) { + echo Process::run([ + $phpBinaryPath->phpBinaryPath, + __DIR__ . '/../bin/pie', + 'install', + 'php/gd', + '--force', + '--no-interaction', + '--with-php-config=' . $phpBinaryPath->phpConfigPath(), + '-v', + '-j2', + ...$options, + ], timeout: null) . PHP_EOL; + + // Start a new PHP process so it loads the extension just installed by PIE. + echo Process::run([ + $phpBinaryPath->phpBinaryPath, + __DIR__ . '/assets/check-bundled-gd.php', + $variant, + $fontPath, + ]) . PHP_EOL; +} diff --git a/test/unit/ComposerIntegration/BundledPhpExtensionsRepositoryTest.php b/test/unit/ComposerIntegration/BundledPhpExtensionsRepositoryTest.php index e66b926f..6d62fef8 100644 --- a/test/unit/ComposerIntegration/BundledPhpExtensionsRepositoryTest.php +++ b/test/unit/ComposerIntegration/BundledPhpExtensionsRepositoryTest.php @@ -6,6 +6,7 @@ use Composer\Package\CompletePackageInterface; use Php\Pie\ComposerIntegration\BundledPhpExtensionsRepository; +use Php\Pie\ConfigureOption; use Php\Pie\DependencyResolver\Package; use Php\Pie\Downloading\DownloadedPackage; use Php\Pie\ExtensionName; @@ -22,6 +23,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Exception\ProcessFailedException; +use function array_map; use function Safe\mkdir; use function Safe\realpath; use function sys_get_temp_dir; @@ -46,6 +48,7 @@ public static function bundledRepositoryPackageNames(): array ['php/enchant'], ['php/exif'], ['php/ffi'], + ['php/gd'], ['php/gettext'], ['php/gmp'], ['php/iconv'], @@ -111,6 +114,38 @@ public function testBundledRepository(string $packageName): void self::assertSame('8.1.0', $package->getPrettyVersion()); } + public function testGdExposesOptionalJpegAndFreeTypeFlags(): void + { + $phpBinary = $this->createMock(PhpBinaryPath::class); + $phpBinary->method('version')->willReturn('8.1.0'); + + $repository = BundledPhpExtensionsRepository::forTargetPlatform( + new TargetPlatform( + OperatingSystem::NonWindows, + OperatingSystemFamily::Linux, + $phpBinary, + Architecture::x86_64, + ThreadSafetyMode::NonThreadSafe, + 1, + null, + null, + ), + ); + + $composerPackage = $repository->findPackage('php/gd', '8.1.0'); + self::assertInstanceOf(CompletePackageInterface::class, $composerPackage); + + $package = Package::fromComposerCompletePackage($composerPackage); + + self::assertSame( + [['with-jpeg', false], ['with-freetype', false]], + array_map( + static fn (ConfigureOption $option): array => [$option->name, $option->needsValue], + $package->configureOptions(), + ), + ); + } + public function testMakeCommandForXmlReader(): void { $phpPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('pie_test_bundled_', true); From 7a5c4c9db9cfd8aa43120d9d512ba3317885feca Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Tue, 10 Nov 2026 20:44:53 +0000 Subject: [PATCH 2/5] Remove separate GD testing script in favour of install-bundled-php-exts test --- .github/workflows/continuous-integration.yml | 5 -- test/assets/check-bundled-gd.php | 63 -------------------- test/install-bundled-gd.php | 41 ------------- 3 files changed, 109 deletions(-) delete mode 100644 test/assets/check-bundled-gd.php delete mode 100644 test/install-bundled-gd.php diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index b60d77e8..76f3ee0c 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -146,7 +146,6 @@ jobs: libfreetype-dev \ libfreetype6 \ libfontconfig1-dev \ - fonts-dejavu-core \ libgmp-dev \ libssl-dev \ libsodium-dev \ @@ -201,10 +200,6 @@ jobs: run: sudo php test/install-bundled-php-exts.php php-config env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Test bundled GD image formats and FreeType rendering - run: sudo php test/install-bundled-gd.php php-config /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} end-to-end-tests: runs-on: ubuntu-latest diff --git a/test/assets/check-bundled-gd.php b/test/assets/check-bundled-gd.php deleted file mode 100644 index dac1f4fc..00000000 --- a/test/assets/check-bundled-gd.php +++ /dev/null @@ -1,63 +0,0 @@ - true, 'JPEG Support' => $configured, 'FreeType Support' => $configured] as $feature => $expected) { - if ($info[$feature] !== $expected) { - throw new RuntimeException('Unexpected GD capability: ' . $feature); - } -} - -$image = imagecreatetruecolor(80, 40); -if ($image === false) { - throw new RuntimeException('Could not create an image'); -} - -$background = imagecolorallocate($image, 20, 40, 60); -imagefill($image, 0, 0, $background); - -foreach ($configured ? ['png', 'jpeg'] : ['png'] as $format) { - ob_start(); - $written = $format === 'png' ? imagepng($image) : imagejpeg($image); - $encoded = ob_get_clean(); - if (! $written || $encoded === false) { - throw new RuntimeException('Could not encode ' . $format); - } - - $decoded = imagecreatefromstring($encoded); - if ($decoded === false || imagesx($decoded) !== 80 || imagesy($decoded) !== 40) { - throw new RuntimeException('Could not round-trip ' . $format); - } - - if ($format === 'png' && imagecolorat($decoded, 0, 0) !== $background) { - throw new RuntimeException('PNG round-trip changed the pixel colour'); - } -} - -if ($configured) { - $font = $argv[2] ?? ''; - if (! is_file($font)) { - throw new RuntimeException('Missing TrueType test font: ' . $font); - } - - $foreground = imagecolorallocate($image, 255, 255, 255); - if (imagettftext($image, 16, 0, 5, 25, $foreground, $font, 'GD') === false) { - throw new RuntimeException('FreeType could not render text'); - } - - $rendered = false; - for ($x = 0; $x < 80; $x++) { - for ($y = 0; $y < 40; $y++) { - $rendered = $rendered || imagecolorat($image, $x, $y) !== $background; - } - } - - if (! $rendered) { - throw new RuntimeException('FreeType did not draw any pixels'); - } -} - -echo 'GD ' . ($configured ? 'JPEG/FreeType' : 'default') . ' checks passed.' . PHP_EOL; diff --git a/test/install-bundled-gd.php b/test/install-bundled-gd.php deleted file mode 100644 index bda635ac..00000000 --- a/test/install-bundled-gd.php +++ /dev/null @@ -1,41 +0,0 @@ - ' . PHP_EOL; - exit(1); -} - -$phpBinaryPath = PhpBinaryPath::fromPhpConfigExecutable($phpConfigPath); - -foreach (['default' => [], 'configured' => ['--with-jpeg', '--with-freetype']] as $variant => $options) { - echo Process::run([ - $phpBinaryPath->phpBinaryPath, - __DIR__ . '/../bin/pie', - 'install', - 'php/gd', - '--force', - '--no-interaction', - '--with-php-config=' . $phpBinaryPath->phpConfigPath(), - '-v', - '-j2', - ...$options, - ], timeout: null) . PHP_EOL; - - // Start a new PHP process so it loads the extension just installed by PIE. - echo Process::run([ - $phpBinaryPath->phpBinaryPath, - __DIR__ . '/assets/check-bundled-gd.php', - $variant, - $fontPath, - ]) . PHP_EOL; -} From 8b889ba4d94a4f53e803235e66d2b6010f60cf5f Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Tue, 10 Nov 2026 21:15:44 +0000 Subject: [PATCH 3/5] Detect GD flags from php_config.h --- src/Building/UnixBuild.php | 5 ++ .../BundledPhpExtensionsRepository.php | 55 ++++++++++++++++ src/Platform/TargetPhp/PhpBinaryPath.php | 17 +++++ test/end-to-end/Dockerfile | 4 ++ .../BundledPhpExtensionsRepositoryTest.php | 62 +++++++++++++++++++ .../Platform/TargetPhp/PhpBinaryPathTest.php | 41 ++++++++++++ 6 files changed, 184 insertions(+) diff --git a/src/Building/UnixBuild.php b/src/Building/UnixBuild.php index 1d19371f..32620247 100644 --- a/src/Building/UnixBuild.php +++ b/src/Building/UnixBuild.php @@ -100,6 +100,11 @@ private function buildFromSource( $io->write('phpize complete.'); $configureOptions = $this->withDetectedLibdirOption($configureOptions, $targetPlatform); + $configureOptions = BundledPhpExtensionsRepository::augmentConfigureOptionsForPhpBundledExtensions( + $configureOptions, + $downloadedPackage, + $targetPlatform, + ); $phpConfigPath = $targetPlatform->phpBinaryPath->phpConfigPath(); if ($phpConfigPath !== null) { diff --git a/src/ComposerIntegration/BundledPhpExtensionsRepository.php b/src/ComposerIntegration/BundledPhpExtensionsRepository.php index 72eb88a6..6ce57804 100644 --- a/src/ComposerIntegration/BundledPhpExtensionsRepository.php +++ b/src/ComposerIntegration/BundledPhpExtensionsRepository.php @@ -25,8 +25,10 @@ use function count; use function implode; use function in_array; +use function Safe\preg_match; use function Safe\realpath; use function sprintf; +use function str_starts_with; /** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */ class BundledPhpExtensionsRepository extends ArrayRepository @@ -296,6 +298,59 @@ private static function findRe2c(): string } } + /** + * @param list $configureOptions + * + * @return list + */ + public static function augmentConfigureOptionsForPhpBundledExtensions( + array $configureOptions, + DownloadedPackage $downloadedPackage, + TargetPlatform $targetPlatform, + ): array { + if ($downloadedPackage->package->name() !== 'php/gd') { + return $configureOptions; + } + + $phpConfigHeader = $targetPlatform->phpBinaryPath->phpConfigHeader(); + if ($phpConfigHeader === null) { + return $configureOptions; + } + + $gdFeatureDefinesToConfigureOptions = [ + 'HAVE_GD_FREETYPE' => '--with-freetype', + 'HAVE_GD_JPG' => '--with-jpeg', + 'HAVE_GD_XPM' => '--with-xpm', + 'HAVE_GD_WEBP' => '--with-webp', + 'HAVE_GD_AVIF' => '--with-avif', + ]; + + foreach ($gdFeatureDefinesToConfigureOptions as $define => $configureOption) { + if ( + ! preg_match('/^#define ' . $define . ' 1$/m', $phpConfigHeader) + || self::hasConfigureOption($configureOptions, $configureOption) + ) { + continue; + } + + $configureOptions[] = $configureOption; + } + + return $configureOptions; + } + + /** @param list $configureOptions */ + private static function hasConfigureOption(array $configureOptions, string $configureOption): bool + { + foreach ($configureOptions as $existingConfigureOption) { + if ($existingConfigureOption === $configureOption || str_starts_with($existingConfigureOption, $configureOption . '=')) { + return true; + } + } + + return false; + } + /** * @param list $makeCommand * diff --git a/src/Platform/TargetPhp/PhpBinaryPath.php b/src/Platform/TargetPhp/PhpBinaryPath.php index 644ade68..f2e6273f 100644 --- a/src/Platform/TargetPhp/PhpBinaryPath.php +++ b/src/Platform/TargetPhp/PhpBinaryPath.php @@ -36,6 +36,7 @@ use function is_executable; use function ltrim; use function rtrim; +use function Safe\file_get_contents; use function Safe\mkdir; use function Safe\preg_match; use function Safe\preg_replace; @@ -213,6 +214,22 @@ public function phpConfigLibdir(): string|null return self::libdirFromConfigureOptions($configureOptions); } + public function phpConfigHeader(): string|null + { + if ($this->phpConfigPath === null) { + return null; + } + + $includeDir = self::cleanWarningAndDeprecationsFromOutput(Process::run([$this->phpConfigPath, '--include-dir'])); + + $phpConfigHeaderPath = $includeDir . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'php_config.h'; + if ($includeDir === '' || ! file_exists($phpConfigHeaderPath)) { + return null; + } + + return file_get_contents($phpConfigHeaderPath); + } + /** @return non-empty-string|null */ private static function libdirFromConfigureOptions(string $configureOptions): string|null { diff --git a/test/end-to-end/Dockerfile b/test/end-to-end/Dockerfile index ad8c1b0e..4290cd25 100644 --- a/test/end-to-end/Dockerfile +++ b/test/end-to-end/Dockerfile @@ -58,6 +58,10 @@ FROM homebrew_base_with_pie AS test_pie_installs_extension_using_pcre_with_brew RUN pie install --auto-install-build-tools -v apcu/apcu RUN php -m | grep -i apcu +FROM homebrew_base_with_pie AS test_pie_installs_bundled_gd_against_php_with_gd_features_with_brew +RUN grep -x '#define HAVE_GD_FREETYPE 1' "$(php-config --include-dir)/main/php_config.h" +RUN pie install --auto-install-build-tools --force -v php/gd + FROM ubuntu_base AS test_pie_installs_system_deps_on_ubuntu RUN apt-get update && apt install -y unzip curl wget gcc make autoconf libtool bison re2c pkg-config libzip-dev libssl-dev libonig-dev RUN mkdir -p /opt/php \ diff --git a/test/unit/ComposerIntegration/BundledPhpExtensionsRepositoryTest.php b/test/unit/ComposerIntegration/BundledPhpExtensionsRepositoryTest.php index 6d62fef8..22257baa 100644 --- a/test/unit/ComposerIntegration/BundledPhpExtensionsRepositoryTest.php +++ b/test/unit/ComposerIntegration/BundledPhpExtensionsRepositoryTest.php @@ -26,6 +26,7 @@ use function array_map; use function Safe\mkdir; use function Safe\realpath; +use function substr; use function sys_get_temp_dir; use function uniqid; @@ -198,6 +199,67 @@ public function testMakeCommandForDom(): void ); } + /** @return array, list}> */ + public static function configureOptionsForPhpConfigHeader(): array + { + $allGdFeatures = "#define HAVE_GD_AVIF 1\n#define HAVE_GD_FREETYPE 1\n#define HAVE_GD_JPG 1\n#define HAVE_GD_PNG 1\n#define HAVE_GD_WEBP 1\n#define HAVE_GD_XPM 1\n"; + + return [ + 'gd with all features' => ['php/gd', $allGdFeatures, [], ['--with-freetype', '--with-jpeg', '--with-xpm', '--with-webp', '--with-avif']], + 'gd with only freetype' => ['php/gd', "#define HAVE_GD_FREETYPE 1\n", [], ['--with-freetype']], + 'gd with undefined freetype' => ['php/gd', "/* #undef HAVE_GD_FREETYPE */\n", [], []], + 'gd keeps existing options first' => ['php/gd', "#define HAVE_GD_FREETYPE 1\n", ['--with-libdir=lib64'], ['--with-libdir=lib64', '--with-freetype']], + 'gd does not duplicate user flag' => ['php/gd', "#define HAVE_GD_FREETYPE 1\n#define HAVE_GD_JPG 1\n", ['--with-freetype'], ['--with-freetype', '--with-jpeg']], + 'gd does not override user flag value' => ['php/gd', "#define HAVE_GD_JPG 1\n", ['--with-jpeg=/opt/jpeg'], ['--with-jpeg=/opt/jpeg']], + 'gd without php_config.h' => ['php/gd', null, [], []], + 'other bundled extension' => ['php/exif', $allGdFeatures, [], []], + ]; + } + + /** + * @param non-empty-string $packageName + * @param list $configureOptions + * @param list $expectedConfigureOptions + */ + #[DataProvider('configureOptionsForPhpConfigHeader')] + public function testConfigureOptionsAreDetectedFromPhpConfigHeader( + string $packageName, + string|null $phpConfigHeader, + array $configureOptions, + array $expectedConfigureOptions, + ): void { + $phpBinary = $this->createMock(PhpBinaryPath::class); + $phpBinary->method('phpConfigHeader')->willReturn($phpConfigHeader); + + self::assertSame( + $expectedConfigureOptions, + BundledPhpExtensionsRepository::augmentConfigureOptionsForPhpBundledExtensions( + $configureOptions, + DownloadedPackage::fromPackageAndExtractedPath( + new Package( + $this->createMock(CompletePackageInterface::class), + ExtensionType::PhpModule, + ExtensionName::normaliseFromString(substr($packageName, 4)), + $packageName, + '1.2.3', + null, + ), + '/path/to/ext', + ), + new TargetPlatform( + OperatingSystem::NonWindows, + OperatingSystemFamily::Linux, + $phpBinary, + Architecture::x86_64, + ThreadSafetyMode::NonThreadSafe, + 1, + null, + null, + ), + ), + ); + } + /** @return list */ public static function dependantsOnRe2c(): array { diff --git a/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php b/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php index 8b7fcbc2..999de270 100644 --- a/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php +++ b/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php @@ -155,6 +155,47 @@ public function testPhpConfigLibdirFromConfigureOptions(string $configureOptions unlink($tmpSh); } + public function testPhpConfigHeaderIsReadFromPhpConfigIncludeDir(): void + { + if (Platform::isWindows()) { + self::markTestSkipped('Bash script does not run on Windows.'); + } + + $includeDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('pie_php_config_header_test', true); + mkdir($includeDir . DIRECTORY_SEPARATOR . 'main', recursive: true); + file_put_contents($includeDir . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'php_config.h', "#define HAVE_GD_FREETYPE 1\n"); + + $tmpSh = tempnam(sys_get_temp_dir(), uniqid('pie_php_config_header_test')); + file_put_contents($tmpSh, "#!/usr/bin/env bash\necho \"" . $includeDir . "\";\n"); + chmod($tmpSh, 0777); + + $phpBinary = $this->createPartialMock(PhpBinaryPath::class, []); + (new ReflectionMethod($phpBinary, '__construct'))->invoke($phpBinary, $tmpSh, $tmpSh, PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION, PHP_VERSION); + + self::assertSame("#define HAVE_GD_FREETYPE 1\n", $phpBinary->phpConfigHeader()); + unlink($tmpSh); + } + + public function testPhpConfigHeaderIsNullWhenHeaderDoesNotExist(): void + { + if (Platform::isWindows()) { + self::markTestSkipped('Bash script does not run on Windows.'); + } + + $includeDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('pie_php_config_header_test', true); + mkdir($includeDir, recursive: true); + + $tmpSh = tempnam(sys_get_temp_dir(), uniqid('pie_php_config_header_test')); + file_put_contents($tmpSh, "#!/usr/bin/env bash\necho \"" . $includeDir . "\";\n"); + chmod($tmpSh, 0777); + + $phpBinary = $this->createPartialMock(PhpBinaryPath::class, []); + (new ReflectionMethod($phpBinary, '__construct'))->invoke($phpBinary, $tmpSh, $tmpSh, PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION, PHP_VERSION); + + self::assertNull($phpBinary->phpConfigHeader()); + unlink($tmpSh); + } + public function testVersionDetailsAreReadCorrectlyWhenSurroundedByWarningsAndDeprecations(): void { if (Platform::isWindows()) { From 958a05ad5bf7e85faf56eeb3a16539af9f1a15f9 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Tue, 10 Nov 2026 21:51:19 +0000 Subject: [PATCH 4/5] Add e2e test for auto php_config.h with HAVE_GD_FREETYPE to validate both configure option autodetection and runtime validation --- test/end-to-end/Dockerfile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/end-to-end/Dockerfile b/test/end-to-end/Dockerfile index 4290cd25..ea3df962 100644 --- a/test/end-to-end/Dockerfile +++ b/test/end-to-end/Dockerfile @@ -84,6 +84,14 @@ RUN apk add php php-phar php-mbstring php-iconv php-openssl bzip2-dev libbz2 bui COPY --from=build_pie_phar /app/pie.phar /usr/local/bin/pie RUN pie install -v --auto-install-system-dependencies --force php/sodium +FROM alpine_base AS test_pie_installs_bundled_gd_against_php_with_gd_features_on_alpine +RUN apk add php php-phar php-mbstring php-iconv php-openssl build-base autoconf libtool pkgconf php85-dev \ + freetype-dev libjpeg-turbo-dev libpng-dev libwebp-dev libavif-dev libxpm-dev +RUN grep -x '#define HAVE_GD_FREETYPE 1' "$(php-config --include-dir)/main/php_config.h" +COPY --from=build_pie_phar /app/pie.phar /usr/local/bin/pie +RUN pie install -v --force php/gd +RUN LD_BIND_NOW=1 php -m | grep -x gd + FROM fedora_base AS test_pie_installs_system_deps_on_fedora RUN dnf install -y php php-pecl-zip unzip gcc make autoconf bison re2c libtool php-devel COPY --from=build_pie_phar /app/pie.phar /usr/local/bin/pie From 50259d007b314c7010073b9197f6a783612922ad Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Tue, 10 Nov 2026 22:13:38 +0000 Subject: [PATCH 5/5] Add other GD configure options so they can be user supplied --- .../BundledPhpExtensionsRepository.php | 15 +++++++++++++++ .../BundledPhpExtensionsRepositoryTest.php | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ComposerIntegration/BundledPhpExtensionsRepository.php b/src/ComposerIntegration/BundledPhpExtensionsRepository.php index 6ce57804..0e3b3d2f 100644 --- a/src/ComposerIntegration/BundledPhpExtensionsRepository.php +++ b/src/ComposerIntegration/BundledPhpExtensionsRepository.php @@ -86,6 +86,21 @@ class BundledPhpExtensionsRepository extends ArrayRepository 'description' => 'Enable FreeType support in bundled GD', 'needs-value' => false, ], + [ + 'name' => 'with-xpm', + 'description' => 'Enable XPM support in bundled GD', + 'needs-value' => false, + ], + [ + 'name' => 'with-webp', + 'description' => 'Enable WebP support in bundled GD', + 'needs-value' => false, + ], + [ + 'name' => 'with-avif', + 'description' => 'Enable AVIF support in bundled GD', + 'needs-value' => false, + ], ], ], ['name' => 'gettext'], diff --git a/test/unit/ComposerIntegration/BundledPhpExtensionsRepositoryTest.php b/test/unit/ComposerIntegration/BundledPhpExtensionsRepositoryTest.php index 22257baa..b38d7472 100644 --- a/test/unit/ComposerIntegration/BundledPhpExtensionsRepositoryTest.php +++ b/test/unit/ComposerIntegration/BundledPhpExtensionsRepositoryTest.php @@ -115,7 +115,7 @@ public function testBundledRepository(string $packageName): void self::assertSame('8.1.0', $package->getPrettyVersion()); } - public function testGdExposesOptionalJpegAndFreeTypeFlags(): void + public function testGdExposesOptionalFeatureFlags(): void { $phpBinary = $this->createMock(PhpBinaryPath::class); $phpBinary->method('version')->willReturn('8.1.0'); @@ -139,7 +139,7 @@ public function testGdExposesOptionalJpegAndFreeTypeFlags(): void $package = Package::fromComposerCompletePackage($composerPackage); self::assertSame( - [['with-jpeg', false], ['with-freetype', false]], + [['with-jpeg', false], ['with-freetype', false], ['with-xpm', false], ['with-webp', false], ['with-avif', false]], array_map( static fn (ConfigureOption $option): array => [$option->name, $option->needsValue], $package->configureOptions(),