Skip to content

Commit

Permalink
Merge pull request #671 from jingjingxyk/build_native_php
Browse files Browse the repository at this point in the history
update Build native php
  • Loading branch information
jingjingxyk committed Jul 6, 2024
2 parents 3664955 + c8e7926 commit a02b9e4
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 58 deletions.
98 changes: 50 additions & 48 deletions docs/extensions.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,56 @@
# support extensions (x64)

| extension name | linux6 | macos | windows(cygwin) | default enabled |
|----------------|--------|-------|-----------------|-----------------|
| curl |||||
| iconv |||||
| bcmath |||||
| pcntl |||||
| filter |||||
| session |||||
| tokenizer |||||
| mbstring |||||
| ctype |||||
| zlib |||||
| zip |||||
| posix |||||
| sockets |||||
| pdo |||||
| sqlite3 |||||
| phar |||||
| mysqlnd |||||
| mysqli |||||
| intl |||||
| fileinfo |||||
| pdo_mysql |||||
| soap |||||
| xsl |||||
| gmp |||||
| exif |||||
| sodium |||||
| openssl |||||
| readline |||||
| libxml |||||
| xml |||||
| xmlreader |||||
| xmlwriter |||||
| dom |||||
| simplexml |||||
| redis |||||
| yaml |||||
| imagick |||||
| gd |||||
| opcache |||||
| swoole |||||
| ssh2 |||||
| apcu |||||
| ds |||||
| inotify |||||
| protobuf |||||
| uuid |||||
| mongodb |||||
|----------------|--------|-------|-----------------|----------------|
| curl |||||
| iconv |||||
| bcmath |||||
| pcntl |||||
| filter |||||
| session |||||
| tokenizer |||||
| mbstring |||||
| ctype |||||
| zlib |||||
| zip |||||
| posix |||||
| sockets |||||
| pdo |||||
| sqlite3 |||||
| phar |||||
| mysqlnd |||||
| mysqli |||||
| intl |||||
| fileinfo |||||
| pdo_mysql |||||
| soap |||||
| xsl |||||
| gmp |||||
| exif |||||
| sodium |||||
| openssl |||||
| readline |||||
| libxml |||||
| xml |||||
| xmlreader |||||
| xmlwriter |||||
| dom |||||
| simplexml |||||
| redis |||||
| yaml |||||
| imagick |||||
| gd |||||
| opcache |||||
| swoole |||||
| ssh2 |||||
| apcu |||||
| ds |||||
| inotify |||||
| protobuf |||||
| uuid |||||
| mailparse |||||
| mongodb |||||




2 changes: 1 addition & 1 deletion sapi/quickstart/linux/alpine-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ apk add libc++-static libltdl-static
apk add yasm nasm
apk add ninja python3 py3-pip
apk add diffutils
apk add netcat-openbsd
apk add netcat-openbsd socat
apk add python3-dev
apk add mercurial
apk add gettext-dev
Expand Down
2 changes: 1 addition & 1 deletion sapi/quickstart/linux/debian-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ apt install -y musl-dev musl-tools
apt install -y python3 python3-pip ninja-build diffutils
apt install -y yasm nasm
apt install -y meson
apt install -y netcat-openbsd
apt install -y netcat-openbsd socat

case "$MIRROR" in
china | tuna | ustc)
Expand Down
29 changes: 29 additions & 0 deletions sapi/quickstart/macos/macos-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,32 @@ brew uninstall --ignore-dependencies --force snappy
brew uninstall --ignore-dependencies --force capstone




brew install xz zip unzip gzip bzip2 7zip p7zip
brew install git ca-certificates

brew install yasm nasm
brew install ninja python3
brew install diffutils
brew install netcat socat
brew install mercurial


case "$MIRROR" in
china | tuna | ustc)
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
test "$MIRROR" = "ustc" && pip3 config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
;;
tencentyun | huaweicloud)
test "$MIRROR" = "tencentyun" && pip3 config set global.index-url https://mirrors.tencentyun.com/pypi/simple/
test "$MIRROR" = "huaweicloud" && pip3 config set global.index-url https://repo.huaweicloud.com/pypi/simple/
esac

pip3 install meson


brew uninstall --ignore-dependencies --force snappy
brew uninstall --ignore-dependencies --force capstone


37 changes: 36 additions & 1 deletion sapi/src/Preprocessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ public function setLogicalProcessors(string $logicalProcessors): static
return $this;
}

/**
* @param string $buildType 构建类型 [ release | dev | debug ]
* @return $this
*
*/
public function setBuildType(string $buildType): static
{
$this->buildType = $buildType;
Expand All @@ -352,33 +357,63 @@ public function getBuildType(): string
return $this->buildType;
}

/**
* 生成代理配置
* @param string $shell (http_proxy 代理配置 + no_proxy配置 )
* @param string $httpProxy (http 代理配置 )
* @return $this
*/
public function setProxyConfig(string $shell = '', string $httpProxy = ''): static
{
$this->proxyConfig = $shell;
$this->httpProxy = $httpProxy;
$proxyInfo = parse_url($httpProxy);
if (!empty($proxyInfo['scheme']) && !empty($proxyInfo['host']) && !empty($proxyInfo['port'])) {
$proto = '';
$socat_proxy_proto = '';

switch (strtolower($proxyInfo['scheme'])) {
case 'socks5':
case "socks5h":
$proto = 5;
$socat_proxy_proto = 'socks4a';
break;
case "socks4a":
case 'socks4':
$proto = 4;
$socat_proxy_proto = 'socks4a';
break;
default:
$proto = "connect";
$socat_proxy_proto = 'proxy';
break;
}

/*
* sockat 代理例子
* http://www.dest-unreach.org/socat/doc/socat.html
* socat - socks4a:<socks-server>::%h:%p,socksport=2000
* socat - proxy:<proxy-server>:%h:%p,proxyport=2000
*/

$socat_proxy_cmd = '';
if ($socat_proxy_proto == 'socks4a') {
$socat_proxy_cmd = "socat - socks4a:{$proxyInfo['host']}:\\$1:\\$2,socksport={$proxyInfo['port']}";
} else {
$socat_proxy_cmd = "socat - proxy:{$proxyInfo['host']}:\\$1:\\$2,proxyport={$proxyInfo['port']}";
}

$this->gitProxyConfig = <<<__GIT_PROXY_CONFIG_EOF
export GIT_PROXY_COMMAND=/tmp/git-proxy;
cat > \$GIT_PROXY_COMMAND <<___EOF___
#!/bin/bash
nc -X {$proto} -x {$proxyInfo['host']}:{$proxyInfo['port']} "\\$1" "\\$2"
# macos环境下 nc 不可用, 使用 socat 代替
# nc -X {$proto} -x {$proxyInfo['host']}:{$proxyInfo['port']} "\\$1" "\\$2"
{$socat_proxy_cmd};
___EOF___
chmod +x \$GIT_PROXY_COMMAND;
Expand Down
16 changes: 16 additions & 0 deletions sapi/src/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,34 @@ public function hashVerify(string $file): bool
return $this->hashVerify;
}

/**
* https 下载地址
* @param string $url
* @return $this
*/
public function withUrl(string $url): static
{
$this->url = $url;
return $this;
}

/**
* 指定下载的源码包名称
* @param string $file
* @return $this
*/
public function withFile(string $file): static
{
$this->file = $file;
return $this;
}

/**
* 使用脚本下载源码包
* @param string $downloadDirName 被打包压缩的的目录
* @param string $script 待执行的下载脚本
* @return $this
*/
public function withDownloadScript(string $downloadDirName, string $script): static
{
$this->enableDownloadScript = true;
Expand Down
12 changes: 10 additions & 2 deletions sapi/src/builder/extension/aaa_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

//默认这个名称应该和扩展名称一致、和本文件名称一致 ;
$ext = (new Extension('aaa_example'))

/*

//设置别名 ; 定义的名字和扩展名字不一致时,需要设置别名为扩展名称
Expand All @@ -37,7 +36,6 @@
->withLicense('https://github.com/swoole/swoole-src/blob/master/LICENSE', Extension::LICENSE_APACHE2)
->withHomePage('https://github.com/swoole/swoole-src')
->withManual('https://wiki.swoole.com/#/')

/*

//明确申明 使用源地址下载
Expand Down Expand Up @@ -135,4 +133,14 @@

return $cmd;
});

//导入环境变量

$p->withExportVariable('FREETYPE2_CFLAGS', '$(pkg-config --cflags --static libbrotlicommon libbrotlidec libbrotlienc freetype2 zlib libpng)');
$p->withExportVariable('FREETYPE2_LIBS', '$(pkg-config --libs --static libbrotlicommon libbrotlidec libbrotlienc freetype2 zlib libpng)');

$libiconv_prefix = ICONV_PREFIX;
$p->withVariable('CPPFLAGS', '$CPPFLAGS -I' . $libiconv_prefix . '/include');
$p->withVariable('LDFLAGS', '$LDFLAGS -L' . $libiconv_prefix . '/lib');
$p->withVariable('LIBS', '$LIBS -liconv');
};
16 changes: 16 additions & 0 deletions sapi/src/builder/extension/mailparse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use SwooleCli\Preprocessor;
use SwooleCli\Extension;

return function (Preprocessor $p) {
$p->addExtension(
(new Extension('mailparse'))
->withHomePage('https://pecl.php.net/package/mailparse')
->withLicense('https://github.com/php/pecl-mail-mailparse/blob/v3.1.6/LICENSE', Extension::LICENSE_BSD)
->withManual('https://github.com/php/pecl-mail-mailparse.git')
->withPeclVersion('3.1.6')
->withOptions(' --enable-mailparse ')
->withDependentExtensions('mbstring')
);
};
3 changes: 1 addition & 2 deletions sapi/src/builder/extension/swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
)
->withBuildCached(false)
->withDependentLibraries(...$dependentLibraries)
->withDependentExtensions(...$dependentExtensions)
;
->withDependentExtensions(...$dependentExtensions);

//call_user_func_array([$ext, 'withDependentLibraries'], $dependentLibraries);
//call_user_func_array([$ext, 'withDependentExtensions'], $dependentExtensions);
Expand Down
39 changes: 39 additions & 0 deletions sapi/src/builder/extension/swoole_v5.1.x.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use SwooleCli\Library;
use SwooleCli\Preprocessor;
use SwooleCli\Extension;

return function (Preprocessor $p) {
$depends = ['curl', 'openssl', 'cares', 'zlib', 'brotli', 'nghttp2', 'pgsql', 'unix_odbc', 'sqlite3'];
$options = '--enable-swoole --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-cares ';
$options .= ' --with-brotli-dir=' . BROTLI_PREFIX;
$options .= ' --with-nghttp2-dir=' . NGHTTP2_PREFIX;
$options .= ' --enable-swoole-pgsql ';
$options .= ' --with-swoole-odbc=unixODBC,' . UNIX_ODBC_PREFIX . ' ';
$options .= ' --enable-swoole-sqlite ';

$ext = (new Extension('swoole_v5.1.x'))
->withOptions($options)
->withLicense('https://github.com/swoole/swoole-src/blob/master/LICENSE', Extension::LICENSE_APACHE2)
->withHomePage('https://github.com/swoole/swoole-src')
->withManual('https://wiki.swoole.com/#/')
->withFile('swoole-v5.1.x.tar.gz')
->withDownloadScript(
'swoole-src',
<<<EOF
git clone -b 5.1.x --depth=1 https://github.com/swoole/swoole-src.git
EOF
)
->withDependentExtensions('curl', 'openssl', 'sockets', 'mysqlnd', 'pdo' );

$ext->withDependentLibraries(...$depends);
$p->addExtension($ext);

$libs = $p->isMacos() ? '-lc++' : ' -lstdc++ ';
$p->withVariable('LIBS', '$LIBS ' . $libs);

$p->withExportVariable('CARES_CFLAGS', '$(pkg-config --cflags --static libcares)');
$p->withExportVariable('CARES_LIBS', '$(pkg-config --libs --static libcares)');

};
4 changes: 2 additions & 2 deletions sapi/src/builder/library/pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
(new Library('pgsql'))
->withHomePage('https://www.postgresql.org/')
->withLicense('https://www.postgresql.org/about/licence/', Library::LICENSE_SPEC)
->withUrl('https://ftp.postgresql.org/pub/source/v16.0/postgresql-16.0.tar.gz')
->withUrl('https://ftp.postgresql.org/pub/source/v16.3/postgresql-16.3.tar.gz')
->withManual('https://www.postgresql.org/docs/current/install-procedure.html#CONFIGURE-OPTIONS')
->withManual('https://www.postgresql.org/docs/current/install-procedure.html#CONFIGURE-OPTIONS#:~:text=Client-only%20installation')
->withFileHash('md5', '30baf5fda60a34230d89c1451119ff91')
->withFileHash('md5', '8a58db4009e1a50106c5e1a8c4b03bed')
->withPrefix($pgsql_prefix)
->withCleanBuildDirectory()
->withBuildScript(
Expand Down
Loading

0 comments on commit a02b9e4

Please sign in to comment.