Skip to content

Commit d0a6e3a

Browse files
authored
update pgsql version to 18.0, php 8.5 to RC2 (#916)
2 parents 6d6a293 + 995187d commit d0a6e3a

File tree

6 files changed

+90
-96
lines changed

6 files changed

+90
-96
lines changed

config/source.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@
880880
"postgresql": {
881881
"type": "ghtagtar",
882882
"repo": "postgres/postgres",
883-
"match": "REL_16_\\d+",
883+
"match": "REL_18_\\d+",
884884
"license": {
885885
"type": "file",
886886
"path": "COPYRIGHT"

src/SPC/ConsoleApplication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
final class ConsoleApplication extends Application
3636
{
37-
public const string VERSION = '2.7.4';
37+
public const string VERSION = '2.7.5';
3838

3939
public function __construct()
4040
{

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,14 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
156156
}
157157
$shared_extensions = array_map('trim', array_filter(explode(',', $this->getOption('build-shared'))));
158158
if (!empty($shared_extensions)) {
159-
logger()->info('Building shared extensions ...');
159+
if (SPCTarget::isStatic()) {
160+
throw new WrongUsageException(
161+
"You're building against musl libc statically (the default on Linux), but you're trying to build shared extensions.\n" .
162+
'Static musl libc does not implement `dlopen`, so your php binary is not able to load shared extensions.' . "\n" .
163+
'Either use SPC_LIBC=glibc to link against glibc on a glibc OS, or use SPC_TARGET="native-native-musl -dynamic" to link against musl libc dynamically using `zig cc`.'
164+
);
165+
}
166+
logger()->info('Building shared extensions...');
160167
$this->buildSharedExts();
161168
}
162169
}

src/SPC/builder/unix/library/postgresql.php

Lines changed: 75 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -4,93 +4,83 @@
44

55
namespace SPC\builder\unix\library;
66

7-
use SPC\builder\linux\library\LinuxLibraryBase;
8-
use SPC\exception\BuildFailureException;
9-
use SPC\exception\FileSystemException;
107
use SPC\store\FileSystem;
8+
use SPC\util\PkgConfigUtil;
9+
use SPC\util\SPCConfigUtil;
1110
use SPC\util\SPCTarget;
1211

1312
trait postgresql
1413
{
15-
protected function build(): void
14+
public function patchBeforeBuild(): bool
1615
{
17-
$builddir = BUILD_ROOT_PATH;
18-
$envs = '';
19-
$packages = 'zlib openssl readline libxml-2.0';
20-
$optional_packages = [
21-
'zstd' => 'libzstd',
22-
'ldap' => 'ldap',
23-
'libxslt' => 'libxslt',
24-
'icu' => 'icu-i18n',
25-
];
26-
$error_exec_cnt = 0;
27-
28-
foreach ($optional_packages as $lib => $pkg) {
29-
if ($this->getBuilder()->getLib($lib)) {
30-
$packages .= ' ' . $pkg;
31-
$output = shell()->execWithResult("pkg-config --static {$pkg}");
32-
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
33-
logger()->info(var_export($output[1], true));
34-
}
16+
if (SPCTarget::getLibcVersion() === '2.17' && GNU_ARCH === 'aarch64') {
17+
FileSystem::replaceFileStr(
18+
$this->source_dir . '/src/port/pg_popcount_aarch64.c',
19+
'HWCAP_SVE',
20+
'0',
21+
);
22+
FileSystem::replaceFileStr(
23+
$this->source_dir . '/src/port/pg_crc32c_armv8_choose.c',
24+
'#if defined(__linux__) && !defined(__aarch64__) && !defined(HWCAP2_CRC32)',
25+
'#if defined(__linux__) && !defined(HWCAP_CRC32)',
26+
);
3527
}
28+
// skip the test on platforms where libpq infrastructure may be provided by statically-linked libraries
29+
FileSystem::replaceFileStr("{$this->source_dir}/src/interfaces/libpq/Makefile", 'invokes exit\'; exit 1;', 'invokes exit\';');
30+
// disable shared libs build
31+
FileSystem::replaceFileStr(
32+
"{$this->source_dir}/src/Makefile.shlib",
33+
[
34+
'$(LINK.shared) -o $@ $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK)',
35+
'$(INSTALL_SHLIB) $< \'$(DESTDIR)$(pkglibdir)/$(shlib)\'',
36+
'$(INSTALL_SHLIB) $< \'$(DESTDIR)$(libdir)/$(shlib)\'',
37+
'$(INSTALL_SHLIB) $< \'$(DESTDIR)$(bindir)/$(shlib)\'',
38+
],
39+
''
40+
);
41+
return true;
42+
}
43+
44+
protected function build(): void
45+
{
46+
$libs = array_map(fn ($x) => $x->getName(), $this->getDependencies());
47+
$spc = new SPCConfigUtil($this->getBuilder(), ['no_php' => true, 'libs_only_deps' => true]);
48+
$config = $spc->config(libraries: $libs, include_suggest_lib: $this->builder->getOption('with-suggested-libs'));
3649

37-
$output = shell()->execWithResult("pkg-config --cflags-only-I --static {$packages}");
38-
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
3950
$macos_15_bug_cflags = PHP_OS_FAMILY === 'Darwin' ? ' -Wno-unguarded-availability-new' : '';
40-
$cflags = '';
41-
if (!empty($output[1][0])) {
42-
$cflags = $output[1][0];
43-
$envs .= ' CPPFLAGS="-DPIC"';
44-
$cflags = "{$cflags} -fno-ident{$macos_15_bug_cflags}";
45-
}
46-
$output = shell()->execWithResult("pkg-config --libs-only-L --static {$packages}");
47-
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
48-
if (!empty($output[1][0])) {
49-
$ldflags = $output[1][0];
50-
$envs .= SPCTarget::isStatic() ? " LDFLAGS=\"{$ldflags} -static\" " : " LDFLAGS=\"{$ldflags}\" ";
51-
}
52-
$output = shell()->execWithResult("pkg-config --libs-only-l --static {$packages}");
53-
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
54-
if (!empty($output[1][0])) {
55-
$libs = $output[1][0];
56-
$libcpp = '';
57-
if ($this->builder->getLib('icu')) {
58-
$libcpp = $this instanceof LinuxLibraryBase ? ' -lstdc++' : ' -lc++';
59-
}
60-
$envs .= " LIBS=\"{$libs}{$libcpp}\" ";
61-
}
62-
if ($error_exec_cnt > 0) {
63-
throw new BuildFailureException('Failed to get pkg-config information!');
51+
52+
$env_vars = [
53+
'CFLAGS' => "{$config['cflags']} -fno-ident{$macos_15_bug_cflags}",
54+
'CPPFLAGS' => '-DPIC',
55+
'LDFLAGS' => $config['ldflags'],
56+
'LIBS' => $config['libs'],
57+
];
58+
59+
if ($ldLibraryPath = getenv('SPC_LD_LIBRARY_PATH')) {
60+
$env_vars['LD_LIBRARY_PATH'] = $ldLibraryPath;
6461
}
6562

6663
FileSystem::resetDir($this->source_dir . '/build');
6764

68-
$version = $this->getVersion();
69-
// 16.1 workaround
70-
if (version_compare($version, '16.1') >= 0) {
71-
# 有静态链接配置 参考文件: src/interfaces/libpq/Makefile
72-
shell()->cd($this->source_dir . '/build')
73-
->exec('sed -i.backup "s/invokes exit\'; exit 1;/invokes exit\';/" ../src/interfaces/libpq/Makefile')
74-
->exec('sed -i.backup "278 s/^/# /" ../src/Makefile.shlib')
75-
->exec('sed -i.backup "402 s/^/# /" ../src/Makefile.shlib');
76-
} else {
77-
throw new BuildFailureException('Unsupported version for postgresql: ' . $version . ' !');
78-
}
65+
// php source relies on the non-private encoding functions in libpgcommon.a
66+
FileSystem::replaceFileStr(
67+
"{$this->source_dir}/src/common/Makefile",
68+
'$(OBJS_FRONTEND): CPPFLAGS += -DUSE_PRIVATE_ENCODING_FUNCS',
69+
'$(OBJS_FRONTEND): CPPFLAGS += -UUSE_PRIVATE_ENCODING_FUNCS -DFRONTEND',
70+
);
7971

8072
// configure
81-
shell()->cd($this->source_dir . '/build')->initializeEnv($this)
82-
->appendEnv(['CFLAGS' => $cflags])
73+
$shell = shell()->cd("{$this->source_dir}/build")->initializeEnv($this)
74+
->appendEnv($env_vars)
8375
->exec(
84-
"{$envs} ../configure " .
85-
"--prefix={$builddir} " .
86-
($this->builder->getOption('enable-zts') ? '--enable-thread-safety ' : '--disable-thread-safety ') .
76+
'../configure ' .
77+
"--prefix={$this->getBuildRootPath()} " .
8778
'--enable-coverage=no ' .
8879
'--with-ssl=openssl ' .
8980
'--with-readline ' .
9081
'--with-libxml ' .
9182
($this->builder->getLib('icu') ? '--with-icu ' : '--without-icu ') .
9283
($this->builder->getLib('ldap') ? '--with-ldap ' : '--without-ldap ') .
93-
// '--without-ldap ' .
9484
($this->builder->getLib('libxslt') ? '--with-libxslt ' : '--without-libxslt ') .
9585
($this->builder->getLib('zstd') ? '--with-zstd ' : '--without-zstd ') .
9686
'--without-lz4 ' .
@@ -99,32 +89,29 @@ protected function build(): void
9989
'--without-pam ' .
10090
'--without-bonjour ' .
10191
'--without-tcl '
102-
)
103-
->exec($envs . ' make -C src/bin/pg_config install')
104-
->exec($envs . ' make -C src/include install')
105-
->exec($envs . ' make -C src/common install')
106-
->exec($envs . ' make -C src/port install')
107-
->exec($envs . ' make -C src/interfaces/libpq install');
92+
);
93+
94+
// patch ldap lib
95+
if ($this->builder->getLib('ldap')) {
96+
$libs = PkgConfigUtil::getLibsArray('ldap');
97+
$libs = clean_spaces(implode(' ', $libs));
98+
FileSystem::replaceFileStr($this->source_dir . '/build/config.status', '-lldap', $libs);
99+
FileSystem::replaceFileStr($this->source_dir . '/build/src/Makefile.global', '-lldap', $libs);
100+
}
101+
102+
$shell
103+
->exec('make -C src/bin/pg_config install')
104+
->exec('make -C src/include install')
105+
->exec('make -C src/common install')
106+
->exec('make -C src/port install')
107+
->exec('make -C src/interfaces/libpq install');
108108

109109
// remove dynamic libs
110110
shell()->cd($this->source_dir . '/build')
111-
->exec("rm -rf {$builddir}/lib/*.so.*")
112-
->exec("rm -rf {$builddir}/lib/*.so")
113-
->exec("rm -rf {$builddir}/lib/*.dylib");
114-
115-
FileSystem::replaceFileStr(BUILD_LIB_PATH . '/pkgconfig/libpq.pc', '-lldap', '-lldap -llber');
116-
}
111+
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.so.*")
112+
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.so")
113+
->exec("rm -rf {$this->getBuildRootPath()}/lib/*.dylib");
117114

118-
private function getVersion(): string
119-
{
120-
try {
121-
$file = FileSystem::readFile($this->source_dir . '/meson.build');
122-
if (preg_match("/^\\s+version:\\s?'(.*)'/m", $file, $match)) {
123-
return $match[1];
124-
}
125-
return 'unknown';
126-
} catch (FileSystemException) {
127-
return 'unknown';
128-
}
115+
FileSystem::replaceFileStr("{$this->getLibDir()}/pkgconfig/libpq.pc", '-lldap', '-lldap -llber');
129116
}
130117
}

src/SPC/store/source/PhpSource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function fetch(bool $force = false, ?array $config = null, int $lock_as =
1616
{
1717
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.4';
1818
if ($major === '8.5') {
19-
Downloader::downloadSource('php-src', ['type' => 'url', 'url' => 'https://downloads.php.net/~edorian/php-8.5.0beta3.tar.xz'], $force);
19+
Downloader::downloadSource('php-src', ['type' => 'url', 'url' => 'https://github.com/php/php-src/archive/refs/tags/php-8.5.0RC2.tar.gz'], $force);
2020
} elseif ($major === 'git') {
2121
Downloader::downloadSource('php-src', ['type' => 'git', 'url' => 'https://github.com/php/php-src.git', 'rev' => 'master'], $force);
2222
} else {

src/globals/test-extensions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
'macos-15', // bin/spc for arm64
2929
// 'ubuntu-latest', // bin/spc-alpine-docker for x86_64
3030
'ubuntu-22.04', // bin/spc-gnu-docker for x86_64
31-
// 'ubuntu-24.04', // bin/spc for x86_64
31+
'ubuntu-24.04', // bin/spc for x86_64
3232
'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64
33-
// 'ubuntu-24.04-arm', // bin/spc for arm64
33+
'ubuntu-24.04-arm', // bin/spc for arm64
3434
// 'windows-latest', // .\bin\spc.ps1
3535
];
3636

@@ -50,13 +50,13 @@
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' => 'readline',
53+
'Linux', 'Darwin' => 'pgsql',
5454
'Windows' => 'bcmath,bz2,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,iconv,xml,mbstring,mbregex,mysqlnd,openssl,pdo,pdo_mysql,pdo_sqlite,phar,session,simplexml,soap,sockets,sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip',
5555
};
5656

5757
// If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`).
5858
$shared_extensions = match (PHP_OS_FAMILY) {
59-
'Linux' => 'grpc,imagick',
59+
'Linux' => '',
6060
'Darwin' => '',
6161
'Windows' => '',
6262
};

0 commit comments

Comments
 (0)