Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决curl 链接brotli库时找不到的问题 #36

Closed
wants to merge 8 commits into from
12 changes: 9 additions & 3 deletions conf.d/swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@
return function (Preprocessor $p) {
// curl/imagemagick 对 brotli 静态库的支持有点问题,暂时关闭
$options = '--enable-swoole --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-cares';
if ($p->getInputOption('with-brotli')) {
if (1 || $p->getInputOption('with-brotli')) {
$p->addLibrary(
(new Library('brotli'))
->withManual('https://github.com/google/brotli')//有多种构建方式,选择cmake 构建
->withUrl('https://github.com/google/brotli/archive/refs/tags/v1.0.9.tar.gz')
->withFile('brotli-1.0.9.tar.gz')
//->withCleanBuildDirectory()
->withPrefix(BROTLI_PREFIX)
->withConfigure('cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=' . BROTLI_PREFIX . ' .')
->withConfigure('cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=' . BROTLI_PREFIX . ' . && \\'.PHP_EOL.
'cmake --build . --config Release --target install'
)
->withSkipMakeAndMakeInstall()
->withScriptAfterInstall(
implode(PHP_EOL, [
'rm -rf ' . BROTLI_PREFIX . '/lib/*.so.*',
'rm -rf ' . BROTLI_PREFIX . '/lib/*.so',
'rm -rf ' . BROTLI_PREFIX . '/lib/*.dylib',
'mv ' . BROTLI_PREFIX . '/lib/libbrotlicommon-static.a ' . BROTLI_PREFIX . '/lib/libbrotli.a',
'cp ' . BROTLI_PREFIX . '/lib/libbrotlicommon-static.a ' . BROTLI_PREFIX . '/lib/libbrotli.a',
'mv ' . BROTLI_PREFIX . '/lib/libbrotlicommon-static.a ' . BROTLI_PREFIX . '/lib/libbrotlicommon.a',
'mv ' . BROTLI_PREFIX . '/lib/libbrotlienc-static.a ' . BROTLI_PREFIX . '/lib/libbrotlienc.a',
'mv ' . BROTLI_PREFIX . '/lib/libbrotlidec-static.a ' . BROTLI_PREFIX . '/lib/libbrotlidec.a',
]))
Expand Down
23 changes: 23 additions & 0 deletions sapi/Preprocessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
abstract class Project
{
public string $name;

public string $manual = '';
public string $homePage = '';
public string $license = '';
public string $prefix = '';
Expand Down Expand Up @@ -47,6 +49,12 @@ function depends(string ...$libs): static
$this->deps += $libs;
return $this;
}

public function withManual(string $manua):static
{
$this->manual = $manua;
return $this;
}
}

class Library extends Project
Expand All @@ -56,6 +64,9 @@ class Library extends Project
public string $configure = '';
public string $file = '';
public string $ldflags = '';

public bool $cleanBuildDirectory = false;
public bool $skipMakeAndMakeInstall = false;
public string $makeOptions = '';
public string $makeVariables = '';
public string $makeInstallCommand = 'install';
Expand Down Expand Up @@ -108,6 +119,18 @@ function withLdflags(string $ldflags): static
return $this;
}


public function withCleanBuildDirectory():static
{
$this->cleanBuildDirectory = true;
return $this;
}

public function withSkipMakeAndMakeInstall():static
{
$this->skipMakeAndMakeInstall = true;
}

function withMakeVariables(string $variables): static
{
$this->makeVariables = $variables;
Expand Down
6 changes: 6 additions & 0 deletions sapi/make.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
make_<?=$item->name?>() {
echo "build <?=$item->name?>"

<?php if($item->cleanBuildDirectory): ?>
# If the build directory exist, clean the build directory
test -d <?=$this->getBuildDir()?>/<?=$item->name?> && rm -rf <?=$this->getBuildDir()?>/<?=$item->name?> ;
<?php endif; ?>
# If the source code directory does not exist, create a directory and decompress the source code archive
if [ ! -d <?= $this->getBuildDir() ?>/<?= $item->name ?> ]; then
mkdir -p <?= $this->getBuildDir() ?>/<?= $item->name . PHP_EOL ?>
Expand Down Expand Up @@ -51,6 +55,7 @@
[[ $result_code -ne 0 ]] && echo "[<?=$item->name?>] [configure FAILURE]" && exit $result_code;
<?php endif; ?>

<?php if(!$item->skipMakeAndMakeInstall): ?>
# make
make -j <?= $this->maxJob ?> <?= $item->makeOptions . PHP_EOL ?>
result_code=$?
Expand All @@ -68,6 +73,7 @@
make <?= $item->makeInstallCommand ?> <?= $item->makeInstallOptions ?> <?= PHP_EOL ?>
result_code=$?
[[ $result_code -ne 0 ]] && echo "[<?=$item->name?>] [make install FAILURE]" && exit $result_code;
<?php endif; ?>
<?php endif; ?>

# after make install
Expand Down