Skip to content

Commit b970bf8

Browse files
authored
Fix gd build on PHP 8.5 (#1043)
1 parent 5491502 commit b970bf8

File tree

3 files changed

+107
-7
lines changed

3 files changed

+107
-7
lines changed

src/SPC/store/SourcePatcher.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,13 @@ public static function patchGDWin32(): bool
634634
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/gd/libgd/gdft.c', '#ifndef MSWIN32', '#ifndef _WIN32');
635635
}
636636
// custom config.w32, because official config.w32 is hard-coded many things
637-
$origin = $ver_id >= 80100 ? file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_81.w32') : file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_80.w32');
637+
if ($ver_id >= 80500) {
638+
$origin = file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_85.w32');
639+
} elseif ($ver_id >= 80100) {
640+
$origin = file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_81.w32');
641+
} else {
642+
$origin = file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_80.w32');
643+
}
638644
file_put_contents(SOURCE_PATH . '/php-src/ext/gd/config.w32.bak', file_get_contents(SOURCE_PATH . '/php-src/ext/gd/config.w32'));
639645
return file_put_contents(SOURCE_PATH . '/php-src/ext/gd/config.w32', $origin) !== false;
640646
}

src/globals/extra/gd_config_85.w32

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// vim:ft=javascript
2+
3+
ARG_WITH("gd", "Bundled GD support", "yes");
4+
5+
if (PHP_GD != "no") {
6+
// check for gd.h (required)
7+
if (!CHECK_HEADER_ADD_INCLUDE("gd.h", "CFLAGS_GD", PHP_GD + ";ext\\gd\\libgd")) {
8+
ERROR("gd not enabled; libraries and headers not found");
9+
}
10+
11+
// zlib ext support (required)
12+
if (!CHECK_LIB("zlib_a.lib;zlib.lib", "gd", PHP_GD)) {
13+
ERROR("gd not enabled; zlib not enabled");
14+
}
15+
16+
// libjpeg lib support
17+
if (CHECK_LIB("libjpeg_a.lib;libjpeg.lib", "gd", PHP_GD) &&
18+
CHECK_HEADER_ADD_INCLUDE("jpeglib.h", "CFLAGS_GD", PHP_GD + ";" + PHP_PHP_BUILD + "\\include")) {
19+
AC_DEFINE("HAVE_LIBJPEG", 1, "JPEG support");
20+
AC_DEFINE("HAVE_GD_JPG", 1, "JPEG support");
21+
}
22+
23+
// libpng16 lib support
24+
if (CHECK_LIB("libpng_a.lib;libpng.lib", "gd", PHP_GD) &&
25+
CHECK_HEADER_ADD_INCLUDE("png.h", "CFLAGS_GD", PHP_GD + ";" + PHP_PHP_BUILD + "\\include\\libpng16")) {
26+
AC_DEFINE("HAVE_LIBPNG", 1, "PNG support");
27+
AC_DEFINE("HAVE_GD_PNG", 1, "PNG support");
28+
}
29+
30+
// freetype lib support
31+
if (CHECK_LIB("libfreetype_a.lib;libfreetype.lib", "gd", PHP_GD) &&
32+
CHECK_HEADER_ADD_INCLUDE("ft2build.h", "CFLAGS_GD", PHP_GD + ";" + PHP_PHP_BUILD + "\\include\\freetype2;" + PHP_PHP_BUILD + "\\include\\freetype")) {
33+
AC_DEFINE("HAVE_LIBFREETYPE", 1, "FreeType support");
34+
AC_DEFINE("HAVE_GD_FREETYPE", 1, "FreeType support");
35+
}
36+
37+
// xpm lib support
38+
if (CHECK_LIB("libXpm_a.lib", "gd", PHP_GD) &&
39+
CHECK_HEADER_ADD_INCLUDE("xpm.h", "CFLAGS_GD", PHP_GD + ";" + PHP_PHP_BUILD + "\\include\\X11")) {
40+
AC_DEFINE("HAVE_LIBXPM", 1, "XPM support");
41+
AC_DEFINE("HAVE_GD_XPM", 1, "XPM support");
42+
}
43+
44+
// iconv lib support
45+
if ((CHECK_LIB("libiconv_a.lib;libiconv.lib", "gd", PHP_GD) || CHECK_LIB("iconv_a.lib;iconv.lib", "gd", PHP_GD)) &&
46+
CHECK_HEADER_ADD_INCLUDE("iconv.h", "CFLAGS_GD", PHP_GD)) {
47+
AC_DEFINE("HAVE_LIBICONV", 1, "Iconv support");
48+
}
49+
50+
// libwebp lib support
51+
if ((CHECK_LIB("libwebp_a.lib", "gd", PHP_GD) || CHECK_LIB("libwebp.lib", "gd", PHP_GD)) &&
52+
CHECK_LIB("libsharpyuv.lib", "gd", PHP_GD) &&
53+
CHECK_HEADER_ADD_INCLUDE("decode.h", "CFLAGS_GD", PHP_GD + ";" + PHP_PHP_BUILD + "\\include\\webp") &&
54+
CHECK_HEADER_ADD_INCLUDE("encode.h", "CFLAGS_GD", PHP_GD + ";" + PHP_PHP_BUILD + "\\include\\webp")) {
55+
AC_DEFINE("HAVE_LIBWEBP", 1, "WebP support");
56+
AC_DEFINE("HAVE_GD_WEBP", 1, "WebP support");
57+
}
58+
59+
// libavif lib support
60+
if (CHECK_LIB("avif_a.lib", "gd", PHP_GD) &&
61+
CHECK_LIB("aom_a.lib", "gd", PHP_GD) &&
62+
CHECK_HEADER_ADD_INCLUDE("avif.h", "CFLAGS_GD", PHP_GD + ";" + PHP_PHP_BUILD + "\\include\\avif")) {
63+
ADD_FLAG("CFLAGS_GD", "/D HAVE_LIBAVIF /D HAVE_GD_AVIF");
64+
} else if (CHECK_LIB("avif.lib", "gd", PHP_GD) &&
65+
CHECK_HEADER_ADD_INCLUDE("avif.h", "CFLAGS_GD", PHP_GD + ";" + PHP_PHP_BUILD + "\\include\\avif")) {
66+
ADD_FLAG("CFLAGS_GD", "/D HAVE_LIBAVIF /D HAVE_GD_AVIF");
67+
}
68+
69+
CHECK_LIB("User32.lib", "gd", PHP_GD);
70+
CHECK_LIB("Gdi32.lib", "gd", PHP_GD);
71+
72+
EXTENSION("gd", "gd.c", null, "-Iext/gd/libgd");
73+
ADD_SOURCES("ext/gd/libgd", "gd.c \
74+
gdcache.c gdfontg.c gdfontl.c gdfontmb.c gdfonts.c gdfontt.c \
75+
gdft.c gd_gd2.c gd_gd.c gd_gif_in.c gd_gif_out.c gdhelpers.c gd_io.c gd_io_dp.c \
76+
gd_io_file.c gd_io_ss.c gd_jpeg.c gdkanji.c gd_png.c gd_ss.c \
77+
gdtables.c gd_topal.c gd_wbmp.c gdxpm.c wbmp.c gd_xbm.c gd_security.c gd_transform.c \
78+
gd_filter.c gd_rotate.c gd_color_match.c gd_webp.c gd_avif.c \
79+
gd_crop.c gd_interpolation.c gd_matrix.c gd_bmp.c gd_tga.c", "gd");
80+
81+
AC_DEFINE('HAVE_LIBGD', 1, 'GD support');
82+
AC_DEFINE('HAVE_GD_BUNDLED', 1, "Bundled GD");
83+
AC_DEFINE('HAVE_GD_BMP', 1, "BMP support");
84+
AC_DEFINE('HAVE_GD_TGA', 1, "TGA support");
85+
ADD_FLAG("CFLAGS_GD", " \
86+
/D PHP_GD_EXPORTS=1 \
87+
/D HAVE_GD_GET_INTERPOLATION \
88+
");
89+
if (ICC_TOOLSET) {
90+
ADD_FLAG("LDFLAGS_GD", "/nodefaultlib:libcmt");
91+
}
92+
93+
PHP_INSTALL_HEADERS("", "ext/gd ext/gd/libgd");
94+
}

src/globals/test-extensions.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
// 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64
3232
// 'ubuntu-24.04-arm', // bin/spc for arm64
3333
// 'windows-2022', // .\bin\spc.ps1
34-
'windows-2025', // .\bin\spc.ps1
34+
'windows-2025',
3535
];
3636

3737
// whether enable thread safe
38-
$zts = false;
38+
$zts = true;
3939

4040
$no_strip = false;
4141

@@ -50,8 +50,8 @@
5050

5151
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
5252
$extensions = match (PHP_OS_FAMILY) {
53-
'Linux', 'Darwin' => 'pdo_odbc',
54-
'Windows' => 'zlib,phar,mbstring,mbregex,sockets',
53+
'Linux', 'Darwin' => 'pgsql',
54+
'Windows' => 'gd,zlib,mbstring,filter',
5555
};
5656

5757
// If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`).
@@ -74,7 +74,7 @@
7474
// You can use `common`, `bulk`, `minimal` or `none`.
7575
// note: combination is only available for *nix platform. Windows must use `none` combination
7676
$base_combination = match (PHP_OS_FAMILY) {
77-
'Linux', 'Darwin' => 'bulk',
77+
'Linux', 'Darwin' => 'minimal',
7878
'Windows' => 'none',
7979
};
8080

@@ -89,7 +89,7 @@ function _getCombination(string $type = 'common'): string
8989
'common' => 'bcmath,bz2,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,gd,gmp,iconv,xml,mbstring,mbregex,' .
9090
'mysqlnd,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,redis,session,simplexml,soap,sockets,' .
9191
'sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip',
92-
'bulk' => 'apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,event,exif,fileinfo,filter,ftp,gd,gmp,iconv,imagick,' .
92+
'bulk' => 'apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,event,exif,fileinfo,filter,ftp,gd,gmp,iconv,imagick,imap,' .
9393
'intl,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,' .
9494
'posix,protobuf,readline,redis,session,shmop,simplexml,soap,sockets,sodium,sqlite3,swoole,sysvmsg,sysvsem,' .
9595
'sysvshm,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib',

0 commit comments

Comments
 (0)