47 lines
1.9 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\builder\linux\library\LinuxLibraryBase;
use SPC\builder\macos\library\MacOSLibraryBase;
2025-06-09 19:32:31 +08:00
use SPC\util\executor\UnixAutoconfExecutor;
2025-06-05 09:44:03 +07:00
trait ngtcp2
{
protected function build(): void
{
2025-06-09 19:32:31 +08:00
UnixAutoconfExecutor::create($this)
->optionalLib('openssl', fn (LinuxLibraryBase|MacOSLibraryBase $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 (LinuxLibraryBase|MacOSLibraryBase $lib) => implode(' ', [
'--with-brotlidec=yes',
"LIBBROTLIDEC_CFLAGS=\"-I{$lib->getIncludeDir()}\"",
"LIBBROTLIDEC_LIBS=\"{$lib->getStaticLibFiles()}\"",
2025-06-09 19:32:31 +08:00
'--with-libbrotlienc=yes',
"LIBBROTLIENC_CFLAGS=\"-I{$lib->getIncludeDir()}\"",
"LIBBROTLIENC_LIBS=\"{$lib->getStaticLibFiles()}\"",
2025-06-09 19:32:31 +08:00
])
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
$AR = getenv('AR') ?: 'ar';
2025-07-27 01:10:21 +07:00
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
}
}