Skip to content

Commit

Permalink
Merge pull request #1358 from driskell/fix-apple-silicon-pcre2
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k committed Mar 22, 2024
2 parents 4934ead + 8b6c9db commit 890e9e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/PhpBrew/Build.php
Expand Up @@ -64,6 +64,8 @@ class Build implements Buildable

public $osRelease;

public $osArch;

/**
* Construct a Build object,.
*
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 18 additions & 0 deletions src/PhpBrew/VariantBuilder.php
Expand Up @@ -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;
}
Expand Down

0 comments on commit 890e9e2

Please sign in to comment.