Build fails with error: Xcode 14: Command PhaseScriptExecution failed with a nonzero exit code
qwertynik opened this issue ยท 32 comments
When building the iOS app using XCode, the build fails with the error Xcode 14: Command PhaseScriptExecution failed with a nonzero exit code
. And in the error the @dr.pogodin/react-native-static-server
package is mentioned. Any reason why the build is failing?
When the app is first built using react-native run-ios
which internally uses xcodebuild -workspace EDetailViewer.xcworkspace -configuration Debug -scheme EDetailViewer -destination id={device-UDID}
, the app building and installation works fine. And subsequently after deleting the app from IPad, XCode manages to build and install the app! So, there is something that react-native is doing for building which XCode isn't. Need to investigate further. However, just in case someone has solved this already, would appreciate it if you can share the solution.
Needs a detailed log to say anything, but I always build using the latest Xcode and had no issues recently.
Sure, will attach detailed logs. Besides XCode run logs, is there anything else that would help?
Can you confirm if you are using the beta version 15.x, or 14.3.1?
I stick to the latest regular, thus 14.3.1
Ok. I am using the same.
Here's an excerpt from the logs:
Start of the log
PhaseScriptExecution [CP-User]\ Build\ native\ dependencies /Users/nikhil/Library/Developer/Xcode/DerivedData/SlideViewer-dgpdxjtyucwfnzemipxsuqjnebdh/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/dr-pogodin-react-native-static-server.build/Script-46EB2E00019CB0.sh (in target 'dr-pogodin-react-native-static-server' from project 'Pods')
make: `/Users/nikhil/Library/Developer/Xcode/DerivedData/SlideViewer-dgpdxjtyucwfnzemipxsuqjnebdh/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/dr-pogodin-react-native-static-server.build/pcre2/CMakeFiles/cmake.check_cache' is up to date.
note: Using global toolchain override 'Xcode Default'. (in target 'pcre2-8-static' from project 'PCRE2')
** BUILD SUCCEEDED **
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Reason given by package: The command
"/usr/local/bin/pkg-config" --libs-only-l --version
failed with output:
stderr:
Ignoring incompatible output option "--version"
Must specify package names on the command line
result:
1
-- found pcre2-config: no
CMake Error at lighttpd1.4/src/CMakeLists.txt:591 (message):
pcre2.h couldn't be found
-- Configuring incomplete, errors occurred!
Command PhaseScriptExecution failed with a nonzero exit code
Command PhaseScriptExecution failed with a nonzero exit code
Build target SlideViewer
The full log file is huge. In case the above doesn't help will share the same. Since it may contain some confidential data, will upload externally.
Ok... this should be a problem:
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Reason given by package: The command
"/usr/local/bin/pkg-config" --libs-only-l --version
failed with output:
stderr:
Ignoring incompatible output option "--version"
Must specify package names on the command line
result:
1
It seems to fail because of --version
option, which I don't know where does it come from, the library CMakeList.txt only sets --libs-only-l
flag. Can you figure it out? And then, if it can't use PkgConfig, it further can't find PCRE2, and thus fails entire build.
Hmm. Yes, so the additional --version
flag is the problem. This error does not come when running the command react-native run-ios
which is good and strange. Does it help lighting some ideas?
Regarding figuring this out, not certain how to go about it. Because, I am newbie in this space. Any pointers will help. But, I think the fact that react-native manages to build it, might help identify what the solution to the problem could be.
I have no idea, the error happens within CMake build of the native C code for Lighttpd... might be CMake picks up something from environment variables, or your CMake / PkgConfig versions behave differently from mine, or whatever...
Highly likely. It is unclear on how react-native CLI manages to build the app, but XCode fails! Do you use XCode for building and launching apps, or some other service?
Can you confirm the CMake/PkgConfig version on your device?
pkg-config --version
- 0.29.2
cmake --version
- 3.27.3
I build in XCode. If you look carefully into Xcode log, you'll see that XCode sets a bunch of environment variables when it runs a shell script it generated for the failing build step. That's the difference with CLI build. You can copy that command from logs into your console, run & modify it, and thus figure out what's up.
Ok. Yes. Had seen a long list of export. But didn't look deeper into the exports. Exploring further, the first command is:
PhaseScriptExecution [CP-User]\ Build\ native\ dependencies /Users/nikhil/Library/Developer/Xcode/DerivedData/SlideViewer-dgpdxjtyucwfnzemipxsuqjnebdh/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/dr-pogodin-react-native-static-server.build/Script-46EB2E00019CB0.sh (in target 'dr-pogodin-react-native-static-server' from project 'Pods')
The last command in the Run custom shell script [CP-User] Build native dependencies
Libtool /Users/nikhil/Library/Developer/Xcode/DerivedData/SlideViewer-dgpdxjtyucwfnzemipxsuqjnebdh/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/dr-pogodin-react-native-static-server.build/pcre2/Release-iphoneos/libpcre2-8.a normal (in target 'pcre2-8-static' from project 'PCRE2')
cd /Users/nikhil/projects/ReactNativeProjects/SlideViewer/node_modules/@dr.pogodin/react-native-static-server/pcre2
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only arm64 -D -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.4.sdk -L/Users/nikhil/Library/Developer/Xcode/DerivedData/SlideViewer-dgpdxjtyucwfnzemipxsuqjnebdh/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/dr-pogodin-react-native-static-server.build/pcre2/Release-iphoneos -filelist /Users/nikhil/Library/Developer/Xcode/DerivedData/SlideViewer-dgpdxjtyucwfnzemipxsuqjnebdh/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/dr-pogodin-react-native-static-server.build/pcre2/build/pcre2-8-static.build/Release-iphoneos/Objects-normal/arm64/pcre2-8.LinkFileList -dependency_info /Users/nikhil/Library/Developer/Xcode/DerivedData/SlideViewer-dgpdxjtyucwfnzemipxsuqjnebdh/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/dr-pogodin-react-native-static-server.build/pcre2/build/pcre2-8-static.build/Release-iphoneos/Objects-normal/arm64/pcre2-8_libtool_dependency_info.dat -o /Users/nikhil/Library/Developer/Xcode/DerivedData/SlideViewer-dgpdxjtyucwfnzemipxsuqjnebdh/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/dr-pogodin-react-native-static-server.build/pcre2/Release-iphoneos/libpcre2-8.a
note: Using global toolchain override 'Xcode Default'. (in target 'ZERO_CHECK' from project 'PCRE2')
note: Run script build phase 'Generate CMakeFiles/ZERO_CHECK' will be run during every build because the option to run the script phase "Based on dependency analysis" is unchecked. (in target 'ZERO_CHECK' from project 'PCRE2')
** BUILD SUCCEEDED **
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Reason given by package: The command
"/usr/local/bin/pkg-config" --libs-only-l --version
failed with output:
stderr:
Ignoring incompatible output option "--version"
Must specify package names on the command line
result:
1
Will continue the exploration to see if I can spot other issues. In case the above logs point to how the error could be fixed, can you point to the same?
Update:
When running the app in Xcode with Build Configuration set as Debug under the scheme, the app builds, provided, react-native run-ios
was run before. When inspecting the CLI output of react-native run-ios
, the command used is this xcodebuild -workspace SlideViewer.xcworkspace -configuration Debug -scheme SlideViewer -destination id=00008020-XXXX
.
Ran the xcodebuild -workspace SlideViewer.xcworkspace -configuration Release -scheme SlideViewer -destination id=00008020-XXXX
command first and then ran using XCode and the build succeeded.
Is there anything that the package does differently when running xcodebuild first?
I'm facing the exact same issue in XCode 14 with M1 chip. It builds with react-native run-ios but fails with XCode. The error I'm getting is identical to what was mentioned before. After running the react-native run-ios, it starts to build in XCode under Debug configuration.
Agh... ok, with the mention of M1 chip, it reminds me the past issue #40 by @ospfranco, which we resolved after I did some corrections in the build configuration, and @ospfranco did the PR #42 to clarify the correct setup of dependencies for M1-based Macs. Perhaps you guys just haven't installed pkg-config
, or haven't linked it correctly to be found within XCode environment?
On my side, for iOS / macOS development I currently only have an older Intel-based Mac Mini, so unless somebody wants to sponsor me a shiny new M1-based Apple device, you'll have to put in more efforts to resolve this issue yourselves :)
Perhaps you guys just haven't installed pkg-config, or haven't linked it correctly to be found within XCode environment?
Hmm, this was done during the setup. However, verified once again and found that the suggested steps regarding additional package setup and linking was taken care of.
On my side, for iOS / macOS development I currently only have an older Intel-based Mac Mini, so unless somebody wants to sponsor me a shiny new M1-based Apple device, you'll have to put in more efforts to resolve this issue yourselves :)
Makes sense. You have already invested a significant amount of time and effort. Would be great if someone would sponsor you the latest Mac!
Will be willing to contribute to the discovery/troubleshooting required to solve this.
Thanks for the swift response.
Perhaps you guys just haven't installed pkg-config, or haven't linked it correctly to be found within XCode environment?
I double-checked and everything's installed and properly linked. I assume that if it wasn't it wouldn't be working at all in the end but weirdly it does work even in the XCode after running the run ios
command in the shell. By the way, if I clean up the iOS build folder and try to run it again in XCode it fails again. So it seems like it adds something to the build folder by running run-ios
in the shell that is causing XCode to build successfully afterward.
you'll have to put in more efforts to resolve this issue yourselves :)
I'll try to ask colleagues if I find time and this issue will be a problem in the production build as well because CMAKE is all Greek to me. Thanks a lot for the efforts!
You probably need to add symlinks because your zsh terminal has the brew variables setup and xcode doesn't
sudo ln -s /opt/homebrew/bin/cmake /usr/local/bin/cmake
sudo ln -s /opt/homebrew/bin/pkg-config /usr/local/bin/pkg-config
I did not test this commands myself, I don't know if you installed via brew... just know that XCode does not run in the same environment as your regular terminal
I did set up the symlinks according to the README, I double-checked. And yes, I'm using zsh and I installed those packages using brew.
Ok... I had another look at this... At a high level this is what seems to happen here...
react-native-static-server/CMakeLists.txt
Lines 65 to 84 in 73c4e3b
โ๏ธ This piece of CMakeLists.txt builds PCRE2 library from its source code included into the static server package. As you see, the build outputs should land into pcre2
subfolder of the project build directory. I don't have my mac around now, but you should be able to locate it somewhere under Libraries / Developer / XCode ... path of you system (i.e. not the same location, where the source project you are building lives). So, first of all, you should locate it, and check when you have this issues, whether PCRE2 library binaries are created at all for you, and if they are โ what processor architectures they have been built for?
Now... for a normal build having those binaries at that path is enough for Lighttpd build to find them here:
So, having no mac with me now, I can't check how exactly it works for me, but looking at the errors you get it looks like pkg-config
does not find PCRE2 library binaries, so it tries to use pcre2-config
command to find it, but in your case it does not have this command either... the --version
argument is intended for that command I believe, so is supposed to run smth like "/usr/local/bin/pkg-config" --libs-only-l "path/to/pcre2-config" --version
I guess, but instead of "path/to/pcre2-config"
you get an empty string, thus trying to run just "/usr/local/bin/pkg-config" --libs-only-l --version
and ending up with the obscure error that pkg-config
gets an invalid --version
argument.
So, again, first of all we need to verify that PCRE2 is correctly build for correct architectures in you case. And if it is, then we should figure out why this libpcre2-8
can't be found later?
Thanks for the quick feedback @birdofpreyru! Looking at the Intermediates
folder, it looks like pcre2 is included (if I'm looking at the right folder). If I look at the Products
, there's nothing (second screenshot).
![Screenshot 2023-09-21 at 15 43 00](https://private-user-images.githubusercontent.com/2011999/269634615-77981755-5c71-487a-84e6-57740f89b5da.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTYwMjgwNDIsIm5iZiI6MTcxNjAyNzc0MiwicGF0aCI6Ii8yMDExOTk5LzI2OTYzNDYxNS03Nzk4MTc1NS01YzcxLTQ4N2EtODRlNi01Nzc0MGY4OWI1ZGEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDUxOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA1MThUMTAyMjIyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTRmMzBiZTIwNWM5ODM0MDkyYWZjYTIyNWI1ZjE3ODhiZmM4Zjg3NDU3YzFhMzJiYTBiYTFjZTYzZjkzODY3NyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.Yw2fqIMtQ6PJ5AquV0UZIrSnV5kn8ZsJHvLvKp-9avs)
![Screenshot 2023-09-21 at 15 45 04](https://private-user-images.githubusercontent.com/2011999/269635229-7d3a17fc-3aad-4a39-b31e-b20bc9f23367.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTYwMjgwNDIsIm5iZiI6MTcxNjAyNzc0MiwicGF0aCI6Ii8yMDExOTk5LzI2OTYzNTIyOS03ZDNhMTdmYy0zYWFkLTRhMzktYjMxZS1iMjBiYzlmMjMzNjcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDUxOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA1MThUMTAyMjIyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZjlhZmY5OWQwMzEyNDdmNjlhZThiZTBiZWVlNjYwZmZiMTA4NTRkMmM3NDVhZTU4MjQwZDVlZTJmZGVkMDcyNyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.7lGgGQkUrGxh5XRZm9rpP9T2OnGywPTTye1ZneQsNj4)
If Intermediates
is the right place to look, can you please advise me on how I can figure out what architecture it was built for?
Hmm... ok, when I build the library's Example App for iPhone Simulator, inside Build/Products/Release-iphonesimulator/dr-pogodin-react-native-static-server
I have just a bunch of static library files:
I guess, you are trying to use it with frameworks option? In my projects relying on this library I rely on use_frameworks! :linkage => :static
in the Podfile (need it for Firebase, otherwise I don't know much, what does this do); and it still works for me, both on real devices and in the simulator. So... one thing to verify is, whether the Example App works for you if you build it as is? And what exactly you are doing with the frameworks?
Then, you want to do lipo -info libpcre2-8.a
to check library architecture. It supposed to output: Architectures in the fat file: libpcre2-8.a are: arm64 x86_64
, meaning it is build to work on either architecture.
I'm using use_frameworks! :linkage => :static
as well because I use the latest firebase as well. I'll try to build the example app and see if there are any issues.
The example app build fails with the exact same issue (missing pcre2.h).
Regarding checking the architecture, I can't check the architecture because I don't have those .a
files in the Product
folder. This led me to an idea of comparing the Product
folder that is generated using XCode and the same folder generated using run-ios
command. Not really surprising but after running run-ios
, the folder contains the files you mentioned (including the .framework
file I shared on the screenshot) and everything runs fine. This means that at some point, those filers are not being generated and thus in the end the build fails using XCode.
Ok, what about Build/Intermediates.noindex/Pods.build/Release-iphonesimulator/dr-pogodin-react-native-static-server.build/pcre2/Release-iphonesimulator
? โ the libpcre2-8.a
should be first created there, and then copied over to the products folder.
Then, find this in your build logs in Xcode:
Click that small button on the right, to see the actual shell command it runs to build the library, it should be similar to this:
โ a lot of exports of environment variables, followed (not visible in the screenshot) by a call to a shell script file in the build folder. So, if you copy all these environment variables & call into your terminal, you can run this build step exactly as Xcode does, and see why it behaves differently from you build in the terminal (most probably, because some environment variables are different, and you'll need to figure out, which one affects the build result).
I am using M1 Macbook and I've managed to get the app building. The issue for me was a $PATH
issue. The Xcode does not uses the system PATH in the bashrc
/zshrc
/profile
etc. it event wont use the path from /etc/paths
. The only solution I've found is to add the PATH to the [CP-User] Build native dependencies
phase. So here is what I did:
- I've installed the cmake using a Homebrew formulae:
brew install cmake
- Homebrew puts binaries to
/opt/homebrew/bin/
directory so this directory have to be added to the path like this:
PATH=${PATH}:/opt/homebrew/bin/
- I've edited the
[CP-User] Build native dependencies
phase and added the PATH command:
![Screenshot](https://private-user-images.githubusercontent.com/107385929/270200834-9655bee9-ee1c-4d2d-a9c0-cb0ea9ddbdd9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTYwMjgwNDIsIm5iZiI6MTcxNjAyNzc0MiwicGF0aCI6Ii8xMDczODU5MjkvMjcwMjAwODM0LTk2NTViZWU5LWVlMWMtNGQyZC1hOWMwLWNiMGVhOWRkYmRkOS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNTE4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDUxOFQxMDIyMjJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mODkwNzY3YTk5ZDBjOWUyNzcyYzU4MGQxM2ExYzFlNDM0NWNhYWY1MDljMjJkOWY1N2ZjZGRmMmM0NjFmMTE2JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.1rjzSO13yZa-I3wsnjnJl00kyBLAyTrRs5pC3p_VLGE)
And it builded successfully with XCode 15.0 (15A240d).
BTW In my case pcre2
library was already installed in my Macbook (most probably it was installed with nginx or openjdk installation) you can check your installation using brew list
command and if its not installed already, you can install it with this command:
brew install pcre2
I hope this will help, happy coding.
@erdincmdj the instructions on the README state you should create symlinks to cmake pcre2, this will not only solve the problem for xcode but for all apps that do not use non-interactive terminal sessions
@erdincmdj The linking considerations for Cmake on M1 Mac are indeed mentioned in Getting Started of our library's README. Btw, you probably can add this PATH export into .xcode.env
of your host RN project (e.g. here is this file of the library's Example App, and it is used there to link against NodeJS installed via NVM). โ if you try, and it (placing it into .xcode.env
) works, please tell, I'd include it into README.
BTW In my case pcre2 library was already installed in my Macbook (most probably it was installed with nginx or openjdk installation) you can check your installation using brew list command and if its not installed already, you can install it with this command:
That's not good. The library comes with its own copy of PCRE2 sources, which it tries to build and use. Although for iOS and M1 macs, which run on the same architecture, it probably works fine with the system-wide-installed PCRE2, it would be better if it relies on the PCRE2 version it is intended to use.
@ospfranco @birdofpreyru The instructions in the README mention only symlinking cmake and pkg-config, what Erdinc suggests is to symlink pcre2. Erdinc's idea led me to another idea. There's no need to modify the build script or to add the path to XCode, the only thing that you need to do is to symlink pcre2-config
binary as follows:
sudo ln -s $(which pcre2-config) /usr/local/bin/pcre2-config
and the build starts running again. I can't say if it's using the pcre2grep from the static server library or the one provided by the OS, but it works. If you don't have pcre2-config installed, you need to brew install pcre2
. This was the case for our self-hosted machine at work which is not running m1 mac (and the build was failing in fastlane + github actions for the same reason as the build on my macbook m1).
By the way, if you're not using m1 and the build is failing, you don't have to symlink anything because brew is already using usr/local/bin
so after installing the pcre2
, everything should run smoothly.
Since I'm not sure if it's using pcre2 from the static server library or the one provided by the OS, I can't say if this should be added to the README.
Aside: taking a peek at the the current config, I did not see the use of any lighttpd modules which use PCRE2. In the config, I did see webdavConfig +=
, but if those paths are anchored with $HTTP["url"] =~ "${webdav[i]}" { webdav.activate = "enable" }
;^
or $
, lighttpd turns them into prefix or suffix matches, respectively, and does not use PCRE2 to evaluate them. I do not know how those paths are configured, but they are probably prefix matches, and could be in the lighttpd config as webdavConfig +=
if they are string literals without regex syntax. Note the $HTTP["url"] =^ "${webdav[i]}" { webdav.activate = "enable" }
;=^
instead of =~
for the lighttpd syntax.
If not using webdav, or those paths are intended to be a prefix match, then you could build lighttpd without PCRE2 support. In the future, when a feature in lighttpd is used that requires PCRE2, then you can work on including PCRE2 as part of the builds on different platforms.
Thanks for comment @gstrauss . Indeed, it does not need PCRE2 now, but as it already builds with it, I prefer to keep it this way (I personally don't have any issues with it in any build environment I have at hands).
Hopefully PCRE2 linking issues are fixed in v0.9.1 release.