PHP8.3.7をmacOS Sonomaにphpenvでインストールする
以下で解決してくださってた......感謝や🙏
macOS に phpenv で PHP 8.3.7 以降をインストールできない場合の対処法 - zenn.dev
要はicu4c 59+以上ではC++11でのビルドが必要だから CXXFLAGS="-std=c++11"を指定されてしまってるから起きてた問題で、とはいえPHP側としてはext-intlをビルドするのにC++17が必要やで〜〜って言ってるんですよね。何が正しいんや......
https://github.com/php-build/php-build/blob/338efe357a3a695268f56d9aebd4e6a407a5d43e/bin/php-build#L726-L732
*
PHP8.3.6をmacOS Sonomaにphpenvでインストールする#66546c7e05f7280000980c27あたりに書いてある、以下のようなエラーを調べてる。
code:console
configure: error: *** A compiler with support for C++17 language features is required.
これ、8.3.7でconfigureをする中でicuに関する各種バージョンチェックを行う箇所に修正が入ったようなんですが、そのチェック処理にバグがあってicuがC++17を必要としたバージョンでなくてもC++17対応しているgccを必要としてしまっているらしいです。
cf. Fix check for newer versions of ICU by NattyNarwhal · Pull Request #14186 · php/php-src · GitHub
(とはいえ、そもそもmacOS Sonomaに入ってるgccは当然C++17に対応しているはずなんですけど、configureした際に「対応してねえけど」って言われるんですよねえ......なんでなんだろ)
以下のissueとかも読んでるけど、解決したっぽいのに今回のような環境だと直らず。
Update compilation parameters for the intl plugin · Issue #14046 · php/php-src
Homebrewでgccを入れて、 CXX="$(brew --prefix gcc)/bin/g++-14" とかで指定して動かしてみたけど変化なし。そもそもgcc@9くらいからC++17はサポートされてるはずなので、別にXCode Command Line Toolsで入れられるgcc@15でもHomebrewで入れられるgcc@14でも十分なはずなんだけどなあ.....
念のためだけど、以下を参考にワンライナーを用意して動かしてみたけど、ちゃんとC++17相当になってた。ホントかわからんけど......
コンパイラの C++ バージョン確認方法【gcc, clang, Visual Studio】 | がりテック
code:shell
echo "#include <iostream>\nint main() { std::cout << __cplusplus << std::endl; return 0; }" 1>/dev/null | $(brew --prefix gcc)/bin/g++-14 -x c++ -o ./tmp.out -std=c++17 - && ./tmp.out && rm ./tmp.out
なんか、以下とかを参照するとmacOSのgccコマンドはApple Clangってやつで、本来のGCCとは違う可能性がある......?
MacでGCCを使用し、C/C++のコードをコンパイルする - zenn.dev
だとするとHomebrew GCCなら上手くいく可能性ある......?と思って CXX に指定しても、結局は以下のようなエラーになる。謎い。
checking whether /opt/homebrew/opt/gcc/bin/g++-14 supports C++17 features with -std=c++17... no
もしかしてphp-buildのせいだったりする......?みたいな気持ちで、php-buildだとconfigureが失敗してるsourceを使って以下のようにconfigureを実行してみたら通ってたりする......
optionsの渡り方が違うのか、ビルドに利用するライブラリがシェルとは違って上手く参照できてないのか、php-build内で参照してるgccがダメなのか、はたまた......みたいなのをphp-buildを読みつつphp-buildコマンドで直接実行したりして試してもよいのかもしれない。 #nextmove
code:shell
PKG_CONFIG_PATH="$(brew --prefix icu4c)/lib/pkgconfig:$(brew --prefix libjpeg)/lib/pkgconfig:$(brew --prefix oniguruma)/lib/pkgconfig:$(brew --prefix libedit)/lib/pkgconfig" ./configure $(cat $(phpenv root)/plugins/php-build/share/php-build/default_configure_options | tr "\n" " ") --with-jpeg --with-zlib-dir=$(brew --prefix zlib) --with-bz2=$(brew --prefix bzip2) --with-curl=$(brew --prefix curl) --with-iconv=$(brew --prefix libiconv) --with-libedit --with-zip=$(brew --prefix libzip) --with-openssl=$(brew --prefix openssl@1.1) --with-tidy=$(brew --prefix tidy-html5)
#WIP
以下はまだ整理できてない。
code:shell
PKG_CONFIG_PATH="$(brew --prefix icu4c)/lib/pkgconfig:$(brew --prefix libjpeg)/lib/pkgconfig:$(brew --prefix oniguruma)/lib/pkgconfig:$(brew --prefix libedit)/lib/pkgconfig" PHP_BUILD_CONFIGURE_OPTS="$(cat $(phpenv root)/plugins/php-build/share/php-build/default_configure_options | tr "\n" " ") --with-jpeg --with-zlib-dir=$(brew --prefix zlib) --with-bz2=$(brew --prefix bzip2) --with-curl=$(brew --prefix curl) --with-iconv=$(brew --prefix libiconv) --with-libedit --with-zip=$(brew --prefix libzip) --with-openssl=$(brew --prefix openssl@1.1) --with-tidy=$(brew --prefix tidy-html5)" $(phpenv root)/plugins/php-build/bin/php-build -v -k --ini development 8.3.8 /tmp/php-8.3.8
https://github.com/php-build/php-build/blob/3c76def9be772b58349e4b349c2addcb02c77422/bin/php-build#L550-L553
This function sets and unsets arguments for configure. Pass it the -D option to unset the argument given in $2. Otherwise the first argument is the name of the option and the second argument contains the optional value.
これはあくまで内部で利用してるfunction configure_option()に渡せるオプションなのか......ソースコードを読むと前述されてるdefault_configure_optionsファイルの値が読み込まれてるCONFIGURE_OPTIONSって変数に追加したり削除したりを操作してるみたい。たぶん直接configureするのとphp-buildを介するのとの違いはこの辺っぽいなあ
参考
PHP8.3.6をmacOS Sonomaにphpenvでインストールする
Update compilation parameters for the intl plugin · Issue #14046 · php/php-src
MacでGCCを使用し、C/C++のコードをコンパイルする - zenn.dev
競技プログラミングC++環境構築 (macOS) 2023年版 #VSCode - Qiita
https://www.php.net/archive/2024.php#2024-06-06-2
PHP8.1.1をmacOS BigSurにphpenvでインストールする
PHP8.0.9をmacOS BigSurにphpenvでインストールする
PHP7.4.2をmacOS Catalinaにphpenvでインストールする
PHP7.1.33をmacOS BigSurにphpenvでインストールする
PHP 8.2.19 compile requires C++17? : r/PHP
#Techlog #PHP #phpenv #macOS_Sonoma #pkg-config #gcc