Skip to content

Commit f6cc6af

Browse files
committed
macos? 3
1 parent 0da8dcf commit f6cc6af

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/SPC/builder/unix/UnixBuilderBase.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use SPC\store\pkg\GoXcaddy;
1616
use SPC\toolchain\GccNativeToolchain;
1717
use SPC\toolchain\ToolchainManager;
18+
use SPC\toolchain\ZigToolchain;
1819
use SPC\util\DependencyUtil;
1920
use SPC\util\GlobalEnvManager;
2021
use SPC\util\SPCConfigUtil;
@@ -33,7 +34,7 @@ abstract class UnixBuilderBase extends BuilderBase
3334

3435
private ?string $dynamic_export_list = null;
3536

36-
public function getDynamicExportSymbolsFile(): ?string
37+
public function getDynamicExportSymbolsArgument(): ?string
3738
{
3839
if ($this->dynamic_export_list) {
3940
return $this->dynamic_export_list;
@@ -78,13 +79,21 @@ public function getDynamicExportSymbolsFile(): ?string
7879
$lines[] = '};';
7980
} else {
8081
foreach ($defined as $sym) {
81-
$lines[] = "_{$sym}";
82+
$lines[] = $sym;
8283
}
8384
}
8485
file_put_contents($exportList, implode("\n", $lines) . "\n");
8586

86-
$this->dynamic_export_list = $exportList;
87-
return $exportList;
87+
$argument = "-Wl,--dynamic-list={$exportList}";
88+
if (ToolchainManager::getToolchainClass() === ZigToolchain::class) {
89+
$argument = "-Wl,--export-dynamic";
90+
}
91+
if (SPCTarget::getTargetOS() !== 'Linux') {
92+
$argument = "-Wl,-exported_symbols_list {$exportList}";
93+
}
94+
95+
$this->dynamic_export_list = $argument;
96+
return $argument;
8897
}
8998

9099
public function proveLibs(array $sorted_libraries): void
@@ -208,13 +217,8 @@ protected function sanityCheck(int $build_target): void
208217
foreach (glob(BUILD_LIB_PATH . "/libphp*.{$suffix}") as $file) {
209218
unlink($file);
210219
}
211-
212-
if ($symbolList = $this->getDynamicExportSymbolsFile()) {
213-
if (SPCTarget::getTargetOS() === 'Linux') {
214-
$dynamic_exports = ' -Wl,--dynamic-list=' . $symbolList;
215-
} else {
216-
$dynamic_exports = ' -Wl,-exported_symbols_list,' . $symbolList;
217-
}
220+
if ($dynamicSymbolsArgument = $this->getDynamicExportSymbolsArgument()) {
221+
$dynamic_exports = ' ' . $dynamicSymbolsArgument;
218222
}
219223
}
220224
[$ret, $out] = shell()->cd($sample_file_path)->execWithResult(getenv('CC') . ' -o embed embed.c ' . $lens . ' ' . $dynamic_exports);
@@ -338,8 +342,9 @@ protected function buildFrankenphp(): void
338342
$debugFlags = $this->getOption('no-strip') ? '-w -s ' : '';
339343
$dynamic_exports = '';
340344
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'static') {
341-
$symbolList = $this->getDynamicExportSymbolsFile();
342-
$dynamic_exports = $symbolList ? (' -Wl,--dynamic-list' . (SPCTarget::getTargetOS() === 'Darwin' ? '-file' : '') . '=' . $symbolList) : '';
345+
if ($dynamicSymbolsArgument = $this->getDynamicExportSymbolsArgument()) {
346+
$dynamic_exports = ' ' . $dynamicSymbolsArgument;
347+
}
343348
}
344349
$extLdFlags = "-extldflags '-pie{$dynamic_exports}'";
345350
$muslTags = '';

0 commit comments

Comments
 (0)