diff --git a/src/PhpBrew/Build.php b/src/PhpBrew/Build.php index 38fe52af..a5d60d5f 100644 --- a/src/PhpBrew/Build.php +++ b/src/PhpBrew/Build.php @@ -64,6 +64,8 @@ class Build implements Buildable public $osRelease; + public $osArch; + /** * Construct a Build object,. * @@ -93,6 +95,7 @@ public function __construct($version, $name = null, $installPrefix = null) $this->setBuildSettings(new BuildSettings()); $this->osName = php_uname('s'); $this->osRelease = php_uname('r'); + $this->osArch = php_uname('m'); } public function getName() diff --git a/src/PhpBrew/VariantBuilder.php b/src/PhpBrew/VariantBuilder.php index 7487204a..fbf3f379 100644 --- a/src/PhpBrew/VariantBuilder.php +++ b/src/PhpBrew/VariantBuilder.php @@ -269,6 +269,24 @@ public function __construct() }; $this->variants['pcre'] = function (ConfigureParameters $params, Build $build, $value) { + // Apple Silicon will crash on < 8.1.11 due to the bundled PCRE2 not being compatible with Apple Sillicon, so get an updated version if we can + // PHP 8.1.11 and above have the fix applied to its bundled PCRE2: https://github.com/php/php-src/commit/f8b217a3452e76113b833eec8a49bc2b6e8d1fdd + if ($build->compareVersion('8.0') >= 0 && $build->compareVersion('8.1.11') < 0 && $build->osName === 'Darwin' && $build->osArch === 'arm64') { + $prefix = Utils::findPrefix([ + new UserProvidedPrefix($value), + new IncludePrefixFinder('pcre2.h'), + new BrewPrefixFinder('pcre2'), + ]); + + if ($prefix === null) { + throw new Exception('Unable to find PCRE2 library. PHP 8.0 on Apple Silicon requires a newer version of PCRE2 than is bundled with PHP 8.0.'); + } + + $params = $params->withOption('--with-external-pcre', $prefix); + return $params; + } + + // PCRE is bundled with PHP since 7.4 if ($build->compareVersion('7.4') >= 0) { return $params; }