2025-06-05 09:44:03 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\builder\unix\library;
|
|
|
|
|
|
2025-07-22 22:25:46 +08:00
|
|
|
use SPC\builder\linux\library\LinuxLibraryBase;
|
|
|
|
|
use SPC\builder\macos\library\MacOSLibraryBase;
|
2025-06-05 09:44:03 +07:00
|
|
|
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)
|
2025-07-22 22:25:46 +08:00
|
|
|
->optionalLib('openssl', fn (LinuxLibraryBase|MacOSLibraryBase $lib) => implode(' ', [
|
2025-06-10 15:37:39 +08:00
|
|
|
'--with-openssl=yes',
|
2025-07-22 22:25:46 +08:00
|
|
|
"OPENSSL_LIBS=\"{$lib->getStaticLibFiles()}\"",
|
|
|
|
|
"OPENSSL_CFLAGS=\"-I{$lib->getIncludeDir()}\"",
|
2025-06-10 15:37:39 +08:00
|
|
|
]), '--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',
|
2025-07-22 22:25:46 +08:00
|
|
|
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',
|
2025-07-22 22:25:46 +08:00
|
|
|
"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
|
|
|
)
|
2025-06-10 15:37:39 +08: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']);
|
2025-06-10 19:46:55 +07:00
|
|
|
$this->patchLaDependencyPrefix();
|
2025-06-07 10:23:10 +07:00
|
|
|
|
|
|
|
|
// 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
|
2025-07-27 00:59:32 +07:00
|
|
|
$AR = getenv('AR') ?: 'ar';
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|