diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 517f6c10..d92d0678 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -290,6 +290,15 @@ class CompilerBase extends \PhpAot\Core\Translator return $this->rootPath . '/vendor/swoole/phpx'; } + public function getPhpDir(): string + { + $phpDir = shell_exec('php-config --prefix'); + if (empty($phpDir)) { + $this->error('The `php-config` is not found'); + } + return trim($phpDir); + } + public function save(string $code, string $file): void { $this->writeFile($file, $code); @@ -2107,6 +2116,11 @@ class CompilerBase extends \PhpAot\Core\Translator if ($this->ldflags) { $cmd .= ' ' . $this->ldflags; } + // macos 没有 ldconfig ,只能配置 rpath 绝对路径 + if ($this->isMacos()) { + $cmd .= ' -Wl,-rpath,' . $this->getPhpDir() . '/lib'; + $cmd .= ' -Wl,-rpath,' . $this->getPhpxDir() . '/lib'; + } } else { if ($this->cxxflags) { $cmd .= ' ' . $this->cxxflags; diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 47e87121..372f6d6f 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -213,13 +213,8 @@ class Translator extends Preprocessor public function prepare(string $path): array { - $phpDir = shell_exec('php-config --prefix'); - if (empty($phpDir)) { - $this->error('The `php-config` is not found'); - } - $phpDir = trim($phpDir); $ext = $this->isMacos() ? 'dylib' : 'so'; - if (!is_file($phpDir . '/lib/libphp.' . $ext)) { + if (!is_file($this->getPhpDir() . '/lib/libphp.' . $ext)) { $this->error("The `libphp.{$ext}` is not found, please run `make` to build it"); } if (!is_file($this->getPhpxDir() . '/lib/libphpx.' . $ext)) {