Skip to content

Commit a33baf8

Browse files
authored
Merge pull request #945 from jingjingxyk/build_native_php
Build native php
2 parents e976a1f + d90dd68 commit a33baf8

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

sapi/quickstart/linux/alpine-init.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,14 @@ apk update
4343
apk add vim alpine-sdk xz autoconf automake linux-headers clang-dev clang lld libtool cmake bison re2c coreutils gcc g++
4444
apk add bash zip unzip flex pkgconf ca-certificates
4545
apk add tar gzip zip unzip bzip2
46+
apk add 7zip
4647
apk add gettext gettext-dev
47-
48-
apk add bash 7zip
49-
# apk add bash p7zip
50-
5148
apk add wget git curl
5249
apk add libc++-static libltdl-static
5350
apk add yasm nasm
5451
apk add ninja python3 py3-pip
5552
apk add diffutils
56-
apk add netcat-openbsd socat
53+
apk add socat
5754
apk add python3-dev
5855
apk add mercurial
5956
apk add pigz parallel

sapi/src/builder/extension/opentelemetry.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
use SwooleCli\Extension;
66

77
return function (Preprocessor $p) {
8-
return null;//待改进
9-
//PHP 构建选项
108
$options = ' --enable-opentelemetry ';
11-
129
$ext = (new Extension('opentelemetry'))
1310
->withOptions($options)
1411
->withHomePage('https://opentelemetry.io/')
@@ -24,5 +21,15 @@
2421
2522
EOF
2623
);
24+
$p->withBeforeConfigureScript('opentelemetry', function (Preprocessor $p) {
25+
$workDir = $p->getPhpSrcDir();
26+
$cmd=<<<EOF
27+
cd {$workDir}/ext/opentelemetry/
28+
29+
sed -i '' 's/static void check_conflicts()/static void check_conflicts(void)/' opentelemetry.c
30+
sed -i '' 's/static otel_observer \*create_observer()/static otel_observer \*create_observer(void)/' otel_observer.c
31+
EOF;
32+
return $cmd;
33+
});
2734
$p->addExtension($ext);
2835
};

sapi/src/builder/extension/swoole.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// v5.1.x 不支持 PHP 8.4
1515
// swoole 支持计划 https://wiki.swoole.com/zh-cn/#/version/supported?id=%e6%94%af%e6%8c%81%e8%ae%a1%e5%88%92
1616

17-
$swoole_tag = 'v6.0.1';
17+
$swoole_tag = 'v6.0.2';
1818
$file = "swoole-{$swoole_tag}.tar.gz";
1919

2020
$url = "https://github.com/swoole/swoole-src/archive/refs/tags/{$swoole_tag}.tar.gz";
@@ -67,6 +67,35 @@
6767
->withDependentLibraries(...$dependentLibraries)
6868
->withDependentExtensions(...$dependentExtensions));
6969

70+
$p->withBeforeConfigureScript('swoole', function (Preprocessor $p) {
71+
$cmd = '';
72+
if ($p->isMacos()) {
73+
$workDir = $p->getPhpSrcDir() ;
74+
$cmd = <<<EOF
75+
cd {$workDir}/
76+
sed -i '' 's/pthread_barrier_init/pthread_barrier_init_x_fake/' ext/swoole/config.m4
77+
EOF;
78+
}
79+
return $cmd;
80+
81+
});
82+
if ($p->isMacos()) {
83+
# 测试 macos 专有特性
84+
# 定义 _GNU_SOURCE 会隐式启用 _POSIX_C_SOURCE=200112L 和 _XOPEN_SOURCE=600
85+
# export CFLAGS="$CFLAGS " # -D_DARWIN_C_SOURCE=1 -D_XOPEN_SOURCE=700 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L
86+
# export LIBS="-Wl,--start-group -pthread -Wl,--end-group"
87+
# export LIBS="-Wl,--whole-archive -pthread -Wl,--no-whole-archive "
88+
89+
# 新版macos getdtablesize 函数缺失
90+
# sed -i '' 's/getdtablesize();/sysconf(_SC_OPEN_MAX);/' ext/standard/php_fopen_wrapper.c
91+
$libc = $p->isMacos() ? '-lc++' : '-lstdc++';
92+
93+
# cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/_pthread
94+
# 或者
95+
# cd /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/sys/_pthread
96+
# grep -r 'pthread_barrier_init' .
97+
# grep -r 'pthread_barrier_t' .
98+
}
7099
$p->withVariable('LIBS', '$LIBS ' . ($p->isMacos() ? '-lc++' : '-lstdc++'));
71100
$p->withExportVariable('CARES_CFLAGS', '$(pkg-config --cflags --static libcares)');
72101
$p->withExportVariable('CARES_LIBS', '$(pkg-config --libs --static libcares)');

sapi/src/template/make.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,6 @@
247247
export LIBS="$LIBS -lcrypto -lssl -lmpdec -lmpdec++ -lbz2 -llzma -lHacl_Hash_SHA2 -lb2 -lexpat -lxml2 -lform -lmenu -ltic -lpanel -lncurses++ -lncurses "
248248
<?php endif; ?>
249249
<?php endif; ?>
250-
<?php if ($this->isMacos()) : ?>
251-
<?php if ($this->hasExtension('swoole')) : ?>
252-
export LIBS="$LIBS -lpthread"
253-
<?php endif; ?>
254-
<?php endif; ?>
255250
<?php if ($this->isLinux() && ($this->get_C_COMPILER() == 'musl-gcc')) : ?>
256251
ln -sf /usr/include/linux/ /usr/include/x86_64-linux-musl/linux
257252
ln -sf /usr/include/x86_64-linux-gnu/asm/ /usr/include/x86_64-linux-musl/asm

0 commit comments

Comments
 (0)