mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
support static-only libs
This commit is contained in:
parent
fed477c81d
commit
1e6ddb86f2
@ -303,6 +303,9 @@
|
|||||||
},
|
},
|
||||||
"krb5": {
|
"krb5": {
|
||||||
"source": "krb5",
|
"source": "krb5",
|
||||||
|
"target": [
|
||||||
|
"static"
|
||||||
|
],
|
||||||
"pkg-configs": [
|
"pkg-configs": [
|
||||||
"krb5-gssapi"
|
"krb5-gssapi"
|
||||||
],
|
],
|
||||||
|
|||||||
@ -96,7 +96,8 @@ class Extension
|
|||||||
fn ($x) => $x->getStaticLibFiles(),
|
fn ($x) => $x->getStaticLibFiles(),
|
||||||
$this->getLibraryDependencies(recursive: true)
|
$this->getLibraryDependencies(recursive: true)
|
||||||
);
|
);
|
||||||
return implode(' ', $ret);
|
$libs = implode(' ', $ret);
|
||||||
|
return deduplicate_flags($libs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -59,11 +59,10 @@ class PkgConfigUtil
|
|||||||
* @param string $pkg_config_str .pc file string, accepts multiple files
|
* @param string $pkg_config_str .pc file string, accepts multiple files
|
||||||
* @return string CFLAGS string, e.g. "-Wno-implicit-int-float-conversion ..."
|
* @return string CFLAGS string, e.g. "-Wno-implicit-int-float-conversion ..."
|
||||||
*/
|
*/
|
||||||
public static function getCflags(string $pkg_config_str): string
|
public static function getCflags(string $pkg_config_str, string $extra = '--static'): string
|
||||||
{
|
{
|
||||||
$static = getenv('SPC_LINK_STATIC') ? '--static' : '';
|
|
||||||
// get other things
|
// get other things
|
||||||
$result = self::execWithResult("pkg-config {$static} --cflags-only-other {$pkg_config_str}");
|
$result = self::execWithResult("pkg-config {$extra} --cflags-only-other {$pkg_config_str}");
|
||||||
return trim($result);
|
return trim($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,15 +75,14 @@ class PkgConfigUtil
|
|||||||
* @param string $pkg_config_str .pc file string, accepts multiple files
|
* @param string $pkg_config_str .pc file string, accepts multiple files
|
||||||
* @return array Unique libs array, e.g. [-lz, -lxml, ...]
|
* @return array Unique libs array, e.g. [-lz, -lxml, ...]
|
||||||
*/
|
*/
|
||||||
public static function getLibsArray(string $pkg_config_str): array
|
public static function getLibsArray(string $pkg_config_str, string $extra = '--static'): array
|
||||||
{
|
{
|
||||||
// Use this instead of shell() to avoid unnecessary outputs
|
// Use this instead of shell() to avoid unnecessary outputs
|
||||||
$static = getenv('SPC_LINK_STATIC') ? '--static' : '';
|
$result = self::execWithResult("pkg-config {$extra} --libs-only-l {$pkg_config_str}");
|
||||||
$result = self::execWithResult("pkg-config {$static} --libs-only-l {$pkg_config_str}");
|
|
||||||
$libs = explode(' ', trim($result));
|
$libs = explode(' ', trim($result));
|
||||||
|
|
||||||
// get other things
|
// get other things
|
||||||
$result = self::execWithResult("pkg-config {$static} --libs-only-other {$pkg_config_str}");
|
$result = self::execWithResult("pkg-config {$extra} --libs-only-other {$pkg_config_str}");
|
||||||
// convert libxxx.a to -L{path} -lxxx
|
// convert libxxx.a to -L{path} -lxxx
|
||||||
$exp = explode(' ', trim($result));
|
$exp = explode(' ', trim($result));
|
||||||
foreach ($exp as $item) {
|
foreach ($exp as $item) {
|
||||||
|
|||||||
@ -235,7 +235,8 @@ class SPCConfigUtil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$pc_cflags = implode(' ', $pc);
|
$pc_cflags = implode(' ', $pc);
|
||||||
if ($pc_cflags !== '' && ($pc_cflags = PkgConfigUtil::getCflags($pc_cflags)) !== '') {
|
$static = getenv('SPC_LINK_STATIC') ? '--static' : '';
|
||||||
|
if ($pc_cflags !== '' && ($pc_cflags = PkgConfigUtil::getCflags($pc_cflags, $static)) !== '') {
|
||||||
$arr = explode(' ', $pc_cflags);
|
$arr = explode(' ', $pc_cflags);
|
||||||
$arr = array_unique($arr);
|
$arr = array_unique($arr);
|
||||||
$arr = array_filter($arr, fn ($x) => !str_starts_with($x, 'SHELL:-Xarch_'));
|
$arr = array_filter($arr, fn ($x) => !str_starts_with($x, 'SHELL:-Xarch_'));
|
||||||
@ -260,6 +261,11 @@ class SPCConfigUtil
|
|||||||
foreach ($libraries as $library) {
|
foreach ($libraries as $library) {
|
||||||
// add pkg-configs libs
|
// add pkg-configs libs
|
||||||
$pkg_configs = Config::getLib($library, 'pkg-configs', []);
|
$pkg_configs = Config::getLib($library, 'pkg-configs', []);
|
||||||
|
$static = getenv('SPC_LINK_STATIC') ? '--static' : null;
|
||||||
|
if (!$static) {
|
||||||
|
$target = Config::getLib($library, 'target');
|
||||||
|
$static = $target && !in_array('shared', $target) ? '--static' : '';
|
||||||
|
}
|
||||||
$pkg_config_path = getenv('PKG_CONFIG_PATH') ?: '';
|
$pkg_config_path = getenv('PKG_CONFIG_PATH') ?: '';
|
||||||
$search_paths = array_filter(explode(is_unix() ? ':' : ';', $pkg_config_path));
|
$search_paths = array_filter(explode(is_unix() ? ':' : ';', $pkg_config_path));
|
||||||
foreach ($pkg_configs as $file) {
|
foreach ($pkg_configs as $file) {
|
||||||
@ -276,7 +282,7 @@ class SPCConfigUtil
|
|||||||
$pkg_configs = implode(' ', $pkg_configs);
|
$pkg_configs = implode(' ', $pkg_configs);
|
||||||
if ($pkg_configs !== '') {
|
if ($pkg_configs !== '') {
|
||||||
// static libs with dependencies come in reverse order, so reverse this too
|
// static libs with dependencies come in reverse order, so reverse this too
|
||||||
$pc_libs = array_reverse(PkgConfigUtil::getLibsArray($pkg_configs));
|
$pc_libs = array_reverse(PkgConfigUtil::getLibsArray($static, $pkg_configs));
|
||||||
$lib_names = [...$lib_names, ...$pc_libs];
|
$lib_names = [...$lib_names, ...$pc_libs];
|
||||||
}
|
}
|
||||||
// convert all static-libs to short names
|
// convert all static-libs to short names
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user