diff --git a/src/Platform/Macos.php b/src/Platform/Macos.php index 3b8d85e5..ee7956e7 100644 --- a/src/Platform/Macos.php +++ b/src/Platform/Macos.php @@ -76,28 +76,4 @@ class Macos extends UnixPlatform self::HOMEBREW_LIBRARY_PATHS, ))); } - - /** - * 获取默认的 RPATH 路径列表(macOS 需要) - */ - public function getDefaultRpaths(?string $phpxDir = null, ?string $phpDir = null): array - { - $rpaths = []; - - if ($phpxDir !== null) { - $phpxLibDir = $phpxDir . '/lib'; - if (is_dir($phpxLibDir)) { - $rpaths[] = $phpxLibDir; - } - } - - if ($phpDir !== null) { - $phpLibDir = $this->resolvePhpLibDir($phpDir); - if ($phpLibDir !== null) { - $rpaths[] = $phpLibDir; - } - } - - return $rpaths; - } } diff --git a/src/Platform/UnixPlatform.php b/src/Platform/UnixPlatform.php index c2bd519b..e1412071 100644 --- a/src/Platform/UnixPlatform.php +++ b/src/Platform/UnixPlatform.php @@ -166,6 +166,36 @@ abstract class UnixPlatform extends PlatformBase throw new \RuntimeException('The `php-config` is not found. Please install PHP development package or set PHP_HOME environment variable'); } + /** + * libphpx and the embed libphp.so live where TypePHP put them: beside the + * phpx checkout, and under the PHP prefix the libphp installer chose. + * Neither is on the loader's search path, so a linked program only finds + * them again if their directories are recorded in the binary. + * + * Cross-compilation targets override this back to an empty list: a path on + * the build host means nothing on the device that runs the output. + */ + public function getDefaultRpaths(?string $phpxDir = null, ?string $phpDir = null): array + { + $rpaths = []; + + if ($phpxDir !== null) { + $phpxLibDir = $phpxDir . '/lib'; + if (is_dir($phpxLibDir)) { + $rpaths[] = $phpxLibDir; + } + } + + if ($phpDir !== null) { + $phpLibDir = $this->resolvePhpLibDir($phpDir); + if ($phpLibDir !== null) { + $rpaths[] = $phpLibDir; + } + } + + return $rpaths; + } + /** * Get the RPATH options. */ diff --git a/src/Platform/Wasi.php b/src/Platform/Wasi.php index 9765d51b..49bf2b5e 100644 --- a/src/Platform/Wasi.php +++ b/src/Platform/Wasi.php @@ -23,6 +23,15 @@ final class Wasi extends UnixPlatform return '.a'; } + /** + * A WASI module resolves no shared libraries, and the build host's paths + * do not exist wherever it runs. + */ + public function getDefaultRpaths(?string $phpxDir = null, ?string $phpDir = null): array + { + return []; + } + public function getExecutableExtension(): string { return '.wasm';