Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Resolve build failure on Apple Silicon of PHP 8.0 due to old bundled pcre2 #1358

Merged
merged 1 commit into from Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/PhpBrew/Build.php
Expand Up @@ -64,6 +64,8 @@ class Build implements Buildable

public $osRelease;

public $osArch;
driskell marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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