52 lines
2.0 KiB
PHP
Raw Normal View History

2025-06-05 09:44:03 +07:00
<?php
declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\exception\WrongUsageException;
2025-06-09 19:32:31 +08:00
use SPC\util\executor\UnixAutoconfExecutor;
2025-06-05 09:44:03 +07:00
trait ngtcp2
{
/**
* @throws FileSystemException
* @throws RuntimeException
* @throws WrongUsageException
*/
protected function build(): void
{
2025-06-09 19:32:31 +08:00
UnixAutoconfExecutor::create($this)
->optionalLib('openssl', fn ($lib) => implode(' ', [
'--with-openssl=yes',
"OPENSSL_LIBS=\"{$lib->getStaticLibFiles()}\"",
"OPENSSL_CFLAGS=\"-I{$lib->getIncludeDir()}\"",
]), '--with-openssl=no')
2025-06-09 19:32:31 +08:00
->optionalLib('libev', ...ac_with_args('libev', true))
->optionalLib('nghttp3', ...ac_with_args('libnghttp3', true))
->optionalLib('jemalloc', ...ac_with_args('jemalloc', true))
->optionalLib(
'brotli',
fn ($lib) => implode(' ', [
'--with-brotlidec=yes',
"LIBBROTLIDEC_CFLAGS=\"-I{$lib->getIncludeDir()}\"",
"LIBBROTLIDEC_LIBS=\"{$lib->getStaticLibFiles()}\"",
'--with-libbrotlienc=yes',
"LIBBROTLIENC_CFLAGS=\"-I{$lib->getIncludeDir()}\"",
"LIBBROTLIENC_LIBS=\"{$lib->getStaticLibFiles()}\"",
])
2025-06-05 09:44:03 +07:00
)
->appendEnv(['PKG_CONFIG' => '$PKG_CONFIG --static'])
2025-06-09 19:32:31 +08:00
->configure('--enable-lib-only')
->make();
2025-06-06 14:58:18 +07:00
$this->patchPkgconfPrefix(['libngtcp2.pc', 'libngtcp2_crypto_ossl.pc']);
$this->patchLaDependencyPrefix();
// on macOS, the static library may contain other static libraries?
// ld: archive member 'libssl.a' not a mach-o file in libngtcp2_crypto_ossl.a
shell()->cd(BUILD_LIB_PATH)->exec("ar -t libngtcp2_crypto_ossl.a | grep '\\.a$' | xargs -n1 ar d libngtcp2_crypto_ossl.a");
2025-06-05 09:44:03 +07:00
}
}