diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 6589f32b0..aca214ce5 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -29,12 +29,14 @@ public function __construct(array $options = []) // check musl-cross make installed if we use musl-cross-make $arch = arch2gnu(php_uname('m')); - // set library path, some libraries need it. (We cannot use `putenv` here, because cmake will be confused) - $this->setOptionIfNotExist('library_path', "LIBRARY_PATH=/usr/local/musl/{$arch}-linux-musl/lib"); - $this->setOptionIfNotExist('ld_library_path', "LD_LIBRARY_PATH=/usr/local/musl/{$arch}-linux-musl/lib"); - GlobalEnvManager::init($this); + // set library path, some libraries need it. (We cannot use `putenv` here, because cmake will be confused) + if (!filter_var(getenv('SPC_NO_MUSL_PATH'), FILTER_VALIDATE_BOOLEAN)) { + $this->setOptionIfNotExist('library_path', "LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\""); + $this->setOptionIfNotExist('ld_library_path', "LD_LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\""); + } + if (str_ends_with(getenv('CC'), 'linux-musl-gcc') && !file_exists("/usr/local/musl/bin/{$arch}-linux-musl-gcc") && (getenv('SPC_NO_MUSL_PATH') !== 'yes')) { throw new WrongUsageException('musl-cross-make not installed, please install it first. (You can use `doctor` command to install it)'); } diff --git a/src/SPC/util/GlobalEnvManager.php b/src/SPC/util/GlobalEnvManager.php index 6c6c9820f..7ad63a5b7 100644 --- a/src/SPC/util/GlobalEnvManager.php +++ b/src/SPC/util/GlobalEnvManager.php @@ -57,10 +57,6 @@ public static function init(?BuilderBase $builder = null): void self::putenv("SPC_LINUX_DEFAULT_CXX={$arch}-linux-musl-g++"); self::putenv("SPC_LINUX_DEFAULT_AR={$arch}-linux-musl-ar"); } - self::putenv("SPC_PHP_DEFAULT_LD_LIBRARY_PATH_CMD=LD_LIBRARY_PATH=/usr/local/musl/{$arch}-linux-musl/lib"); - if (getenv('SPC_NO_MUSL_PATH') !== 'yes') { - self::putenv("PATH=/usr/local/musl/bin:/usr/local/musl/{$arch}-linux-musl/bin:" . getenv('PATH')); - } } // Init env.ini file, read order: @@ -91,6 +87,11 @@ public static function init(?BuilderBase $builder = null): void 'BSD' => self::applyConfig($ini['freebsd']), default => null, }; + + if (PHP_OS_FAMILY === 'Linux' && !filter_var(getenv('SPC_NO_MUSL_PATH'), FILTER_VALIDATE_BOOLEAN)) { + self::putenv("SPC_PHP_DEFAULT_LD_LIBRARY_PATH_CMD=LD_LIBRARY_PATH=/usr/local/musl/{$arch}-linux-musl/lib"); + self::putenv("PATH=/usr/local/musl/bin:/usr/local/musl/{$arch}-linux-musl/bin:" . getenv('PATH')); + } } public static function putenv(string $val): void