Skip to content

Commit e0734fe

Browse files
committed
Add frameworks for extension
1 parent 2ea8a7e commit e0734fe

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

config/ext.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@
424424
"openssl",
425425
"zstd",
426426
"zlib"
427+
],
428+
"frameworks": [
429+
"CoreFoundation",
430+
"Security"
427431
]
428432
},
429433
"msgpack": {

src/SPC/builder/Extension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public function __construct(protected string $name, protected BuilderBase $build
5353
}
5454
}
5555

56+
public function getFrameworks(): array
57+
{
58+
return Config::getExt($this->getName(), 'frameworks', []);
59+
}
60+
5661
/**
5762
* 获取开启该扩展的 PHP 编译添加的参数
5863
*

src/SPC/builder/macos/MacOSBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public function getFrameworks(bool $asString = false): array|string
6767
array_push($frameworks, ...$lib->getFrameworks());
6868
}
6969

70+
foreach ($this->exts as $ext) {
71+
array_push($frameworks, ...$ext->getFrameworks());
72+
}
73+
7074
if ($asString) {
7175
return implode(' ', array_map(fn ($x) => "-framework {$x}", $frameworks));
7276
}

src/SPC/util/SPCConfigUtil.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ public function config(array $extensions = [], array $libraries = [], bool $incl
5555
ob_get_clean();
5656
$ldflags = $this->getLdflagsString();
5757
$libs = $this->getLibsString($libraries, $with_dependencies);
58+
if (PHP_OS_FAMILY === 'Darwin') {
59+
$libs .= " {$this->getFrameworksString($extensions)}";
60+
}
5861
$cflags = $this->getIncludesString();
5962

6063
// embed
61-
$libs = '-lphp -lc ' . $libs;
64+
$libs = trim("-lphp -lc {$libs}");
6265
$extra_env = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS');
6366
if (is_string($extra_env)) {
6467
$libs .= ' ' . trim($extra_env, '"');
@@ -157,4 +160,18 @@ private function getShortLibName(string $lib): string
157160
// get short name
158161
return '-l' . substr($lib, 3, -2);
159162
}
163+
164+
private function getFrameworksString(array $extensions): string
165+
{
166+
$list = [];
167+
foreach ($extensions as $extension) {
168+
foreach (Config::getExt($extension, 'frameworks', []) as $fw) {
169+
$ks = '-framework ' . $fw;
170+
if (!in_array($ks, $list)) {
171+
$list[] = $ks;
172+
}
173+
}
174+
}
175+
return implode(' ', $list);
176+
}
160177
}

0 commit comments

Comments
 (0)