Skip to content

Commit a161fcb

Browse files
domr@qq.comdomr@qq.com
authored andcommitted
Build PHP 8.6 with Event and native PDO drivers
1 parent 87d0030 commit a161fcb

11 files changed

Lines changed: 111 additions & 64 deletions

File tree

‎.github/jit/probe.php‎

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function silencedYield(): int {
1313
return $level;
1414
}
1515

16-
check(extension_loaded('swoole'), 'Swoole missing');
16+
$hasSwoole = extension_loaded('swoole');
1717
check(!function_exists('swoole_call_array_method'), 'stdext still enabled');
1818
$disabledJit = ['enabled' => false, 'on' => false, 'buffer_size' => 0, 'buffer_free' => 0];
1919
$before = opcache_get_status(false)['jit'] ?? $disabledJit;
@@ -27,62 +27,66 @@ function silencedYield(): int {
2727
maybeExit(false);
2828
}
2929
$after = opcache_get_status(false)['jit'] ?? $disabledJit;
30-
$events = [];
31-
Swoole\Coroutine\run(function () use (&$events): void {
32-
$channel = new Swoole\Coroutine\Channel(1);
33-
Swoole\Coroutine::create(function () use ($channel): void {
30+
function checkCoroutines(): array {
31+
$events = [];
32+
Swoole\Coroutine\run(function () use (&$events): void {
33+
$channel = new Swoole\Coroutine\Channel(1);
34+
Swoole\Coroutine::create(function () use ($channel): void {
35+
for ($i = 0; $i < 100; $i++) {
36+
$channel->push(numeric($i % 10));
37+
Swoole\Coroutine::sleep(0.001);
38+
}
39+
});
40+
$total = 0;
3441
for ($i = 0; $i < 100; $i++) {
35-
$channel->push(numeric($i % 10));
42+
$total += $channel->pop();
43+
}
44+
check($total === array_sum(array_map('numeric', array_map(fn($i) => $i % 10, range(0, 99)))), 'channel result mismatch');
45+
$events[] = 'channel';
46+
try {
3647
Swoole\Coroutine::sleep(0.001);
48+
throw new LogicException('after-yield');
49+
} catch (LogicException $e) {
50+
check($e->getMessage() === 'after-yield', 'exception changed');
51+
$events[] = 'exception';
52+
}
53+
$normal = error_reporting();
54+
@silencedYield();
55+
check(error_reporting() === $normal, 'error_reporting not restored');
56+
$events[] = 'silence';
57+
$server = new Swoole\Coroutine\Socket(AF_INET, SOCK_STREAM, 0);
58+
check($server->bind('127.0.0.1', 0) && $server->listen(), 'TCP listen failed');
59+
$port = $server->getsockname()['port'];
60+
Swoole\Coroutine::create(function () use ($server): void {
61+
$peer = $server->accept(3);
62+
check($peer !== false, 'TCP accept failed');
63+
check($peer->recvAll(4, 3) === 'ping', 'TCP receive failed');
64+
check($peer->sendAll('pong') === 4, 'TCP send failed');
65+
$peer->close();
66+
$server->close();
67+
});
68+
$client = new Swoole\Coroutine\Socket(AF_INET, SOCK_STREAM, 0);
69+
check($client->connect('127.0.0.1', $port, 3), 'TCP connect failed');
70+
$client->sendAll('ping');
71+
check($client->recvAll(4, 3) === 'pong', 'TCP round trip failed');
72+
$client->close();
73+
$events[] = 'tcp';
74+
try {
75+
maybeExit(true);
76+
throw new RuntimeException('exit did not throw');
77+
} catch (Swoole\ExitException $e) {
78+
check($e->getStatus() === 37, 'coroutine exit status changed');
79+
check(($e->getFlags() & SWOOLE_EXIT_IN_COROUTINE) !== 0, 'coroutine exit flag missing');
80+
$events[] = 'exit';
3781
}
3882
});
39-
$total = 0;
40-
for ($i = 0; $i < 100; $i++) {
41-
$total += $channel->pop();
42-
}
43-
check($total === array_sum(array_map('numeric', array_map(fn($i) => $i % 10, range(0, 99)))), 'channel result mismatch');
44-
$events[] = 'channel';
45-
try {
46-
Swoole\Coroutine::sleep(0.001);
47-
throw new LogicException('after-yield');
48-
} catch (LogicException $e) {
49-
check($e->getMessage() === 'after-yield', 'exception changed');
50-
$events[] = 'exception';
51-
}
52-
$normal = error_reporting();
53-
@silencedYield();
54-
check(error_reporting() === $normal, 'error_reporting not restored');
55-
$events[] = 'silence';
56-
$server = new Swoole\Coroutine\Socket(AF_INET, SOCK_STREAM, 0);
57-
check($server->bind('127.0.0.1', 0) && $server->listen(), 'TCP listen failed');
58-
$port = $server->getsockname()['port'];
59-
Swoole\Coroutine::create(function () use ($server): void {
60-
$peer = $server->accept(3);
61-
check($peer !== false, 'TCP accept failed');
62-
check($peer->recvAll(4, 3) === 'ping', 'TCP receive failed');
63-
check($peer->sendAll('pong') === 4, 'TCP send failed');
64-
$peer->close();
65-
$server->close();
66-
});
67-
$client = new Swoole\Coroutine\Socket(AF_INET, SOCK_STREAM, 0);
68-
check($client->connect('127.0.0.1', $port, 3), 'TCP connect failed');
69-
$client->sendAll('ping');
70-
check($client->recvAll(4, 3) === 'pong', 'TCP round trip failed');
71-
$client->close();
72-
$events[] = 'tcp';
73-
try {
74-
maybeExit(true);
75-
throw new RuntimeException('exit did not throw');
76-
} catch (Swoole\ExitException $e) {
77-
check($e->getStatus() === 37, 'coroutine exit status changed');
78-
check(($e->getFlags() & SWOOLE_EXIT_IN_COROUTINE) !== 0, 'coroutine exit flag missing');
79-
$events[] = 'exit';
80-
}
81-
});
82-
check($events === ['channel', 'exception', 'silence', 'tcp', 'exit'], 'coroutine checks incomplete');
83+
check($events === ['channel', 'exception', 'silence', 'tcp', 'exit'], 'coroutine checks incomplete');
84+
return $events;
85+
}
86+
$events = $hasSwoole ? checkCoroutines() : [];
8387
echo 'JIT_REPORT:', json_encode([
8488
'php' => PHP_VERSION,
85-
'swoole' => swoole_version(),
89+
'swoole' => $hasSwoole ? swoole_version() : null,
8690
'stdext' => function_exists('swoole_call_array_method'),
8791
'before' => $before,
8892
'after' => $after,

‎.github/jit/run_checks.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def main():
1010
p = argparse.ArgumentParser()
1111
p.add_argument("--php", default="php")
1212
p.add_argument("--swoole")
13+
p.add_argument("--without-swoole", action="store_true")
1314
p.add_argument("--expect-jit", choices=["yes", "no"], required=True)
1415
p.add_argument("--output", type=Path, required=True)
1516
p.add_argument("--fixture", type=Path, default=Path(__file__).with_name("probe.php"))
@@ -36,6 +37,8 @@ def main():
3637
if len(lines) != 1:
3738
raise RuntimeError("Missing runtime report")
3839
report = json.loads(lines[0])
40+
if (report["swoole"] is not None) != (not args.without_swoole):
41+
raise RuntimeError(f"Unexpected Swoole extension state: {report}")
3942
expect = mode != "disable" and args.expect_jit == "yes"
4043
if bool(report["after"]["on"]) != expect:
4144
raise RuntimeError(f"Unexpected JIT state: {report}")
@@ -52,7 +55,7 @@ def main():
5255
raise RuntimeError(f"Plain CLI exit status changed: {plain.returncode}")
5356
args.output.parent.mkdir(parents=True, exist_ok=True)
5457
args.output.write_text(json.dumps(reports, indent=2) + "\n")
55-
print("PASS: numeric JIT, channels, exceptions, silence, TCP, coroutine exit, CLI exit")
58+
print("PASS: numeric JIT and CLI exit" + ("" if args.without_swoole else ", plus Swoole coroutine checks"))
5659

5760

5861
if __name__ == "__main__":

‎.github/jit/run_micro_checks.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
p = argparse.ArgumentParser()
1111
p.add_argument('--micro', type=Path, required=True)
1212
p.add_argument('--output', type=Path, required=True)
13+
p.add_argument('--without-swoole', action='store_true')
1314
p.add_argument('--enable-opcache-jit', action='store_true', help='Experimental: current and historical public micro binaries crash with OPcache enabled')
1415
args = p.parse_args()
1516
reports = {}
@@ -37,6 +38,8 @@
3738
if len(lines) != 1:
3839
raise RuntimeError('Missing micro report')
3940
report = json.loads(lines[0])
41+
if (report['swoole'] is not None) != (not args.without_swoole):
42+
raise RuntimeError(f'Unexpected micro Swoole extension state: {report}')
4043
expect = mode != 'disable'
4144
if bool(report['after']['on']) != expect:
4245
raise RuntimeError(f'Unexpected micro JIT state: {report}')
@@ -52,4 +55,4 @@
5255
raise RuntimeError(f'micro JIT {mode} numeric results differ')
5356
args.output.parent.mkdir(parents=True, exist_ok=True)
5457
args.output.write_text(json.dumps(reports, indent=2) + '\n')
55-
print('PASS: micro production defaults, numeric results, coroutines and exit status')
58+
print('PASS: micro defaults, numeric results and exit status' + ('' if args.without_swoole else ', plus Swoole coroutine checks'))

‎.github/jit/run_published.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ def fetch(name, limit=80 * 1024 * 1024):
5151
cli.write_bytes(binary)
5252
cli.chmod(0o755)
5353
cli_report = results / (branch + '-cli.json')
54+
profile = ['--without-swoole'] if branch == '8.6' else []
5455
subprocess.run(['python3', str(Path(__file__).with_name('run_checks.py')), '--php', str(cli),
55-
'--expect-jit', 'yes', '--output', str(cli_report)], check=True)
56+
'--expect-jit', 'yes', '--output', str(cli_report), *profile], check=True)
5657
assert json.loads(cli_report.read_text())['tracing']['php'] == version
57-
if branch in ('8.5', '8.6'):
58+
if branch == '8.5':
5859
subprocess.run(['python3', str(Path(__file__).with_name('run_checks.py')), '--php', str(cli),
5960
'--fixture', str(Path(__file__).with_name('repro-php85-jit.php')),
6061
'--jit-modes', 'tracing', '--expect-jit', 'yes',
@@ -66,6 +67,6 @@ def fetch(name, limit=80 * 1024 * 1024):
6667
micro.write_bytes(micro_data)
6768
micro_report = results / (branch + '-micro.json')
6869
subprocess.run(['python3', str(Path(__file__).with_name('run_micro_checks.py')), '--micro', str(micro),
69-
'--output', str(micro_report)], check=True)
70+
'--output', str(micro_report), *profile], check=True)
7071
assert json.loads(micro_report.read_text())['disable']['php'] == version
7172
print('PUBLIC DOWNLOAD PASS:', name, version, flush=True)

‎.github/patches/php86/README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# PHP 8.6 构建说明
2+
3+
PHP 8.6 使用 event 3.2.0,省略 Swoole 及其协程数据库钩子。CLI 与 micro 均编入原生 PDO MySQL、PostgreSQL 和 SQLite 驱动。
4+
5+
APCu、Redis、igbinary、msgpack 和 xlswriter 保留各自的发布版本。兼容补丁来自 [Remi 的扩展构建](https://github.com/remicollet/remirepo/issues/342)及 [xlswriter 上游](https://github.com/viest/php-ext-xlswriter/pull/591)。
6+
7+
本目录在 master 的变更会触发 PHP 8.6 的六平台构建、验证与发布。

‎.github/scripts/php_binary.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ def current_jit_profile(info):
1717
and info.get("swoole_stdext") is False)
1818

1919

20+
def matches_swoole_profile(extensions, version):
21+
return ("swoole" in extensions) == (not version.startswith("8.6."))
22+
23+
2024
def current_linux_profile(info, target):
2125
if info.get("upx_version") != UPX_VERSION:
2226
return False
@@ -69,10 +73,14 @@ def verify_runtime(cli, version):
6973
actual = metadata(cli)
7074
assert actual["version"] == version, actual
7175
assert "intl" not in actual["extensions"] and not actual["icu"], actual
76+
assert matches_swoole_profile(actual["extensions"], version), actual
7277
subprocess.run([str(cli), "-n", "-r", '''
7378
foreach (["pcntl", "posix", "sockets", "openssl", "curl", "mbstring", "event", "redis", "apcu", "sodium", "gd", "imagick"] as $ext) {
7479
if (!extension_loaded($ext)) { throw new RuntimeException("Missing extension: " . $ext); }
7580
}
81+
if (array_diff(["mysql", "pgsql", "sqlite"], PDO::getAvailableDrivers())) {
82+
throw new RuntimeException("Missing PDO driver");
83+
}
7684
$server = stream_socket_server("tcp://127.0.0.1:0", $errno, $error);
7785
if (!$server) { throw new RuntimeException($error); }
7886
$client = stream_socket_client("tcp://" . stream_socket_get_name($server, false));

‎.github/scripts/php_releases.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ def decide_updates(current, latest, published):
127127
pending.append(f"{name}: {metadata['php_version']} -> {new['version']}")
128128
elif "intl" in metadata.get("extensions", []):
129129
pending.append(f"{name}: replace the obsolete intl/ICU build")
130+
elif branch == "8.6" and "swoole" in metadata.get("extensions", []):
131+
pending.append(f"{name}: publish PHP 8.6 without Swoole")
130132
elif target["os"] == "linux" and not current_linux_profile(metadata, target):
131133
pending.append(f"{name}: publish the UPX {UPX_VERSION} profile")
132134
elif not current_jit_profile(metadata):

‎.github/scripts/test_php_releases.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ def test_stdext_cannot_claim_jit_compatibility(self):
6161
self.published["php-8.2-linux-x86_64"]["swoole_stdext"] = True
6262
self.assertEqual(["php-8.2-linux-x86_64: publish the compatible JIT profile"], releases.decide_updates(self.current, self.current, self.published))
6363

64+
def test_php86_replaces_packages_built_with_swoole(self):
65+
self.published["php-8.6-linux-x86_64"]["extensions"] = ["event", "swoole"]
66+
self.assertEqual(["php-8.6-linux-x86_64: publish PHP 8.6 without Swoole"],
67+
releases.decide_updates(self.current, self.current, self.published))
68+
6469
def test_native_verified_arm_glibc_hatch_fallback_does_not_rebuild_weekly(self):
6570
info = self.published["php-8.4-linux-aarch64-glibc"]
6671
info.update(packing="none", packing_reason=UPX_ARM_GLIBC_FALLBACK)

‎.github/scripts/verify-release-artifacts.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import tarfile
77
import zipfile
88

9-
from php_binary import current_jit_profile, current_linux_profile
9+
from php_binary import current_jit_profile, current_linux_profile, matches_swoole_profile
1010
from php_releases import MANIFEST, build_targets, package_name, select_releases, validate_manifest
1111

1212
root = Path(os.environ.get("RELEASE_DIR", "release"))
@@ -22,6 +22,7 @@
2222
assert info["php_version"] == release["version"], base + ": stale PHP version"
2323
assert "intl" not in info["extensions"], base + ": obsolete intl profile"
2424
assert current_jit_profile(info), base + ": incompatible JIT profile"
25+
assert matches_swoole_profile(info["extensions"], release["version"]), base + ": unexpected Swoole extension"
2526
if target["os"] != "linux":
2627
continue
2728
assert current_linux_profile(info, target), base + ": obsolete UPX profile"

‎.github/workflows/build-php-unix.yml‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
env:
5757
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5858
SPC_TARGET: ${{ matrix.target.triple }}
59-
# Keep JIT with Swoole using the traditional VM on PHP 8.5 and 8.6.
59+
# Use the traditional VM for the release JIT profile on PHP 8.5 and 8.6.
6060
SPC_EXTRA_PHP_VARS: ${{ (matrix.php.branch == '8.5' || matrix.php.branch == '8.6') && 'php_cv_preserve_none=no' || '' }}
6161
runs-on: ${{ matrix.target.runner }}
6262
timeout-minutes: 240
@@ -82,6 +82,19 @@ jobs:
8282
- name: Apply Swoole JIT and PHP 8.6 static extension compatibility
8383
run: python3 .release-tools/.github/jit/apply_spc_profile.py --profile stdext-off
8484

85+
- name: Select the PHP 8.6 extension profile
86+
if: matrix.php.branch == '8.6'
87+
run: |
88+
IFS=, read -r -a extensions <<< "$EXTENSIONS"
89+
selected=(pdo_pgsql pdo_sqlite)
90+
for extension in "${extensions[@]}"; do
91+
case "$extension" in
92+
swoole|swoole-hook-*) ;;
93+
*) selected+=("$extension");;
94+
esac
95+
done
96+
(IFS=,; echo "EXTENSIONS=${selected[*]}") >> "$GITHUB_ENV"
97+
8598
- name: Setup build runtime
8699
uses: shivammathur/setup-php@v2
87100
with:
@@ -141,10 +154,10 @@ jobs:
141154
run: bin/spc build:php "$EXTENSIONS" --build-cli --build-micro --no-download --dl-with-php=${{ matrix.php.version }}
142155

143156
- name: Verify actual JIT code generation and coroutine behavior
144-
run: python3 .release-tools/.github/jit/run_checks.py --php "$PWD/buildroot/bin/php" --expect-jit yes --output validation/jit-unpacked.json
157+
run: python3 .release-tools/.github/jit/run_checks.py --php "$PWD/buildroot/bin/php" --expect-jit yes --output validation/jit-unpacked.json ${{ matrix.php.branch == '8.6' && '--without-swoole' || '' }}
145158

146159
- name: Check the tracing JIT regression with Swoole
147-
if: matrix.php.branch == '8.5' || matrix.php.branch == '8.6'
160+
if: matrix.php.branch == '8.5'
148161
run: python3 .release-tools/.github/jit/run_checks.py --php "$PWD/buildroot/bin/php" --fixture .release-tools/.github/jit/repro-php85-jit.php --jit-modes tracing --expect-jit yes --output validation/jit-original-repro.json
149162

150163
- name: Verify unpacked binaries contain no intl, ICU or oversized payload
@@ -163,11 +176,11 @@ jobs:
163176

164177
- name: Verify Linux JIT after UPX packing
165178
if: matrix.target.os == 'linux'
166-
run: python3 .release-tools/.github/jit/run_checks.py --php "$PWD/buildroot/bin/php" --expect-jit yes --output validation/jit-packed.json
179+
run: python3 .release-tools/.github/jit/run_checks.py --php "$PWD/buildroot/bin/php" --expect-jit yes --output validation/jit-packed.json ${{ matrix.php.branch == '8.6' && '--without-swoole' || '' }}
167180

168-
- name: Verify published micro coroutine behavior
181+
- name: Verify published micro defaults and runtime behavior
169182
if: matrix.target.os == 'linux' && matrix.target.arch == 'x86_64' && matrix.target.suffix == ''
170-
run: python3 .release-tools/.github/jit/run_micro_checks.py --micro buildroot/bin/micro.sfx --output validation/micro-defaults.json
183+
run: python3 .release-tools/.github/jit/run_micro_checks.py --micro buildroot/bin/micro.sfx --output validation/micro-defaults.json ${{ matrix.php.branch == '8.6' && '--without-swoole' || '' }}
171184

172185
- name: Verify and package
173186
env:

0 commit comments

Comments
 (0)