Skip to content

Commit 93d6a45

Browse files
committed
*full* shared extension build linked against musl libc dynamically works!
1 parent 2ac20cf commit 93d6a45

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ protected function buildCli(): void
192192
->exec('sed -i "s|//lib|/lib|g" Makefile')
193193
->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} cli");
194194

195+
if (!$this->getOption('no-strip', false)) {
196+
shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-all php');
197+
}
195198
if ($this->getOption('with-upx-pack')) {
196199
shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')
197-
->exec('strip --strip-all php')
198200
->exec(getenv('UPX_EXEC') . ' --best php');
199-
} elseif (!$this->getOption('no-strip', false)) {
200-
shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-all php');
201201
}
202202

203203
$this->deployBinary(BUILD_TARGET_CLI);
@@ -255,12 +255,12 @@ protected function buildFpm(): void
255255
->exec('sed -i "s|//lib|/lib|g" Makefile')
256256
->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} fpm");
257257

258+
if (!$this->getOption('no-strip', false)) {
259+
shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')->exec('strip --strip-all php-fpm');
260+
}
258261
if ($this->getOption('with-upx-pack')) {
259262
shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')
260-
->exec('strip --strip-all php-fpm')
261263
->exec(getenv('UPX_EXEC') . ' --best php-fpm');
262-
} elseif (!$this->getOption('no-strip', false)) {
263-
shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')->exec('strip --strip-all php-fpm');
264264
}
265265
$this->deployBinary(BUILD_TARGET_FPM);
266266
}

src/SPC/store/SourcePatcher.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,23 @@ public static function patchSwoole(): bool
256256
*/
257257
public static function patchBeforeMake(BuilderBase $builder): void
258258
{
259-
// Try to fix debian environment build lack HAVE_STRLCAT problem
260-
if ($builder instanceof LinuxBuilder) {
261-
FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/main/php_config.h', '/^#define HAVE_STRLCPY 1$/m', '');
262-
FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/main/php_config.h', '/^#define HAVE_STRLCAT 1$/m', '');
263-
}
264259
if ($builder instanceof UnixBuilderBase) {
265260
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/Makefile', 'install-micro', '');
266261
}
262+
if (!SPCTarget::isStatic() && SPCTarget::getLibc() === 'musl') {
263+
// we need to patch the symbol to global visibility, otherwise extensions with `initial-exec` TLS model will fail to load
264+
FileSystem::replaceFileStr(
265+
SOURCE_PATH . '/php-src/TSRM/TSRM.h',
266+
'#define TSRMLS_MAIN_CACHE_DEFINE() TSRM_TLS void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR = NULL;',
267+
'#define TSRMLS_MAIN_CACHE_DEFINE() TSRM_TLS __attribute__((visibility("default"))) void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR = NULL;',
268+
);
269+
} else {
270+
FileSystem::replaceFileStr(
271+
SOURCE_PATH . '/php-src/TSRM/TSRM.h',
272+
'#define TSRMLS_MAIN_CACHE_DEFINE() TSRM_TLS __attribute__((visibility("default"))) void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR = NULL;',
273+
'#define TSRMLS_MAIN_CACHE_DEFINE() TSRM_TLS void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR = NULL;',
274+
);
275+
}
267276

268277
// no asan
269278
// if (strpos(file_get_contents(SOURCE_PATH . '/php-src/Makefile'), 'CFLAGS_CLEAN = -g') === false) {

src/globals/test-extensions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ function quote2(string $param): string
158158
break;
159159
case 'ubuntu-24.04':
160160
case 'ubuntu-24.04-arm':
161-
putenv('SPC_TARGET=native-native-gnu');
162-
if (getenv('SPC_TARGET') && !str_contains((string) getenv('SPC_TARGET'), '-musl')) {
161+
putenv('SPC_TARGET=native-native-musl -dynamic');
162+
if (getenv('SPC_TARGET') && !str_contains(getenv('SPC_TARGET'), '-musl') || str_contains(getenv('SPC_TARGET'), '-dynamic')) {
163163
$shared_cmd = ' --build-shared=' . quote2($shared_extensions) . ' ';
164164
}
165165
break;

0 commit comments

Comments
 (0)