Add PKG_CONFIG_PATH environment variables to phpbrew build process#1085
Add PKG_CONFIG_PATH environment variables to phpbrew build process#1085morozov merged 1 commit intophpbrew:masterfrom markwu:fix-pkgconfig-for-PHP74
Conversation
There was a problem hiding this comment.
@markwu I see that there's a pattern in the changes made for the curl and openssl variant. Could you describe the change in the logic so that we could see if it's worth generalizing into a reusable concept similar to the PrefixFinder?
|
The logic of I try to convert the logic current to the following, and remain the same
$prefix = Utils::findPrefix(array(
new BrewPrefixFinder('libxml2'),
new PkgConfigPrefixFinder('libxml'),
new IncludePrefixFinder('libxml2/libxml/globals.h'),
new LibPrefixFinder('libxml2.a'),
)); $prefix = Utils::findPrefix(array(
new BrewPrefixFinder('curl'),
new PkgConfigPrefixFinder('curl'),
new IncludePrefixFinder('curl/curl.h'),
));
if ($build->compareVersion('7.4') < 0) {
$options[] = '--enable-libxml';
if ($prefix !== null) {
$options[] = '--with-libxml-dir=' . $prefix;
}
} else {
$options[] = '--with-libxml';
if ($prefix !== null) {
$build->setEnvVar('PKG_CONFIG_PATH', $prefix.'/lib/pkgconfig');
}
}
$options = array_merge($options, array(
'--enable-simplexml',
'--enable-xml',
'--enable-xmlreader',
'--enable-xmlwriter',
'--with-xsl',
));
return $options; if ($build->compareVersion('7.4') < 0) {
if ($val) {
return "--with-curl=$val";
}
if ($prefix !== null) {
return '--with-curl=' . $prefix;
}
} else {
if ($prefix !== null) {
$build->setEnvVar('PKG_CONFIG_PATH', $prefix.'/lib/pkgconfig');
}
return '--with-curl';
}So, the only thing I really change is set the $build->setEnvVar('PKG_CONFIG_PATH', $prefix.'/lib/pkgconfig');And, why should I do this, because for none standard system library just like Actually, I also want the flexibility, I also plan accept if ($build->compareVersion('7.4') < 0) {
if ($val) {
return "--with-curl=$val";
}
if ($prefix !== null) {
return '--with-curl=' . $prefix;
}
} else {
if ($val) {
$build->setEnvVar('PKG_CONFIG_PATH', $val.'/lib/pkgconfig');
return '--with-curl';
}
if ($prefix !== null) {
$build->setEnvVar('PKG_CONFIG_PATH', $prefix.'/lib/pkgconfig');
}
return '--with-curl';
}Then, I can pass my personal build or none standard |
|
Here comes the $ brew info openssl
openssl@1.1: stable 1.1.1d (bottled) [keg-only]
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/usr/local/Cellar/openssl@1.1/1.1.1d (7,983 files, 17.9MB)
Poured from bottle on 2019-12-03 at 02:20:51
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/openssl@1.1.rb
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl@1.1/certs
and run
/usr/local/opt/openssl@1.1/bin/c_rehash
openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because openssl/libressl is provided by macOS so don't link an incompatible version.
If you need to have openssl@1.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile
For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"You can see it says: openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because openssl/libressl is provided by macOS so don't link an incompatible version. |
This is confusing. Isn't the sole purpose of the |
|
Okay, let me explain this way.
To build PHP outside But, to avoid problems, Take # it is system wide
$ /usr/bin/openssl version
LibreSSL 2.6.5
# it is only available inside homebrew building system, unless you link to system directories
$ /usr/local/opt/openssl/bin/openssl version
OpenSSL 1.1.1d 10 Sep 2019Okay, if we build PHP inside homebrew(through homebrew formula), it will find But, if we install PHP outside homebrew, like phpbrew. There is no way to find So, even Before PHP 7.3(with), we can pass the openssl After PHP 7.4(with), there is no way to pass openssl prefix to php configure, because there is only That's why after 7.4, we have to export The purpose of this PR:
Hope this explanation is clear for you. Reference: https://docs.brew.sh/How-to-build-software-outside-Homebrew-with-Homebrew-keg-only-dependencies |
|
Thank you for this detailed writeup. It really helps understand the changes.
For future reference, it happened in php/php-src#3654. |
This is a shortcoming of the current design. In fact, all the prefixes should be determined on the per-extension basis regardless whether it's |
|
I just fixed the issues we discussed. There are 4 extensions need to set PKG_CONFIG_PATH when building php-7.4, they are:
I just test them with all 5.6/7/2/7.3/7.4 building process. |
There was a problem hiding this comment.
We're almost there. Excellent job so far!
BTW, from this command, it follows that PHPBrew doesn't properly discover the Homebrew-managed prefixes for |
Yes, I plan to use another PR for this, because it seems different issue. I'll add If you don't mind, I can add them in this PR, because it already done in my local branch. |
|
Please address the CI failure. You'll want to rebase your branch first because some of the code style issues are already addressed in the upstream branch. Then please squash all commits. |
configure errors for libxml2, openssl, curl and zlib.
|
@morozov I just fixed the issues you mentioned, and squashed all commits into one. Thanks for your review. I will fire another PR for add |
|
Thank you @markwu! |
|
I just checked this approach on macOS and it seems not working. First I tried I've never used PHPBrew on macOS so I may be doing something wrong. Any ideas? |
|
The same is if I do: |
I think there are some homebrew dependency need to installed first to run phpbrew, for example $ brew list | grep pkg-config
pkg-configI build a formula before to install depends_on "autoconf"
depends_on "automake"
depends_on "curl"
depends_on "gd"
depends_on "gettext"
depends_on "gmp"
depends_on "icu4c"
depends_on "bison"
depends_on "jpeg"
depends_on "libevent"
depends_on "libtool"
depends_on "libxml2"
depends_on "mcrypt"
depends_on "mhash"
depends_on "openssl"
depends_on "pcre"
depends_on "re2c"I think it is not a complete list, I need some time to figure them out. Maybe we can host our own homebrew formula to install all these dependencies with Mark |
|
you can try the following steps to install phpbrew by homebrew:
|
Exactly. It was missing on my machine. After I installed it, I was able to build PHP 7.4. Added it to the requirements page. |
I think what we could do instead is to document all variant dependencies for all supported platforms and implement integration of PHPBrew with dependency managers (including Homebrew). This way, it could just run or offer to run the needed commands w/o the need to install additional software. But this is a really long-going plan. |
|
Thanks a lot for the work! 🥇 |
I try to dig the source code and add
PKG_CONFIG_PATHto build process, it makes easier for user when build php 7.4.It is just a proof of concept, for discussion only.
With the PR, you can build php 7.4, with the following command only, no more
export PKG_CONFIG_PATH=....But, there is a problem when build extensions, take
ftpandsoapfor example. You can install it withphpbrew install 7.4.0 +default +ftp, the build process will set the PKG_CONFIG_PATH for you.But, with this PR, you still can't install extension by following command only.
Because the current extension manager install them by
phpize,configure,make. Without the capability likeVariantBuilderadd extra settings for you...So, You still need to export
PKG_CONFIG_PATH,LDFLAGS,CPPFLAGSmanually. Then, install the extension.@morozov Need your review and ideas.
Reference: #1040 (comment)