Compare commits

...

16 Commits

Author SHA1 Message Date
DubbleClick
efb1ff5a93 test fix 2? 2025-06-27 22:56:49 +07:00
DubbleClick
aff9ff20e8 test fix? 2025-06-27 22:55:23 +07:00
DubbleClick
4c8a173213 build_lib_path is better 2025-06-27 22:53:18 +07:00
DubbleClick
b6240f16fb clean files before compiling because it may try to link the wrong one 2025-06-27 22:51:53 +07:00
DubbleClick
f5281535d9 strip libphp.so and frankenphp 2025-06-27 22:48:15 +07:00
DubbleClick
96babd0939 crazy test 2025-06-27 22:06:19 +07:00
DubbleClick
464c2dca85 cs fix 2025-06-27 22:01:56 +07:00
DubbleClick
43dc04b4d0 building shared libphp.so on musl is really pointless and should be an error, since static compilations cannot load it 2025-06-27 22:01:37 +07:00
DubbleClick
e92f043cfa really stupid patch for swoole 2025-06-27 21:38:16 +07:00
DubbleClick
ff95b464ce really stupid patch for swoole 2025-06-27 21:26:06 +07:00
DubbleClick
69e1acd5ae really stupid patch 2025-06-27 20:28:59 +07:00
DubbleClick
e162a0ecd6 libaom uses different PIC check 2025-06-27 19:37:10 +07:00
DubbleClick
383045d1c0 cs fix 2025-06-27 19:27:02 +07:00
DubbleClick
e6bec8eb57 fix lib extra cflags 2025-06-27 19:26:08 +07:00
DubbleClick
d2dea83c63 don't check for musl toolkit when running zig, add -static to ncurses 2025-06-27 18:21:22 +07:00
DubbleClick
797aaf1ea8 remove libdir 2025-06-27 14:51:36 +07:00
11 changed files with 81 additions and 22 deletions

View File

@@ -7,6 +7,7 @@ namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\builder\macos\MacOSBuilder;
use SPC\store\FileSystem;
use SPC\store\SourcePatcher;
use SPC\util\CustomExt;
#[CustomExt('swoole')]
@@ -14,13 +15,18 @@ class swoole extends Extension
{
public function patchBeforeMake(): bool
{
$patched = false;
if (PHP_OS_FAMILY === 'Linux') {
SourcePatcher::patchFile('swoole_fix_date_time.patch', $this->source_dir);
$patched = true;
}
if ($this->builder instanceof MacOSBuilder) {
// Fix swoole with event extension <util.h> conflict bug
$util_path = shell()->execWithResult('xcrun --show-sdk-path', false)[1][0] . '/usr/include/util.h';
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/swoole/thirdparty/php/standard/proc_open.cc', 'include <util.h>', 'include "' . $util_path . '"');
return true;
$patched = true;
}
return false;
return $patched;
}
public function getExtVersion(): ?string

View File

@@ -139,6 +139,9 @@ class LinuxBuilder extends UnixBuilderBase
}
$embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static';
if ($embed_type !== 'static' && getenv('SPC_LIBC') === 'musl') {
throw new WrongUsageException('Musl libc does not support dynamic linking of PHP embed!');
}
shell()->cd(SOURCE_PATH . '/php-src')
->exec(
getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' .
@@ -297,6 +300,7 @@ class LinuxBuilder extends UnixBuilderBase
->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install");
$ldflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS');
$realLibName = 'libphp.so';
if (preg_match('/-release\s+(\S+)/', $ldflags, $matches)) {
$release = $matches[1];
$realLibName = 'libphp-' . $release . '.so';
@@ -335,6 +339,9 @@ class LinuxBuilder extends UnixBuilderBase
}
chdir($cwd);
}
if (!$this->getOption('no-strip', false) && file_exists(BUILD_LIB_PATH . '/' . $realLibName)) {
shell()->cd(BUILD_LIB_PATH)->exec("strip --strip-all {$realLibName}");
}
$this->patchPhpScripts();
}

View File

@@ -119,9 +119,9 @@ trait UnixLibraryTrait
{
$env = getenv($this->getSnakeCaseName() . '_CFLAGS') ?: '';
if (!str_contains($env, $this->builder->arch_c_flags)) {
$env .= $this->builder->arch_c_flags;
$env .= ' ' . $this->builder->arch_c_flags;
}
return $env;
return trim($env);
}
public function getLibExtraLdFlags(): string
@@ -138,8 +138,8 @@ trait UnixLibraryTrait
{
$env = getenv($this->getSnakeCaseName() . '_CXXFLAGS') ?: '';
if (!str_contains($env, $this->builder->arch_cxx_flags)) {
$env .= $this->builder->arch_cxx_flags;
$env .= ' ' . $this->builder->arch_cxx_flags;
}
return $env;
return trim($env);
}
}

View File

@@ -205,18 +205,20 @@ abstract class UnixBuilderBase extends BuilderBase
if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') {
$lens .= ' -static';
}
// if someone changed to EMBED_TYPE=shared, we need to add LD_LIBRARY_PATH
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') {
$ext_path = 'LD_LIBRARY_PATH=' . BUILD_LIB_PATH . ':$LD_LIBRARY_PATH ';
FileSystem::removeFileIfExists(BUILD_LIB_PATH . '/libphp.a');
} else {
$ext_path = '';
foreach (glob(BUILD_LIB_PATH . '/libphp*.so') as $file) {
unlink($file);
}
}
[$ret, $out] = shell()->cd($sample_file_path)->execWithResult(getenv('CC') . ' -o embed embed.c ' . $lens);
if ($ret !== 0) {
throw new RuntimeException('embed failed sanity check: build failed. Error message: ' . implode("\n", $out));
}
// if someone changed to --enable-embed=shared, we need to add LD_LIBRARY_PATH
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') {
$ext_path = 'LD_LIBRARY_PATH=' . BUILD_ROOT_PATH . '/lib:$LD_LIBRARY_PATH ';
FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.a');
} else {
$ext_path = '';
FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.so');
}
[$ret, $output] = shell()->cd($sample_file_path)->execWithResult($ext_path . './embed');
if ($ret !== 0 || trim(implode('', $output)) !== 'hello') {
throw new RuntimeException('embed failed sanity check: run failed. Error message: ' . implode("\n", $output));
@@ -327,9 +329,11 @@ abstract class UnixBuilderBase extends BuilderBase
$debugFlags = $this->getOption('no-strip') ? "'-w -s' " : '';
$extLdFlags = "-extldflags '-pie'";
$muslTags = '';
$staticFlags = '';
if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') {
$extLdFlags = "-extldflags '-static-pie -Wl,-z,stack-size=0x80000'";
$muslTags = 'static_build,';
$staticFlags = '-static -static-pie';
}
$config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list, with_dependencies: true);
@@ -337,7 +341,7 @@ abstract class UnixBuilderBase extends BuilderBase
$env = [
'CGO_ENABLED' => '1',
'CGO_CFLAGS' => $config['cflags'],
'CGO_LDFLAGS' => "{$config['ldflags']} {$config['libs']} {$lrt}",
'CGO_LDFLAGS' => "{$staticFlags} {$config['ldflags']} {$config['libs']} {$lrt}",
'XCADDY_GO_BUILD_FLAGS' => '-buildmode=pie ' .
'-ldflags \"-linkmode=external ' . $extLdFlags . ' ' . $debugFlags .
'-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' .
@@ -355,5 +359,9 @@ abstract class UnixBuilderBase extends BuilderBase
shell()->cd(BUILD_BIN_PATH)
->setEnv($env)
->exec("xcaddy build --output frankenphp {$xcaddyModules}");
if (!$this->getOption('no-strip', false) && file_exists(BUILD_BIN_PATH . '/frankenphp')) {
shell()->cd(BUILD_BIN_PATH)->exec('strip --strip-all frankenphp');
}
}
}

View File

@@ -16,10 +16,20 @@ trait libaom
*/
protected function build(): void
{
$cc = getenv('CC');
$cxx = getenv('CXX');
if (str_contains($cc, 'zig') && getenv('SPC_LIBC') === 'musl') {
putenv('CC=' . $cc . ' -D_POSIX_SOURCE');
putenv('CXX=' . $cxx . ' -D_POSIX_SOURCE');
}
UnixCMakeExecutor::create($this)
->setBuildDir("{$this->source_dir}/builddir")
->addConfigureArgs('-DAOM_TARGET_CPU=generic')
->build();
if (str_contains($cc, 'zig') && getenv('SPC_LIBC') === 'musl') {
putenv('CC=' . $cc);
putenv('CXX=' . $cxx);
}
$this->patchPkgconfPrefix(['aom.pc']);
}
}

View File

@@ -14,6 +14,9 @@ trait ncurses
$filelist = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true);
UnixAutoconfExecutor::create($this)
->appendEnv([
'LDFLAGS' => getenv('SPC_LIBC') === 'musl' ? '-static' : '',
])
->configure(
'--enable-overwrite',
'--with-curses-h',

View File

@@ -29,6 +29,9 @@ class LinuxMuslCheck
if (getenv('SPC_LIBC') === 'glibc') {
return CheckResult::ok('Building with glibc, skipped');
}
if (str_contains(getenv('CC'), 'zig')) {
return CheckResult::ok('Building with zig, skipped');
}
$musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m'));
if (file_exists($musl_wrapper_lib) && file_exists('/usr/local/musl/lib/libc.a')) {
@@ -46,6 +49,9 @@ class LinuxMuslCheck
if (getenv('SPC_LIBC') === 'glibc') {
return CheckResult::ok('Building with glibc, skipped');
}
if (str_contains(getenv('CC'), 'zig')) {
return CheckResult::ok('Building with zig, skipped');
}
$arch = arch2gnu(php_uname('m'));
$cross_compile_lib = "/usr/local/musl/{$arch}-linux-musl/lib/libc.a";

View File

@@ -1,6 +1,5 @@
#!/usr/bin/env bash
LIBDIR="$(realpath "$(dirname "$(gcc -print-file-name=libc.so)")")"
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
BUILDROOT_ABS="$(realpath "$SCRIPT_DIR/../../buildroot/include" 2>/dev/null || echo "")"
PARSED_ARGS=()
@@ -69,7 +68,7 @@ else
TARGET="${SPC_TARGET}-${SPC_LIBC}"
[ -n "$SPC_LIBC_VERSION" ] && TARGET="${TARGET}.${SPC_LIBC_VERSION}"
output=$(zig cc -target "$TARGET" -L"$LIBDIR" -lstdc++ "${PARSED_ARGS[@]}" 2>&1)
output=$(zig cc -target "$TARGET" -lstdc++ "${PARSED_ARGS[@]}" 2>&1)
status=$?
filtered_output=$(echo "$output" | grep -v "version '.*' in target triple")
@@ -81,7 +80,7 @@ else
if echo "$output" | grep -q "version '.*' in target triple"; then
TARGET_FALLBACK="${SPC_TARGET}-${SPC_LIBC}"
output=$(zig cc -target "$TARGET_FALLBACK" -L"$LIBDIR" -lstdc++ "${PARSED_ARGS[@]}" 2>&1)
output=$(zig cc -target "$TARGET_FALLBACK" -lstdc++ "${PARSED_ARGS[@]}" 2>&1)
status=$?
filtered_output=$(echo "$output" | grep -v "version '.*' in target triple")

View File

@@ -44,7 +44,13 @@ class GlobalEnvManager
// Define env vars for linux
if (PHP_OS_FAMILY === 'Linux') {
$arch = getenv('GNU_ARCH');
if (SystemUtil::isMuslDist() || getenv('SPC_LIBC') === 'glibc') {
if (str_contains((string) getenv('CC'), 'zig')) {
self::putenv('SPC_LINUX_DEFAULT_CC=zig-cc');
self::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++');
self::putenv('SPC_LINUX_DEFAULT_AR=ar');
self::putenv('SPC_LINUX_DEFAULT_LD=ld.lld');
} elseif (SystemUtil::isMuslDist() || getenv('SPC_LIBC') === 'glibc') {
self::putenv('SPC_LINUX_DEFAULT_CC=gcc');
self::putenv('SPC_LINUX_DEFAULT_CXX=g++');
self::putenv('SPC_LINUX_DEFAULT_AR=ar');

View File

@@ -0,0 +1,11 @@
--- a/config.m4
+++ b/config.m4
@@ -1307,7 +1307,7 @@
PHP_REQUIRE_CXX()
- CXXFLAGS="$CXXFLAGS -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations"
+ CXXFLAGS="$CXXFLAGS -Wall -Wno-date-time -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations"
if test "$SW_OS" = "CYGWIN" || test "$SW_OS" = "MINGW"; then
CXXFLAGS="$CXXFLAGS -std=gnu++14"

View File

@@ -35,10 +35,13 @@ $test_os = [
$zig = true;
// temporary!
if ($zig) {
putenv('SPC_LIBC=glibc');
putenv('SPC_LIBC_VERSION=2.17');
putenv('SPC_LIBC=musl');
// putenv('SPC_LIBC_VERSION=2.17');
putenv('CC=zig-cc');
putenv('CXX=zig-c++');
putenv('AR=ar');
putenv('LD=ld.lld');
exec('ulimit -n 2048');
}
// whether enable thread safe
@@ -57,7 +60,7 @@ $prefer_pre_built = true;
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'apcu,ast,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,iconv,libxml,mbregex,mbstring,opcache,openssl,pcntl,phar,posix,readline,session,simplexml,sockets,sodium,tokenizer,xml,xmlreader,xmlwriter,zip,zlib',
'Linux', 'Darwin' => 'apcu,ast,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,iconv,libxml,mbregex,mbstring,opcache,openssl,pcntl,phar,posix,readline,session,simplexml,sockets,sodium,tokenizer,xml,xmlreader,xmlwriter,zip,zlib,amqp,brotli,bz2,dio,ds,ev,event,ffi,ftp,gd,gettext,gmp,gmssl,igbinary,imagick,inotify,intl,ldap,lz4,memcache,memcached,mongodb,msgpack,mysqli,mysqlnd,odbc,opentelemetry,parallel,pdo,pdo_mysql,pdo_odbc,pdo_pgsql,pdo_sqlite,pdo_sqlsrv,pgsql,protobuf,rar,redis,rdkafka,shmop,spx,sqlite3,sqlsrv,ssh2,swoole,sysvmsg,sysvsem,sysvshm,tidy,uuid,uv,xhprof,xlswriter,xsl,xz,yac,yaml,zstd',
'Windows' => 'intl',
};