Skip to content

Commit 22a8191

Browse files
committed
Fix opcache jit option parsing in builder
1 parent 17ff5f6 commit 22a8191

File tree

8 files changed

+51
-19
lines changed

8 files changed

+51
-19
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,6 @@ jobs:
202202
if: ${{ !startsWith(matrix.os, 'windows-') }}
203203
run: php src/globals/test-extensions.php build_embed_cmd ${{ matrix.os }} ${{ matrix.php }}
204204

205-
- name: Setup tmate session
206-
if: ${{ failure() }}
207-
uses: mxschmitt/action-tmate@v3
205+
# - name: Setup tmate session
206+
# if: ${{ failure() }}
207+
# uses: mxschmitt/action-tmate@v3

config/ext.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@
488488
"opcache": {
489489
"type": "builtin",
490490
"arg-type-unix": "custom",
491+
"arg-type-windows": "enable",
491492
"zend-extension": true
492493
},
493494
"openssl": {

src/SPC/builder/extension/opcache.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,7 @@ public function patchBeforeBuildconf(): bool
5151

5252
public function getUnixConfigureArg(bool $shared = false): string
5353
{
54-
$version = $this->builder->getPHPVersion();
55-
$opcache_jit = !$this->builder->getOption('disable-opcache-jit', false);
56-
$opcache_jit = $opcache_jit ? '--enable-opcache-jit' : '--disable-opcache-jit';
57-
if (version_compare($version, '8.5.0-dev', '<')) {
58-
return "--enable-opcache {$opcache_jit}";
59-
}
60-
return $opcache_jit;
54+
return '--enable-opcache';
6155
}
6256

6357
public function getDistName(): string

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,25 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
6666
$phpVersionID = $this->getPHPVersionID();
6767
$json_74 = $phpVersionID < 80000 ? '--enable-json ' : '';
6868

69+
$opcache_jit = !$this->getOption('disable-opcache-jit', false);
70+
if ($opcache_jit && ($phpVersionID >= 80500 || $this->getExt('opcache'))) {
71+
// php 8.5 contains opcache extension by default,
72+
// if opcache_jit is enabled for 8.5 or opcache enabled,
73+
// we need to disable undefined behavior sanitizer.
74+
f_putenv('SPC_COMPILER_EXTRA=-fno-sanitize=undefined');
75+
} elseif ($opcache_jit) {
76+
$opcache_jit = false;
77+
}
78+
$opcache_jit_arg = $opcache_jit ? '--enable-opcache-jit' : '--disable-opcache-jit';
79+
6980
if ($this->getOption('enable-zts', false)) {
7081
$maxExecutionTimers = $phpVersionID >= 80100 ? '--enable-zend-max-execution-timers ' : '';
7182
$zts = '--enable-zts --disable-zend-signals ';
7283
} else {
7384
$maxExecutionTimers = '';
7485
$zts = '';
7586
}
76-
$disable_jit = $this->getOption('disable-opcache-jit', false) ? '--disable-opcache-jit ' : '';
77-
if (!$disable_jit && $this->getExt('opcache')) {
78-
f_putenv('SPC_COMPILER_EXTRA=-fno-sanitize=undefined');
79-
}
87+
8088
$config_file_path = $this->getOption('with-config-file-path', false) ?
8189
('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : '';
8290
$config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ?
@@ -114,7 +122,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
114122
($enableMicro ? '--enable-micro=all-static ' : '--disable-micro ') .
115123
$config_file_path .
116124
$config_file_scan_dir .
117-
$disable_jit .
125+
$opcache_jit_arg .
118126
$json_74 .
119127
$zts .
120128
$maxExecutionTimers .

src/SPC/builder/macos/MacOSBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
102102
$json_74 = $phpVersionID < 80000 ? '--enable-json ' : '';
103103
$zts = $this->getOption('enable-zts', false) ? '--enable-zts --disable-zend-signals ' : '';
104104

105+
$opcache_jit = !$this->getOption('disable-opcache-jit', false);
106+
// disable opcache jit for PHP < 8.5.0 when opcache is not enabled
107+
if ($opcache_jit && $phpVersionID < 80500 && !$this->getExt('opcache')) {
108+
$opcache_jit = false;
109+
}
110+
$opcache_jit_arg = $opcache_jit ? '--enable-opcache-jit' : '--disable-opcache-jit';
111+
105112
$config_file_path = $this->getOption('with-config-file-path', false) ?
106113
('--with-config-file-path=' . $this->getOption('with-config-file-path') . ' ') : '';
107114
$config_file_scan_dir = $this->getOption('with-config-file-scan-dir', false) ?
@@ -136,6 +143,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
136143
($enableFpm ? '--enable-fpm ' : '--disable-fpm ') .
137144
($enableEmbed ? "--enable-embed={$embed_type} " : '--disable-embed ') .
138145
($enableMicro ? '--enable-micro ' : '--disable-micro ') .
146+
$opcache_jit_arg .
139147
$config_file_path .
140148
$config_file_scan_dir .
141149
$json_74 .

src/SPC/builder/windows/WindowsBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
8989
}
9090
}
9191

92+
$opcache_jit = !$this->getOption('disable-opcache-jit', false);
93+
$opcache_jit_arg = $opcache_jit ? '--enable-opcache-jit=yes ' : '--enable-opcache-jit=no ';
94+
9295
if (($logo = $this->getOption('with-micro-logo')) !== null) {
9396
// realpath
9497
// $logo = realpath($logo);
@@ -115,6 +118,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
115118
($enableMicro ? ('--enable-micro=yes ' . $micro_logo . $micro_w32) : '--enable-micro=no ') .
116119
($enableEmbed ? '--enable-embed=yes ' : '--enable-embed=no ') .
117120
$config_file_scan_dir .
121+
$opcache_jit_arg .
118122
"{$this->makeStaticExtensionArgs()} " .
119123
$zts .
120124
'"'

src/SPC/store/SourcePatcher.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ public static function patchBeforeBuildconf(BuilderBase $builder): void
6969
);
7070
}
7171

72+
// Fix PHP VS version
73+
if ($builder instanceof WindowsBuilder) {
74+
// get vs version
75+
$vc = \SPC\builder\windows\SystemUtil::findVisualStudio();
76+
$vc_matches = match ($vc['version']) {
77+
'vs17' => ['VS17', 'Visual C++ 2022'],
78+
'vs16' => ['VS16', 'Visual C++ 2019'],
79+
default => ['unknown', 'unknown'],
80+
};
81+
// patch php-src/win32/build/confutils.js
82+
FileSystem::replaceFileStr(
83+
SOURCE_PATH . '\php-src\win32\build\confutils.js',
84+
'var name = "unknown";',
85+
"var name = short ? \"{$vc_matches[0]}\" : \"{$vc_matches[1]}\";return name;"
86+
);
87+
}
88+
7289
// patch php-src/build/php.m4 PKG_CHECK_MODULES -> PKG_CHECK_MODULES_STATIC
7390
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/build/php.m4', 'PKG_CHECK_MODULES(', 'PKG_CHECK_MODULES_STATIC(');
7491

src/globals/test-extensions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
// test php version (8.1 ~ 8.4 available, multiple for matrix)
1515
$test_php_version = [
16-
'8.1',
17-
'8.2',
18-
'8.3',
16+
// '8.1',
17+
// '8.2',
18+
// '8.3',
1919
'8.4',
2020
'8.5',
2121
'git',
@@ -31,7 +31,7 @@
3131
// 'ubuntu-24.04', // bin/spc for x86_64
3232
// 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64
3333
'ubuntu-24.04-arm', // bin/spc for arm64
34-
// 'windows-latest', // .\bin\spc.ps1
34+
'windows-latest', // .\bin\spc.ps1
3535
];
3636

3737
// whether enable thread safe

0 commit comments

Comments
 (0)